From ab4b0f54157249b2ff15828efabfd2b713bb02cd Mon Sep 17 00:00:00 2001 From: Ryuichi Arafune Date: Tue, 19 Mar 2024 16:04:12 +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 --- docs/source/api.rst | 12 ++++++++++++ pyproject.toml | 2 +- src/arpes/_typing.py | 2 +- src/arpes/analysis/mask.py | 6 +++--- src/arpes/utilities/dict.py | 10 +++++----- src/arpes/utilities/xarray.py | 8 +++++--- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/source/api.rst b/docs/source/api.rst index 10ad35c3..c8c4b13c 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -104,6 +104,18 @@ Self-Energy analysis.self_energy.quasiparticle_lifetime +Time-Resolved ARPES Related +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. autosummary:: + + analysis.tarpes.find_t0 + analysis.tarpes.relative_change + analysis.tarpes.normalized_relative_change + analysis.tarpes.build_crosscorrelation + analysis.tarpes.delaytime_fs + analysis.tarpes.position_to_delaytime + Spin-ARPES Related ~~~~~~~~~~~~~~~~~~ diff --git a/pyproject.toml b/pyproject.toml index e707d81e..67a4d732 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,7 +98,7 @@ lint.ignore = [ "NPY201", # Numpy 2.0, ] lint.select = ["ALL"] -target-version = "py310" +target-version = "py311" line-length = 100 indent-width = 4 diff --git a/src/arpes/_typing.py b/src/arpes/_typing.py index 2f78e58a..bd31e6bc 100644 --- a/src/arpes/_typing.py +++ b/src/arpes/_typing.py @@ -126,7 +126,7 @@ class ConfigSettings(TypedDict, total=False): class WorkSpaceType(TypedDict, total=False): """TypedDict for arpes.config.CONFIG["WORKSPACE"].""" - path: str | Path + path: Required[str | Path] name: str diff --git a/src/arpes/analysis/mask.py b/src/arpes/analysis/mask.py index e8721015..9ff45e76 100644 --- a/src/arpes/analysis/mask.py +++ b/src/arpes/analysis/mask.py @@ -55,7 +55,7 @@ def polys_to_mask( radius: float = 0, *, invert: bool = False, -) -> NDArray[np.float_] | NDArray[np.bool_]: +) -> NDArray[np.bool_]: """Converts a mask definition in terms of the underlying polygon to a True/False mask array. Uses the coordinates and shape of the target data in order to determine which pixels @@ -70,7 +70,7 @@ def polys_to_mask( coords: shape: radius (float): Additional margin on the path in coordinates of *points*. - invert (bool): + invert (bool): if true, flip True/False in mask. Returns: The mask. @@ -108,7 +108,7 @@ def apply_mask_to_coords( dims: list[str], *, invert: bool = True, -): +) -> NDArray[np.bool_]: """Performs broadcasted masking along a given dimension. Args: diff --git a/src/arpes/utilities/dict.py b/src/arpes/utilities/dict.py index 729b160b..e7c3d08a 100644 --- a/src/arpes/utilities/dict.py +++ b/src/arpes/utilities/dict.py @@ -16,6 +16,9 @@ ) +T = TypeVar("T") + + def _rename_key( d: dict[str, Any], original_name_k: str, @@ -27,9 +30,9 @@ def _rename_key( def rename_keys( - d: dict[str, Any], + d: dict[str, T], keys_dict: dict[str, str], -) -> dict[str, Any]: +) -> dict[str, T]: """Renames all the keys of `d` according to the remapping in `keys_dict`. Args: @@ -46,9 +49,6 @@ def rename_keys( return d -T = TypeVar("T") - - def clean_keys(d: dict[str, T]) -> dict[str, T]: """Renames dict key to fit Pythonic more. diff --git a/src/arpes/utilities/xarray.py b/src/arpes/utilities/xarray.py index 35a7d33d..96f47f1a 100644 --- a/src/arpes/utilities/xarray.py +++ b/src/arpes/utilities/xarray.py @@ -3,7 +3,7 @@ from __future__ import annotations from logging import DEBUG, INFO, Formatter, StreamHandler, getLogger -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, TypeVar import xarray as xr @@ -38,6 +38,8 @@ logger.addHandler(handler) logger.propagate = False +T = TypeVar("T") + def unwrap_xarray_item(item: xr.DataArray) -> xr.DataArray | float: """Unwraps something that might or might not be an xarray like with .item() attribute. @@ -115,7 +117,7 @@ def g(arr: xr.DataArray, *args: Incomplete, **kwargs: Incomplete) -> xr.DataArra def lift_dataarray_attrs( - f: Callable[[dict[str, Any], Any], dict[str, Any]], + f: Callable[[dict[str, T], Any], dict[str, T]] | Callable[[dict[str, T]], dict[str, T]], ) -> Callable[[xr.DataArray], xr.DataArray]: """Lifts a function that operates dicts to a function that acts on dataarray attrs. @@ -154,7 +156,7 @@ def g( def lift_datavar_attrs( - f: Callable[[dict[str, Any], Any], dict[str, Any]], + f: Callable[[dict[str, T], Any], dict[str, T]] | Callable[[dict[str, T]], dict[str, T]], ) -> Callable[..., DataType]: """Lifts a function that operates dicts to a function that acts on xr attrs.