@@ -136,21 +136,21 @@ def get_header_information(master_file):
136
136
h ['oscillation_axis_values' ] = master_file ["/entry/sample/goniometer/%s" % oscillation_axis .lower ()][()]
137
137
image_path = os .path .dirname (os .path .abspath (master_file .filename ))
138
138
h ['image_path' ] = image_path
139
- filename_template = master_file .filename .replace ('_master.h5' , '_#####.cbf' )
139
+ filename_template = master_file .filename .replace ('_master.h5' , '_###### .cbf' )
140
140
h ['filename_template' ] = filename_template
141
141
h ['image_numbers' ] = get_image_numbers (master_file )
142
142
return h
143
143
144
144
def get_image_numbers (master_file ):
145
- data_items = master_file ['/entry/data' ].items ()
145
+ data_items = list ( master_file ['/entry/data' ].items () )
146
146
data_items .sort (key = lambda x : x [0 ])
147
147
image_numbers = []
148
148
for key , value in data_items :
149
149
log .debug ('key, value: %s, %s' % (key , value ))
150
150
try :
151
151
low = value .attrs .get ('image_nr_low' )
152
152
high = value .attrs .get ('image_nr_high' )
153
- image_numbers += range (low , high + 1 , 1 )
153
+ image_numbers += list ( range (low , high + 1 , 1 ) )
154
154
except :
155
155
log .exception (traceback .format_exc ())
156
156
return image_numbers
@@ -183,10 +183,7 @@ def get_wedges(start, nimages, n_cpu):
183
183
return wedges
184
184
185
185
def get_nimages (master_file , first , last ):
186
- #nimages = master_file["/entry/instrument/detector/detectorSpecific/nimages"][()]
187
- #ntrigger = master_file["/entry/instrument/detector/detectorSpecific/ntrigger"][()]
188
- #nimages *= ntrigger
189
- nimages = sum ([d .shape [0 ] for d in master_file ['/entry/data' ].values () if d is not None ])
186
+ nimages = sum ([d .shape [0 ] for d in list (master_file ['/entry/data' ][()]) if d is not None ])
190
187
if first != 0 and last != - 1 and last > first :
191
188
nimages = last - first
192
189
elif first > 0 :
@@ -235,7 +232,7 @@ def extract_cbfs(master_file, master_file_absolute_path, destination_directory,
235
232
def save_image (header_dictionary , master_file_absolute_path , destination_directory , n , compress = None ):
236
233
filename_template = header_dictionary ['filename_template' ]
237
234
image_number = header_dictionary ['image_numbers' ][n ] # n+1
238
- filename = os .path .basename (filename_template .replace ('#####' , str (image_number ).zfill (5 )))
235
+ filename = os .path .basename (filename_template .replace ('###### ' , str (image_number ).zfill (6 )))
239
236
header_dictionary ['filename' ] = 'data_%s' % (filename .replace ('.cbf' ,'' ))
240
237
omegas = header_dictionary ['omegas' ]
241
238
phis = header_dictionary ['phis' ]
@@ -266,12 +263,12 @@ def save_image(header_dictionary, master_file_absolute_path, destination_directo
266
263
267
264
268
265
header = header_template .format (** header_dictionary )
269
- header_filename = 'header_%s' % (str (image_number ).zfill (5 ))
266
+ header_filename = 'header_%s' % (str (image_number ).zfill (6 ))
270
267
f = open (header_filename , 'w' )
271
268
f .write (header )
272
269
f .close ()
273
270
274
- raw_cbf_filename = '%s.cbf' % str (image_number ).zfill (5 )
271
+ raw_cbf_filename = '%s.cbf' % str (image_number ).zfill (6 )
275
272
H5ToXds_line = 'H5ToXds %s %s %s' % (master_file_absolute_path , image_number , raw_cbf_filename )
276
273
os .system (H5ToXds_line )
277
274
log .debug (H5ToXds_line )
@@ -315,8 +312,8 @@ def get_dataset_filenames(master_file_absolute_path):
315
312
parser .add_option ('-O' , '--overwrite' , action = 'store_true' , help = 'Overwrite existing files.' )
316
313
317
314
options , args = parser .parse_args ()
318
- print 'options'
319
- print options
315
+ print ( 'options' )
316
+ print ( options )
320
317
if options .n_cpu <= 0 :
321
318
options .n_cpu = get_n_cpu ()
322
319
@@ -325,7 +322,7 @@ def get_dataset_filenames(master_file_absolute_path):
325
322
source_directory = os .path .dirname (master_file_absolute_path )
326
323
327
324
dataset_filenames = get_dataset_filenames (master_file_absolute_path )
328
- print 'dataset_filenames' , dataset_filenames
325
+ print ( 'dataset_filenames' , dataset_filenames )
329
326
330
327
for f in dataset_filenames :
331
328
shutil .copy2 (f , options .treatment_directory )
@@ -358,11 +355,11 @@ def get_dataset_filenames(master_file_absolute_path):
358
355
359
356
cbf_files = glob .glob (filename_template )
360
357
if nimages == len (cbf_files ) and options .overwrite != True :
361
- print 'It seems conversion of %s to cbf has already been done. Please use option --overwrite if you wish to regenerate the files. Exiting ...'
358
+ print ( 'It seems conversion of %s to cbf has already been done. Please use option --overwrite if you wish to regenerate the files. Exiting ...' )
362
359
sys .exit ()
363
360
364
- print 'Starting h5 to cbf conversion. The conversion time per image should be below 0.1 second. If it is more, there may be something wrong with the system.'
365
- print '%d images to extract. Using %d threads. Processing in %d wedges of %d images.\n ' % (nimages , options .n_cpu , len (wedges ), len (wedges [0 ]))
361
+ print ( 'Starting h5 to cbf conversion. The conversion time per image should be below 0.1 second. If it is more, there may be something wrong with the system.' )
362
+ print ( '%d images to extract. Using %d threads. Processing in %d wedges of %d images.\n ' % (nimages , options .n_cpu , len (wedges ), len (wedges [0 ]) ))
366
363
367
364
extract_cbfs (master_file , master_file_absolute_path .replace (source_directory , options .treatment_directory ), destination_directory , options .first , options .last , options .n_cpu , compress )
368
365
0 commit comments