Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
b5a84d76
Commit
b5a84d76
authored
2 years ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Remove unused ePix100 pre notebook
parent
23518b6a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!821
[ePix100] [Correct] Remove pre notebook
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/ePix100/ePix100_retrieve_constants_precorrection.ipynb
+0
-214
0 additions, 214 deletions
...ks/ePix100/ePix100_retrieve_constants_precorrection.ipynb
with
0 additions
and
214 deletions
notebooks/ePix100/ePix100_retrieve_constants_precorrection.ipynb
deleted
100644 → 0
+
0
−
214
View file @
23518b6a
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ePix100 retrieve constants precorrection\n",
"\n",
"Author: European XFEL Detector Group, Version: 1.0\n",
"\n",
"The following notebook provides constants for the selected ePix100 modules before executing correction on the selected sequence files."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"in_folder = \"/gpfs/exfel/exp/CALLAB/202031/p900113/raw\" # input folder, required\n",
"out_folder = \"/gpfs/exfel/data/scratch/ahmedk/test/remove/epix_correct\" # output folder, required\n",
"metadata_folder = \"\" # Directory containing calibration_metadata.yml when run by xfel-calibrate\n",
"sequences = [-1] # sequences to correct, set to -1 for all, range allowed\n",
"run = 9988 # which run to read data from, required\n",
"\n",
"# Parameters for accessing the raw data.\n",
"karabo_id = \"MID_EXP_EPIX-1\" # Detector Karabo_ID\n",
"karabo_da = \"EPIX01\" # data aggregators\n",
"receiver_template = \"RECEIVER\" # detector receiver template for accessing raw data files\n",
"instrument_source_template = '{}/DET/{}:daqOutput' # instrument detector data source in h5files\n",
"\n",
"# Parameters for the calibration database.\n",
"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\n",
"cal_db_interface = \"tcp://max-exfl016:8015#8025\" # calibration DB interface to use\n",
"cal_db_timeout = 300000 # timeout on CalibrationDB requests\n",
"\n",
"# Conditions for retrieving calibration constants.\n",
"bias_voltage = 200 # bias voltage\n",
"in_vacuum = False # detector operated in vacuum\n",
"fix_temperature = 290 # fixed temperature value in Kelvin. Default value -1 to use the value from files.\n",
"integration_time = -1 # Detector integration time, Default value -1 to use the value from the slow data.\n",
"gain_photon_energy = 9.0 # Photon energy used for gain calibration\n",
"\n",
"# Flags to select type of applied corrections.\n",
"relative_gain = True # Apply relative gain correction."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from logging import warning\n",
"\n",
"import numpy as np\n",
"from extra_data import RunDirectory\n",
"from pathlib import Path\n",
"\n",
"import cal_tools.restful_config as rest_cfg\n",
"from cal_tools.calcat_interface import EPIX100_CalibrationData\n",
"from cal_tools.epix100 import epix100lib\n",
"from cal_tools.tools import (\n",
" calcat_creation_time,\n",
" CalibrationMetadata,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"in_folder = Path(in_folder)\n",
"out_folder = Path(out_folder)\n",
"\n",
"out_folder.mkdir(parents=True, exist_ok=True)\n",
"\n",
"metadata = CalibrationMetadata(metadata_folder or out_folder)\n",
"# NOTE: this notebook will not overwrite calibration metadata file,\n",
"# if it already contains details about which constants to use.\n",
"retrieved_constants = metadata.setdefault(\"retrieved-constants\", {})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"creation_time = calcat_creation_time(in_folder, run, creation_time)\n",
"print(f\"Using {creation_time.isoformat()} as creation time\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Read control data.\n",
"run_dc = RunDirectory(in_folder / f\"r{run:04d}\")\n",
"\n",
"ctrl_data = epix100lib.epix100Ctrl(\n",
" run_dc=run_dc,\n",
" instrument_src=f\"{karabo_id}/DET/{receiver_template}:daqOutput\",\n",
" ctrl_src=f\"{karabo_id}/DET/CONTROL\",\n",
" )\n",
"\n",
"if integration_time < 0:\n",
" integration_time = ctrl_data.get_integration_time()\n",
" integration_time_str_add = \"\"\n",
"else:\n",
" integration_time_str_add = \"(manual input)\"\n",
"\n",
"if fix_temperature < 0:\n",
" temperature = ctrl_data.get_temprature()\n",
" temperature_k = temperature + 273.15\n",
" temp_str_add = \"\"\n",
"else:\n",
" temperature_k = fix_temperature\n",
" temperature = fix_temperature - 273.15\n",
" temp_str_add = \"(manual input)\"\n",
"\n",
"\n",
"print(f\"Bias voltage is {bias_voltage} V\")\n",
"print(f\"Detector integration time is set to {integration_time} \\u03BCs {integration_time_str_add}\")\n",
"print(f\"Mean temperature: {temperature:0.2f}°C / {temperature_k:0.2f} K {temp_str_add}\")\n",
"print(f\"Operated in vacuum: {in_vacuum}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"epix_cal = EPIX100_CalibrationData(\n",
" detector_name=karabo_id,\n",
" sensor_bias_voltage=bias_voltage,\n",
" integration_time=integration_time,\n",
" sensor_temperature=temperature_k,\n",
" in_vacuum=in_vacuum,\n",
" source_energy=gain_photon_energy,\n",
" event_at=creation_time,\n",
" client=rest_cfg.calibration_client(),\n",
" )\n",
"\n",
"mdata_dict = {\"constants\": dict()}\n",
"\n",
"constant_names = [\"OffsetEPix100\", \"NoiseEPix100\"]\n",
"if relative_gain:\n",
" constant_names += [\"RelativeGainEPix100\"]\n",
"\n",
"# Retrieve metadata for all epix100 constants.\n",
"\n",
"epix_metadata = epix_cal.metadata(constant_names)[karabo_da]\n",
"\n",
"# Validate the constants availability and raise/warn correspondingly.\n",
"missing_dark_constants = {\"OffsetEPix100\", \"NoiseEPix100\"} - set(epix_metadata)\n",
"if missing_dark_constants:\n",
" raise ValueError(\n",
" f\"Dark constants {missing_dark_constants} are not available to correct {karabo_da}.\")\n",
"\n",
"if relative_gain and \"RelativeGainEPix100\" not in epix_metadata.keys():\n",
" warning(\"RelativeGainEPix100 is not found in CALCAT.\")\n",
"\n",
"for cname, ccv_metadata in epix_metadata.items():\n",
" mdata_dict[\"constants\"][cname] = {\n",
" \"path\": str(epix_cal.caldb_root / ccv_metadata[\"path\"]),\n",
" \"dataset\": ccv_metadata[\"dataset\"],\n",
" \"creation-time\": ccv_metadata[\"begin_validity_at\"],\n",
" \"ccv_id\": ccv_metadata[\"ccv_id\"],\n",
" }\n",
" print(f\"Retrieved {cname} with creation-time: {ccv_metadata['begin_validity_at']}\")\n",
"\n",
"mdata_dict[\"physical-name\"] = ccv_metadata[\"physical_name\"]\n",
"retrieved_constants[karabo_da] = mdata_dict\n",
"metadata.save()\n",
"print(f\"Stored retrieved constants in {metadata.filename}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.11 ('.cal4_venv')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.11"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "ccde353e8822f411c1c49844e1cbe3edf63293a69efd975d1b44f5e852832668"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% 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
:
04
d
}
"
)
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
}
\u03BC
s
{
integration_time_str_add
}
"
)
print
(
f
"
Mean temperature:
{
temperature
:
0.2
f
}
°C /
{
temperature_k
:
0.2
f
}
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
}
"
)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment