Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new begin_at_strategy argument and split dataset_obj() #210

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Added:
to create & display a markdown table of the constants found. This is primarily for
use in Jupyter notebooks (!202).
- More informative plots from [Scan.plot()][extra.components.Scan.plot] (!201).
- Add new `begin_at_strategy` calcat argument and split create `full_path()` method from `dataset_obj()` (!210)

Fixed:

Expand Down
32 changes: 22 additions & 10 deletions src/extra/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,16 @@
_have_calcat_metadata=True,
)

def dataset_obj(self, caldb_root=None) -> h5py.Dataset:
def file_path(self, caldb_root=None) -> Path:
if caldb_root is not None:
caldb_root = Path(caldb_root)
else:
caldb_root = _get_default_caldb_root()
return caldb_root / self.path

Check warning on line 285 in src/extra/calibration.py

View check run for this annotation

Codecov / codecov/patch

src/extra/calibration.py#L285

Added line #L285 was not covered by tests

f = h5py.File(caldb_root / self.path, "r")
def dataset_obj(self, caldb_root=None) -> h5py.Dataset:
calpath = self.file_path(caldb_root)
f = h5py.File(calpath, "r")

Check warning on line 289 in src/extra/calibration.py

View check run for this annotation

Codecov / codecov/patch

src/extra/calibration.py#L288-L289

Added lines #L288 - L289 were not covered by tests
return f[self.dataset]["data"]

def ndarray(self, caldb_root=None):
Expand Down Expand Up @@ -542,20 +545,28 @@
}

