Skip to content
Snippets Groups Projects
Commit fdd0338d authored by David Hammer's avatar David Hammer
Browse files

Formatting + minor typos

parent 80de4713
No related branches found
No related tags found
2 merge requests!451Feat/agipd fixed gain correction,!438Feat/agipd add fixed gain mode to dark notebook
...@@ -15,8 +15,7 @@ from cal_tools.cython import agipdalgs as calgs ...@@ -15,8 +15,7 @@ from cal_tools.cython import agipdalgs as calgs
def get_num_cells(fname, loc, module): def get_num_cells(fname, loc, module):
with h5py.File(fname, "r") as f: with h5py.File(fname, "r") as f:
cells = \ cells = f[f"INSTRUMENT/{loc}/DET/{module}CH0:xtdf/image/cellId"][()]
f[f"INSTRUMENT/{loc}/DET/{module}CH0:xtdf/image/cellId"][()]
if cells.shape[0] == 0: if cells.shape[0] == 0:
return None return None
maxcell = np.max(cells) maxcell = np.max(cells)
...@@ -88,7 +87,7 @@ def get_gain_setting(fname: str, h5path_ctrl: str) -> int: ...@@ -88,7 +87,7 @@ def get_gain_setting(fname: str, h5path_ctrl: str) -> int:
gain-setting 1: setupr@dark=8, setupr@slopespc=40 gain-setting 1: setupr@dark=8, setupr@slopespc=40
gain-setting 0: setupr@dark=0, setupr@slopespc=32 gain-setting 0: setupr@dark=0, setupr@slopespc=32
patternTypeIndex 1: High-gian patternTypeIndex 1: High-gain
patternTypeIndex 2: Medium-gain patternTypeIndex 2: Medium-gain
patternTypeIndex 3: Low-gain patternTypeIndex 3: Low-gain
patternTypeIndex 4: SlopesPC patternTypeIndex 4: SlopesPC
...@@ -187,9 +186,7 @@ class AgipdCorrections: ...@@ -187,9 +186,7 @@ class AgipdCorrections:
const_yaml = metadata["retrieved-constants"] const_yaml = metadata["retrieved-constants"]
for mod in modules: for mod in modules:
qm = f"Q{mod // 4 + 1}M{mod % 4 + 1}" agipd_corr.initialize_from_yaml(karabo_da, const_yaml, mod)
agipd_corr.initialize_from_yaml(karabo_da,
const_yaml, mod)
data_shape = (n_images_max, 512, 128) data_shape = (n_images_max, 512, 128)
agipd_corr.allocate_images(data_shape, n_cores_files) agipd_corr.allocate_images(data_shape, n_cores_files)
...@@ -315,8 +312,7 @@ class AgipdCorrections: ...@@ -315,8 +312,7 @@ class AgipdCorrections:
data_dict['rawgain'][:n_img] = raw_data[:, 1] data_dict['rawgain'][:n_img] = raw_data[:, 1]
data_dict['cellId'][:n_img] = allcells[firange] data_dict['cellId'][:n_img] = allcells[firange]
data_dict['pulseId'][:n_img] = allpulses[firange] data_dict['pulseId'][:n_img] = allpulses[firange]
data_dict['trainId'][:n_img] = np.squeeze( data_dict['trainId'][:n_img] = np.squeeze(group['trainId'][:][firange])
group['trainId'][:][firange])
except Exception as e: except Exception as e:
print(f'Error during reading data from file {file_name}: {e}') print(f'Error during reading data from file {file_name}: {e}')
print(f'Error traceback: {traceback.format_exc()}') print(f'Error traceback: {traceback.format_exc()}')
...@@ -354,10 +350,10 @@ class AgipdCorrections: ...@@ -354,10 +350,10 @@ class AgipdCorrections:
# Copy any other data from the input file. # Copy any other data from the input file.
# This includes indexes, so it's important that the corrected data # This includes indexes, so it's important that the corrected data
# we write is aligned with the raw data. # we write is aligned with the raw data.
with h5py.File(file_name, 'r') as infile: with h5py.File(file_name, "r") as infile:
self.copy_and_sanitize_non_cal_data(infile, outfile, self.copy_and_sanitize_non_cal_data(
agipd_base, infile, outfile, agipd_base, idx_base, trains
idx_base, trains) )
# All corrected data goes in a /INSTRUMENT/.../image group # All corrected data goes in a /INSTRUMENT/.../image group
image_grp = outfile[data_path] image_grp = outfile[data_path]
...@@ -545,9 +541,9 @@ class AgipdCorrections: ...@@ -545,9 +541,9 @@ class AgipdCorrections:
cellid = self.shared_dict[i_proc]['cellId'][first:last] cellid = self.shared_dict[i_proc]['cellId'][first:last]
# output is saved in sharedmem to pass for correct_agipd() # output is saved in sharedmem to pass for correct_agipd()
# as this function takes about 3 seconds. # as this function takes about 3 seconds.
self.shared_dict[i_proc]['msk'][first:last] = \ self.shared_dict[i_proc]["msk"][first:last] = calgs.gain_choose_int(
calgs.gain_choose_int(gain, gain, self.mask[module_idx][:, cellid]
self.mask[module_idx][:, cellid]) # noqa )
if hasattr(self, "rel_gain"): if hasattr(self, "rel_gain"):
# Get the correct rel_gain depending on cell-id # Get the correct rel_gain depending on cell-id
...@@ -620,14 +616,12 @@ class AgipdCorrections: ...@@ -620,14 +616,12 @@ class AgipdCorrections:
# if baseline correction was not requested # if baseline correction was not requested
# msk and rel_corr will still be empty shared_mem arrays # msk and rel_corr will still be empty shared_mem arrays
if not any(self.blc_bools): if not any(self.blc_bools):
msk = calgs.gain_choose_int(gain, msk = calgs.gain_choose_int(gain, self.mask[module_idx][:, cellid])
self.mask[module_idx][:, cellid])
# same for relative gain and then bad pixel mask # same for relative gain and then bad pixel mask
if hasattr(self, "rel_gain"): if hasattr(self, "rel_gain"):
# Get the correct rel_gain depending on cell-id # Get the correct rel_gain depending on cell-id
rel_corr = calgs.gain_choose(gain, rel_corr = calgs.gain_choose(gain, self.rel_gain[module_idx][:, cellid])
self.rel_gain[module_idx][:, cellid]) # noqa
# Correct for relative gain # Correct for relative gain
if self.corr_bools.get("rel_gain") and hasattr(self, "rel_gain"): if self.corr_bools.get("rel_gain") and hasattr(self, "rel_gain"):
...@@ -690,11 +684,9 @@ class AgipdCorrections: ...@@ -690,11 +684,9 @@ class AgipdCorrections:
# Copy the data across into the existing shared-memory array # Copy the data across into the existing shared-memory array
mask[...] = msk[...] mask[...] = msk[...]
def get_valid_image_idx(self, idx_base: str, infile: str, def get_valid_image_idx(self, idx_base: str, infile: str, raw_format_version: int = 2):
index_v: Optional[int] = 2): """Return the indices of valid data"""
""" Return the indices of valid data if raw_format_version == 2:
"""
if index_v == 2:
count = np.squeeze(infile[idx_base + "image/count"]) count = np.squeeze(infile[idx_base + "image/count"])
first = np.squeeze(infile[idx_base + "image/first"]) first = np.squeeze(infile[idx_base + "image/first"])
if np.count_nonzero(count != 0) == 0: if np.count_nonzero(count != 0) == 0:
...@@ -719,13 +711,16 @@ class AgipdCorrections: ...@@ -719,13 +711,16 @@ class AgipdCorrections:
# Creating an array of validated indices. # Creating an array of validated indices.
# If all indices were validated this array will be the same, # If all indices were validated this array will be the same,
# as what is stored at /DET/image/trainId # as what is stored at /DET/image/trainId
valid_indices = np.concatenate([np.arange(validf[i], valid_indices = np.concatenate(
validf[i]+validc[i]) [
for i in range(validf.size)], np.arange(validf[i], validf[i] + validc[i])
axis=0) for i in range(validf.size)
],
axis=0,
)
valid_indices = np.squeeze(valid_indices).astype(np.int32) valid_indices = np.squeeze(valid_indices).astype(np.int32)
elif index_v == 1: elif raw_format_version == 1:
status = np.squeeze(infile[idx_base + "image/status"]) status = np.squeeze(infile[idx_base + "image/status"])
if np.count_nonzero(status != 0) == 0: if np.count_nonzero(status != 0) == 0:
raise IOError(f"File {infile} has no valid counts") raise IOError(f"File {infile} has no valid counts")
...@@ -743,10 +738,9 @@ class AgipdCorrections: ...@@ -743,10 +738,9 @@ class AgipdCorrections:
valid_indices = None valid_indices = None
else: else:
raise AttributeError( raise AttributeError(
f"Not a known raw format version: {index_v}") f"Not a known raw format version: {raw_format_version}")
return (valid, first_index, last_index, idxtrains, return (valid, first_index, last_index, idxtrains, valid_indices)
valid_indices)
def apply_selected_pulses(self, i_proc: int) -> int: def apply_selected_pulses(self, i_proc: int) -> int:
"""Select sharedmem data indices to correct based on selected """Select sharedmem data indices to correct based on selected
......
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