Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor upgrade of the prodixy_xy #7

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ rainsty
kcurrier6
Tommaso (Tommaso Pincelli)
cgfatuzzo (Claudia Fatuzzo)
Marek Kopciuszynski
42 changes: 11 additions & 31 deletions src/arpes/endstations/prodigy_xy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import re
from pathlib import Path
from typing import TYPE_CHECKING, Literal, TypedDict, cast
from typing import TYPE_CHECKING

import numpy as np
import xarray as xr
Expand All @@ -35,32 +35,9 @@
MAP_DIMENSION = 3
SECOND_DIM_NAME = "nonenergy"

Measure_type = Literal["FAT", "SnapshotFAT", "Magnification"]
__all__ = ["load_xy"]


class ProdigyXYParams(TypedDict, total=False):
group: str
region: str
acquisition_date: str
analysis_method: str
analyzer: str
analyzer_lens: str
analyzer_slit: str
scan_mode: Measure_type
curves_scan: int
values_curve: int
dwell_time: float
excitation_energy: float
kinetic_energy: float
pass_energy: float
bias_voltage: float
detector_voltage: float
eff_workfunction: float
source: str
comment: str
ordinate_range: str


class ProdigyXY:
"""Class for Prodigy exported xy file.
Expand All @@ -79,7 +56,7 @@ class ProdigyXY:

def __init__(self, list_from_xy_file: list[str] | None = None) -> None:
"""Initialize."""
self.params: ProdigyXYParams = cast(ProdigyXYParams, {})
self.params: dict[str, str | float | int] = {}
self.axis_info: dict[str, tuple[NDArray[np.float_], str]] = {}
self.intensity: NDArray[np.float_]
if list_from_xy_file is not None:
Expand Down Expand Up @@ -203,7 +180,7 @@ def load_xy(
return data_array


def _parse_xy_head(xy_data_params: list[str]) -> ProdigyXYParams:
def _parse_xy_head(xy_data_params: list[str]) -> dict[str, str | int | float]:
"""Parse Common head part.

Parameters
Expand All @@ -228,8 +205,12 @@ def _parse_xy_head(xy_data_params: list[str]) -> ProdigyXYParams:
break
key, _, value = line[1:].partition(":")
temp_params[key.strip()] = _formatted_value(value)
common_params: ProdigyXYParams = cast(ProdigyXYParams, clean_keys(temp_params))
return common_params

temp_params = clean_keys(temp_params)
temp_params["curves_scan"] = int(temp_params["curves_scan"])
temp_params["values_curve"] = int(temp_params["values_curve"])

return temp_params


def _parse_xy_dims(xy_data_params: list[str]) -> dict[str, NDArray[np.float_]]:
Expand Down Expand Up @@ -282,10 +263,9 @@ def _parse_xy_dims(xy_data_params: list[str]) -> dict[str, NDArray[np.float_]]:
return clean_keys(xy_dims)


def _formatted_value(value: str) -> int | float | str:
def _formatted_value(value: str) -> float | str:
"""Convert string value to float if possible."""
value = value.strip()
if value.isnumeric():
return int(value)
try:
return float(value)
except ValueError:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_prodigy_xy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def test_parameters(self, sample_xy: ProdigyXY) -> None:
assert sample_xy.axis_info["d1"][1] == "eV"
assert sample_xy.axis_info["d2"][1] == "nonenergy"
assert sample_xy.axis_info["d3"][1] == "polar"
assert isinstance(sample_xy.params["detector_voltage"], float)
assert isinstance(sample_xy.params["values_curve"], int)
np.testing.assert_almost_equal(sample_xy.params["eff_workfunction"], 4.31)
np.testing.assert_almost_equal(sample_xy.params["excitation_energy"], 21.2182)
np.testing.assert_almost_equal(sample_xy.axis_info["d1"][0][5], 20.080305)
Expand Down
Loading