Skip to content

Commit 07b7c1c

Browse files
author
Chris Bridge
committed
Docstring improvements
1 parent 6b4e409 commit 07b7c1c

2 files changed

Lines changed: 69 additions & 59 deletions

File tree

docs/legacy.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ For example, to sort by ``KVP`` and then ``SliceLocation``:
202202
# Save out the new multiframe conversion
203203
multiframe.save_as("legacy_converted_ct.dcm")
204204
205-
Alternatively, you could use highdicom's ``sort_datasets`` function to sort the
206-
datasets based purely on spatial location:
205+
Alternatively, you could use highdicom's
206+
:func:`highdicom.spatial.sort_datasets` function to sort the datasets based
207+
purely on spatial location:
207208

208209
.. code-block:: python
209210

src/highdicom/legacy/sop.py

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,55 @@
113113

114114

115115
def _istag_file_meta_information_group(t: BaseTag) -> bool:
116+
"""Determine whether a tag represents a file meta element.
117+
118+
Parameters
119+
----------
120+
t: pydicom.tag.BaseTag
121+
The tag in question
122+
123+
Returns
124+
-------
125+
bool:
126+
True if this tag sits in the file meta information group (group 2),
127+
False otherwise.
128+
129+
"""
116130
return t.group == 0x0002
117131

118132

119133
def _istag_repeating_group(t: BaseTag) -> bool:
134+
"""Determine whether a tag lies in a repeating group.
135+
136+
Parameters
137+
----------
138+
t: pydicom.tag.BaseTag
139+
The tag in question
140+
141+
Returns
142+
-------
143+
bool:
144+
True if this tag sits in a repeating group. False otherwise.
145+
146+
"""
120147
g = t.group
121148
return (g >= 0x5000 and g <= 0x501E) or (g >= 0x6000 and g <= 0x601E)
122149

123150

124151
def _istag_group_length(t: BaseTag) -> bool:
152+
"""Determine whether a tag represents a group length.
153+
154+
Parameters
155+
----------
156+
t: pydicom.tag.BaseTag
157+
The tag in question
158+
159+
Returns
160+
-------
161+
bool:
162+
True if this tag represents a group length. False otherwise.
163+
164+
"""
125165
return t.element == 0
126166

127167

@@ -198,12 +238,12 @@ def get_source_keywords(self) -> list[str]:
198238
return [self.dest_kw]
199239

200240

201-
def _default_sort_key(x: Dataset) -> Tuple[Union[int, str, UID], ...]:
241+
def _default_sort_key(ds: Dataset) -> Tuple[Union[int, str, UID], ...]:
202242
"""The default sort key to sort single frames before conversion.
203243
204244
Parameters
205245
----------
206-
x: pydicom.Dataset
246+
ds: pydicom.Dataset
207247
input Dataset to be sorted.
208248
209249
Returns
@@ -216,12 +256,12 @@ def _default_sort_key(x: Dataset) -> Tuple[Union[int, str, UID], ...]:
216256
217257
"""
218258
out: tuple = tuple()
219-
if "SeriesNumber" in x:
220-
out += (x.SeriesNumber,)
221-
if "InstanceNumber" in x:
222-
out += (x.InstanceNumber,)
223-
if "SOPInstanceUID" in x:
224-
out += (x.SOPInstanceUID,)
259+
if "SeriesNumber" in ds:
260+
out += (ds.SeriesNumber,)
261+
if "InstanceNumber" in ds:
262+
out += (ds.InstanceNumber,)
263+
if "SOPInstanceUID" in ds:
264+
out += (ds.SOPInstanceUID,)
225265

226266
return out
227267

