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
1 file
+ 29
18
Compare changes
  • Side-by-side
  • Inline
%% Cell type:markdown id:49b6577f-96a5-4dd2-bdd9-da661b2c4619 tags:
%% Cell type:markdown id:49b6577f-96a5-4dd2-bdd9-da661b2c4619 tags:
The following is a processing for the dark constants (`Offset`, `Noise`, and `BadPixelsDark`) maps using dark images taken with Gotthard2 detector (GH2 50um or 25um).
The following is a processing for the dark constants (`Offset`, `Noise`, and `BadPixelsDark`) maps using dark images taken with Gotthard2 detector (GH2 50um or 25um).
All constants are evaluated per strip, per pulse, and per memory cell. The maps are calculated for each gain stage that is acquired in 3 separate runs.
All constants are evaluated per strip, per pulse, and per memory cell. The maps are calculated for each gain stage that is acquired in 3 separate runs.
The three maps can be injected to the database (`db_output`) and/or stored locally (`local_output`).
The three maps are of shape (stripes, cells, gains): (1280, 2, 3). They can be injected to the database (`db_output`) and/or stored locally (`local_output`).
%% Cell type:code id:818e24e8 tags:
%% Cell type:code id:818e24e8 tags:
from extra_data import RunDirectory
from extra_data import RunDirectory
from pathlib import Path
from pathlib import Path
 
from cal_tools.calcat_interface import CalCatApi
from cal_tools.enums import BadPixels
from cal_tools.enums import BadPixels
from cal_tools.gotthard2 import gotthard2algs, gotthard2lib
from cal_tools.gotthard2 import gotthard2algs, gotthard2lib
from cal_tools.step_timing import StepTimer
from cal_tools.step_timing import StepTimer
 
from cal_tools.restful_config import calibration_client
from cal_tools.tools import (
from cal_tools.tools import (
calcat_creation_time,
calcat_creation_time,
get_constant_from_db_and_time,
get_constant_from_db_and_time,
save_const_to_h5,
save_const_to_h5,
send_to_db,
send_to_db,
)
)
 
from iCalibrationDB import Conditions, Constants
from iCalibrationDB import Conditions, Constants
%matplotlib inline
%matplotlib inline
in_folder = Path(in_folder)
in_folder = Path(in_folder)
out_folder = Path(out_folder)
out_folder = Path(out_folder)
out_folder.mkdir(parents=True, exist_ok=True)
out_folder.mkdir(parents=True, exist_ok=True)
print(f"Process modules: {karabo_da}")
ctrl_src = ctrl_source_template.format(karabo_id_control, control_template)
ctrl_src = ctrl_source_template.format(karabo_id_control, control_template)
creation_time = calcat_creation_time(in_folder, run_high, creation_time)
creation_time = calcat_creation_time(in_folder, run_high, creation_time)
print(f"Creation time: {creation_time}")
print(f"Creation time: {creation_time}")
if not karabo_id_control:
if not karabo_id_control:
karabo_id_control = karabo_id
karabo_id_control = karabo_id
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)
 
%% Cell type:code id:f64bc150-cfcd-4f98-83f9-a982fdacedd7 tags:
 
``` python
# Decide if GH2 is 25um or 50um
# Decide if GH2 is 25um or 50um
gh2_hostname = run_dc.get_run_value(ctrl_src, "rxHostname")
gh2_hostname = run_dc.get_run_value(ctrl_src, "rxHostname")
# gh2_hostname is a vector of bytes objects.
# gh2_hostname is a vector of bytes objects.
# GH2 25um has two host-names unlike 50um which has one.
# 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"]
calcat = CalCatApi(client=calibration_client())
print("Processing 25um Gotthard2.")
detector_id = calcat.detector(karabo_id)['id']
 
pdus_by_da = calcat.physical_detector_units(detector_id, pdu_snapshot_at=creation_time)
 
da_to_pdu = {da: p['physical_name'] for (da, p) in pdus_by_da.items()}
 
 
if karabo_da != [""]:
 
# Filter DA connected to detector in CALCAT
 
karabo_da = [da for da in karabo_da if da in da_to_pdu]
 
# Exclude non selected DA from processing.
 
da_to_pdu = {da: da_to_pdu[da] for da in karabo_da}
 
else:
 
karabo_da = sorted(da_to_pdu.keys())
 
 
if gh2_hostname[1].decode("utf-8"):
 
print("Data is for 25um Gotthard2.")
 
 
print(f"Processing {karabo_da}")
%% Cell type:code id:ac9c5dc3-bc66-4e7e-b6a1-360259be535c tags:
%% Cell type:code id:ac9c5dc3-bc66-4e7e-b6a1-360259be535c tags:
exposure_period=exposure_period,
exposure_period=exposure_period,
acquisition_rate=acquisition_rate,
acquisition_rate=acquisition_rate,
single_photon=single_photon,
single_photon=single_photon,
)
)
db_modules = get_pdu_from_db(
karabo_id=karabo_id,
karabo_da=karabo_da,
constant=Constants.Gotthard2.LUT(),
condition=condition,
cal_db_interface=cal_db_interface,
snapshot_at=creation_time,
)
step_timer.start()
step_timer.start()
g_name = ["G0", "G1", "G2"]
g_name = ["G0", "G1", "G2"]
for mod, pdu in zip(karabo_da, db_modules):
for mod, pdu in da_to_pdu.items():
display(Markdown(f"### Badpixels for module {mod}:"))
display(Markdown(f"### Badpixels for module {mod}:"))
badpixels_map[mod][
badpixels_map[mod][
``` python
``` python
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):
for mod, pdu in da_to_pdu.items():
display(Markdown(f"### {cname} for module {mod}:"))
display(Markdown(f"### {cname} for module {mod}:"))
for cell in [0, 1]:
for cell in [0, 1]:
``` python
``` python
step_timer.start()
step_timer.start()
for mod, db_mod in zip(karabo_da, db_modules):
for mod, db_mod in da_to_pdu.items():
constants = {
constants = {
"Offset": offset_map[mod],
"Offset": offset_map[mod],
"Noise": noise_map[mod],
"Noise": noise_map[mod],
Loading