@@ -114,7 +114,7 @@ def generate_voxel_data(self, series):
114114 vol_data = np .stack ([s .get_pixel_array () for s in slices ], axis = 0 )
115115 # The above get_pixel_array() already considers the PixelRepresentation attribute,
116116 # 0 is unsigned int, 1 is signed int
117- if slices [0 ][0x0028 ,0x0103 ].value == 0 :
117+ if slices [0 ][0x0028 , 0x0103 ].value == 0 :
118118 vol_data = vol_data .astype (np .uint16 )
119119
120120 # For now we support monochrome image only, for which DICOM Photometric Interpretation
@@ -157,24 +157,35 @@ def generate_voxel_data(self, series):
157157 except KeyError :
158158 slope = 1
159159
160-
161160 # check if vol_data, intercept, and slope can be cast to uint16 without data loss
162- if np .can_cast (vol_data , np .uint16 , casting = 'safe' ) and np .can_cast (intercept , np .uint16 , casting = 'safe' ) and np .can_cast (slope , np .uint16 , casting = 'safe' ):
163- logging .info (f"Casting to uint16" )
161+ if (
162+ np .can_cast (vol_data , np .uint16 , casting = "safe" )
163+ and np .can_cast (intercept , np .uint16 , casting = "safe" )
164+ and np .can_cast (slope , np .uint16 , casting = "safe" )
165+ ):
166+ logging .info ("Casting to uint16" )
164167 vol_data = np .array (vol_data , dtype = np .uint16 )
165168 intercept = np .uint16 (intercept )
166169 slope = np .uint16 (slope )
167- elif np .can_cast (vol_data , np .float32 , casting = 'safe' ) and np .can_cast (intercept , np .float32 , casting = 'safe' ) and np .can_cast (slope , np .float32 , casting = 'safe' ):
168- logging .info (f"Casting to float32" )
170+ elif (
171+ np .can_cast (vol_data , np .float32 , casting = "safe" )
172+ and np .can_cast (intercept , np .float32 , casting = "safe" )
173+ and np .can_cast (slope , np .float32 , casting = "safe" )
174+ ):
175+ logging .info ("Casting to float32" )
169176 vol_data = np .array (vol_data , dtype = np .float32 )
170177 intercept = np .float32 (intercept )
171178 slope = np .float32 (slope )
172- elif np .can_cast (vol_data , np .float64 , casting = 'safe' ) and np .can_cast (intercept , np .float64 , casting = 'safe' ) and np .can_cast (slope , np .float64 , casting = 'safe' ):
173- logging .info (f"Casting to float64" )
179+ elif (
180+ np .can_cast (vol_data , np .float64 , casting = "safe" )
181+ and np .can_cast (intercept , np .float64 , casting = "safe" )
182+ and np .can_cast (slope , np .float64 , casting = "safe" )
183+ ):
184+ logging .info ("Casting to float64" )
174185 vol_data = np .array (vol_data , dtype = np .float64 )
175186 intercept = np .float64 (intercept )
176187 slope = np .float64 (slope )
177-
188+
178189 if slope != 1 :
179190 vol_data = slope * vol_data
180191
0 commit comments