Skip to content

Commit

Permalink
💬 Update type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Mar 27, 2024
1 parent 36cfe8a commit d1d6a9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
30 changes: 19 additions & 11 deletions src/arpes/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -336,7 +344,7 @@ class ExperimentInfo(
AnalyzerInfo,
total=False,
):
pass
analyzer_detail: AnalyzerDetail


class ARPESAttrs(Spectrometer, LightSourceInfo, SampleInfo, total=False):
Expand Down
14 changes: 7 additions & 7 deletions src/arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@

from ._typing import (
ANGLE,
AnalyzerDetail,
AnalyzerInfo,
BeamLineSettings,
DAQInfo,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/test_basic_data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class TestMetadata:
"photocurrent": np.nan,
"probe": None,
"probe_detail": None,
"analyzer": "Specs PHOIBOS 150",
"analyzer_detail": {
"type": "hemispherical",
"radius": 150,
Expand Down Expand Up @@ -160,7 +159,6 @@ class TestMetadata:
"photocurrent": np.nan,
"probe": None,
"probe_detail": None,
"analyzer": "R8000",
"analyzer_detail": {
"name": "Scienta R8000",
"parallel_deflectors": False,
Expand Down Expand Up @@ -249,7 +247,6 @@ class TestMetadata:
"photocurrent": np.nan,
"probe": None,
"probe_detail": None,
"analyzer": "R4000",
"analyzer_detail": {
"type": "hemispherical",
"radius": np.nan,
Expand Down

0 comments on commit d1d6a9d

Please sign in to comment.