@@ -741,10 +781,6 @@ def _check_attribute_consistency(
741781
742782
Parameters
743783
----------
744-
tag_shared_dict: dict[pydicom.uid.BaseTag, bool]
745-
Dictionary whose keys include all tags present in any dataset. The
746-
corresponding value is a boolean that indicates whether that tag
747-
is consistent (in presence and value) across all datasets.
748784
require_volume: bool, optional
749785
If True, require that the orientations, slice thickness, and pixel
750786
spacings of all instances are the same.
@@ -1416,12 +1452,10 @@ def _frame_content_custom_logic(
14161452
if "AcquisitionDateTime" in source:
14171453
fa_dt = DT(source.AcquisitionDateTime)
14181454
elif "AcquisitionDate" in source and "AcquisitionTime" in source:
1419-
fa_dt = DT(
1420-
datetime.combine(
1421-
DA(source.AcquisitionDate),
1422-
TM(source.AcquisitionTime)
1423-
)
1424-
)
1455+
da = DA(source.AcquisitionDate)
1456+
tm = TM(source.AcquisitionTime)
1457+
if da is not None and tm is not None:
1458+
fa_dt = DT(datetime.combine(da, tm))
14251459

14261460
if fa_dt is not None:
14271461
acq_time_kws = [
@@ -1462,7 +1496,15 @@ def _add_series_description(self) -> None:
14621496
self._destination.SeriesDescription = desc
14631497

14641498
def _add_stack_info_frame_content(self, require_volume: bool) -> None:
1465-
"""Adds stack info to the FrameContentSequence dicom attribute."""
1499+
"""Adds stack info to the FrameContentSequence dicom attribute.
1500+
1501+
Parameters
1502+
----------
1503+
require_volume: bool
1504+
Whether to require that the frames represent a regularly-spaced
1505+
volume.
1506+
1507+
"""
14661508
spacing, position_indices = get_series_volume_positions(
14671509
self._legacy_datasets,
14681510
)
@@ -1613,7 +1655,9 @@ def _add_unassigned_attributes(self) -> None:
16131655

16141656
@staticmethod
16151657
def _copy_private_attribute(
1616-
tag: BaseTag, source: Dataset, destination: Dataset
1658+
tag: BaseTag,
1659+
source: Dataset,
1660+
destination: Dataset,
16171661
) -> None:
16181662
"""Copy a private attribute from source to destination.
16191663
@@ -1829,40 +1873,6 @@ def _add_common_instance_reference(self) -> None:
18291873
def _copy_pixel_data(self) -> None:
18301874
"""Set pixel data by optionally transcoding and combining legacy frames.
18311875
1832-
Parameters
1833-
----------
1834-
legacy_datasets: list[pydicom.Dataset]
1835-
Legacy datasets (in order) whose pixel data is to combined.
1836-
transfer_syntax_uid: str | None
1837-
Transfer syntax UID to use to encode the frames in the new object.
1838-
If None, the transfer syntax of the original objects is used.
1839-
workers: int | concurrent.futures.Executor, optional
1840-
Number of worker processes to use for frame compression, if
1841-
compression or transcoding is needed. If 0, no workers are used and
1842-
compression is performed in the main process (this is the default
1843-
behavior). If negative, as many processes are created as the
1844-
machine has processors.
1845-
1846-
Alternatively, you may directly pass an instance of a class derived
1847-
from ``concurrent.futures.Executor`` (most likely an instance of
1848-
``concurrent.futures.ProcessPoolExecutor``) for highdicom to use.
1849-
You may wish to do this either to have greater control over the
1850-
setup of the executor, or to avoid the setup cost of spawning new
1851-
processes each time this ``__init__`` method is called if your
1852-
application creates a large number of objects.
1853-
1854-
Note that if you use worker processes, you must ensure that your
1855-
main process uses the ``if __name__ == "__main__"`` idiom to guard
1856-
against spawned child processes creating further workers.
1857-
use_extended_offset_table: bool, optional
1858-
Include an extended offset table instead of a basic offset table
1859-
for encapsulated transfer syntaxes. Extended offset tables avoid
1860-
size limitations on basic offset tables, and separate the offset
1861-
table from the pixel data by placing it into metadata. However,
1862-
they may be less widely supported than basic offset tables. This
1863-
parameter is ignored if using a native (uncompressed) transfer
1864-
syntax. The default value may change in a future release.
1865-
18661876
"""
18671877
allowed_transfer_syntaxes = (
18681878
ImplicitVRLittleEndian,
@@ -2084,6 +2094,7 @@ def __init__(
20842094
instance_number: int,
20852095
transfer_syntax_uid: str | None = None,
20862096
use_extended_offset_table: bool = False,
2097+
*,
20872098
require_volume: bool = False,
20882099
sort: bool = True,
20892100
contributing_equipment: Sequence[ContributingEquipment] | None = None,
@@ -2133,9 +2144,7 @@ def __init__(
21332144
datasets were passed. When True, sorting is performed first by
21342145
Series Number, then Instance Number, then SOP Instance UID. To use
21352146
an alternative sort order, pre-sort the legacy datasets, and pass
2136-
``sort=False``. Though there are no requirements on sort order in
2137-
the standard, it is generally a best practice to use some sensible
2138-
sort order.
2147+
``sort=False``.
21392148
contributing_equipment: Sequence[highdicom.ContributingEquipment] | None, optional
21402149
Additional equipment that has contributed to the acquisition,
21412150
creation or modification of this instance.

0 commit comments

Comments
 (0)