Skip to content
Snippets Groups Projects
Commit c7fb9eed authored by Loïc Le Guyader's avatar Loïc Le Guyader
Browse files

discard DSSC1module saturated shots

parent c8d0095a
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ class DSSC1module: ...@@ -55,6 +55,7 @@ class DSSC1module:
self.max_fraction_memory = 0.8 self.max_fraction_memory = 0.8
self.Nworker = 10 self.Nworker = 10
self.rois = None self.rois = None
self.maxSaturatedPixel = 1
def open_run(self, run_nr, t0=0.0): def open_run(self, run_nr, t0=0.0):
""" Open a run with karabo-data and prepare the virtual dataset for multiprocessing """ Open a run with karabo-data and prepare the virtual dataset for multiprocessing
...@@ -98,7 +99,7 @@ class DSSC1module: ...@@ -98,7 +99,7 @@ class DSSC1module:
print(f'Loading mono nrj data') print(f'Loading mono nrj data')
self.nrj = self.run.get_array(tb.mnemonics['nrj']['source'], self.nrj = self.run.get_array(tb.mnemonics['nrj']['source'],
tb.mnemonics['nrj']['key']) tb.mnemonics['nrj']['key'])
print(f'Loading daly line data') print(f'Loading delay line data')
try: try:
self.delay_mm = self.run.get_array(tb.mnemonics['PP800_DelayLine']['source'], self.delay_mm = self.run.get_array(tb.mnemonics['PP800_DelayLine']['source'],
tb.mnemonics['PP800_DelayLine']['key']) tb.mnemonics['PP800_DelayLine']['key'])
...@@ -157,7 +158,8 @@ class DSSC1module: ...@@ -157,7 +158,8 @@ class DSSC1module:
Nworker=self.Nworker, Nworker=self.Nworker,
dark_data=dark, dark_data=dark,
rois=rois, rois=rois,
mask=mask mask=mask,
maxSaturatedPixel=self.maxSaturatedPixel
)) ))
timestamp = strftime('%X') timestamp = strftime('%X')
...@@ -337,6 +339,7 @@ def process_one_module(job): ...@@ -337,6 +339,7 @@ def process_one_module(job):
rois = job['rois'] rois = job['rois']
mask = job['mask'] mask = job['mask']
h5fname = job['h5fname'] h5fname = job['h5fname']
maxSaturatedPixel = job['maxSaturatedPixel']
image_path = f"INSTRUMENT/SCS_DET_DSSC1M-1/DET/{module}CH0:xtdf/image/data" image_path = f"INSTRUMENT/SCS_DET_DSSC1M-1/DET/{module}CH0:xtdf/image/data"
npulse_path = f"INDEX/SCS_DET_DSSC1M-1/DET/{module}CH0:xtdf/image/count" npulse_path = f"INDEX/SCS_DET_DSSC1M-1/DET/{module}CH0:xtdf/image/count"
...@@ -388,9 +391,32 @@ def process_one_module(job): ...@@ -388,9 +391,32 @@ def process_one_module(job):
if rois is not None: if rois is not None:
temp2 = temp.where(mask) temp2 = temp.where(mask)
for k,v in rois.items(): for k,v in rois.items():
val = temp2.isel({'x':slice(v['x'][0], v['x'][1]), bkg = dark_data.isel({'x':slice(v['x'][0], v['x'][1]),
'y':slice(v['y'][0], v['y'][1])}).sum(dim=['x','y']) 'y':slice(v['y'][0], v['y'][1])})
module_data[k] = val
im = data.isel({'x':slice(v['x'][0], v['x'][1]),
'y':slice(v['y'][0], v['y'][1])})
smask = mask.isel({'x':slice(v['x'][0], v['x'][1]),
'y':slice(v['y'][0], v['y'][1])})
im = im.where(smask)
cim = im - bkg.where(smask)
val = cim.sum(dim=['x','y'])
tokeep = (im>254).sum(dim=['x', 'y']) < maxSaturatedPixel
tokeep = tokeep.assign_coords(pulseId = val.coords['pulseId'].values)
todrop = 1-tokeep
Ndropped = todrop.sum().values
percent_dropped = 100*Ndropped/(n_trains * fpt)
print(f'Dropped: {Ndropped}, i.e. {percent_dropped:.2f}%')
gval = val.where(tokeep, np.nan)
module_data[k] = gval
module_data['dark_corrected_data'] += temp.sum(dim='trainId') module_data['dark_corrected_data'] += temp.sum(dim='trainId')
module_data['std_data'] += (temp**2).sum(dim='trainId') module_data['std_data'] += (temp**2).sum(dim='trainId')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment