Skip to content

Commit 4864e88

Browse files
committed
Supporting Python 3.
A lot of new functionalities. Production code 12-2023.
1 parent a27b1d7 commit 4864e88

File tree

126 files changed

+14653
-3883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+14653
-3883
lines changed

H5ToCBF.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ def get_header_information(master_file):
136136
h['oscillation_axis_values'] = master_file["/entry/sample/goniometer/%s" % oscillation_axis.lower()][()]
137137
image_path = os.path.dirname(os.path.abspath(master_file.filename))
138138
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')
140140
h['filename_template'] = filename_template
141141
h['image_numbers'] = get_image_numbers(master_file)
142142
return h
143143

144144
def get_image_numbers(master_file):
145-
data_items = master_file['/entry/data'].items()
145+
data_items = list(master_file['/entry/data'].items())
146146
data_items.sort(key=lambda x: x[0])
147147
image_numbers=[]
148148
for key, value in data_items:
149149
log.debug('key, value: %s, %s' % (key, value))
150150
try:
151151
low = value.attrs.get('image_nr_low')
152152
high = value.attrs.get('image_nr_high')
153-
image_numbers += range(low, high+1, 1)
153+
image_numbers += list(range(low, high+1, 1))
154154
except:
155155
log.exception(traceback.format_exc())
156156
return image_numbers
@@ -183,10 +183,7 @@ def get_wedges(start, nimages, n_cpu):
183183
return wedges
184184

185185
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])
190187
if first!=0 and last!=-1 and last>first:
191188
nimages = last - first
192189
elif first > 0:
@@ -235,7 +232,7 @@ def extract_cbfs(master_file, master_file_absolute_path, destination_directory,
235232
def save_image(header_dictionary, master_file_absolute_path, destination_directory, n, compress=None):
236233
filename_template = header_dictionary['filename_template']
237234
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)))
239236
header_dictionary['filename'] = 'data_%s' % (filename.replace('.cbf',''))
240237
omegas = header_dictionary['omegas']
241238
phis = header_dictionary['phis']
@@ -266,12 +263,12 @@ def save_image(header_dictionary, master_file_absolute_path, destination_directo
266263

267264

268265
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))
270267
f = open(header_filename, 'w')
271268
f.write(header)
272269
f.close()
273270

274-
raw_cbf_filename = '%s.cbf' % str(image_number).zfill(5)
271+
raw_cbf_filename = '%s.cbf' % str(image_number).zfill(6)
275272
H5ToXds_line = 'H5ToXds %s %s %s' % (master_file_absolute_path, image_number, raw_cbf_filename)
276273
os.system(H5ToXds_line)
277274
log.debug(H5ToXds_line)
@@ -315,8 +312,8 @@ def get_dataset_filenames(master_file_absolute_path):
315312
parser.add_option('-O', '--overwrite', action='store_true', help='Overwrite existing files.')
316313

317314
options, args = parser.parse_args()
318-
print 'options'
319-
print options
315+
print('options')
316+
print(options)
320317
if options.n_cpu <= 0:
321318
options.n_cpu = get_n_cpu()
322319

@@ -325,7 +322,7 @@ def get_dataset_filenames(master_file_absolute_path):
325322
source_directory = os.path.dirname(master_file_absolute_path)
326323

327324
dataset_filenames = get_dataset_filenames(master_file_absolute_path)
328-
print 'dataset_filenames', dataset_filenames
325+
print('dataset_filenames', dataset_filenames)
329326

330327
for f in dataset_filenames:
331328
shutil.copy2(f, options.treatment_directory)
@@ -358,11 +355,11 @@ def get_dataset_filenames(master_file_absolute_path):
358355

359356
cbf_files = glob.glob(filename_template)
360357
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 ...')
362359
sys.exit()
363360

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])))
366363

367364
extract_cbfs(master_file, master_file_absolute_path.replace(source_directory, options.treatment_directory), destination_directory, options.first, options.last, options.n_cpu, compress)
368365

XDS_from_H5.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
try:
88
import albula as dec
99
except ImportError:
10-
print "\nThe DECTRIS ALBULA API could not be loaded."
11-
print "If you did not install ALBULA with \"--python=</path/to/python_interpreter>\","
12-
print "please modify the \'sys.path.insert\' line in the script to point"
13-
print "to the DECTRIS ALBULA API and uncomment the line."
10+
print("\nThe DECTRIS ALBULA API could not be loaded.")
11+
print("If you did not install ALBULA with \"--python=</path/to/python_interpreter>\",")
12+
print("please modify the \'sys.path.insert\' line in the script to point")
13+
print("to the DECTRIS ALBULA API and uncomment the line.")
1414
raise SystemExit
1515

1616
import os.path
@@ -447,15 +447,15 @@ def request_parameter(parameter):
447447
elif (parameter == nimages):
448448
return raw_input("Please enter the number of images.\n")
449449
elif (parameter == description):
450-
print "Please enter the description of the detector, e.g."
450+
print("Please enter the description of the detector, e.g.")
451451
return raw_input("Dectris Eiger 4M\n")
452452
elif (parameter == countrate_correction_count_cutoff):
453453
return raw_input("Please enter the maximum trusted pixel value.\n")
454454
elif (parameter == resolution_cutoff):
455455
#return raw_input("Please enter a resolution limit for processing.\n")
456456
return 0
457457
else:
458-
print "Unknown software version. Please check."
458+
print("Unknown software version. Please check.")
459459
return 0
460460

