dbdicom 0.2.5__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbdicom might be problematic. Click here for more details.

Files changed (52) hide show
  1. dbdicom/__init__.py +1 -28
  2. dbdicom/api.py +267 -0
  3. dbdicom/const.py +144 -0
  4. dbdicom/dataset.py +752 -0
  5. dbdicom/dbd.py +719 -0
  6. dbdicom/external/__pycache__/__init__.cpython-311.pyc +0 -0
  7. dbdicom/external/dcm4che/__pycache__/__init__.cpython-311.pyc +0 -0
  8. dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-311.pyc +0 -0
  9. dbdicom/register.py +527 -0
  10. dbdicom/{ds/types → sop_classes}/ct_image.py +2 -16
  11. dbdicom/{ds/types → sop_classes}/enhanced_mr_image.py +153 -26
  12. dbdicom/{ds/types → sop_classes}/mr_image.py +185 -140
  13. dbdicom/sop_classes/parametric_map.py +307 -0
  14. dbdicom/sop_classes/secondary_capture.py +140 -0
  15. dbdicom/sop_classes/segmentation.py +311 -0
  16. dbdicom/{ds/types → sop_classes}/ultrasound_multiframe_image.py +1 -15
  17. dbdicom/{ds/types → sop_classes}/xray_angiographic_image.py +2 -17
  18. dbdicom/utils/arrays.py +36 -0
  19. dbdicom/utils/files.py +0 -20
  20. dbdicom/utils/image.py +10 -629
  21. dbdicom-0.3.0.dist-info/METADATA +28 -0
  22. dbdicom-0.3.0.dist-info/RECORD +53 -0
  23. {dbdicom-0.2.5.dist-info → dbdicom-0.3.0.dist-info}/WHEEL +1 -1
  24. dbdicom/create.py +0 -457
  25. dbdicom/dro.py +0 -174
  26. dbdicom/ds/__init__.py +0 -10
  27. dbdicom/ds/create.py +0 -63
  28. dbdicom/ds/dataset.py +0 -869
  29. dbdicom/ds/dictionaries.py +0 -620
  30. dbdicom/ds/types/parametric_map.py +0 -226
  31. dbdicom/extensions/__init__.py +0 -9
  32. dbdicom/extensions/dipy.py +0 -448
  33. dbdicom/extensions/elastix.py +0 -503
  34. dbdicom/extensions/matplotlib.py +0 -107
  35. dbdicom/extensions/numpy.py +0 -271
  36. dbdicom/extensions/scipy.py +0 -1512
  37. dbdicom/extensions/skimage.py +0 -1030
  38. dbdicom/extensions/sklearn.py +0 -243
  39. dbdicom/extensions/vreg.py +0 -1390
  40. dbdicom/manager.py +0 -2132
  41. dbdicom/message.py +0 -119
  42. dbdicom/pipelines.py +0 -66
  43. dbdicom/record.py +0 -1893
  44. dbdicom/types/database.py +0 -107
  45. dbdicom/types/instance.py +0 -231
  46. dbdicom/types/patient.py +0 -40
  47. dbdicom/types/series.py +0 -2874
  48. dbdicom/types/study.py +0 -58
  49. dbdicom-0.2.5.dist-info/METADATA +0 -71
  50. dbdicom-0.2.5.dist-info/RECORD +0 -66
  51. {dbdicom-0.2.5.dist-info → dbdicom-0.3.0.dist-info/licenses}/LICENSE +0 -0
  52. {dbdicom-0.2.5.dist-info → dbdicom-0.3.0.dist-info}/top_level.txt +0 -0
