-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl_bnl_compress.py
1957 lines (1853 loc) · 100 KB
/
l_bnl_compress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''l_bnl_compress.py, lossy, but not lossy, compresss,
a script to apply lossy compression to HDF5 MX image files.
usage: l_bnl_compress.py [-h] [-1 FIRST_IMAGE] [-b BIN_RANGE] [-c COMPRESSION] [-d DATA_BLOCK_SIZE] \
[-H HCOMP_SCALE] [-i INFILE] [-J J2K_TARGET_COMPRESSION_RATIO] \
[-l COMPRESSION_LEVEL] [-m OUT_MASTER] [-N LAST_IMAGE] [-o OUT_FILE] \
[-q OUT_SQUASH] [-s SUM_RANGE] [-v]
Bin and sum images from a range
options:
-h, --help show this help message and exit
-1 FIRST_IMAGE, --first_image FIRST_IMAGE
first selected image counting from 1
-b BIN_RANGE, --bin BIN_RANGE
an integer image binning range (1 ...) to apply to each selected image
-c COMPRESSION, --compression COMPRESSION
optional compression, bslz4, bszstd, or bshuf
-d DATA_BLOCK_SIZE, --data_block_size DATA_BLOCK_SIZE
data block size in images for out_file
-H HCOMP_SCALE, --Hcompress HCOMP_SCALE
Hcompress scale compression, immediately followed by decompression
-i INFILE, --infile INFILE
the input hdf5 file to read images from
-J J2K_TARGET_COMPRESSION_RATIO, --J2K J2K_TARGET_COMPRESSION_RATIO
JPEG-2000 target compression ratio, immediately followed by decompression
-l COMPRESSION_LEVEL, --compression_level COMPRESSION_LEVEL
optional compression level for bszstd
-m OUT_MASTER, --out_master OUT_MASTER
the output hdf5 master to which to write metadata, defaults to OUT_FILE_MASTER
if not given, out given as out_file
-N LAST_IMAGE, --last_image LAST_IMAGE
last selected image counting from 1
-o OUT_FILE, --out_file OUT_FILE
the output hdf5 data file out_file_?????? with an .h5 extension are files to which to write images
-q OUT_SQUASH, --out_squash OUT_SQUASH
an optional hdf5 data file out_squash_?????? with an .h5 extension are optional files to which
raw j2k or hcomp files paralleling OUT_FILE are written, defaults to OUT_FILE_SQUASH
if given as out_file
-s SUM_RANGE, --sum SUM_RANGE
an integer image summing range (1 ...) to apply to the selected images
-v, --verbose provide addtional information
-V, --version report the version and build_date
'''
import sys
import os
import argparse
import numpy as np
import skimage as ski
import h5py
import tifffile
from astropy.io import fits
import glymur
import hdf5plugin
import tempfile
import numcodecs
from astropy.io.fits.hdu.compressed._codecs import HCompress1
version = "1.1.0"
version_date = "02Aug24"
xnt=int(1)
def ntstr(xstr):
return str(xstr)
def ntstrdt(str):
return h5py.string_dtype(encoding='utf-8',length=len(str)+xnt)
def conv_pixel_mask(old_mask,bin_range):
''' conv_pixel_mask -- returns a new pixel_mask
array, adjusting for binning
'''
if bin_range < 2 :
return np.asarray(old_mask,dtype='u4')
old_shape=old_mask.shape
if len(old_shape) != 2:
print('l_bnl_compress.py: invalid mask shape for 2D binning')
return None
sy=old_shape[0]
nsy=int(sy+bin_range-1)//bin_range
ymargin=0
if nsy*bin_range > sy:
ymargin=bin_range-(sy%bin_range)
sx=old_shape[1]
nsx=int(sx+bin_range-1)//bin_range
xmargin=0
if nsx*bin_range > sx:
xmargin=bin_range-(sx%bin_range)
if ((xmargin > 0) or (ymargin > 0)):
old_mask_rev=np.pad(np.asarray(old_mask,dtype='u4'),((0,ymargin),(0,xmargin)),\
'constant',constant_values=((0,0),(0,0)))
else:
old_mask_rev=np.asaary(old_mask,dtype='u4')
new_mask=np.zeros((nsy,nsx),dtype='u4')
for iy in range(0,sy,bin_range):
for ix in range(0,sx,bin_range):
for iyy in range(0,bin_range):
for ixx in range(0,bin_range):
if ix+ixx < sx and iy+iyy < sy:
if old_mask_rev[iy+iyy,ix+ixx] != 0:
new_mask[iy//bin_range,ix//bin_range] = new_mask[iy//bin_range,ix//bin_range]| \
old_mask_rev[iy+iyy,ix+ixx]
return new_mask
def conv_image_to_block_offset(img,npb):
''' conv_image_to_block_offset(img,npb)
convert an image number, img, counting from 1,
given the number of images per block, npb,
into a 2-tuple consisting of the block
number, counting from zero, and an image
nuber within that block counting from zero.
'''
nblk=(img-1)//npb
return (nblk,(int(img-1)%int(npb)))
def conv_image_shqpe(old_shape,bin_range):
if len(old_shape) != 2:
print('l_bnl_compress.py: invalid image shape for 2D binning')
return None
sy=old_shape[0]
nsy=int(sy+bin_range-1)//bin_range
ymargin=0
if nsy*bin_range > sy:
ymargin=bin_range-(sy%bin_range)
sx=old_shape[1]
nsx=int(sx+bin_range-1)//bin_range
xmargin=0
if nsx*bin_range > sx:
xmargin=bin_range-(sx%bin_range)
return ((sy+ymargin)//bin_range,(sx+xmargin)//bin_range)
def xfer_axis_attrs(dst,src):
if src != None:
mykeys=src.attrs.keys()
if 'units' in mykeys:
dst.attrs.create('units',ntstr(src.attrs['units'].decode('utf8')),\
dtype=ntstrdt(src.attrs['units'].decode('utf8')))
if 'depends_on' in mykeys:
dst.attrs.create('depends_on',ntstr(src.attrs['depends_on'].decode('utf8')),\
dtype=ntstrdt(src.attrs['depends_on'].decode('utf8')))
if 'transformation_type' in mykeys:
dst.attrs.create('transformation_type',ntstr(src.attrs['transformation_type'].decode('utf8')),\
dtype=ntstrdt(src.attrs['transformation_type'].decode('utf8')))
if 'vector' in mykeys:
dst.attrs.create('vector',src.attrs['vector'],\
dtype=src.attrs['vector'].dtype)
if 'offset' in mykeys:
dst.attrs.create('offset',src.attrs['offset'],\
dtype=src.attrs['offset'].dtype)
def bin(old_image,bin_range,satval):
''' bin(old_image,bin_range,satval)
convert an image in old_image to a returned u2 numpy array by binning
the pixels in old_image in by summing bin_range by bin_range rectanglar
blocks, clipping values between 0 and satval. If bin_range does not divide
the original dimensions exactly, the old_image is padded with zeros.
'''
if bin_range < 2:
return (np.asarray(old_image,dtype='i2')).clip(0,satval)
s=old_image.shape
if len(s) != 2:
print('l_bnl_compress.py: invalid image shape for 2D binning')
return None
sy=s[0]
nsy=int(sy+bin_range-1)//bin_range
ymargin=0
if nsy*bin_range > sy:
ymargin=bin_range-(sy%bin_range)
sx=s[1]
nsx=int(sx+bin_range-1)//bin_range
xmargin=0
if nsx*bin_range > sx:
xmargin=bin_range-(sx%bin_range)
if ((xmargin > 0) or (ymargin > 0)):
new_image=np.clip(np.pad(np.asarray(old_image,dtype='i2'),((0,ymargin),(0,xmargin)),'constant',constant_values=((0,0),(0,0))),0,satval)
else:
new_image=np.clip(np.asarray(old_image,dtype='i2'),0,satval)
new_image=(np.asarray(new_image,dtype='i2')).clip(0,satval)
new_image=np.round(ski.measure.block_reduce(new_image,(bin_range,bin_range),np.sum))
new_image=np.asarray(np.clip(new_image,0,satval),dtype='i2')
return new_image
parser = argparse.ArgumentParser(description='Bin and sum images from a range')
parser.add_argument('-1','--first_image', dest='first_image', type=int,
help= 'first selected image counting from 1')
parser.add_argument('-b','--bin', dest='bin_range', type=int,
help= 'an integer image binning range (1 ...) to apply to each selected image')
parser.add_argument('-c','--compression', dest='compression',
help= 'optional compression, bslz4, bszstd, or bshuf')
parser.add_argument('-d','--data_block_size', dest='data_block_size', type=int,
help= 'data block size in images for out_file')
parser.add_argument('-H','--Hcompress', dest='hcomp_scale', type=int,
help= 'Hcompress scale compression, immediately followed by decompression')
parser.add_argument('-i','--infile',dest='infile',
help= 'the input hdf5 file to read images from')
parser.add_argument('-J','--J2K', dest='j2k_target_compression_ratio', type=int,
help= 'JPEG-2000 target compression ratio, immediately followed by decompression')
parser.add_argument('-l','--compression_level', dest='compression_level', type=int,
help= 'optional compression level for bszstd')
parser.add_argument('-m','--out_master',dest='out_master',
help= 'the output hdf5 master to which to write metadata')
parser.add_argument('-N','--last_image', dest='last_image', type=int,
help= 'last selected image counting from 1')
parser.add_argument('-o','--out_file',dest='out_file',default='out_data',
help= 'the output hdf5 data file out_file_?????? with an .h5 extension are files to which to write images')
parser.add_argument('-q','--out_squash',dest='out_squash',default='out_squash',
help= 'the output hdf5 data file out_squash_?????? with an .h5 extension are optional files to which to write raw j2k or hcomp images')
parser.add_argument('-s','--sum', dest='sum_range', type=int,
help= 'an integer image summing range (1 ...) to apply to the selected images')
parser.add_argument('-v','--verbose',dest='verbose',action='store_true',
help= 'provide addtional information')
parser.add_argument('-V','--version',dest='report_version',action='store_true',
help= 'report version and version_date')
args = vars(parser.parse_args())
#h5py._hl.filters._COMP_FILTERS['blosc'] =32001
#h5py._hl.filters._COMP_FILTERS['lz4'] =32004
#h5py._hl.filters._COMP_FILTERS['bshuf'] =32008
#h5py._hl.filters._COMP_FILTERS['zfp'] =32013
#h5py._hl.filters._COMP_FILTERS['zstd'] =32015
#h5py._hl.filters._COMP_FILTERS['sz'] =32017
#h5py._hl.filters._COMP_FILTERS['fcidecomp']=32018
#h5py._hl.filters._COMP_FILTERS['jpeg'] =32019
#h5py._hl.filters._COMP_FILTERS['sz3'] =32024
#h5py._hl.filters._COMP_FILTERS['blosc2'] =32026
#h5py._hl.filters._COMP_FILTERS['j2k'] =32029
#h5py._hl.filters._COMP_FILTERS['hcomp'] =32030
if args['report_version'] == True:
print('l_bnl_compress-'+version+'-'+version_date)
if args['verbose'] == True:
print(args)
#print(h5py._hl.filters._COMP_FILTERS)
try:
fin = h5py.File(args['infile'], 'r')
except:
print('l_bnl_compress.py: infile not specified')
sys.exit(-1)
try:
top_definition=fin['entry']['definition']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/definition: ', top_definition)
print(' entry/definition[()]: ', top_definition[()])
except:
print('l_bnl_compress.py: entry/definition not found')
top_definition = None
try:
detector=fin['entry']['instrument']['detector']
if args['verbose'] == True:
print('l_bnl_compress.py: detector: ', detector)
except:
print('l_bnl_compress.py: detector not found')
detector = None
try:
description=detector['description']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/description: ', description)
print(' detector/description[()]: ', description[()])
except:
print('l_bnl_compress.py: detector/description not found')
description = None
try:
detector_number=detector['detector_number']
if args['verbose'] == True:
print('l_bnl_compress.py: detector_number: ', detector_number)
print(' detector_number[()]: ', detector_number[()])
except:
print('l_bnl_compress.py: detector/detector_number not found')
detector_number=None
try:
depends_on=detector['depends_on']
if args['verbose'] == True:
print('l_bnl_compress.py: depends_on: ', depends_on)
print(' depends_on[()]: ', depends_on[()])
except:
print('l_bnl_compress.py: detector/depends_on not found')
depends_on=None
try:
bit_depth_image=detector['bit_depth_image']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/bit_depth_image: ', bit_depth_image)
print(' detector/bit_depth_image[()]: ', bit_depth_image[()])
except:
print('l_bnl_compress.py: detector/bit_depth_image not found')
bit_depth_image=None
try:
bit_depth_readout=detector['bit_depth_readout']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/bit_depth_readout: ', bit_depth_readout)
print(' detector/bit_depth_readout[()]: ', bit_depth_readout[()])
except:
print('l_bnl_compress.py: detector/bit_depth_readout not found')
bit_depth_readout = None
try:
thickness=detector['sensor_thickness']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/sensor_thickness: ', thickness)
print(' detector/sensor_thickness[()]: ', thickness[()])
except:
print('l_bnl_compress.py: detector/sensor_thickness not found')
thickness='unknown'
pixel_mask=None
try:
pixel_mask=detector['pixel_mask']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/pixel_mask: ', pixel_mask)
print(' detector/pixel_mask[()]: ', pixel_mask[()])
except:
print('l_bnl_compress.py: detector/pixel_mask not found')
pixel_mask=None
try:
beamx=detector['beam_center_x']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/beam_center_x: ', beamx)
print(' detector/beam_center_x[()]: ', beamx[()])
except:
print('l_bnl_compress.py: detector/beam_center_x not found')
fin.close()
sys.exit(-1)
try:
beamy=detector['beam_center_y']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/beam_center_y: ', beamy)
print(' detector/beam_center_y[()]: ', beamy[()])
except:
print('l_bnl_compress.py: detector/beam_center_y not found')
fin.close()
sys.exit(-1)
try:
count_time=detector['count_time']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/count_time: ', count_time)
print(' detector/count_time[()]: ', count_time[()])
except:
print('l_bnl_compress.py: detector/count_time not found')
fin.close()
sys.exit(-1)
try:
countrate_correction_applied=detector['countrate_correction_applied']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/countrate_correction_applied: ', countrate_correction_applied)
print(' detector/countrate_correction_applied[()]: ', countrate_correction_applied[()])
except:
print('l_bnl_compress.py: detector/countrate_correction_applied not found')
countrate_correction_applied=None
try:
distance=detector['distance']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/distance: ', distance)
print(' detector/distance[()]: ', distance[()])
except:
print('l_bnl_compress.py: detector/detector_distance not found')
try:
distance=detector['detector_distance']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/detector_distance: ', distance)
print(' detector/detector_distance[()]: ', distance[()])
except:
print('l_bnl_compress.py: detector/detector_distance not found')
fin.close()
sys.exit(-1)
try:
frame_time=detector['frame_time']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/frame_time: ', frame_time)
print(' detector/frame_time[()]: ', frame_time[()])
print(' detector/frame_time.attrs.keys(): ',frame_time.attrs.keys())
except:
print('l_bnl_compress.py: detector/frame_time not found')
fin.close()
sys.exit(-1)
satval = 32767
satval_not_found = True
try:
saturation_value = detector['saturation_value']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/saturation_value: ', saturation_value)
print(' detector/saturation_value[()]: ', saturation_value[()])
satval = saturation_value[()]
satval_not_found = False
except:
print('l_bnl_compress.py: detector/saturation_value not found')
saturation_value = None
try:
pixelsizex=detector['x_pixel_size']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/x_pixel_size: ', pixelsizex)
print(' detector/x_pixel_size[()]: ', pixelsizex[()])
except:
print('l_bnl_compress.py: detector/x_pixel_size not found')
fin.close()
sys.exit(-1)
try:
pixelsizey=detector['y_pixel_size']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/y_pixel_size: ', pixelsizey)
print(' detector/y_pixel_size[()]: ', pixelsizey[()])
except:
print('l_bnl_compress.py: detector/y_pixel_size not found')
fin.close()
sys.exit(-1)
try:
detectorSpecific=fin['entry']['instrument']['detector']['detectorSpecific']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific: ', detectorSpecific)
except:
print('l_bnl_compress.py: detectorSpecific not found')
fin.close()
sys.exit(-1)
try:
xpixels=detectorSpecific['x_pixels_in_detector']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/x_pixels_in_detector: ', xpixels)
print(' detectorSpecific/x_pixels_in_detector[()]: ', xpixels[()])
except:
print('l_bnl_compress.py: detectorSpecific/x_pixels_in_detector not found')
fin.close()
sys.exit(-1)
try:
ypixels=detectorSpecific['y_pixels_in_detector']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/y_pixels_in_detector: ', ypixels)
print('l_bnl_compress.py: detectorSpecific/y_pixels_in_detector: ', ypixels[()])
except:
print('l_bnl_compress.py: detectorSpecific/y_pixels_in_detector not found')
fin.close()
sys.exit(-1)
try:
xnimages=detectorSpecific['nimages']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/nimages: ', xnimages)
print(' detectorSpecific/nimages[()]: ', xnimages[()])
except:
print('l_bnl_compress.py: detectorSpecific/nimages not found')
fin.close()
sys.exit(-1)
try:
xntrigger=detectorSpecific['ntrigger']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/ntrigger: ', xntrigger)
print(' detectorSpecific/ntrigger[()]: ', xntrigger[()])
except:
print('l_bnl_compress.py: detectorSpecific/ntrigger not found')
fin.close()
sys.exit(-1)
try:
software_version=detectorSpecific['software_version']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/software_version: ', software_version)
print(' detectorSpecific/software_version[()]: ', software_version[()])
except:
print('l_bnl_compress.py: detectorSpecific/software_version not found')
fin.close()
sys.exit(-1)
try:
countrate_correction_count_cutoff = detectorSpecific['countrate_correction_count_cutoff']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/countrate_correction_count_cutoff: ', countrate_correction_count_cutoff)
print(' detectorSpecific/countrate_correction_count_cutoff[()]: ', countrate_correction_count_cutoff[()])
if satval_not_found:
satval = countrate_correction_count_cutoff[()]
satval_not_found = False
except:
print('l_bnl_compress.py: detectorSpecific/countrate_correction_count_cutoff not found')
countrate_correction_count_cutoff = None
try:
dS_saturation_value = detectorSpecific['saturation_value']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/saturation_value: ', dS_saturation_value)
print(' detectorSpecific/saturation_value[()]: ', dS_saturation_value[()])
if satval_not_found:
satval = dS_saturation_value[()]
satval_not_found = False
except:
print('l_bnl_compress.py: detectorSpecific/saturation_value not found')
dS_saturation_value = None
try:
mod0_countrate_cutoff = detectorSpecific['detectorModule_000']['countrate_correction_count_cutoff']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/detectorModule_000/countrate_correction_count_cutoff: ',mod0_countrate_cutoff)
print(' detectorSpecific/detectorModule_000countrate_correction_count_cutoff[()]: ', mod0_countrate_cutoff[()])
print(' *** use of this dataset is deprecated ***')
if satval_not_found:
satval = mod0_countrate_cutoff[()]
satval_not_found = False
except:
print('l_bnl_compress.py: detectorSpecific/detectorModule_000/countrate_correction_count_cutoff not found')
if satval_not_found:
print('l_bnl_compress.py: ...count_cutoff not found, using 32765')
satval=32765
mod0_countrate_cutoff = None
dS_pixel_mask = None
try:
dS_pixel_mask=detectorSpecific['pixel_mask']
if args['verbose'] == True:
print('l_bnl_compress.py: detectorSpecific/pixel_mask: ', dS_pixel_mask)
print(' detectorSpecific/pixel_mask[()]: ', dS_pixel_mask[()])
except:
print('l_bnl_compress.py: detectorSpecific/pixel_mask not found')
dS_pixel_mask=None
det_gon = None
det_gon_two_theta = None
det_gon_two_theta_end = None
det_gon_two_theta_range_average = None
det_gon_two_theta_range_total = None
try:
det_gon = detector['goniometer']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/goniometer: ', det_gon)
print(' detector/goniometer[()]: ', det_gon[()])
try:
det_gon_two_theta = detector['goniometer']['two_theta']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/goniometer/two_theta: ', det_gon_two_theta)
print(' detector/goniometer/two_theta[()]: ', det_gon_two_theta[()])
except:
print('l_bnl_compress.py: detector/goniometer/two_theta not found')
det_gon_translation = None
try:
det_gon_two_theta_end = detector['goniometer']['two_theta_end']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/goniometer/two_theta_end: ', det_gon_two_theta_end)
print(' detector/goniometer/two_theta_end[()]: ', det_gon_two_theta_end[()])
except:
print('l_bnl_compress.py: detector/goniometer/two_theta_end not found')
det_gon_two_theta_end = None
try:
det_gon_two_theta_range_average = detector['goniometer']['two_theta_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/goniometer/two_theta_range_average: ',\
det_gon_two_theta_range_average)
print(' detector/goniometer/two_theta_range_average[()]: ',\
det_gon_two_theta_range_average[()])
except:
print('l_bnl_compress.py: detector/goniometer/two_theta_range_average not found')
det_gon_range_average = None
try:
det_gon_two_theta_range_total = detector['goniometer']['two_theta_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/goniometer/two_theta_range_total: ',\
det_gon_two_theta_range_total)
print(' detector/goniometer/two_theta_range_total[()]: ',\
det_gon_two_theta_range_total[()])
except:
print('l_bnl_compress.py: detector/goniometer/two_theta_range_total not found')
det_gon_two_theta_range_total = None
except:
print('l_bnl_compress.py: detector/goniometer not found')
det_gon = None
det_nxt = None
det_nxt_transation = None
det_nxt_two_theta = None
det_nxt_two_theta_end = None
det_nxt_two_theta_range_average = None
det_nxt_two_theta_range_total = None
try:
det_nxt = detector['transformations']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/transformations: ', det_nxt)
print(' detector/transformations[()]: ', det_nxt[()])
try:
det_nxt_translation = detector['transformations']['translation']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/transformations/translation: ', det_nxt_translation)
print(' detector/transformations/translation[()]: ', det_nxt_translation[()])
except:
print('l_bnl_compress.py: detector/transformations/translation not found')
det_nxt_translation = None
try:
det_nxt_two_theta = detector['transformations']['two_theta']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/transformations/two_theta: ', det_nxt_two_theta)
print(' detector/transformations/two_theta[()]: ', det_nxt_two_theta[()])
except:
print('l_bnl_compress.py: detector/transformations/two_theta not found')
det_nxt_translation = None
try:
det_nxt_two_theta_end = detector['transformations']['two_theta_end']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/transformations/two_theta_end: ', det_nxt_two_theta_end)
print(' detector/transformations/two_theta_end[()]: ', det_nxt_two_theta_end[()])
except:
print('l_bnl_compress.py: detector/transformations/two_theta_end not found')
det_nxt_two_theta_end = None
try:
det_nxt_two_theta_range_average = detector['transformations']['two_theta_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/transformations/two_theta_range_average: ',\
det_nxt_two_theta_range_average)
print(' detector/transformations/two_theta_range_average[()]: ',\
det_nxt_two_theta_range_average[()])
except:
print('l_bnl_compress.py: detector/transformations/two_theta_range_average not found')
det_nxt_range_average = None
try:
det_nxt_two_theta_range_total = detector['transformations']['two_theta_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: detector/transformations/two_theta_range_total: ',\
det_nxt_two_theta_range_total)
print(' detector/transformations/two_theta_range_total[()]: ',\
det_nxt_two_theta_range_total[()])
except:
print('l_bnl_compress.py: detector/transformations/two_theta_range_total not found')
det_nxt_two_theta_range_total = None
except:
print('l_bnl_compress.py: detector/transformations not found')
det_nxt = None
best_wavelength = None
try:
sample_wavelength=fin['entry']['sample']['beam']['incident_wavelength']
if best_wavelength == None:
best_wavelength = sample_wavelength
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/beam/incident_wavelength: ', sample_wavelength)
print(' entry/sample/beam/incident_wavelength[()]: ', sample_wavelength[()])
except:
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/beam/incident_wavelength not found')
sample_wavelength = None
try:
instrument_wavelength=fin['entry']['instrument']['beam']['wavelength']
if best_wavelength == None:
best_wavelength = instrument_wavelength
if args['verbose'] == True:
print('l_bnl_compress.py: entry/instrument/beam/wavelength: ', instrument_wavelength)
print(' entry/instrument/beam/wavelength[()]: ', instrument_wavelength[()])
except:
if args['verbose'] == True:
print('l_bnl_compress.py: entry/instrument/beam/wavelength not found')
instrument_wavelength = None
try:
monochromater_wavelength=fin['entry']['instrument']['monochromater']['wavelength']
if best_wavelength == None:
best_wavelength = monochromater_wavelength
if args['verbose'] == True:
print('l_bnl_compress.py: entry/instrument/monochromater/wavelength: ', monochromater_wavelength)
print(' entry/instrument/monochromater/wavelength[()]: ', monochromater_wavelength[()])
except:
if args['verbose'] == True:
print('l_bnl_compress.py: entry/instrument/monochromater/wavelength not found')
monochromater_wavelength=None
try:
beam_incident_wavelength=fin['entry']['instrument']['beam']['incident_wavelength']
if best_wavelength == None:
best_wavelength = beam_incident_wavelength
if args['verbose'] == True:
print('l_bnl_compress.py: entry/instrument/beam/incident_wavelength: ', beam_incident_wavelength)
print(' entry/instrument/beam/incident_wavelength[()]: ', beam_incident_wavelength[()])
except:
print('l_bnl_compress.py:entry/instrument/beam/incident_wavelength not found')
beam_incident_wavelength = None
if best_wavelength==None:
print('l_bnl_compress.py: ... wavelength not found')
fin.close()
sys.exit(-1)
# find {chi, kappa, omega, phi, translation} in entry/sample/transformations/*
try:
nxt_chi=fin['entry']['sample']['transformations']['chi']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/chi: ', nxt_chi)
print(' entry/sample/transformations/chi[()]: ', nxt_chi[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/chi not found')
nxt_chi = None
try:
nxt_kappa=fin['entry']['sample']['transformations']['kappa']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/kappa: ', nxt_kappa)
print(' entry/sample/transformations/kappa[()]: ', nxt_kappa[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/kappa not found')
nxt_kappa = None
try:
nxt_omega=fin['entry']['sample']['transformations']['omega']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/omega: ', nxt_omega)
print(' entry/sample/transformations/omega[()]: ', nxt_omega[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/omega not found')
nxt_omega = None
try:
nxt_phi=fin['entry']['sample']['transformations']['phi']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/phi: ', nxt_phi)
print(' entry/sample/transformations/phi[()]: ', nxt_phi[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/phi not found')
nxt_phi = None
try:
nxt_translation=fin['entry']['sample']['transformations']['translation']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/translation: ', nxt_translation)
print(' entry/sample/transformations/translation[()]: ', nxt_translation[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/translation not found')
nxt_translation = None
# find {chi_end, kappa_end, omega_end, phi_end} in entry/sample/transformations/*
try:
nxt_chi_end=fin['entry']['sample']['transformations']['chi_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/chi_end: ', nxt_chi_end)
print(' entry/sample/transformations/chi_end[()]: ', nxt_chi_end[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/chi_end not found')
nxt_chi_end = None
try:
nxt_kappa_end=fin['entry']['sample']['transformations']['kappa_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/kappa_end: ', nxt_kappa_end)
print(' entry/sample/transformations/kappa_end[()]: ', nxt_kappa_end[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/kappa_end not found')
nxt_kappa_end = None
try:
nxt_omega_end=fin['entry']['sample']['transformations']['omega_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/omega_end: ', nxt_omega_end)
print(' entry/sample/transformations/omega_end[()]: ', nxt_omega_end[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/omega_end not found')
nxt_omega_end = None
try:
nxt_phi_end=fin['entry']['sample']['transformations']['phi_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/phi_end: ', nxt_phi_end)
print(' entry/sample/transformations/phi_end[()]: ', nxt_phi_end[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/phi_end not found')
nxt_phi_end = None
# find {chi_range_average, kappa_range_average, omega_range_average, phi_range_average}
# in entry/sample/transformations/*_end
try:
nxt_chi_range_average=fin['entry']['sample']['transformations']['chi_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/chi_range_average: ', \
nxt_chi_range_average)
print(' entry/sample/transformations/chi_range_average[()]: ', \
nxt_chi_range_average[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/chi_range_average not found')
nxt_chi_range_average = None
try:
nxt_kappa_range_average=fin['entry']['sample']['transformations']['kappa_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/kappa_range_average: ', \
nxt_kappa_range_average)
print(' entry/sample/transformations/kappa_range_average[()]: ', \
nxt_kappa_range_average[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/kappa_range_average not found')
nxt_kappa_range_average = None
try:
nxt_omega_range_average=fin['entry']['sample']['transformations']['omega_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/omega_range_average: ', \
nxt_omega_range_average)
print(' entry/sample/transformations/omega_range_average[()]: ', \
nxt_omega_range_average[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/omega_range_average not found')
nxt_omega_range_average = None
try:
nxt_phi_range_average=fin['entry']['sample']['transformations']['phi_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/phi_range_average: ', \
nxt_phi_range_average)
print(' entry/sample/transformations/phi_range_average[()]: ', \
nxt_phi_range_average[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/phi_range_average not found')
nxt_phi_range_average = None
# find {chi_range_total, kappa_range_total, omega_range_total, phi_range_total}
# in entry/sample/transformations/*_range_total
try:
nxt_chi_range_total=fin['entry']['sample']['transformations']['chi_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/chi_range_total: ', \
nxt_chi_range_total)
print(' entry/sample/transformations/chi_range_total[()]: ', \
nxt_chi_range_total[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/chi_range_total not found')
nxt_chi_range_total = None
try:
nxt_kappa_range_total=fin['entry']['sample']['transformations']['kappa_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/kappa_range_total: ', \
nxt_kappa_range_total)
print(' entry/sample/transformations/kappa_range_total[()]: ', \
nxt_kappa_range_total[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/kappa_range_total not found')
nxt_kappa_range_total = None
try:
nxt_omega_range_total=fin['entry']['sample']['transformations']['omega_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/omega_range_total: ', \
nxt_omega_range_total)
print(' entry/sample/transformations/omega_range_total[()]: ', \
nxt_omega_range_total[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/omega_range_total not found')
nxt_omega_range_total = None
try:
nxt_phi_range_total=fin['entry']['sample']['transformations']['phi_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/transformations/phi_range_total: ', \
nxt_phi_range_total)
print(' entry/sample/transformations/phi_range_total[()]: ', \
nxt_phi_range_total[()])
except:
print('l_bnl_compress.py: entry/sample/transformations/phi_range_total not found')
nxt_phi_range_total = None
samp_gon = None
chi = None
chi_end = None
chi_range_average = None
chi_range_total = None
kappa = None
kappa_end = None
kappa_range_average = None
kappa_range_total = None
angles = None
angles_end = None
osc_width = None
osc_total = None
phi = None
phi_end = None
phi_range_average = None
phi_range_total = None
try:
samp_gon = fin['entry']['sample']['goniometer']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/goniometer: ', samp_gon)
print(' entry/sample/goniometer[()]: ', samp_gon[()])
try:
chi=samp_gon['chi']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/chi: ', chi)
print('l_bnl_compress.py: entry/sample/chi[()]: ', chi[()])
except:
print('l_bnl_compress.py: entry/sample/gonimeter/chi not found')
chi=None
try:
chi_end=samp_gon['chi_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/chi_end: ', chi_end)
print('l_bnl_compress.py: entry/sample/chi_end[()]: ', chi_end[()])
except:
print('l_bnl_compress.py: entry/sample/gonimeter/chi_end not found')
chi_end=None
try:
chi_range_average = samp_gon['chi_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/goniometer/chi_range_average: ', \
chi_range_average)
print(' entry/sample/goniometer/chi_range_average[()]: ', \
chi_range_average[()])
except:
print('l_bnl_compress.py: entry/sample/goniometer/chi_range_average not found')
chi_range_average=None
try:
chi_range_total = samp_gon['chi_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/goniometer/chi_range_total: ', \
chi_range_total)
print(' entry/sample/goniometer/chi_range_total[()]: ', \
chi_range_total[()])
except:
print('l_bnl_compress.py: entry/sample/goniometer/chi_range_total not found')
chi_range_total=None
try:
kappa=samp_gon['kappa']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/kappa: ', kappa)
print('l_bnl_compress.py: entry/sample/kappa[()]: ', kappa[()])
except:
print('l_bnl_compress.py: entry/sample/gonimeter/kappa not found')
kappa=None
try:
kappa_end=samp_gon['kappa_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/kappa_end: ', kappa_end)
print('l_bnl_compress.py: entry/sample/kappa_end[()]: ', kappa_end[()])
except:
print('l_bnl_compress.py: entry/sample/gonimeter/kappa_end not found')
kappa_end=None
try:
kappa_range_average = samp_gon['kappa_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/goniometer/kappa_range_average: ', \
kappa_range_average)
print(' entry/sample/goniometer/kappa_range_average[()]: ', \
kappa_range_average[()])
except:
print('l_bnl_compress.py: entry/sample/goniometer/kappa_range_average not found')
kappa_range_average=None
try:
kappa_range_total = samp_gon['kappa_range_total']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/goniometer/kappa_range_total: ', \
kappa_range_total)
print(' entry/sample/goniometer/kappa_range_total[()]: ', \
kappa_range_total[()])
except:
print('l_bnl_compress.py: entry/sample/goniometer/kappa_range_total not found')
kappa_range_total=None
try:
angles=samp_gon['omega']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/omega: ', angles)
print('l_bnl_compress.py: entry/sample/omega[()]: ', angles[()])
except:
print('l_bnl_compress.py: entry/sample/gonimeter/omega not found')
angles=None
try:
angles_end=samp_gon['omega_end']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/omega_end: ', angles_end)
print('l_bnl_compress.py: entry/sample/omega_end[()]: ', angles_end[()])
except:
print('l_bnl_compress.py: entry/sample/gonimeter/omega_end not found')
angles_end=None
try:
osc_width = samp_gon['omega_range_average']
if args['verbose'] == True:
print('l_bnl_compress.py: entry/sample/goniometer/omega_range_average: ', osc_width)
print(' entry/sample/goniometer/omega_range_average[()]: ', osc_width[()])