461461
def calculate_gaps(det_size, mod_size, gap_size):
@@ -503,8 +503,8 @@ def get_params(hdf5_file):
503503
neXus_root = neXus_tree.root()
504504
neXus_string_tree = iterate_children(neXus_root)
505505
if (len(sys.argv) == 2):
506-
print "Extracting metadata from " + hdf5_file
507-
print "Please modify XDS.INP if these numbers are incorrect.\n"
506+
print("Extracting metadata from " + hdf5_file)
507+
print("Please modify XDS.INP if these numbers are incorrect.\n")
508508
for i in parameters:
509509
if (neXus_string_tree.has_key(i)):
510510
extracted[i] = str(neXus_string_tree[i])
@@ -530,40 +530,40 @@ def calculate_size(n_modules, mod_size, gap_size):
530530
if len(sys.argv) == 2:
531531
# Make sure that XDS.INP does not already exist
532532
if os.path.isfile ("XDS.INP"):
533-
print "\nERROR: XDS.INP exists already. Please rename and rerun script."
533+
print("\nERROR: XDS.INP exists already. Please rename and rerun script.")
534534
else:
535535
# test whether argument 1 is HDF5 file.
536536
# attach ".h5" if necessary
537537
clean_file = isFile(sys.argv[1])
538538
if (clean_file):
539-
print warning()
539+
print(warning())
540540
full_parameters = get_params(clean_file)
541541
for i, v in full_parameters.iteritems():
542542
if (v in zero_values):
543-
print i + " = " + str(v) + " <== WARNING: Should this really be 0?"
543+
print(i + " = " + str(v) + " <== WARNING: Should this really be 0?")
544544
full_parameters[i] = request_parameter(i)
545-
print i + " = " + str(full_parameters[i])
545+
print(i + " = " + str(full_parameters[i]))
546546
elif (v == "NaN") or (v == ""):
547-
print i + " = " + v + " <== ERROR: undefined value."
547+
print(i + " = " + v + " <== ERROR: undefined value.")
548548
full_parameters[i] = request_parameter(i)
549-
print i + " = " + str(full_parameters[i])
549+
print(i + " = " + str(full_parameters[i]))
550550
else:
551-
print i + " = " + str(v)
551+
print(i + " = " + str(v))
552552
para_version = str(full_parameters[software_version])
553553
if version_check(para_version):
554554
param_lines = create_XDS_INP(full_parameters, clean_file)
555555
open("XDS.INP", 'w').writelines(param_lines)
556-
print "\nFile XDS.INP was created successfully."
556+
print("\nFile XDS.INP was created successfully.")
557557
if (int(full_parameters["/entry/instrument/detector/detectorSpecific/nimages"]) == 1):
558-
print "However, there's not much you can do with one image.\n"
558+
print("However, there's not much you can do with one image.\n")
559559
else:
560-
print "Please verify its contents before processing data.\n"
560+
print("Please verify its contents before processing data.\n")
561561
else:
562-
print "\nThe HDF5 file was created with version %s of the detector firmware" % (para_version)
563-
print "This script supports versions 1.5 and up."
564-
print "Please extract metadata with hdfview or h5dump.\n"
562+
print("\nThe HDF5 file was created with version %s of the detector firmware" % (para_version))
563+
print("This script supports versions 1.5 and up.")
564+
print("Please extract metadata with hdfview or h5dump.\n")
565565
else:
566-
print help()
566+
print(help())
567567
elif (len(sys.argv) == 3):
568568
# This assumes the second argument is the rotation range
569569
# The script will run non-interactively
@@ -574,6 +574,6 @@ def calculate_size(n_modules, mod_size, gap_size):
574574
param_lines = create_XDS_INP(full_parameters, sys.argv[1])
575575
open("XDS.INP", 'w').writelines(param_lines)
576576
else:
577-
print help()
577+
print(help())
578578
exit(-1)
579579

adxv_follow

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Pierre Legrand ([email protected])
3+
4+
# kill previous adxv with socket option
5+
function pid_adxv_follow () {
6+
echo $(ps -ef | grep adxv | grep socket | tail -1 | awk '{print $2 }')
7+
}
8+
9+
pid=$(pid_adxv_follow)
10+
while [ ! -z $pid ]; do
11+
kill -9 $pid
12+
pid=$(pid_adxv_follow)
13+
done
14+
15+
export ADXV_SHOW_PIXELS="120000"
16+
# export ADXV_PATTERN="*.h5"
17+
export ADXV_PATTERN="*.*"
18+
export OMP_NUM_THREADS=10
19+
export MARHOME=${prog_dir}
20+
#exec_file=/usr/local/bin/adxv.x86_64Centos5
21+
exec_file=/data/bioxsoft/bin/adxv
22+
23+
if [ $# -gt 0 ]
24+
then
25+
echo "Loading adxv in directory $1"
26+
cd $1
27+
fi
28+
29+
exec $exec_file -slabs 10 -fix_contrast -small_spots -verbose -socket -parallel -rings -socket_no_list_files -no_default_win_pos -no_adxv_beam_center -dectris_kludge -dectris_kludge2 "$@"
30+

adxv_follow_embl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
LOGFILE=$HOME/adxv.log
4+
5+
export OMP_NUM_THREADS=10
6+
export ADXV_PATTERN="*.*"
7+
export ADXV_SHOW_PIXELS="120000"
8+
adxv -parallel -rings -socket_no_list_files -slabs 10 -socket -no_default_win_pos -no_adxv_beam_center -dectris_kludge -dectris_kludge2 | tee -a %LOGFILE | grep --line-buffered -e "Loading" -e "Unknown file type:" -e "read error" -e "No such file " -e "Warning: " -e "is not and file" -e "is not a file" | ncat --broker -l -k 7100 &
9+
10+

0 commit comments

Comments
 (0)