Skip to content
Snippets Groups Projects
Commit 2a045d6e authored by Hampus Wikmark Kreuger's avatar Hampus Wikmark Kreuger
Browse files

Merge branch 'p2866_updates_darksubtraction_jhns' into 'p2866_updates_darksubtraction'

Modified and commented dark_load

See merge request !193
parents a2ffa1b9 96e004b0
No related branches found
No related tags found
4 merge requests!195Commented centroid,!194Modified and commented dark_load,!193Modified and commented dark_load,!188P2866 updates
......@@ -328,30 +328,56 @@ class hRIXS:
return data
def load_dark(self, runNB, proposal=None, use_dark=True, mask=True,
mask_threshold=None):
#*************************************************************
# Loads a dark image and assigns it to the hRIXS instance
# In addition sets attributes whether or not
# - hot pixels are identified and masked out
# - the dark image is to be used in background subtraction
# In addition a threshold value for hot pixel mask generation
# can be given.
#*************************************************************
if mask_threshold == None:
mask_threshold = self.DARK_MASK_THRESHOLD
try:
# Checks to see if runNB can be iterated over (is list-like)
#*************************************************************
# If given a list of runs, iterate over them.
# Otherwise read one. Give an exception if neither is the case.
#*************************************************************
if type(runNB) == type([]):
data_list = []
for run in runNB:
data_list.append(self.from_run(run, proposal))
data = xr.concat(data_list, dim='trainId')
except TypeError:
# If runNB cannot be iterated over, we assume it's a single run
data = xr.concat(data_list, dim='trainId')
elif type(runNB) == type(1):
data = self.from_run(runNB, proposal)
else:
raise Exception('load_dark() expects a list of indeces or an integer.')
#*************************************************************
# Store the dark image (mean over aqs.) in two formats
#*************************************************************
self.dark_image = data['hRIXS_det'].mean(dim='trainId')
self.dark_im_array = self.dark_image.to_numpy()
#*************************************************************
# Set a flag whether the dark image is to be used later
#*************************************************************
if use_dark:
self.USE_DARK = True
#*************************************************************
# If hot/dead pixel masking is requested, find the mask and
# set a flag in the instance. Set the masked dark values to
# mean intensity.
#*************************************************************
if mask:
dark_avg = np.mean(self.dark_im_array[self.MASK_AVG_Y,
self.MASK_AVG_X], (0, 1))
self.dark_mask = np.abs(self.dark_im_array - dark_avg) > mask_threshold
self.dark_mask = self.dark_im_array > dark_avg + mask_threshold
self.dark_im_array_m = np.array(self.dark_im_array)
self.dark_im_array_m[self.dark_mask] = dark_avg
self.USE_DARK_MASK = True
return
def find_curvature(self, runNB, proposal=None, plot=True, args=None, **kwargs):
data = self.from_run(runNB, proposal)
......@@ -406,12 +432,18 @@ class hRIXS:
data = data.assign_coords(
energy=np.linspace(self.Y_RANGE.start, self.Y_RANGE.stop, bins)
* self.ENERGY_SLOPE + self.ENERGY_INTERCEPT)
#**********************************************
# If hits were requested, assign them to data
#**********************************************
if return_hits:
return data.assign(hits=(("trainId"), hits),
xhits=(("trainId"), hit_x),
yhits=(("trainId"), hit_y))
else:
return data.assign(spectrum=(("trainId", "energy"), ret))
data = data.assign(hits=(("trainId"), hits),
xhits=(("trainId"), hit_x),
yhits=(("trainId"), hit_y))
#**********************************************
# Always assign the spectrum to data
#**********************************************
data = data.assign(spectrum=(("trainId", "energy"), ret))
return data
def integrate(self, data):
bins = self.Y_RANGE.stop - self.Y_RANGE.start
......
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