Skip to content

Commit

Permalink
🧼 correction: update TypedDict classes
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Sep 3, 2023
1 parent c02364e commit 28ff3b0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
39 changes: 16 additions & 23 deletions arpes/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"NAN_POLICY",
"CONFIGTYPE",
"WORKSPACETYPE",
"ANALYZERINFO",
]

DataType = TypeVar("DataType", xr.DataArray, xr.Dataset)
Expand All @@ -52,23 +53,6 @@
NAN_POLICY = Literal["raise", "propagate", "omit"]


class SPECTROMETER(TypedDict, total=False):
name: str
rad_per_pixel: float
type: str
is_slit_vertical: bool
dof: list[str]
scan_dof: list[str]
mstar: float
dof_type: dict[str, list[str]]
length: float
##
analyzer: str
analyzer_name: str
parallel_deflectors: bool
perpendicular_deflectors: bool


class COORDINATES(TypedDict, total=False):
x: NDArray[np.float_] | float | None
y: NDArray[np.float_] | float | None
Expand All @@ -80,6 +64,10 @@ class COORDINATES(TypedDict, total=False):


class ANALYZERINFO(TypedDict, total=False):
analyzer: str
analyzer_name: str
parallel_deflectors: bool
perpendicular_deflectors: bool
lens_mode: str | None
lens_mode_name: str | None
acquisition_mode: float
Expand Down Expand Up @@ -188,12 +176,17 @@ class DAQINFO(TypedDict, total=False):
center_energy: float | None


class EXPECTEDD(TypedDict, total=False):
scan_info: SCANINFO


class SCENARIO(TypedDict, total=False):
file: str
class SPECTROMETER(ANALYZERINFO, COORDINATES, total=False):
name: str
rad_per_pixel: float
type: str
is_slit_vertical: bool
dof: list[str]
scan_dof: list[str]
mstar: float
dof_type: dict[str, list[str]]
length: float
##


RGBColorType = tuple[float, float, float] | str
Expand Down
2 changes: 1 addition & 1 deletion arpes/endstations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def resolve_frame_locations(self, scan_desc: SCANDESC | None = None) -> list[str

def load_single_frame(
self,
frame_path: str | None = None,
frame_path: str | None = None, # TODO<RA> should be str and default is ""
scan_desc: SCANDESC | None = None,
**kwargs,
) -> xr.Dataset:
Expand Down
14 changes: 14 additions & 0 deletions arpes/endstations/plugin/SPD_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ class SPDEndstation(HemisphericalEndstation, SingleFileEndstation):
"Detector Voltage": "mcp_voltage",
"Spectrum ID": "id",
"DwellTime": "dwelltime",
"Created Date (UTC)": "created_date_utc",
"Created by": "created_by",
"Scan Mode": "scan_mode",
"User Comment": "user_comment",
"Analysis Mode": "analyais_mode",
"Analyzer Slits": "analyzer_slits",
"Number of Scans": "number_of_scans",
"Number of Samples": "number_of_samples",
"Scan Step": "scan_step",
"Kinetic Energy": "kinetic_energy",
"Binding Energy": "kinetic_energy",
"Bias Voltage": "bias_voltage",
"Igor Text File Exporter Version": "igor_text_file_exporter_version",
"Lens Voltage": "lens voltage",
}
MERGE_ATTRS: ClassVar[SPECTROMETER] = {
"analyzer": "Specs PHOIBOS 100",
Expand Down
3 changes: 1 addition & 2 deletions arpes/utilities/funcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def is_leaf(x):
if is_leaf(v):
yield k, v
else:
for item in iter_leaves(v):
yield item
yield from iter_leaves(v)


def lift_dataarray_to_generic(f):
Expand Down
7 changes: 4 additions & 3 deletions arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import pandas as pd
from matplotlib.axes import Axes
from numpy.typing import DTypeLike, NDArray
from typeshed import Incomplete

from arpes._typing import ANGLE, SPECTROMETER, DataType, RGBColorType

Expand Down Expand Up @@ -104,7 +105,7 @@ def _iter_groups(grouped: dict[str, Any]) -> Iterator[Any]:
class ARPESAccessorBase:
"""Base class for the xarray extensions in PyARPES."""

def along(self, directions, **kwargs):
def along(self, directions, **kwargs: Incomplete):
return slice_along_path(self._obj, directions, **kwargs)

def find(self, name: str) -> list[str]:
Expand All @@ -119,7 +120,7 @@ def find(self, name: str) -> list[str]:
return [n for n in dir(self) if name in n]

@property
def sherman_function(self):
def sherman_function(self) -> Incomplete:
for option in ["sherman", "sherman_function", "SHERMAN"]:
if option in self._obj.attrs:
return self._obj.attrs[option]
Expand Down Expand Up @@ -280,7 +281,7 @@ def hv(self) -> float | None:
return 5.93
return None

def fetch_ref_attrs(self):
def fetch_ref_attrs(self) -> Incomplete:
"""Get reference attrs."""
if "ref_attrs" in self._obj.attrs:
return self._obj.attrs
Expand Down
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, TypedDict

import pytest

Expand All @@ -17,7 +17,15 @@

import xarray as xr

from arpes._typing import WORKSPACETYPE
from arpes._typing import SCANINFO, WORKSPACETYPE


class EXPECTEDD(TypedDict, total=False):
scan_info: SCANINFO


class SCENARIO(TypedDict, total=False):
file: str


@dataclass
Expand Down

0 comments on commit 28ff3b0

Please sign in to comment.