|
1 | | -#============================================================================== |
2 | | -# File: |
3 | | -# Multiframes_to_EDF.nxe |
4 | | -# |
5 | | -# @desc Produce a EDF (ESRF Data Format) file for each image captured in 'multiframe' CCD camera mode |
6 | | -# |
7 | | -# @param dir directory 'Target directory for extracted data' $(_data_extraction_folder_) |
8 | | -# @param header_length number 'EDF file header length' 4096 |
9 | | -# |
10 | | -# Usage: |
11 | | -# nxextractor -t Multiframes_to_EDF.nxe -D dir=<destination directory> [-m <mode>] [-w uid:gid] <NeXus source file> |
12 | | -# |
13 | | -# $Author: poirier $ |
14 | | -# |
15 | | -# $Revision: 1.7 $ |
16 | | -#============================================================================== |
17 | | -
|
18 | | -# output to console |
19 | | -> |
20 | | -"%s\n" $(_FILE_NAME_) |
21 | | -
|
22 | | -# loop other all entries |
23 | | -# variable $(entry) will contain current entry path (ex: '/entry1') |
24 | | -# variable $(entry_name) will contain curren tentry name (ex: 'entry1') |
25 | | -@( entry = [nxs:/<NXentry>/] |
26 | | -
|
27 | | - # loop other range [0, n[ |
28 | | - @( i = 0, nxs:$(entry)<NXentry>/<NXinstrument>/<NXdetector>/Frames/data |
29 | | -
|
30 | | - # define a new variable |
31 | | - % image_grp = $(entry)<NXentry>/image#$(i)<NXdata> |
32 | | - |
33 | | - # define image name for edf file name using a data bloc named 'image_name' |
34 | | - ( image_name |
35 | | - "im_%02d" $(i) |
36 | | - ) |
37 | | - |
38 | | - # define variable |
39 | | - % image_full_name = $(entry_name)_$(image_name) |
40 | | -
|
41 | | - # Test data dimensions |
42 | | - ?( nxs:$(image_grp)/<SDS-signal>._rank_ = 2 |
43 | | -
|
44 | | - # Define data bloc for image data |
45 | | - ( binarydata |
46 | | - # output into this bloc as 2 bytes unsigned integers |
47 | | - 'ui2' nxs:$(image_grp)/<SDS-signal> |
48 | | - ) |
49 | | - |
50 | | - # Define data bloc in memory for EDF header base content |
51 | | - ( edf_header |
52 | | - |
53 | | - "EDF_DataBlockID = 1.Image.Psd ;\n" |
54 | | - "EDF_BinarySize = %s ;\n" $(binarydata_size) |
55 | | - "EDF_HeaderSize = %s ;\n" $(header_length) |
56 | | - "ByteOrder = LowByteFirst ;\n" |
57 | | - "DataType = UnsignedShort ;\n" |
58 | | - "Dim_1 = %d ;\n" nxs:$(image_grp)/data._size_(1) |
59 | | - "Dim_2 = %d ;\n" nxs:$(image_grp)/data._size_(2) |
60 | | - "Title = %s ;\n" $(image_full_name) |
61 | | - "Time = ;\n" |
62 | | - "HeaderID = EH:000001:000000:000000 ;\n" |
63 | | - "Compression = None ;\n" |
64 | | - "Image = 1 ;\n" |
65 | | - "Size = %s ;\n" $(binarydata_size) |
66 | | - ) |
67 | | -
|
68 | | - # Define data bloc for specific metadata |
69 | | - ( specific_metadata |
70 | | - # loop other all NXintensity_monitor groups inside first (and unique) NXinstrument group |
71 | | - @( mi_channel = [nxs:$(entry)/<NXinstrument>/<NXintensity_monitor>] |
72 | | - "Intensity(%s) = %g ;\n" $(mi_channel_name), nxs:$(mi_channel)/intensity[i] |
73 | | - "Gain(%s) = %g ;\n" $(mi_channel_name), nxs:$(mi_channel)/Gain/data |
74 | | - "Offset(%s) = %g ;\n" $(mi_channel_name), nxs:$(mi_channel)/offset/data |
75 | | - @) |
76 | | - |
77 | | - "Machine_Current = %? ;\n" nxs:$(entry)/<NXinstrument>/<NXsource>/current |
78 | | - "Monochromator_energy = %?%s ;\n" nxs:$(entry)/<NXinstrument>/<NXmonochromator>/energy, nxs:$(entry)/<NXinstrument>/<NXmonochromator>/energy.units |
79 | | - "Distance_sample-detector = %?mm ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/distance |
80 | | - |
81 | | - # aviex parameters |
82 | | - "_diffrn_detector.detector = %s ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/type |
83 | | - "Exposure_time = %?%s ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/Exposure/data, nxs:$(entry)/<NXinstrument>/<NXdetector>/Exposure/data.units |
84 | | - "Shutter_close_delay = %?%s ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/ShutterCloseDelay/data, nxs:$(entry)/<NXinstrument>/<NXdetector>/ShutterCloseDelay/data.units |
85 | | - "Xbin = %? ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/Xbin/data |
86 | | - "Ybin = %? ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/Ybin/data |
87 | | - |
88 | | - # motors |
89 | | - @( motor_data = [nxs:$(entry)/<NXinstrument>/<NXpositioner>] |
90 | | - "Position(%s) = %g ;\n" $(motor_data_name), nxs:$(motor_data)/raw_value |
91 | | - @) |
92 | | - ) |
93 | | -
|
94 | | - # Define a data bloc with a fixed size given by 'header_length' parameter |
95 | | - # the default value for 'header_length' (4096) is given in the header of this file |
96 | | - # the lines begining with '@param' are interpreted by the parsor |
97 | | - ( header $(header_length) |
98 | | -
|
99 | | - "{\n" |
100 | | - 'b' edf_header |
101 | | - 'b' specific_metadata |
102 | | - # padding pattern (default is a 80 blank spaces string terminating with a CR) |
103 | | - ... |
104 | | - "\n}\n" |
105 | | - ) |
106 | | -
|
107 | | - # Define output as binary file |
108 | | - b> $(dir)/$(image_full_name).edf |
109 | | -
|
110 | | - # Output header bloc as binary data |
111 | | - 'b' header |
112 | | - # Output data bloc as binary data |
113 | | - 'b' binarydata |
114 | | - |
115 | | - ?) |
116 | | - |
117 | | - @) |
118 | | - |
119 | | -@) |
| 1 | +#============================================================================== |
| 2 | +# File: |
| 3 | +# Multiframes_to_EDF.nxe |
| 4 | +# |
| 5 | +# @desc Produce a EDF (ESRF Data Format) file for each image captured in 'multiframe' CCD camera mode |
| 6 | +# |
| 7 | +# @param dir directory 'Target directory for extracted data' $(_data_extraction_folder_) |
| 8 | +# @param header_length number 'EDF file header length' 4096 |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# nxextractor -t Multiframes_to_EDF.nxe -D dir=<destination directory> [-m <mode>] [-w uid:gid] <NeXus source file> |
| 12 | +# |
| 13 | +# $Author: poirier $ |
| 14 | +# |
| 15 | +# $Revision: 1.7 $ |
| 16 | +#============================================================================== |
| 17 | + |
| 18 | +# output to console |
| 19 | +> |
| 20 | +"%s\n" $(_FILE_NAME_) |
| 21 | + |
| 22 | +# loop other all entries |
| 23 | +# variable $(entry) will contain current entry path (ex: '/entry1') |
| 24 | +# variable $(entry_name) will contain curren tentry name (ex: 'entry1') |
| 25 | +@( entry = [nxs:/<NXentry>/] |
| 26 | + |
| 27 | + # loop other range [0, n[ |
| 28 | + @( i = 0, nxs:$(entry)<NXentry>/<NXinstrument>/<NXdetector>/Frames/data |
| 29 | + |
| 30 | + # define a new variable |
| 31 | + % image_grp = $(entry)<NXentry>/image#$(i)<NXdata> |
| 32 | + |
| 33 | + # define image name for edf file name using a data bloc named 'image_name' |
| 34 | + ( image_name |
| 35 | + "im_%02d" $(i) |
| 36 | + ) |
| 37 | + |
| 38 | + # define variable |
| 39 | + % image_full_name = $(entry_name)_$(image_name) |
| 40 | + |
| 41 | + # Test data dimensions |
| 42 | + ?( nxs:$(image_grp)/<SDS-signal>._rank_ = 2 |
| 43 | + |
| 44 | + # Define data bloc for image data |
| 45 | + ( binarydata |
| 46 | + # output into this bloc as 2 bytes unsigned integers |
| 47 | + 'ui2' nxs:$(image_grp)/<SDS-signal> |
| 48 | + ) |
| 49 | + |
| 50 | + # Define data bloc in memory for EDF header base content |
| 51 | + ( edf_header |
| 52 | + |
| 53 | + "EDF_DataBlockID = 1.Image.Psd ;\n" |
| 54 | + "EDF_BinarySize = %s ;\n" $(binarydata_size) |
| 55 | + "EDF_HeaderSize = %s ;\n" $(header_length) |
| 56 | + "ByteOrder = LowByteFirst ;\n" |
| 57 | + "DataType = UnsignedShort ;\n" |
| 58 | + "Dim_1 = %d ;\n" nxs:$(image_grp)/data._size_(1) |
| 59 | + "Dim_2 = %d ;\n" nxs:$(image_grp)/data._size_(2) |
| 60 | + "Title = %s ;\n" $(image_full_name) |
| 61 | + "Time = ;\n" |
| 62 | + "HeaderID = EH:000001:000000:000000 ;\n" |
| 63 | + "Compression = None ;\n" |
| 64 | + "Image = 1 ;\n" |
| 65 | + "Size = %s ;\n" $(binarydata_size) |
| 66 | + ) |
| 67 | + |
| 68 | + # Define data bloc for specific metadata |
| 69 | + ( specific_metadata |
| 70 | + # loop other all NXintensity_monitor groups inside first (and unique) NXinstrument group |
| 71 | + @( mi_channel = [nxs:$(entry)/<NXinstrument>/<NXintensity_monitor>] |
| 72 | + "Intensity(%s) = %g ;\n" $(mi_channel_name), nxs:$(mi_channel)/intensity[i] |
| 73 | + "Gain(%s) = %g ;\n" $(mi_channel_name), nxs:$(mi_channel)/Gain/data |
| 74 | + "Offset(%s) = %g ;\n" $(mi_channel_name), nxs:$(mi_channel)/offset/data |
| 75 | + @) |
| 76 | + |
| 77 | + "Machine_Current = %? ;\n" nxs:$(entry)/<NXinstrument>/<NXsource>/current |
| 78 | + "Monochromator_energy = %?%s ;\n" nxs:$(entry)/<NXinstrument>/<NXmonochromator>/energy, nxs:$(entry)/<NXinstrument>/<NXmonochromator>/energy.units |
| 79 | + "Distance_sample-detector = %?mm ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/distance |
| 80 | + |
| 81 | + # aviex parameters |
| 82 | + "_diffrn_detector.detector = %s ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/type |
| 83 | + "Exposure_time = %?%s ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/Exposure/data, nxs:$(entry)/<NXinstrument>/<NXdetector>/Exposure/data.units |
| 84 | + "Shutter_close_delay = %?%s ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/ShutterCloseDelay/data, nxs:$(entry)/<NXinstrument>/<NXdetector>/ShutterCloseDelay/data.units |
| 85 | + "Xbin = %? ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/Xbin/data |
| 86 | + "Ybin = %? ;\n" nxs:$(entry)/<NXinstrument>/<NXdetector>/Ybin/data |
| 87 | + |
| 88 | + # motors |
| 89 | + @( motor_data = [nxs:$(entry)/<NXinstrument>/<NXpositioner>] |
| 90 | + "Position(%s) = %g ;\n" $(motor_data_name), nxs:$(motor_data)/raw_value |
| 91 | + @) |
| 92 | + ) |
| 93 | + |
| 94 | + # Define a data bloc with a fixed size given by 'header_length' parameter |
| 95 | + # the default value for 'header_length' (4096) is given in the header of this file |
| 96 | + # the lines begining with '@param' are interpreted by the parsor |
| 97 | + ( header $(header_length) |
| 98 | + |
| 99 | + "{\n" |
| 100 | + 'b' edf_header |
| 101 | + 'b' specific_metadata |
| 102 | + # padding pattern (default is a 80 blank spaces string terminating with a CR) |
| 103 | + ... |
| 104 | + "\n}\n" |
| 105 | + ) |
| 106 | + |
| 107 | + # Define output as binary file |
| 108 | + b> $(dir)/$(image_full_name).edf |
| 109 | + |
| 110 | + # Output header bloc as binary data |
| 111 | + 'b' header |
| 112 | + # Output data bloc as binary data |
| 113 | + 'b' binarydata |
| 114 | + |
| 115 | + ?) |
| 116 | + |
| 117 | + @) |
| 118 | + |
| 119 | +@) |
0 commit comments