11
11
import numpy as np
12
12
import dask .array as da
13
13
14
+
14
15
class SST1RSoXSLoader (FileLoader ):
15
16
'''
16
17
Loader for TIFF files from NSLS-II SST1 RSoXS instrument
@@ -29,7 +30,6 @@ def __init__(self,corr_mode=None,user_corr_func=None,dark_pedestal=100,exposure_
29
30
dark_pedestal (numeric): value to subtract(/add, if negative) to the whole image. this should match the instrument setting for suitcased tiffs, typically 100.
30
31
exposure_offset (numeric): value to add to the exposure time. Measured at 2ms with the piezo shutter in Dec 2019 by Jacob Thelen, NIST
31
32
constant_md (dict): values to insert into every metadata load.
32
- use_chunked_loading (bool): flag to use chunked loading with dask or not.
33
33
'''
34
34
35
35
if corr_mode == None :
@@ -39,13 +39,14 @@ def __init__(self,corr_mode=None,user_corr_func=None,dark_pedestal=100,exposure_
39
39
else :
40
40
self .corr_mode = corr_mode
41
41
42
+
42
43
self .constant_md = constant_md
44
+
43
45
self .dark_pedestal = dark_pedestal
44
46
self .user_corr_func = user_corr_func
45
47
self .exposure_offset = exposure_offset
46
48
self .use_chunked_loading = use_chunked_loading
47
49
# self.darks = {}
48
-
49
50
# def loadFileSeries(self,basepath):
50
51
# try:
51
52
# flist = list(basepath.glob('*primary*.tiff'))
@@ -61,6 +62,8 @@ def __init__(self,corr_mode=None,user_corr_func=None,dark_pedestal=100,exposure_
61
62
#
62
63
# return out
63
64
65
+
66
+
64
67
def loadSingleImage (self ,filepath ,coords = None , return_q = False ,image_slice = None ,use_cached_md = False ,** kwargs ):
65
68
'''
66
69
HELPER FUNCTION that loads a single image and returns an xarray with either pix_x / pix_y dimensions (if return_q == False) or qx / qy (if return_q == True)
@@ -79,12 +82,11 @@ def loadSingleImage(self,filepath,coords=None, return_q=False,image_slice=None,u
79
82
raise NotImplementedError ('Image slicing is not supported for SST1' )
80
83
if use_cached_md != False :
81
84
raise NotImplementedError ('Caching of metadata is not supported for SST1' )
82
-
85
+
83
86
img = np .array (Image .open (filepath ))
84
87
85
88
if self .use_chunked_loading :
86
89
img = da .from_array (img , chunks = 'auto' )
87
-
88
90
89
91
headerdict = self .loadMd (filepath )
90
92
# two steps in this pre-processing stage:
@@ -117,7 +119,6 @@ def loadSingleImage(self,filepath,coords=None, return_q=False,image_slice=None,u
117
119
# # step 2: dark subtraction
118
120
# this is already done in the suitcase, but we offer the option to add/subtract a pedestal.
119
121
image_data = (img - self .dark_pedestal )/ corr
120
- image_data = img
121
122
if return_q :
122
123
qpx = 2 * np .pi * 60e-6 / (headerdict ['sdd' ]/ 1000 )/ (headerdict ['wavelength' ]* 1e10 )
123
124
qx = (np .arange (1 ,img .size [0 ]+ 1 )- headerdict ['beamcenter_y' ])* qpx
@@ -130,10 +131,19 @@ def loadSingleImage(self,filepath,coords=None, return_q=False,image_slice=None,u
130
131
131
132
def read_json (self ,jsonfile ):
132
133
json_dict = {}
133
- with open (jsonfile ) as f :
134
- data = json .load (f )
135
- meas_time = datetime .datetime .fromtimestamp (data [1 ]['time' ])
136
- json_dict ['sample_name' ] = data [1 ]['sample_name' ]
134
+
135
+ # Try / except statment to be compatible with local rsoxs data before
136
+ # and after SST1 cycle 2 2023
137
+ try : # For earlier cyles
138
+ with open (jsonfile ) as f :
139
+ data = json .load (f )
140
+ meas_time = datetime .datetime .fromtimestamp (data [1 ]['time' ])
141
+ except KeyError : # For later cycles (confirmed working for cycle 2 2023)
142
+ with open (jsonfile ) as f :
143
+ data = [0 , json .load (f )] # Quick fix to load the json in a list
144
+ meas_time = datetime .datetime .fromtimestamp (data [1 ]['time' ])
145
+
146
+ json_dict ['sample_name' ] = data [1 ]['sample_name' ]
137
147
if data [1 ]['RSoXS_Main_DET' ] == 'SAXS' :
138
148
json_dict ['rsoxs_config' ] = 'saxs'
139
149
# discrepency between what is in .json and actual
@@ -155,7 +165,7 @@ def read_json(self,jsonfile):
155
165
json_dict ['beamcenter_y' ] = data [1 ]['RSoXS_SAXS_BCY' ]
156
166
json_dict ['sdd' ] = data [1 ]['RSoXS_SAXS_SDD' ]
157
167
158
- elif data [1 ]['RSoXS_Main_DET' ] == 'WAXS' :
168
+ elif ( data [1 ]['RSoXS_Main_DET' ] == 'WAXS' ) | ( data [ 1 ][ 'RSoXS_Main_DET' ] == 'waxs_det' ): # additional name for for cycle 2 2023
159
169
json_dict ['rsoxs_config' ] = 'waxs'
160
170
if (meas_time > datetime .datetime (2020 ,11 ,16 )) and (meas_time < datetime .datetime (2021 ,1 ,15 )):
161
171
json_dict ['beamcenter_x' ] = 400.46
@@ -172,7 +182,7 @@ def read_json(self,jsonfile):
172
182
json_dict ['sdd' ] = data [1 ]['RSoXS_WAXS_SDD' ]
173
183
174
184
else :
175
- json_dict ['rsoxs_config' ] == 'unknown'
185
+ json_dict ['rsoxs_config' ] = 'unknown'
176
186
warnings .warn ('RSoXS_Config is neither SAXS or WAXS. Check json file' ,stacklevel = 2 )
177
187
178
188
if json_dict ['sdd' ] == None :
@@ -252,9 +262,15 @@ def loadMd(self,filepath):
252
262
else :
253
263
cwd = pathlib .Path (dirPath )
254
264
255
- json_fname = list (cwd .glob ('*.jsonl' ))
256
- json_dict = self .read_json (json_fname [0 ])
257
-
265
+ # Another try/except statement to be compatible with local data pre and
266
+ # post SST1 cycle 2 2023
267
+ try : # For earlier data
268
+ json_fname = list (cwd .glob ('*.jsonl' ))
269
+ json_dict = self .read_json (json_fname [0 ])
270
+ except IndexError : # For later data (works for cycle 2 2023)
271
+ json_fname = list (cwd .glob ('*.json' )) # Changed '*.jsonl' to '*.json'
272
+ json_dict = self .read_json (json_fname [0 ])
273
+
258
274
baseline_fname = list (cwd .glob ('*baseline.csv' ))
259
275
baseline_dict = self .read_baseline (baseline_fname [0 ])
260
276
0 commit comments