From fe4ea1e09cdb0c7ca6e1a8b481c7a7f7b099bee1 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 31 Oct 2024 12:08:40 +0000 Subject: [PATCH 1/6] Fix input arguments bug --- src/nexgen/beamlines/I19_2_gda_nxs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nexgen/beamlines/I19_2_gda_nxs.py b/src/nexgen/beamlines/I19_2_gda_nxs.py index fb168ecc..06253f39 100644 --- a/src/nexgen/beamlines/I19_2_gda_nxs.py +++ b/src/nexgen/beamlines/I19_2_gda_nxs.py @@ -277,12 +277,12 @@ def write_nxs(**tr_params): beam_center=tr_params["beam_center"], geometry_json=( tr_params["geometry_json"] - if find_in_dict(tr_params, "geometry_json") + if find_in_dict("geometry_json", tr_params) else None ), detector_json=( tr_params["detector_json"] - if find_in_dict(tr_params, "detector_json") + if find_in_dict("detector_json", tr_params) else None ), ) @@ -342,14 +342,14 @@ def write_nxs(**tr_params): _start_time = ( ( tr_params["start_time"].strftime("%Y-%m-%dT%H:%M:%S") - if find_in_dict(tr_params, "start_time") + if find_in_dict("start_time", tr_params) else None ), ) # This should be datetiem type _stop_time = ( ( tr_params["stop_time"].strftime("%Y-%m-%dT%H:%M:%S") - if find_in_dict(tr_params, "stop_time") + if find_in_dict("stop_time", tr_params) else None ), ) # idem. @@ -363,7 +363,7 @@ def write_nxs(**tr_params): else: vds_dtype = ( np.uint16 - if not find_in_dict(tr_params, "vds_dtype") + if not find_in_dict("vds_dtype", tr_params) else tr_params["vds_dtype"] ) eiger_writer(master_file, TR, axes_params, det_params, timestamps, vds_dtype) From dde525e70db48c2520f3acd4b65c0e360608e6f8 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 31 Oct 2024 12:12:53 +0000 Subject: [PATCH 2/6] Fix some params types --- src/nexgen/beamlines/beamline_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nexgen/beamlines/beamline_utils.py b/src/nexgen/beamlines/beamline_utils.py index d56b82a5..293d25bd 100644 --- a/src/nexgen/beamlines/beamline_utils.py +++ b/src/nexgen/beamlines/beamline_utils.py @@ -27,9 +27,9 @@ class GeneralParams(BaseModel): exposure_time: float beam_center: Sequence[float] - wavelength: Optional[float] - transmission: Optional[float] - flux: Optional[float] + wavelength: float + transmission: Optional[float] = None + flux: Optional[float] = None class PumpProbe(BaseModel): From af54daa63dfc63c96825c93d1e6d3ad55b4958ad Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 31 Oct 2024 12:24:00 +0000 Subject: [PATCH 3/6] Fix some input args --- src/nexgen/beamlines/I19_2_gda_nxs.py | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/nexgen/beamlines/I19_2_gda_nxs.py b/src/nexgen/beamlines/I19_2_gda_nxs.py index 06253f39..95609c6f 100644 --- a/src/nexgen/beamlines/I19_2_gda_nxs.py +++ b/src/nexgen/beamlines/I19_2_gda_nxs.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging +from datetime import datetime from pathlib import Path from typing import Optional, Tuple @@ -250,31 +251,43 @@ def eiger_writer( ) -def write_nxs(**tr_params): +def write_nxs( + meta_file: Path | str, + xml_file: Path | str, + detector_name: str, + exposure_time: float, + wavelength: float, + beam_center: list[float, float], + start_time: datetime | None = None, + stop_time: datetime | None = None, + **tr_params, +): """ Gather all parameters from the beamline and call the NeXus writers. - Keyword Args: + Args: meta_file (Path | str): Path to _meta.h5 file. xml_file (Path | str): Path to gda-generated xml file. detector_name (str): Detector in use. exposure_time (float): Exposure time, in s. wavelength (float): Wavelength of incident beam, in A. beam_center (List[float, float]): Beam center position, in pixels. - start_time (datetime): Experiment start time. - stop_time (datetime): Experiment end time. + start_time (datetime, optional): Experiment start time. Defaults to None. + stop_time (datetime, optional): Experiment end time. Defaults to None. + + Keyword Args: geometry_json (Path | str): Path to GDA generated geometry json file. detector_json (Path | str): Path to GDA generated detector json file. vds_dtype (DtypeLike): Data type for vds as np.uint##. """ # Get info from the beamline TR = GDACollectionParams( - meta_file=Path(tr_params["meta_file"]).expanduser().resolve(), - xml_file=Path(tr_params["xml_file"]).expanduser().resolve(), - detector_name=tr_params["detector_name"], - exposure_time=tr_params["exposure_time"], - wavelength=tr_params["wavelength"], - beam_center=tr_params["beam_center"], + meta_file=Path(meta_file).expanduser().resolve(), + xml_file=Path(xml_file).expanduser().resolve(), + detector_name=detector_name, + exposure_time=exposure_time, + wavelength=wavelength, + beam_center=beam_center, geometry_json=( tr_params["geometry_json"] if find_in_dict("geometry_json", tr_params) @@ -340,18 +353,10 @@ def write_nxs(**tr_params): # Get timestamps in the correct format if they aren't already _start_time = ( - ( - tr_params["start_time"].strftime("%Y-%m-%dT%H:%M:%S") - if find_in_dict("start_time", tr_params) - else None - ), + (start_time.strftime("%Y-%m-%dT%H:%M:%S") if start_time else None), ) # This should be datetiem type _stop_time = ( - ( - tr_params["stop_time"].strftime("%Y-%m-%dT%H:%M:%S") - if find_in_dict("stop_time", tr_params) - else None - ), + (stop_time.strftime("%Y-%m-%dT%H:%M:%S") if stop_time else None), ) # idem. timestamps = ( get_iso_timestamp(_start_time), From 33744f0467aff3d2a53166730d323ec6c2f6a5dc Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 31 Oct 2024 12:25:20 +0000 Subject: [PATCH 4/6] Where did that tuple come from --- src/nexgen/beamlines/I19_2_gda_nxs.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nexgen/beamlines/I19_2_gda_nxs.py b/src/nexgen/beamlines/I19_2_gda_nxs.py index 95609c6f..b75677f5 100644 --- a/src/nexgen/beamlines/I19_2_gda_nxs.py +++ b/src/nexgen/beamlines/I19_2_gda_nxs.py @@ -353,11 +353,9 @@ def write_nxs( # Get timestamps in the correct format if they aren't already _start_time = ( - (start_time.strftime("%Y-%m-%dT%H:%M:%S") if start_time else None), + start_time.strftime("%Y-%m-%dT%H:%M:%S") if start_time else None ) # This should be datetiem type - _stop_time = ( - (stop_time.strftime("%Y-%m-%dT%H:%M:%S") if stop_time else None), - ) # idem. + _stop_time = stop_time.strftime("%Y-%m-%dT%H:%M:%S") if stop_time else None # idem. timestamps = ( get_iso_timestamp(_start_time), get_iso_timestamp(_stop_time), From 3e2c7eddae4f87e7bfae27e93b73781db901e84b Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 31 Oct 2024 13:19:19 +0000 Subject: [PATCH 5/6] Workaround for flatfield file in gda --- src/nexgen/beamlines/I19_2_gda_nxs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nexgen/beamlines/I19_2_gda_nxs.py b/src/nexgen/beamlines/I19_2_gda_nxs.py index b75677f5..34380b25 100644 --- a/src/nexgen/beamlines/I19_2_gda_nxs.py +++ b/src/nexgen/beamlines/I19_2_gda_nxs.py @@ -329,6 +329,10 @@ def write_nxs( from .I19_2_params import I19_2Tristan as axes_params det_params = TristanDetector("Tristan 10M", (3043, 4183)) + # Temporary worksround, flatfield from gda has different file name + det_params.constants["flatfield"] = ( + "Tristan10M_flat_field_coeff_with_Mo_17.479keV.h5" + ) else: raise UnknownDetectorTypeError("Unknown detector name passed.") From 2fa6b568043c330615b3dd884768a6635c5ea819 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 31 Oct 2024 13:22:37 +0000 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b71f973..f72139c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,18 @@ # CHANGELOG +## 0.9.8 + +### Fixed +- Bugfixes and input argument improvement for I19 gda writer. + + ## 0.9.7 ### Added - Possibility of adding an NXnote to nexus file for I19 writers. + ## 0.9.6 ### Added