Skip to content
Snippets Groups Projects

[GH2][CORRECT][DARK] Feat/add support for gh2 25um

Merged Karim Ahmed requested to merge feat/add_support_for_GH2_25um into master
10 unresolved threads
Compare and
2 files
+ 175
120
Compare changes
  • Side-by-side
  • Inline
Files
2
run_nums = [run_high, run_med, run_low]
run_nums = [run_high, run_med, run_low]
in_folder = Path(in_folder)
in_folder = Path(in_folder)
out_folder = Path(out_folder)
out_folder = Path(out_folder)
out_folder.mkdir(exist_ok=True)
out_folder.mkdir(parents=True, exist_ok=True)
print(f"Process modules: {karabo_da}")
print(f"Process modules: {karabo_da}")
run_dc = RunDirectory(in_folder / f"r{run_high:04d}")
file_loc = f"proposal:{run_dc.run_metadata()['proposalNumber']} runs:{run_high} {run_med} {run_low}" # noqa
instrument_src = instrument_source_template.format(karabo_id, receiver_template)
ctrl_src = ctrl_source_template.format(karabo_id_control, control_template)
ctrl_src = ctrl_source_template.format(karabo_id_control, control_template)
# Read report path to associate it later with injected constants.
# Read report path to associate it later with injected constants.
report = get_report(out_folder)
report = get_report(out_folder)
creation_time = None
if overwrite_creation_time:
if overwrite_creation_time:
creation_time = datetime.datetime.strptime(
creation_time = datetime.datetime.strptime(
overwrite_creation_time, "%Y-%m-%d %H:%M:%S.%f"
overwrite_creation_time, "%Y-%m-%d %H:%M:%S.%f"
karabo_id_control = karabo_id
karabo_id_control = karabo_id
 
%% Cell type:code id:c176a86f tags:
 
``` python
 
run_dc = RunDirectory(in_folder / f"r{run_high:04d}")
 
file_loc = f"proposal:{run_dc.run_metadata()['proposalNumber']} runs:{run_high} {run_med} {run_low}" # noqa
 
 
receivers = list(run_dc.select(f'{karabo_id}/DET/{receiver_template}*').all_sources)
%% Cell type:code id:108be688 tags:
%% Cell type:code id:108be688 tags:
single_photon = conditions["single_photon"].pop()
single_photon = conditions["single_photon"].pop()
print("Single photon: ", single_photon)
print("Single photon: ", single_photon)
acquisition_rate = conditions["acquisition_rate"].pop()
acquisition_rate = conditions["acquisition_rate"].pop()
print("Acquisition rate: ", acquisition_rate)
print("Acquisition rate: ", acquisition_rate)
 
 
# Decide if GH2 is 25um or 50um
 
gh2_hostname = run_dc.get_run_value(ctrl_src, "rxHostname")
 
# gh2_hostname is a vector of bytes objects.
 
# GH2 25um has two host-names unlike 50um which has one.
 
if gh2_hostname[1].decode("utf-8"): # For 25um use virtual karabo_das for CALCAT data mapping.
 
karabo_da = [f"{karabo_da[0]}/1", f"{karabo_da[0]}/2"]
 
print("Processing 25um Gotthard2.")
%% Cell type:code id:ac9c5dc3-bc66-4e7e-b6a1-360259be535c tags:
%% Cell type:code id:ac9c5dc3-bc66-4e7e-b6a1-360259be535c tags:
``` python
``` python
def specify_trains_to_process(
def specify_trains_to_process(
img_key_data: "extra_data.KeyData", # noqa
img_key_data: "extra_data.KeyData",
max_trains: int = 0,
min_trains: int = 0,
):
):
"""Specify total number of trains to process.
"""Specify total number of trains to process.
Based on given min_trains and max_trains, if given.
Based on given min_trains and max_trains, if given.
n_trains = img_key_data.shape[0]
n_trains = img_key_data.shape[0]
all_trains = len(img_key_data.train_ids)
all_trains = len(img_key_data.train_ids)
print(
print(
f"{mod} has {all_trains - n_trains} "
f"{receiver} has {all_trains - n_trains} "
f"trains with empty frames out of {all_trains} trains"
f"trains with empty frames out of {all_trains} trains"
)
)
def convert_train(wid, index, tid, d):
def convert_train(wid, index, tid, d):
"""Convert a Gotthard2 train from 12bit to 10bit."""
"""Convert a Gotthard2 train from 12bit to 10bit."""
gotthard2algs.convert_to_10bit(
gotthard2algs.convert_to_10bit(
d[instr_mod_src]["data.adc"], lut, data_10bit[index, ...]
d[receiver]["data.adc"], lut, data_10bit[index, ...]
)
)
np.uint16
np.uint16
)
)
empty_lut = np.stack(1280 * [np.stack([empty_lut] * 2)], axis=0)
empty_lut = np.stack(1280 * [np.stack([empty_lut] * 2)], axis=0)
for mod in karabo_da:
for mod, receiver in zip(karabo_da, receivers):
# Retrieve LUT constant
# Retrieve LUT constant
lut, time = get_constant_from_db_and_time(
lut, time = get_constant_from_db_and_time(
print_once=False,
print_once=False,
)
)
print(f"Retrieved LUT constant with creation-time {time}")
print(f"Retrieved LUT constant with creation-time {time}")
# Path to pixels ADC values
instr_mod_src = instrument_src.format(int(mod[-2:]))
# TODO: Validate the final shape to store constants.
cshape = (1280, 2, 3)
cshape = (1280, 2, 3)
offset_map[mod] = context.alloc(shape=cshape, dtype=np.float32)
offset_map[mod] = context.alloc(shape=cshape, dtype=np.float32)
for run_num, [gain, run_dc] in run_dcs_dict.items():
for run_num, [gain, run_dc] in run_dcs_dict.items():
step_timer.start()
step_timer.start()
n_trains = specify_trains_to_process(run_dc[instr_mod_src, "data.adc"])
n_trains = specify_trains_to_process(run_dc[receiver, "data.adc"])
# Select requested number of trains to process.
# Select requested number of trains to process.
dc = run_dc.select(instr_mod_src, require_all=True).select_trains(
dc = run_dc.select(receiver, require_all=True).select_trains(
np.s_[:n_trains]
np.s_[:n_trains]
)
)
step_timer.start()
step_timer.start()
# Convert 12bit data to 10bit
# Convert 12bit data to 10bit
data_10bit = context.alloc(
data_10bit = context.alloc(
shape=dc[instr_mod_src, "data.adc"].shape, dtype=np.float32
shape=dc[receiver, "data.adc"].shape, dtype=np.float32
)
)
context.map(convert_train, dc)
context.map(convert_train, dc)
step_timer.done_step("convert to 10bit")
step_timer.done_step("convert to 10bit")
context.map(offset_noise_cell, (even_data, odd_data))
context.map(offset_noise_cell, (even_data, odd_data))
# Split even and odd gain data.
# Split even and odd gain data.
data_gain = dc[instr_mod_src, "data.gain"].ndarray()
data_gain = dc[receiver, "data.gain"].ndarray()
even_gain = data_gain[:, 20::2, :]
even_gain = data_gain[:, 20::2, :]
odd_gain = data_gain[:, 21::2, :]
odd_gain = data_gain[:, 21::2, :]
raw_g = 3 if gain == 2 else gain
raw_g = 3 if gain == 2 else gain
ax.set_xticks(np.arange(0, 1281, 80))
ax.set_xticks(np.arange(0, 1281, 80))
ax.set_xlabel("Stripes #")
ax.set_xlabel("Stripes #")
ax.set_xlabel("BadPixels")
ax.set_xlabel("BadPixels")
ax.set_title(f"Cell {cell} - Module {mod} ({pdu})")
ax.set_title(f"BadPixels map - Cell {cell} - Module {mod} ({pdu})")
ax.set_ylim([0, 5])
ax.set_ylim([0, 5])
ax.legend()
ax.legend()
pass
plt.show()
step_timer.done_step(f"Creating bad pixels constant and plotting it.")
step_timer.done_step(f"Creating bad pixels constant and plotting it.")
``` python
``` python
for mod, pdu in zip(karabo_da, db_modules):
for cons, cname in zip([offset_map, noise_map], ["Offset", "Noise"]):
for cons, cname in zip([offset_map, noise_map], ["Offset", "Noise"]):
for mod, pdu in zip(karabo_da, db_modules):
 
display(Markdown(f"### {cname} for module {mod}:"))
 
for cell in [0, 1]:
for cell in [0, 1]:
fig, ax = plt.subplots(figsize=(10, 5))
fig, ax = plt.subplots(figsize=(10, 5))
for g_idx in [0, 1, 2]:
for g_idx in [0, 1, 2]:
ax.set_xlabel(cname)
ax.set_xlabel(cname)
ax.set_title(f"{cname} map - Cell {cell} - Module {mod} ({pdu})")
ax.set_title(f"{cname} map - Cell {cell} - Module {mod} ({pdu})")
ax.legend()
ax.legend()
pass
plt.show()
%% Cell type:code id:1c4eddf7-7d6e-49f4-8cbb-12d2bc496a8f tags:
%% Cell type:code id:1c4eddf7-7d6e-49f4-8cbb-12d2bc496a8f tags:
Loading