@classmethod
def from_condition(
cls,
condition: "ConditionsBase",
detector_name,
calibrations=None,
client=None,
event_at=None,
pdu_snapshot_at=None,
def from_condition(cls,
condition: "ConditionsBase",
detector_name,
calibrations=None,
client=None,
event_at=None,
pdu_snapshot_at=None,
begin_at_strategy="closest",

):
"""Look up constants for the given detector conditions & timestamp.

`condition` should be a conditions object for the relevant detector type,
e.g. `DSSCConditions`.
"""

accepted_strategies = ["closest", "prior"]
if begin_at_strategy not in accepted_strategies:
raise ValueError(
"Invalid begin_at_strategy. "
f"Expected one of {accepted_strategies}")

if calibrations is None:
calibrations = set(condition.calibration_types)
if pdu_snapshot_at is None:
Expand Down Expand Up @@ -599,6 +610,7 @@
"karabo_da": "",
"event_at": client.format_time(event_at),
"pdu_snapshot_at": client.format_time(pdu_snapshot_at),
"begin_at_strategy": begin_at_strategy,
},
data=json.dumps(cls._format_cond(condition_dict)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B1%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B1%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":141880,"name":"20220902_060534_sIdx=0","file_name":"cal.1662098732.6664886.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m337/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M337/Offset/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2022-09-02T07:42:33.000+02:00","end_validity_at":null,"begin_at":"2022-09-02T07:42:33.000+02:00","start_idx":0,"end_idx":0,"raw_data_location":"proposal:003049
Expand Down Expand Up @@ -470,7 +470,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B19%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B19%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":118111,"name":"20220225_174759_sIdx=0","file_name":"cal.1645811278.2248814.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m337/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M337/SlopesFF/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2022-02-05T13:07:49.000+01:00","end_validity_at":null,"begin_at":"2022-02-05T13:07:49.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"Proposal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B1%2C+2%2C+11%2C+14%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B1%2C+2%2C+11%2C+14%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":38191,"name":"20200225_180910_sIdx=0","file_name":"cal.1582654148.5093198.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m305/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M305/Offset/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2020-02-25T18:21:23.000+01:00","end_validity_at":null,"begin_at":"2020-02-25T18:21:23.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"proposal:p900138
Expand Down Expand Up @@ -762,7 +762,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B15%2C+17%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B15%2C+17%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":45612,"name":"20200518_221141_sIdx=0","file_name":"cal.1589839899.5748584.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m305/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M305/BadPixelsPC/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2020-03-04T15:41:27.000+01:00","end_validity_at":null,"begin_at":"2020-03-04T15:41:27.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"p900138
Expand Down Expand Up @@ -1076,7 +1076,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B20%2C+19%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B20%2C+19%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":45638,"name":"20200519_093826_sIdx=0","file_name":"cal.1589881105.0254447.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m305/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M305/BadPixelsFF/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2020-02-27T11:04:56.000+01:00","end_validity_at":null,"begin_at":"2020-02-27T11:04:56.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"p900138
Expand Down
6 changes: 3 additions & 3 deletions tests/cassettes/test_calibration/test_AGIPD_load_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B1%2C+2%2C+11%2C+14%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B1%2C+2%2C+11%2C+14%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":38191,"name":"20200225_180910_sIdx=0","file_name":"cal.1582654148.5093198.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m305/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M305/Offset/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2020-02-25T18:21:23.000+01:00","end_validity_at":null,"begin_at":"2020-02-25T18:21:23.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"proposal:p900138
Expand Down Expand Up @@ -341,7 +341,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B15%2C+17%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B15%2C+17%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":45612,"name":"20200518_221141_sIdx=0","file_name":"cal.1589839899.5748584.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m305/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M305/BadPixelsPC/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2020-03-04T15:41:27.000+01:00","end_validity_at":null,"begin_at":"2020-03-04T15:41:27.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"p900138
Expand Down Expand Up @@ -585,7 +585,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B20%2C+19%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SPB_DET_AGIPD1M-1&calibration_id=%5B20%2C+19%5D&karabo_da=&event_at=2020-01-07+13%3A26%3A48.00&pdu_snapshot_at=2020-01-07+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":45638,"name":"20200519_093826_sIdx=0","file_name":"cal.1589881105.0254447.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m305/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M305/BadPixelsFF/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2020-02-27T11:04:56.000+01:00","end_validity_at":null,"begin_at":"2020-02-27T11:04:56.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"p900138
Expand Down
4 changes: 2 additions & 2 deletions tests/cassettes/test_calibration/test_AGIPD_merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B1%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B1%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":141880,"name":"20220902_060534_sIdx=0","file_name":"cal.1662098732.6664886.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m337/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M337/Offset/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2022-09-02T07:42:33.000+02:00","end_validity_at":null,"begin_at":"2022-09-02T07:42:33.000+02:00","start_idx":0,"end_idx":0,"raw_data_location":"proposal:003049
Expand Down Expand Up @@ -197,7 +197,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B19%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=MID_DET_AGIPD1M-1&calibration_id=%5B19%5D&karabo_da=&event_at=2022-09-01+13%3A26%3A48.00&pdu_snapshot_at=2022-09-01+13%3A26%3A48.00&begin_at_strategy=closest
response:
body:
string: '[{"id":118111,"name":"20220225_174759_sIdx=0","file_name":"cal.1645811278.2248814.h5","path_to_file":"xfel/cal/agipd-type/agipd_siv1_agipdv11_m337/","data_set_name":"/AGIPD_SIV1_AGIPDV11_M337/SlopesFF/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2022-02-05T13:07:49.000+01:00","end_validity_at":null,"begin_at":"2022-02-05T13:07:49.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"Proposal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SQS_DET_DSSC1M-1&calibration_id=%5B1%2C+2%5D&karabo_da=&event_at=2023-11-29+00%3A00%3A00&pdu_snapshot_at=2023-11-29+00%3A00%3A00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=SQS_DET_DSSC1M-1&calibration_id=%5B1%2C+2%5D&karabo_da=&event_at=2023-11-29+00%3A00%3A00&pdu_snapshot_at=2023-11-29+00%3A00%3A00&begin_at_strategy=closest
response:
body:
string: '[{"id":190329,"name":"20231128_094249_sIdx=0","file_name":"cal.1701164568.7374022.h5","path_to_file":"xfel/cal/dssc-type/dssc_minisddv1_f2_004/","data_set_name":"/DSSC_MiniSDDV1_F2_004/Offset/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2023-11-28T10:40:01.000+01:00","end_validity_at":null,"begin_at":"2023-11-28T10:40:01.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"proposal:900388
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ interactions:
content-type:
- application/json
method: GET
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=FXE_XAD_JF1M&calibration_id=%5B21%2C+22%2C+23%2C+30%2C+39%5D&karabo_da=&event_at=2024-03-04+17%3A56%3A05.172132%2B00%3A00&pdu_snapshot_at=2024-03-04+17%3A56%3A05.172132%2B00%3A00
uri: http://exflcalproxy.desy.de:8080/api/calibration_constant_versions/get_by_detector_conditions?detector_identifier=FXE_XAD_JF1M&calibration_id=%5B21%2C+22%2C+23%2C+30%2C+39%5D&karabo_da=&event_at=2024-03-04+17%3A56%3A05.172132%2B00%3A00&pdu_snapshot_at=2024-03-04+17%3A56%3A05.172132%2B00%3A00&begin_at_strategy=closest
response:
body:
string: '[{"id":196179,"name":"20240304_125702_sIdx=0","file_name":"cal.1709557021.2759159.h5","path_to_file":"xfel/cal/jungfrau-type/jungfrau_m530/","data_set_name":"/Jungfrau_M530/Offset10Hz/0","flg_deployed":true,"flg_good_quality":true,"begin_validity_at":"2024-03-04T13:33:29.000+01:00","end_validity_at":null,"begin_at":"2024-03-04T13:33:29.000+01:00","start_idx":0,"end_idx":0,"raw_data_location":"proposal:p007136
Expand Down
Loading