@@ -21,6 +21,25 @@ def __init__(self, series_instance_uid):
21
21
self ._series_instance_uid = series_instance_uid
22
22
self ._sop_instances = []
23
23
24
+ # Do not set attributes in advance to save memory
25
+
26
+ # self._series_date: Any = None
27
+ # self._series_time: Any = None
28
+ # self._modality: Any = None
29
+ # self._series_description: Any = None
30
+ # self._body_part_examined: Any = None
31
+ # self._patient_position: Any = None
32
+ # self._series_number: Any = None
33
+ # self._laterality: Any = None
34
+ # self._row_pixel_spacing: Any = None
35
+ # self._col_pixel_spacing: Any = None
36
+ # self._depth_pixel_spacing: Any = None
37
+ # self._row_direction_cosine: Any = None
38
+ # self._col_direction_cosine: Any = None
39
+ # self._depth_direction_cosine: Any = None
40
+ # self._dicom_affine_transform: Any = None
41
+ # self._nifti_affine_transform: Any = None
42
+
24
43
def get_series_instance_uid (self ):
25
44
return self ._series_instance_uid
26
45
@@ -33,215 +52,188 @@ def get_sop_instances(self):
33
52
34
53
@property
35
54
def series_date (self ):
36
- return self . __series_date
55
+ return getattr ( self , "_series_date" , None )
37
56
38
57
@series_date .setter
39
58
def series_date (self , val ):
40
- self .__series_date = val
59
+ self ._series_date = val
41
60
42
61
@property
43
62
def series_time (self ):
44
- return self . __series_time
63
+ return getattr ( self , "_series_time" , None )
45
64
46
65
@series_time .setter
47
66
def series_time (self , val ):
48
- self .__series_time = val
67
+ self ._series_time = val
49
68
50
69
@property
51
70
def modality (self ):
52
- return self . __modality
71
+ return getattr ( self , "_modality" , None )
53
72
54
73
@modality .setter
55
74
def modality (self , val ):
56
- self .__modality = val
75
+ self ._modality = val
57
76
58
77
@property
59
78
def series_description (self ):
60
- return self . __series_description
79
+ return getattr ( self , "_series_description" , None )
61
80
62
81
@series_description .setter
63
82
def series_description (self , val ):
64
- self .__series_description = val
83
+ self ._series_description = val
65
84
66
85
@property
67
86
def body_part_examined (self ):
68
- return self . __body_part_examined
87
+ return getattr ( self , "_body_part_examined" , None )
69
88
70
89
@body_part_examined .setter
71
90
def body_part_examined (self , val ):
72
- self .__body_part_examined = val
91
+ self ._body_part_examined = val
73
92
74
93
@property
75
94
def patient_position (self ):
76
- return self . __patient_position
95
+ return getattr ( self , "_patient_position" , None )
77
96
78
97
@patient_position .setter
79
98
def patient_position (self , val ):
80
- self .__patient_position = val
99
+ self ._patient_position = val
81
100
82
101
@property
83
102
def series_number (self ):
84
- return self . __series_number
103
+ return getattr ( self , "_series_number" , None )
85
104
86
105
@series_number .setter
87
106
def series_number (self , val ):
88
- self .__series_number = val
107
+ self ._series_number = val
89
108
90
109
@property
91
110
def laterality (self ):
92
- return self . __laterality
111
+ return getattr ( self , "_laterality" , None )
93
112
94
113
@laterality .setter
95
114
def laterality (self , val ):
96
- self .__laterality = val
115
+ self ._laterality = val
97
116
98
117
@property
99
118
def row_pixel_spacing (self ):
100
- return self . __row_pixel_spacing
119
+ return getattr ( self , "_row_pixel_spacing" , None )
101
120
102
121
@row_pixel_spacing .setter
103
122
def row_pixel_spacing (self , val ):
104
- self .__row_pixel_spacing = val
123
+ self ._row_pixel_spacing = val
105
124
106
125
@property
107
126
def col_pixel_spacing (self ):
108
- return self . __col_pixel_spacing
127
+ return getattr ( self , "_col_pixel_spacing" , None )
109
128
110
129
@col_pixel_spacing .setter
111
130
def col_pixel_spacing (self , val ):
112
- self .__col_pixel_spacing = val
131
+ self ._col_pixel_spacing = val
113
132
114
133
@property
115
134
def depth_pixel_spacing (self ):
116
- return self . __depth_pixel_spacing
135
+ return getattr ( self , "_depth_pixel_spacing" , None )
117
136
118
137
@depth_pixel_spacing .setter
119
138
def depth_pixel_spacing (self , val ):
120
- self .__depth_pixel_spacing = val
139
+ self ._depth_pixel_spacing = val
121
140
122
141
@property
123
142
def row_direction_cosine (self ):
124
- return self . __row_direction_cosine
143
+ return getattr ( self , "_row_direction_cosine" , None )
125
144
126
145
@row_direction_cosine .setter
127
146
def row_direction_cosine (self , val ):
128
- self .__row_direction_cosine = val
147
+ self ._row_direction_cosine = val
129
148
130
149
@property
131
150
def col_direction_cosine (self ):
132
- return self . __col_direction_cosine
151
+ return getattr ( self , "_col_direction_cosine" , None )
133
152
134
153
@col_direction_cosine .setter
135
154
def col_direction_cosine (self , val ):
136
- self .__col_direction_cosine = val
155
+ self ._col_direction_cosine = val
137
156
138
157
@property
139
158
def depth_direction_cosine (self ):
140
- return self . __depth_direction_cosine
159
+ return getattr ( self , "_depth_direction_cosine" , None )
141
160
142
161
@depth_direction_cosine .setter
143
162
def depth_direction_cosine (self , val ):
144
- self .__depth_direction_cosine = val
163
+ self ._depth_direction_cosine = val
145
164
146
165
@property
147
166
def dicom_affine_transform (self ):
148
- return self . __dicom_affine_transform
167
+ return getattr ( self , "_dicom_affine_transform" , None )
149
168
150
169
@dicom_affine_transform .setter
151
170
def dicom_affine_transform (self , val ):
152
- self .__dicom_affine_transform = val
171
+ self ._dicom_affine_transform = val
153
172
154
173
@property
155
174
def nifti_affine_transform (self ):
156
- return self . __nifti_affine_transform
175
+ return getattr ( self , "_nifti_affine_transform" , None )
157
176
158
177
@nifti_affine_transform .setter
159
178
def nifti_affine_transform (self , val ):
160
- self .__nifti_affine_transform = val
179
+ self ._nifti_affine_transform = val
161
180
162
181
def __str__ (self ):
163
182
result = "---------------" + "\n "
164
183
165
184
series_instance_uid_attr = "Series Instance UID: " + self ._series_instance_uid + "\n "
166
185
result += series_instance_uid_attr
167
186
168
- try :
169
- num_sop_instances = "Num SOP Instances: " + str (len (self ._sop_instances )) + "\n "
170
- result += num_sop_instances
171
- except AttributeError :
172
- pass
187
+ num_sop_instances = "Num SOP Instances: " + str (len (self ._sop_instances )) + "\n "
188
+ result += num_sop_instances
173
189
174
- try :
190
+ if self . series_date is not None :
175
191
series_date_attr = "Series Date: " + self .series_date + "\n "
176
192
result += series_date_attr
177
- except AttributeError :
178
- pass
179
193
180
- try :
194
+ if self . series_time is not None :
181
195
series_time_attr = "Series Time: " + self .series_time + "\n "
182
196
result += series_time_attr
183
- except AttributeError :
184
- pass
185
197
186
- try :
198
+ if self . modality is not None :
187
199
modality_attr = "Modality: " + self .modality + "\n "
188
200
result += modality_attr
189
- except AttributeError :
190
- pass
191
201
192
- try :
202
+ if self . series_description is not None :
193
203
series_desc_attr = "Series Description: " + self .series_description + "\n "
194
204
result += series_desc_attr
195
- except AttributeError :
196
- pass
197
205
198
- try :
206
+ if self . row_pixel_spacing is not None :
199
207
row_pixel_spacing_attr = "Row Pixel Spacing: " + str (self .row_pixel_spacing ) + "\n "
200
208
result += row_pixel_spacing_attr
201
- except AttributeError :
202
- pass
203
209
204
- try :
210
+ if self . col_pixel_spacing is not None :
205
211
col_pixel_spacing_attr = "Column Pixel Spacing: " + str (self .col_pixel_spacing ) + "\n "
206
212
result += col_pixel_spacing_attr
207
- except AttributeError :
208
- pass
209
213
210
- try :
214
+ if self . depth_pixel_spacing is not None :
211
215
depth_pixel_spacing_attr = "Depth Pixel Spacing: " + str (self .depth_pixel_spacing ) + "\n "
212
216
result += depth_pixel_spacing_attr
213
- except AttributeError :
214
- pass
215
217
216
- try :
218
+ if self . row_direction_cosine is not None :
217
219
row_direction_cosine_attr = "Row Direction Cosine: " + str (self .row_direction_cosine ) + "\n "
218
220
result += row_direction_cosine_attr
219
- except AttributeError :
220
- pass
221
221
222
- try :
222
+ if self . col_direction_cosine is not None :
223
223
col_direction_cosine_attr = "Column Direction Cosine: " + str (self .col_direction_cosine ) + "\n "
224
224
result += col_direction_cosine_attr
225
- except AttributeError :
226
- pass
227
225
228
- try :
226
+ if self . depth_direction_cosine is not None :
229
227
depth_direction_cosine_attr = "Depth Direction Cosine: " + str (self .depth_direction_cosine ) + "\n "
230
228
result += depth_direction_cosine_attr
231
- except AttributeError :
232
- pass
233
229
234
- try :
230
+ if self . dicom_affine_transform is not None :
235
231
dicom_affine_transform_attr = "DICOM affine transform: " + "\n " + str (self .dicom_affine_transform ) + "\n "
236
232
result += dicom_affine_transform_attr
237
- except AttributeError :
238
- pass
239
233
240
- try :
234
+ if self . nifti_affine_transform is not None :
241
235
nifti_affine_transform_attr = "NIFTI affine transform: " + "\n " + str (self .nifti_affine_transform ) + "\n "
242
236
result += nifti_affine_transform_attr
243
- except AttributeError :
244
- pass
245
237
246
238
result += "---------------" + "\n "
247
239
0 commit comments