Skip to content
Snippets Groups Projects
Commit b5a84d76 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Remove unused ePix100 pre notebook

parent 23518b6a
No related branches found
No related tags found
1 merge request!821[ePix100] [Correct] Remove pre notebook
%% Cell type:markdown id: tags:
# ePix100 retrieve constants precorrection
Author: European XFEL Detector Group, Version: 1.0
The following notebook provides constants for the selected ePix100 modules before executing correction on the selected sequence files.
%% Cell type:code id: tags:
``` python
in_folder = "/gpfs/exfel/exp/CALLAB/202031/p900113/raw" # input folder, required
out_folder = "/gpfs/exfel/data/scratch/ahmedk/test/remove/epix_correct" # output folder, required
metadata_folder = "" # Directory containing calibration_metadata.yml when run by xfel-calibrate
sequences = [-1] # sequences to correct, set to -1 for all, range allowed
run = 9988 # which run to read data from, required
# Parameters for accessing the raw data.
karabo_id = "MID_EXP_EPIX-1" # Detector Karabo_ID
karabo_da = "EPIX01" # data aggregators
receiver_template = "RECEIVER" # detector receiver template for accessing raw data files
instrument_source_template = '{}/DET/{}:daqOutput' # instrument detector data source in h5files
# Parameters for the calibration database.
creation_time = "" # The timestamp to use with Calibration DB. Required Format: "YYYY-MM-DD hh:mm:ss" e.g. 2019-07-04 11:02:41
cal_db_interface = "tcp://max-exfl016:8015#8025" # calibration DB interface to use
cal_db_timeout = 300000 # timeout on CalibrationDB requests
# Conditions for retrieving calibration constants.
bias_voltage = 200 # bias voltage
in_vacuum = False # detector operated in vacuum
fix_temperature = 290 # fixed temperature value in Kelvin. Default value -1 to use the value from files.
integration_time = -1 # Detector integration time, Default value -1 to use the value from the slow data.
gain_photon_energy = 9.0 # Photon energy used for gain calibration
# Flags to select type of applied corrections.
relative_gain = True # Apply relative gain correction.
```
%% Cell type:code id: tags:
``` python
from logging import warning
import numpy as np
from extra_data import RunDirectory
from pathlib import Path
import cal_tools.restful_config as rest_cfg
from cal_tools.calcat_interface import EPIX100_CalibrationData
from cal_tools.epix100 import epix100lib
from cal_tools.tools import (
calcat_creation_time,
CalibrationMetadata,
)
```
%% Cell type:code id: tags:
``` python
in_folder = Path(in_folder)
out_folder = Path(out_folder)
out_folder.mkdir(parents=True, exist_ok=True)
metadata = CalibrationMetadata(metadata_folder or out_folder)
# NOTE: this notebook will not overwrite calibration metadata file,
# if it already contains details about which constants to use.
retrieved_constants = metadata.setdefault("retrieved-constants", {})
```
%% Cell type:code id: tags:
``` python
creation_time = calcat_creation_time(in_folder, run, creation_time)
print(f"Using {creation_time.isoformat()} as creation time")
```
%% Cell type:code id: tags:
``` python
# Read control data.
run_dc = RunDirectory(in_folder / f"r{run:04d}")
ctrl_data = epix100lib.epix100Ctrl(
run_dc=run_dc,
instrument_src=f"{karabo_id}/DET/{receiver_template}:daqOutput",
ctrl_src=f"{karabo_id}/DET/CONTROL",
)
if integration_time < 0:
integration_time = ctrl_data.get_integration_time()
integration_time_str_add = ""
else:
integration_time_str_add = "(manual input)"
if fix_temperature < 0:
temperature = ctrl_data.get_temprature()
temperature_k = temperature + 273.15
temp_str_add = ""
else:
temperature_k = fix_temperature
temperature = fix_temperature - 273.15
temp_str_add = "(manual input)"
print(f"Bias voltage is {bias_voltage} V")
print(f"Detector integration time is set to {integration_time} \u03BCs {integration_time_str_add}")
print(f"Mean temperature: {temperature:0.2f}°C / {temperature_k:0.2f} K {temp_str_add}")
print(f"Operated in vacuum: {in_vacuum}")
```
%% Cell type:code id: tags:
``` python
epix_cal = EPIX100_CalibrationData(
detector_name=karabo_id,
sensor_bias_voltage=bias_voltage,
integration_time=integration_time,
sensor_temperature=temperature_k,
in_vacuum=in_vacuum,
source_energy=gain_photon_energy,
event_at=creation_time,
client=rest_cfg.calibration_client(),
)
mdata_dict = {"constants": dict()}
constant_names = ["OffsetEPix100", "NoiseEPix100"]
if relative_gain:
constant_names += ["RelativeGainEPix100"]
# Retrieve metadata for all epix100 constants.
epix_metadata = epix_cal.metadata(constant_names)[karabo_da]
# Validate the constants availability and raise/warn correspondingly.
missing_dark_constants = {"OffsetEPix100", "NoiseEPix100"} - set(epix_metadata)
if missing_dark_constants:
raise ValueError(
f"Dark constants {missing_dark_constants} are not available to correct {karabo_da}.")
if relative_gain and "RelativeGainEPix100" not in epix_metadata.keys():
warning("RelativeGainEPix100 is not found in CALCAT.")
for cname, ccv_metadata in epix_metadata.items():
mdata_dict["constants"][cname] = {
"path": str(epix_cal.caldb_root / ccv_metadata["path"]),
"dataset": ccv_metadata["dataset"],
"creation-time": ccv_metadata["begin_validity_at"],
"ccv_id": ccv_metadata["ccv_id"],
}
print(f"Retrieved {cname} with creation-time: {ccv_metadata['begin_validity_at']}")
mdata_dict["physical-name"] = ccv_metadata["physical_name"]
retrieved_constants[karabo_da] = mdata_dict
metadata.save()
print(f"Stored retrieved constants in {metadata.filename}")
```
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