Skip to content

Commit

Permalink
🔨 update PRETTY_KEYS definition
Browse files Browse the repository at this point in the history
💬  update type hints
  • Loading branch information
arafune committed Oct 18, 2023
1 parent a0f6363 commit 04c649e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions arpes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pint

if TYPE_CHECKING:
from arpes._typing import CONFIGTYPE, ConfigSettings
from arpes._typing import CONFIGTYPE, WORKSPACETYPE, ConfigSettings

# pylint: disable=global-statement

Expand Down Expand Up @@ -124,8 +124,8 @@ def __init__(self, workspace: str | None = None) -> None:
Args:
workspace: The name of the workspace to enter temporarily. Defaults to None.
"""
self._cached_workspace: CONFIGTYPE = {}
self._workspace = workspace
self._cached_workspace: WORKSPACETYPE = {}
self._workspace: str | None = workspace

def __enter__(self) -> None:
"""Caches the current workspace and enters a new one.
Expand Down
4 changes: 2 additions & 2 deletions arpes/corrections/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def remove_incoherent_background(data: DataType, *, set_zero: bool = True) -> xr
pulses).
Args:
data:
set_zero:
data (DataType): input ARPES data
set_zero (bool): set zero if the negative value is obtained after background subtraction.
Returns:
Data with a background subtracted.
Expand Down
2 changes: 1 addition & 1 deletion arpes/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Rudimentary band analysis code."""
from __future__ import annotations

from .band import *
from .band import BackgroundBand, Band, MultifitBand, VoigtBand
25 changes: 14 additions & 11 deletions arpes/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ class WindowedDetectorEffect(DetectorEffect):
"""TODO model the finite width of the detector window as recorded on a camera."""


def cloud_to_arr(point_cloud, shape) -> NDArray[np.float_]:
def cloud_to_arr(
point_cloud: list[list[float]],
shape: tuple[int, int],
) -> NDArray[np.float_]:
"""Converts a point cloud (list of xy pairs) to an array representation.
Uses linear interpolation for points that have non-integral coordinates.
Expand All @@ -164,7 +167,7 @@ def cloud_to_arr(point_cloud, shape) -> NDArray[np.float_]:
"""
cloud_as_image = np.zeros(shape)

for x, y in zip(*point_cloud):
for x, y in zip(*point_cloud, strict=True):
frac_low_x = 1 - (x - np.floor(x))
frac_low_y = 1 - (y - np.floor(y))
shape_x, shape_y = shape
Expand All @@ -174,9 +177,9 @@ def cloud_to_arr(point_cloud, shape) -> NDArray[np.float_]:
cloud_as_image[(int(np.floor(x)) + 1) % shape_x][int(np.floor(y)) % shape_y] += (
1 - frac_low_x
) * frac_low_y
cloud_as_image[int(np.floor(x)) % shape_x][
(int(np.floor(y)) + 1) % shape_y
] += frac_low_x * (1 - frac_low_y)
cloud_as_image[int(np.floor(x)) % shape_x][(int(np.floor(y)) + 1) % shape_y] += (
frac_low_x * (1 - frac_low_y)
)
cloud_as_image[(int(np.floor(x)) + 1) % shape_x][(int(np.floor(y)) + 1) % shape_y] += (
1 - frac_low_x
) * (1 - frac_low_y)
Expand All @@ -185,8 +188,8 @@ def cloud_to_arr(point_cloud, shape) -> NDArray[np.float_]:


def apply_psf_to_point_cloud(
point_cloud,
shape,
point_cloud: list[list[float]],
shape: tuple[int, int],
sigma: tuple[int, int] = (10, 3),
) -> NDArray[np.float_]:
"""Takes a point cloud and turns it into a broadened spectrum.
Expand Down Expand Up @@ -220,9 +223,9 @@ def sample_from_distribution(
sample individual events coming from this PDF.
Args:
distribution: The probability density. The probability of drawing a sample at (i, j)
will be proportional to `distribution[i, j]`.
N: The desired number of electrons/samples to pull from the distribution.
distribution(xr.DataArray): The probability density. The probability of drawing a
sample at (i, j) will be proportional to `distribution[i, j]`.
n(int): The desired number of electrons/samples to pull from the distribution.
Returns:
An array with the arrival locations.
Expand Down Expand Up @@ -347,7 +350,7 @@ def sampled_spectral_function(
spectral = self.measured_spectral_function()
sampled = [
apply_psf_to_point_cloud(
sample_from_distribution(spectral, N=n_electrons),
sample_from_distribution(spectral, n=n_electrons),
spectral.values.shape,
sigma=psf,
)
Expand Down
7 changes: 4 additions & 3 deletions arpes/utilities/qt/help_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
from arpes.utilities.ui import PRETTY_KEYS, label, vertical

if TYPE_CHECKING:
from _typeshed import Incomplete
from PySide6.QtGui import QKeyEvent

from arpes.utilities.ui import KeyBinding
__all__ = ("BasicHelpDialog",)


class BasicHelpDialog(QtWidgets.QDialog):
"""A help dialog showing keyboard shortcuts for Qt application."""

def __init__(self, shortcuts: Incomplete | None = None) -> None:
def __init__(self, shortcuts: list[KeyBinding] | None = None) -> None:
"""Initialize the help window and build widgets for the registered shortcuts."""
super().__init__()

Expand Down Expand Up @@ -65,6 +66,6 @@ def __init__(self, shortcuts: Incomplete | None = None) -> None:

def keyPressEvent(self, event: QKeyEvent) -> None:
"""If the user preset H we should toggle the dialog, or close it if they pressed Esc."""
if event.key() == QtCore.Qt.Key_H or event.key() == QtCore.Qt.Key_Escape:
if event.key() == QtCore.Qt.Key.Key_H or event.key() == QtCore.Qt.Key.Key_Escape:
self._main_window._help_dialog = None # pylint: disable=protected-access
self.close()
2 changes: 1 addition & 1 deletion arpes/utilities/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class CursorMode(NamedTuple):


PRETTY_KEYS = {}
for key, value in vars(QtCore.Qt).items():
for key, value in vars(QtCore.Qt.Key).items():
if isinstance(value, QtCore.Qt.Key):
PRETTY_KEYS[value] = key.partition("_")[2]

Expand Down
2 changes: 1 addition & 1 deletion arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def iter_symmetry_points(self) -> Generator[tuple[str, float], None, None]:
yield from self.iter_projected_symmetry_points

@property
def history(self):
def history(self) -> dict:
provenance_recorded = self._obj.attrs.get("provenance", None)

def unlayer(prov: dict[str, Incomplete] | None) -> tuple[list[Incomplete], Incomplete]:
Expand Down

0 comments on commit 04c649e

Please sign in to comment.