From d1d6a9dccd5b439cce96ca7597c4bac90fcd967f Mon Sep 17 00:00:00 2001 From: Ryuichi Arafune Date: Wed, 27 Mar 2024 18:26:28 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AC=20=20Update=20type=20hints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arpes/_typing.py | 30 +++++++++++++++++++----------- src/arpes/xarray_extensions.py | 14 +++++++------- tests/test_basic_data_loading.py | 3 --- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/arpes/_typing.py b/src/arpes/_typing.py index bd31e6bc..9acbf226 100644 --- a/src/arpes/_typing.py +++ b/src/arpes/_typing.py @@ -178,7 +178,7 @@ class Coordinates(TypedDict, total=False): class AnalyzerInfo(TypedDict, total=False): """TypedDict for attrs. - see analyzer_info in xarray_extensions.py + see analyzer_info in xarray_extensions.py (around line# 1490) """ lens_mode: str | None @@ -193,13 +193,20 @@ class AnalyzerInfo(TypedDict, total=False): mcp_voltage: float work_function: float # - analyzer_radius: float - analyzer: str | None - analyzer_name: str | None + is_slit_vertical: bool + + +class AnalyzerDetail(TypedDict, total=False): + """TypedDict for analyzer_detail. + + Used in analyzer_detail in xarray_extensions.py (around line# 1597) + """ + + name: str parallel_deflectors: bool perpendicular_deflectors: bool - # - is_slit_vertical: bool + type: str + radius: str | float class _PumpInfo(TypedDict, total=False): @@ -253,12 +260,12 @@ class _BeamLineInfo(TypedDict, total=False): hv: float | xr.DataArray linewidth: float photon_polarization: tuple[float, float] - undulation_info: Incomplete + undulator_info: Incomplete repetition_rate: float beam_current: float entrance_slit: float | str exit_slit: float | str - monochrometer_info: dict[str, float] + monochromator_info: dict[str, float] class BeamLineSettings(TypedDict, total=False): @@ -269,6 +276,8 @@ class BeamLineSettings(TypedDict, total=False): class LightSourceInfo(_ProbeInfo, _PumpInfo, _BeamLineInfo, total=False): + """TypedDict for beamline_info.""" + polarization: float | tuple[float, float] | str photon_flux: float photocurrent: float @@ -313,7 +322,7 @@ class DAQInfo(TypedDict, total=False): prebinning: dict[str, float] trapezoidal_correction_strategy: Incomplete dither_settings: Incomplete - sweep_setting: Incomplete + sweep_settings: Incomplete frames_per_slice: int frame_duration: float @@ -327,7 +336,6 @@ class Spectrometer(AnalyzerInfo, Coordinates, DAQInfo, total=False): mstar: float dof_type: dict[str, list[str]] length: float - probe_linewidth: float class ExperimentInfo( @@ -336,7 +344,7 @@ class ExperimentInfo( AnalyzerInfo, total=False, ): - pass + analyzer_detail: AnalyzerDetail class ARPESAttrs(Spectrometer, LightSourceInfo, SampleInfo, total=False): diff --git a/src/arpes/xarray_extensions.py b/src/arpes/xarray_extensions.py index 65011a19..7b335206 100644 --- a/src/arpes/xarray_extensions.py +++ b/src/arpes/xarray_extensions.py @@ -104,6 +104,7 @@ from ._typing import ( ANGLE, + AnalyzerDetail, AnalyzerInfo, BeamLineSettings, DAQInfo, @@ -1431,7 +1432,6 @@ def experiment_info(self) -> ExperimentInfo: "photocurrent": self._obj.attrs.get("photocurrent", np.nan), "probe": self._obj.attrs.get("probe"), "probe_detail": self._obj.attrs.get("probe_detail"), - "analyzer": self._obj.attrs.get("analyzer"), "analyzer_detail": self.analyzer_detail, } return experiment_info @@ -1593,14 +1593,14 @@ def undulator_info(self) -> dict[str, str | float | None]: } @property - def analyzer_detail(self) -> dict[str, str | float | None]: + def analyzer_detail(self) -> AnalyzerDetail: """Details about the analyzer, its capabilities, and metadata.""" return { - "name": self._obj.attrs.get("analyzer_name"), - "parallel_deflectors": self._obj.attrs.get("parallel_deflectors"), - "perpendicular_deflectors": self._obj.attrs.get("perpendicular_deflectors"), - "type": self._obj.attrs.get("analyzer_type"), - "radius": self._obj.attrs.get("analyzer_radius"), + "name": self._obj.attrs.get("analyzer_name", self._obj.attrs.get("analyzer", "")), + "parallel_deflectors": self._obj.attrs.get("parallel_deflectors", False), + "perpendicular_deflectors": self._obj.attrs.get("perpendicular_deflectors", False), + "type": self._obj.attrs.get("analyzer_type", ""), + "radius": self._obj.attrs.get("analyzer_radius", np.nan), } @property diff --git a/tests/test_basic_data_loading.py b/tests/test_basic_data_loading.py index 426dd99b..cbd6d1f7 100644 --- a/tests/test_basic_data_loading.py +++ b/tests/test_basic_data_loading.py @@ -69,7 +69,6 @@ class TestMetadata: "photocurrent": np.nan, "probe": None, "probe_detail": None, - "analyzer": "Specs PHOIBOS 150", "analyzer_detail": { "type": "hemispherical", "radius": 150, @@ -160,7 +159,6 @@ class TestMetadata: "photocurrent": np.nan, "probe": None, "probe_detail": None, - "analyzer": "R8000", "analyzer_detail": { "name": "Scienta R8000", "parallel_deflectors": False, @@ -249,7 +247,6 @@ class TestMetadata: "photocurrent": np.nan, "probe": None, "probe_detail": None, - "analyzer": "R4000", "analyzer_detail": { "type": "hemispherical", "radius": np.nan,