Skip to content

Commit

Permalink
add pre-commit with ruff and typos, run --all-files
Browse files Browse the repository at this point in the history
  • Loading branch information
dyollb committed Sep 14, 2024
1 parent cc77bbe commit 124e881
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 208 deletions.
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
exclude: '.*\.nrrd$'
- id: trailing-whitespace
exclude: '.*\.nrrd$'
- id: check-executables-have-shebangs

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/crate-ci/typos
rev: v1.24.5
hooks:
- id: typos
exclude: '.*\.nrrd$'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ print("First segment info:\n" + json.dumps(segment0, sort_keys=False, indent=4))
#### Extract segments by terminology

Example for getting a 3D [NRRD](SegmentationFileFormat.md) file that has label values assigned based on [standard terminology codes](UsingStandardTerminology.md).
Terminology is a `dict` that must specify `category` and `type` codes and may optionally also specify `typeModifier`, `anatomicRegion`, and `anatomicRegionModifier`. Each code is specifed by a triplet of "coding scheme designator", "code value", "code meaning" in a list.
Terminology is a `dict` that must specify `category` and `type` codes and may optionally also specify `typeModifier`, `anatomicRegion`, and `anatomicRegionModifier`. Each code is specified by a triplet of "coding scheme designator", "code value", "code meaning" in a list.

Coding scheme designator is typically `SCT` (SNOMED-CT) for clinical images. You can find codes in the [SNOMED-CT browser](https://browser.ihtsdotools.org/). When code exists for "entire X" and "structure of X" then always use the "structure" code ("entire" code has a very strict meaning that is rarely applicable in practice).

Expand Down Expand Up @@ -227,7 +227,7 @@ for segmentId in segments:
List of available nodes can be retrieved using `node_names` and `node_ids`functions:

```python
# Retreve node names of all images
# Retrieve node names of all images
slicerio.server.node_names(class_name="vtkMRMLVolumeNode")

# Retrieve all node IDs
Expand Down
4 changes: 2 additions & 2 deletions UsingStandardTerminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Segmentation tools usually provide a labelmap volume as output, with each label

To avoid these issues, standard terms can be used to specify what each segment represents. A standard term has well-defined meaning, thus allowing aggregating data from many sources, and since they have to be selected from a predefined list, there is no risk of typos or inconsistencies that often occur when typing free text.

Terminology is a `dict` that must specify `category` and `type` codes and may optionally also specify `typeModifier`, `anatomicRegion`, and `anatomicRegionModifier`. Each code is specifed by a triplet of "coding scheme designator", "code value", "code meaning" in a list.
Terminology is a `dict` that must specify `category` and `type` codes and may optionally also specify `typeModifier`, `anatomicRegion`, and `anatomicRegionModifier`. Each code is specified by a triplet of "coding scheme designator", "code value", "code meaning" in a list.
`Coding scheme designator` is typically `SCT` (SNOMED-CT) for clinical images. You can find codes in the [SNOMED-CT browser](https://browser.ihtsdotools.org/). `Code value` is a unique string within the coding scheme, most commonly an integer number. `Code meaning` (third component of codes, such as "Anatomical Structure", "Ribs", "Right") is informational only, it can be used for troubleshooting or displayed to the user, but it is ignored in information processing (e.g., two codes match if their coding scheme designator and code value are the same even if code meaning is different).

According to the DICOM standard, content of a segment is specified by its `category` (such as "Anatomical structure", "Physical object", "Body substance", ...) and `type` (such as "Liver" or "Cardiac Pacemaker", ...). Optionally a modifier (`typeModifier`, such as "left" or "right") and anatomical location (`anatomicRegion` and `anatomicRegionModifier`) can be specified as well. Each of these are specifed by a standard code, which is a triplet of "coding scheme designator", "code value", and "code meaning":
According to the DICOM standard, content of a segment is specified by its `category` (such as "Anatomical structure", "Physical object", "Body substance", ...) and `type` (such as "Liver" or "Cardiac Pacemaker", ...). Optionally a modifier (`typeModifier`, such as "left" or "right") and anatomical location (`anatomicRegion` and `anatomicRegionModifier`) can be specified as well. Each of these are specified by a standard code, which is a triplet of "coding scheme designator", "code value", and "code meaning":
- `Coding scheme designator` is a string identifying the terminology. It is typically set to `SCT` (SNOMED-CT) for clinical images. However, Uberon (`UBERON`), Foundational Model of Anatomy (`FMA`) and [others](https://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_8.html) may be used, too.
- `Code value` is a unique string within the coding scheme, most commonly an integer number.
- `Code meaning` is a human-readable meaning of the term (such as "Anatomical Structure", "Ribs", "Right"). It is informational only: it can be used for troubleshooting or displayed to the user, but it is ignored in information processing. For example, two codes match if and only if their coding scheme designator and code value are the same; it does not matter the if code meaning values are the same.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from setuptools import setup


if __name__ == '__main__':
if __name__ == "__main__":
setup()
28 changes: 17 additions & 11 deletions slicerio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""slicerio package -- Python utilities for readin and writing 3D Slicer supporte data sets.
"""slicerio package -- Python utilities for readin and writing 3D Slicer supported data sets.
-----------
Quick Start
Expand All @@ -12,17 +12,23 @@
"""

from .segmentation import extract_segments, read_segmentation, write_segmentation, segment_from_name, segment_names
from .segmentation import (
extract_segments,
read_segmentation,
write_segmentation,
segment_from_name,
segment_names,
)
from .data_helper import get_testdata_file
from ._version import __version__, __version_info__

__all__ = [
'extract_segments',
'get_testdata_file',
'read_segmentation',
'write_segmentation',
'segment_from_name',
'segment_names',
'__version__',
'__version_info__'
]
"extract_segments",
"get_testdata_file",
"read_segmentation",
"write_segmentation",
"segment_from_name",
"segment_names",
"__version__",
"__version_info__",
]
4 changes: 2 additions & 2 deletions slicerio/_version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
from typing import Tuple

__version__: str = '1.1.1'
__version__: str = "1.1.1"

__version_info__: Tuple[str, str, str] = tuple(
re.match(r'(\d+\.\d+\.\d+).*', __version__).group(1).split('.')
re.match(r"(\d+\.\d+\.\d+).*", __version__).group(1).split(".")
)
5 changes: 2 additions & 3 deletions slicerio/data_helper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Copyright 2008-2020 pydicom authors. See LICENSE file for details.
"""Helper functions for accessing test data.
"""
"""Helper functions for accessing test data."""

import os
from pathlib import Path

DATA_ROOT = Path(__file__).parent.joinpath('data')
DATA_ROOT = Path(__file__).parent.joinpath("data")
"""The absolute path to the data_files directory."""


Expand Down
Loading

0 comments on commit 124e881

Please sign in to comment.