dbdicom/__init__.py CHANGED
@@ -1,28 +1 @@
1
-
2
- from .create import (
3
- database,
4
- patient,
5
- study,
6
- series,
7
- as_series,
8
- zeros,
9
- ones,
10
- empty_series,
11
- )
12
- from .record import (
13
- copy_to,
14
- move_to,
15
- group,
16
- merge,
17
- )
18
- from .types.series import (
19
- array
20
- )
21
- from .record import Record
22
- from .types.database import Database
23
- from .types.patient import Patient
24
- from .types.study import Study
25
- from .types.series import Series
26
- from .utils import image
27
- from . import extensions
28
- from . import dro
1
+ from dbdicom.api import *
dbdicom/api.py ADDED
@@ -0,0 +1,267 @@
1
+
2
+ import numpy as np
3
+ import vreg
4
+
5
+ from dbdicom.dbd import DataBaseDicom
6
+
7
+
8
+ def open(path:str) -> DataBaseDicom:
9
+ """Open a DICOM database
10
+
11
+ Args:
12
+ path (str): path to the DICOM folder
13
+
14
+ Returns:
15
+ DataBaseDicom: database instance.
16
+ """
17
+ return DataBaseDicom(path)
18
+
19
+ def print(path):
20
+ """Print the contents of the DICOM folder
21
+
22
+ Args:
23
+ path (str): path to the DICOM folder
24
+ """
25
+ dbd = open(path)
26
+ dbd.print()
27
+
28
+
29
+ def summary(path) -> dict:
30
+ """Return a summary of the contents of the database.
31
+
32
+ Args:
33
+ path (str): path to the DICOM folder
34
+
35
+ Returns:
36
+ dict: Nested dictionary with summary information on the database.
37
+ """
38
+ dbd = open(path)
39
+ return dbd.summary()
40
+
41
+
42
+ def patients(path, name:str=None, contains:str=None, isin:list=None)->list:
43
+ """Return a list of patients in the DICOM folder.
44
+
45
+ Args:
46
+ path (str): path to the DICOM folder
47
+ name (str, optional): value of PatientName, to search for
48
+ individuals with a given name. Defaults to None.
49
+ contains (str, optional): substring of PatientName, to
50
+ search for individuals based on part of their name.
51
+ Defaults to None.
52
+ isin (list, optional): List of PatientName values, to search
53
+ for patients whose name is in the list. Defaults to None.
54
+
55
+ Returns:
56
+ list: list of patients fulfilling the criteria.
57
+ """
58
+ dbd = open(path)
59
+ return dbd.patients(name, contains, isin)
60
+
61
+
62
+ def studies(entity:str | list, name:str=None, contains:str=None, isin:list=None)->list:
63
+ """Return a list of studies in the DICOM folder.
64
+
65
+ Args:
66
+ entity (str or list): path to a DICOM folder (to search in
67
+ the whole folder), or a two-element list identifying a
68
+ patient (to search studies of a given patient).
69
+ name (str, optional): value of StudyDescription, to search for
70
+ studies with a given description. Defaults to None.
71
+ contains (str, optional): substring of StudyDescription, to
72
+ search for studies based on part of their description.
73
+ Defaults to None.
74
+ isin (list, optional): List of StudyDescription values, to search
75
+ for studies whose description is in a list. Defaults to None.
76
+
77
+ Returns:
78
+ list: list of studies fulfilling the criteria.
79
+ """
80
+ if isinstance(entity, str): # path = folder
81
+ dbd = open(entity)
82
+ return dbd.studies(entity, name, contains, isin)
83
+ elif len(entity)==2: # path = patient
84
+ dbd = open(entity[0])
85
+ return dbd.studies(entity, name, contains, isin)
86
+ else:
87
+ raise ValueError(
88
+ "The path must be a folder or a 2-element list "
89
+ "with a folder and a patient name."
90
+ )
91
+
92
+ def series(entity:str | list, name:str=None, contains:str=None, isin:list=None)->list:
93
+ """Return a list of series in the DICOM folder.
94
+
95
+ Args:
96
+ entity (str or list): path to a DICOM folder (to search in
97
+ the whole folder), or a list identifying a
98
+ patient or a study (to search series of a given patient
99
+ or study).
100
+ name (str, optional): value of SeriesDescription, to search for
101
+ series with a given description. Defaults to None.
102
+ contains (str, optional): substring of SeriesDescription, to
103
+ search for series based on part of their description.
104
+ Defaults to None.
105
+ isin (list, optional): List of SeriesDescription values, to search
106
+ for series whose description is in a list. Defaults to None.
107
+
108
+ Returns:
109
+ list: list of series fulfilling the criteria.
110
+ """
111
+ if isinstance(entity, str): # path = folder
112
+ dbd = open(entity)
113
+ return dbd.series(entity, name, contains, isin)
114
+ elif len(entity) in [2,3]:
115
+ dbd = open(entity[0])
116
+ return dbd.series(entity, name, contains, isin)
117
+ else:
118
+ raise ValueError(
119
+ "To retrieve a series, the entity must be a database, patient or study."
120
+ )
121
+
122
+ def copy(from_entity:list, to_entity:list):
123
+ """Copy a DICOM entity (patient, study or series)
124
+
125
+ Args:
126
+ from_entity (list): entity to copy
127
+ to_entity (list): entity after copying.
128
+ """
129
+ dbd = open(from_entity[0])
130
+ dbd.copy(from_entity, to_entity)
131
+ dbd.close()
132
+
133
+
134
+ def delete(entity:list):
135
+ """Delete a DICOM entity
136
+
137
+ Args:
138
+ entity (list): entity to delete
139
+ """
140
+ dbd = open(entity[0])
141
+ dbd.delete(entity)
142
+ dbd.close()
143
+
144
+
145
+ def move(from_entity:list, to_entity:list):
146
+ """Move a DICOM entity
147
+
148
+ Args:
149
+ entity (list): entity to move
150
+ """
151
+ dbd = open(from_entity[0])
152
+ dbd.copy(from_entity, to_entity)
153
+ dbd.delete(from_entity)
154
+ dbd.close()
155
+
156
+
157
+ def volume(series:list, dims:list=None, multislice=False) -> vreg.Volume3D:
158
+ """Read a vreg.Volume3D from a DICOM series
159
+
160
+ Args:
161
+ series (list): DICOM series to read
162
+ dims (list, optional): Non-spatial dimensions of the volume. Defaults to None.
163
+ multislice (bool, optional): Whether the data are to be read
164
+ as multislice or not. In multislice data the voxel size
165
+ is taken from the slice gap rather thsan the slice thickness. Defaults to False.
166
+
167
+ Returns:
168
+ vreg.Volume3D: vole read from the series.
169
+ """
170
+ dbd = open(series[0])
171
+ return dbd.volume(series, dims, multislice)
172
+
173
+ def write_volume(vol:vreg.Volume3D, series:list, ref:list=None,
174
+ multislice=False):
175
+ """Write a vreg.Volume3D to a DICOM series
176
+
177
+ Args:
178
+ vol (vreg.Volume3D): Volume to write to the series.
179
+ series (list): DICOM series to read
180
+ dims (list, optional): Non-spatial dimensions of the volume. Defaults to None.
181
+ multislice (bool, optional): Whether the data are to be read
182
+ as multislice or not. In multislice data the voxel size
183
+ is taken from the slice gap rather thsan the slice thickness. Defaults to False.
184
+ """
185
+ dbd = open(series[0])
186
+ dbd.write_volume(vol, series, ref, multislice)
187
+ dbd.close()
188
+
189
+ def to_nifti(series:list, file:str, dims:list=None, multislice=False):
190
+ """Save a DICOM series in nifti format.
191
+
192
+ Args:
193
+ series (list): DICOM series to read
194
+ file (str): file path of the nifti file.
195
+ dims (list, optional): Non-spatial dimensions of the volume.
196
+ Defaults to None.
197
+ multislice (bool, optional): Whether the data are to be read
198
+ as multislice or not. In multislice data the voxel size
199
+ is taken from the slice gap rather thaan the slice thickness. Defaults to False.
200
+ """
201
+ dbd = open(series[0])
202
+ dbd.to_nifti(series, file, dims, multislice)
203
+
204
+ def from_nifti(file:str, series:list, ref:list=None, multislice=False):
205
+ """Create a DICOM series from a nifti file.
206
+
207
+ Args:
208
+ file (str): file path of the nifti file.
209
+ series (list): DICOM series to create
210
+ ref (list): DICOM series to use as template.
211
+ multislice (bool, optional): Whether the data are to be written
212
+ as multislice or not. In multislice data the voxel size
213
+ is written in the slice gap rather thaan the slice thickness. Defaults to False.
214
+ """
215
+ dbd = open(series[0])
216
+ dbd.from_nifti(file, series, ref, multislice)
217
+ dbd.close()
218
+
219
+ def pixel_data(series:list, dims:list=None, include:list=None) -> tuple:
220
+ """Read the pixel data from a DICOM series
221
+
222
+ Args:
223
+ series (list): DICOM series to read
224
+ dims (list, optional): Dimensions of the array.
225
+ include (list, optional): list of DICOM attributes that are
226
+ read on the fly to avoid reading the data twice.
227
+
228
+ Returns:
229
+ tuple: numpy array with pixel values and an array with
230
+ coordinates of the slices according to dims. If include
231
+ is provide these are returned as a dictionary in a third
232
+ return value.
233
+ """
234
+ dbd = open(series[0])
235
+ return dbd.pixel_data(series, dims, include)
236
+
237
+ # write_pixel_data()
238
+ # values()
239
+ # write_values()
240
+ # to_png(series, folder, dims)
241
+ # to_npy(series, folder, dims)
242
+ # split(series, attribute)
243
+ # extract(series, *kwargs) # subseries
244
+
245
+ # zeros(series, shape, dims)
246
+
247
+ def unique(pars:list, entity:list) -> dict:
248
+ """Return a list of unique values for a DICOM entity
249
+
250
+ Args:
251
+ pars (list): attributes to return.
252
+ entity (list): DICOM entity to search (Patient, Study or Series)
253
+
254
+ Returns:
255
+ dict: dictionary with unique values for each attribute.
256
+ """
257
+ dbd = open(entity[0])
258
+ return dbd.unique(pars, entity)
259
+
260
+
261
+
262
+
263
+
264
+
265
+ if __name__=='__main__':
266
+
267
+ pass
dbdicom/const.py ADDED
@@ -0,0 +1,144 @@
1
+
2
+
3
+ PATIENT_MODULE = [
4
+ 'ReferencedPatientSequence',
5
+ 'PatientName',
6
+ 'PatientID',
7
+ 'IssuerOfPatientID',
8
+ 'TypeOfPatientID',
9
+ 'IssuerOfPatientIDQualifiersSequence',
10
+ 'SourcePatientGroupIdentificationSequence',
11
+ 'GroupOfPatientsIdentificationSequence',
12
+ 'PatientBirthDate',
13
+ 'PatientBirthTime',
14
+ 'PatientBirthDateInAlternativeCalendar',
15
+ 'PatientDeathDateInAlternativeCalendar',
16
+ 'PatientAlternativeCalendar',
17
+ 'PatientSex',
18
+ 'QualityControlSubject',
19
+ 'StrainDescription',
20
+ 'StrainNomenclature',
21
+ 'StrainStockSequence',
22
+ 'StrainAdditionalInformation',
23
+ 'StrainCodeSequence',
24
+ 'GeneticModificationsSequence',
25
+ 'OtherPatientNames',
26
+ 'OtherPatientIDsSequence',
27
+ 'ReferencedPatientPhotoSequence',
28
+ 'EthnicGroup',
29
+ 'PatientSpeciesDescription',
30
+ 'PatientSpeciesCodeSequence',
31
+ 'PatientBreedDescription',
32
+ 'PatientBreedCodeSequence',
33
+ 'BreedRegistrationSequence',
34
+ 'ResponsiblePerson',
35
+ 'ResponsiblePersonRole',
36
+ 'ResponsibleOrganization',
37
+ 'PatientComments',
38
+ 'PatientIdentityRemoved',
39
+ 'DeidentificationMethod',
40
+ 'DeidentificationMethodCodeSequence',
41
+ 'ClinicalTrialSponsorName',
42
+ 'ClinicalTrialProtocolID',
43
+ 'ClinicalTrialProtocolName',
44
+ 'ClinicalTrialSiteID',
45
+ 'ClinicalTrialSiteName',
46
+ 'ClinicalTrialSubjectID',
47
+ 'ClinicalTrialSubjectReadingID',
48
+ 'ClinicalTrialProtocolEthicsCommitteeName',
49
+ 'ClinicalTrialProtocolEthicsCommitteeApprovalNumber',
50
+ ]
51
+
52
+
53
+
54
+ STUDY_MODULE = [
55
+ 'StudyDate',
56
+ 'StudyTime',
57
+ 'AccessionNumber',
58
+ 'IssuerOfAccessionNumberSequence',
59
+ 'ReferringPhysicianName',
60
+ 'ReferringPhysicianIdentificationSequence',
61
+ 'ConsultingPhysicianName',
62
+ 'ConsultingPhysicianIdentificationSequence',
63
+ 'StudyDescription',
64
+ 'ProcedureCodeSequence',
65
+ 'PhysiciansOfRecord',
66
+ 'PhysiciansOfRecordIdentificationSequence',
67
+ 'NameOfPhysiciansReadingStudy',
68
+ 'PhysiciansReadingStudyIdentificationSequence',
69
+ 'ReferencedStudySequence',
70
+ 'StudyInstanceUID',
71
+ 'StudyID',
72
+ 'RequestingService',
73
+ 'RequestingServiceCodeSequence',
74
+ 'ReasonForPerformedProcedureCodeSequence',
75
+ 'AdmittingDiagnosesDescription',
76
+ 'AdmittingDiagnosesCodeSequence',
77
+ 'PatientAge',
78
+ 'PatientSize',
79
+ 'PatientSizeCodeSequence',
80
+ 'PatientBodyMassIndex',
81
+ 'MeasuredAPDimension',
82
+ 'MeasuredLateralDimension',
83
+ 'PatientWeight',
84
+ 'MedicalAlerts',
85
+ 'Allergies',
86
+ 'Occupation',
87
+ 'SmokingStatus',
88
+ 'AdditionalPatientHistory',
89
+ 'PregnancyStatus',
90
+ 'LastMenstrualDate',
91
+ 'PatientSexNeutered',
92
+ 'ReasonForVisit',
93
+ 'ReasonForVisitCodeSequence',
94
+ 'AdmissionID',
95
+ 'IssuerOfAdmissionIDSequence',
96
+ 'ServiceEpisodeID',
97
+ 'ServiceEpisodeDescription',
98
+ 'IssuerOfServiceEpisodeIDSequence',
99
+ 'PatientState',
100
+ 'ClinicalTrialTimePointID',
101
+ 'ClinicalTrialTimePointDescription',
102
+ 'LongitudinalTemporalOffsetFromEvent',
103
+ 'LongitudinalTemporalEventType',
104
+ 'ConsentForClinicalTrialUseSequence',
105
+ ]
106
+
107
+
108
+
109
+ SERIES_MODULE = [
110
+ 'SeriesDate',
111
+ 'SeriesTime',
112
+ 'Modality',
113
+ 'SeriesDescription',
114
+ 'SeriesDescriptionCodeSequence',
115
+ 'PerformingPhysicianName',
116
+ 'PerformingPhysicianIdentificationSequence',
117
+ 'OperatorsName',
118
+ 'OperatorIdentificationSequence',
119
+ 'ReferencedPerformedProcedureStepSequence',
120
+ 'RelatedSeriesSequence',
121
+ 'AnatomicalOrientationType',
122
+ 'BodyPartExamined',
123
+ 'ProtocolName',
124
+ 'PatientPosition',
125
+ 'ReferencedDefinedProtocolSequence',
126
+ 'ReferencedPerformedProtocolSequence',
127
+ 'SeriesInstanceUID',
128
+ 'SeriesNumber',
129
+ 'Laterality',
130
+ 'SmallestPixelValueInSeries',
131
+ 'LargestPixelValueInSeries',
132
+ 'PerformedProcedureStepStartDate',
133
+ 'PerformedProcedureStepStartTime',
134
+ 'PerformedProcedureStepEndDate',
135
+ 'PerformedProcedureStepEndTime',
136
+ 'PerformedProcedureStepID',
137
+ 'PerformedProcedureStepDescription',
138
+ 'PerformedProtocolCodeSequence',
139
+ 'RequestAttributesSequence',
140
+ 'CommentsOnThePerformedProcedureStep',
141
+ 'ClinicalTrialCoordinatingCenterName',
142
+ 'ClinicalTrialSeriesID',
143
+ 'ClinicalTrialSeriesDescription',
144
+ ]