Skip to content

Commit

Permalink
💥 Remove a value/variable/constatns effective only for a specific group.
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Apr 21, 2024
1 parent 2690bd6 commit 8997442
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 146 deletions.
95 changes: 0 additions & 95 deletions src/arpes/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np

if TYPE_CHECKING:
from ._typing import Spectrometer

# eV, A reasonablish value if you aren't sure for the particular sample
WORK_FUNCTION = 4.3

Expand Down Expand Up @@ -45,91 +38,3 @@
HV_CONVERSION = 3.814697265625

TWO_DIMENSION = 2

# TODO: these should be migrated into their appropriate loaders
#
#

SPECTROMETER_MC: Spectrometer = {
"name": "MC",
"rad_per_pixel": np.deg2rad(1 / 10),
"type": "hemisphere",
"is_slit_vertical": False,
}

SPECTROMETER_MC_OLD: Spectrometer = {
"name": "MC_OLD",
"type": "hemisphere",
"rad_per_pixel": np.deg2rad(0.125),
"is_slit_vertical": False,
}

SPECTROMETER_STRAIGHT_TOF: Spectrometer = {
"name": "STRAIGHT_ToF",
"length": STRAIGHT_TOF_LENGTH,
"mstar": 1.0,
"type": "tof",
"dof": ["t"],
"scan_dof": ["theta"],
}

SPECTROMETER_SPIN_TOF: Spectrometer = {
"name": "SPIN_ToF",
"length": SPIN_TOF_LENGTH,
"mstar": 0.5,
"type": "tof",
"dof": ["time", "spin"],
"scan_dof": ["theta", "beta"],
}

SPECTROMETER_DLD: Spectrometer = {
"name": "DLD",
"length": DLD_LENGTH,
"type": "tof",
"dof_type": {
"timing": ["x_pixels", "t_pixels"],
"spatial": ["x_pixels", "y_pixels"],
},
"scan_dof": ["theta"],
}

SPECTROMETER_BL4: Spectrometer = {
"name": "BL4",
"is_slit_vertical": True,
"type": "hemisphere",
"dof": ["theta", "sample_phi"],
}

SPECTROMETER_BL7: Spectrometer = {
"name": "BL7",
"is_slit_vertical": True,
"type": "hemisphere",
"dof": ["theta", "sample_phi"],
}

SPECTROMETER_ANTARES: Spectrometer = {
"name": "ANTARES",
"is_slit_vertical": True,
"type": "hemisphere",
"dof": ["theta", "sample_phi"],
}

SPECTROMETER_KAINDL: Spectrometer = {
"name": "Kaindl",
"is_slit_vertical": True,
"type": "hemisphere",
"dof": ["theta", "sample_phi"],
}


SPECTROMETERS = {
"ALG-MC": SPECTROMETER_MC,
"ALG-SToF": SPECTROMETER_STRAIGHT_TOF,
"BL403": SPECTROMETER_BL4,
"Kaindl": SPECTROMETER_KAINDL,
"BL7": SPECTROMETER_BL7,
"ANTARES": SPECTROMETER_ANTARES,
"SToF": SPECTROMETER_SPIN_TOF,
"ToF": SPECTROMETER_STRAIGHT_TOF,
"DLD": SPECTROMETER_DLD,
}
4 changes: 1 addition & 3 deletions src/arpes/endstations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,7 @@ def prep_spectrum(data: xr.DataArray) -> xr.DataArray:
# at least consistently records the offset from the edge
# of the recorded window
if "pixel" in data.coords:
phi_axis = (
data.coords["pixel"].values * arpes.constants.SPECTROMETER_MC["rad_per_pixel"]
)
phi_axis = data.coords["pixel"].values * np.deg2rad(1 / 10)

if "pixel" in data.coords:
data = data.rename(pixel="phi")
Expand Down
7 changes: 7 additions & 0 deletions src/arpes/endstations/plugin/ALG_spin_ToF.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from arpes.endstations import EndstationBase, ScanDesc, find_clean_coords
from arpes.provenance import Provenance, provenance_from_file
from arpes.utilities import rename_keys
from arpes._typing import Spectrometer

__all__ = ("SpinToFEndstation",)

Expand Down Expand Up @@ -88,6 +89,11 @@ class SpinToFEndstation(EndstationBase):
"Phi": "phi",
}

MERGE_ATTRS: ClassVar[Spectrometer] = {
"length": 1.1456, # This isn't correct but it should be a reasonable guess
"mstar": 0.5,
}

def load_SToF_hdf5(self, scan_desc: ScanDesc | None = None) -> xr.Dataset:
"""Imports a FITS file that contains ToF spectra.
Expand Down Expand Up @@ -123,6 +129,7 @@ def load_SToF_hdf5(self, scan_desc: ScanDesc | None = None) -> xr.Dataset:
}

provenance_from_file(dataset_contents["raw"], str(data_loc), pronance_context)

return xr.Dataset(dataset_contents, attrs=scan_desc)

def load_SToF_fits(self, scan_desc: ScanDesc) -> xr.Dataset:
Expand Down
7 changes: 6 additions & 1 deletion src/arpes/endstations/plugin/SToF_DLD.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import warnings
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, ClassVar

import h5py
import numpy as np
Expand All @@ -17,13 +17,18 @@
if TYPE_CHECKING:
from _typeshed import Incomplete

from arpes._typing import Spectrometer

__all__ = ("SToFDLDEndstation",)


class SToFDLDEndstation(EndstationBase):
"""Provides data loading for the Lanzara group experimental ARToF."""

PRINCIPAL_NAME = "ALG-SToF-DLD"
MERGE_ATTRS: ClassVar[Spectrometer] = {
"length": 1.1456, # This isn't correct but it should be a reasonable guess
}

def load(self, scan_desc: ScanDesc | None = None, **kwargs: Incomplete) -> xr.Dataset:
"""Load a FITS file containing run data from Ping and Anton's delay line detector ARToF.
Expand Down
22 changes: 5 additions & 17 deletions src/arpes/preparation/tof_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ def convert_to_kinetic_energy(
"""
# This should be simplified
# Removed factors of ten and substituted mstar = 0.5
c = (
(0.5)
* (9.11e6)
* dataarray.S.spectrometer["mstar"]
* (dataarray.S.spectrometer["length"] ** 2)
/ 1.6
)
c = (0.5) * (9.11e6) * dataarray.attrs["mstar"] * (dataarray.attrs["length"] ** 2) / 1.6

new_dim_order = list(dataarray.dims)
new_dim_order.remove("time")
Expand Down Expand Up @@ -117,10 +111,10 @@ def build_KE_coords_to_time_pixel_coords(
) -> Callable[..., tuple[xr.DataArray]]:
"""Constructs a coordinate conversion function from kinetic energy to time pixels."""
conv = (
dataset.S.spectrometer["mstar"]
dataset.attrs["mstar"]
* (BARE_ELECTRON_MASS * 1e37)
* 0.5
* (dataset.S.spectrometer["length"] ** 2)
* (dataset.attrs["length"] ** 2)
/ 1.6
)
time_res = 0.17 # this is only approximate
Expand Down Expand Up @@ -162,15 +156,9 @@ def build_KE_coords_to_time_coords(
Geometric transform assumes pixel -> pixel transformations so we need to get
the index associated to the appropriate timing value
"""
conv = (
dataset.S.spectrometer["mstar"]
* (9.11e6)
* 0.5
* (dataset.S.spectrometer["length"] ** 2)
/ 1.6
)
conv = dataset.attrs["mstar"] * (9.11e6) * 0.5 * (dataset.attrs["length"] ** 2) / 1.6
timing = dataset.coords["time"]
photon_offset = dataset.attrs["laser_t0"] + dataset.S.spectrometer["length"] * (10 / 3)
photon_offset = dataset.attrs["laser_t0"] + dataset.attrs["length"] * (10 / 3)
low_offset = np.min(timing)
d_timing = timing[1] - timing[0]

Expand Down
21 changes: 0 additions & 21 deletions src/arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,23 +744,6 @@ def _unwrap_provenance(prov: Provenance | None) -> list[Provenance | None]:

return _unwrap_provenance(provenance_recorded)

@property
def spectrometer(self) -> Spectrometer:
ds = self._obj
if "spectrometer_name" in ds.attrs:
return arpes.constants.SPECTROMETERS.get(ds.attrs["spectrometer_name"], {})
if isinstance(ds, xr.Dataset):
if "up" in ds.data_vars or ds.attrs.get("18 MCP3") == 0:
return arpes.constants.SPECTROMETERS["SToF"]
elif isinstance(ds, xr.DataArray) and (ds.name == "up" or ds.attrs.get("18 MCP3") == 0):
return arpes.constants.SPECTROMETERS["SToF"]
if "location" in ds.attrs:
return arpes.constants.SPECTROMETERS.get(ds.attrs["location"], {})
try:
return arpes.constants.SPECTROMETERS[ds.attrs["spectrometer_name"]]
except KeyError:
return {}

@property
def scan_name(self) -> str:
"""Return scan name.
Expand Down Expand Up @@ -1686,11 +1669,7 @@ def coordinate_dataarray_to_flat_rep(value: xr.DataArray) -> str | float:
)

def _repr_html_spectrometer_info(self) -> str:
skip_keys = {
"dof",
}
ordered_settings = OrderedDict(self.spectrometer_settings)
ordered_settings.update({k: v for k, v in self.spectrometer.items() if k not in skip_keys})

return ARPESAccessorBase.dict_to_html(ordered_settings)

Expand Down
9 changes: 0 additions & 9 deletions tests/test_xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ def test_transpose_front_back(self, dataarray_cut: xr.DataArray) -> None:
np.testing.assert_array_equal(original_ndarray, transpose_to_front_ndarray.T)
np.testing.assert_array_equal(original_ndarray, transpose_to_back_ndarray)

def test_spectrometer_property(self, dataarray_cut: xr.DataArray) -> None:
"""Test for spectrometer property."""
assert dataarray_cut.S.spectrometer == {
"name": "MC",
"rad_per_pixel": (1 / 10) * (np.pi / 180),
"type": "hemisphere",
"is_slit_vertical": False,
}

def test_property_for_degrees_of_freedom(
self,
dataset_cut: xr.Dataset,
Expand Down

0 comments on commit 8997442

Please sign in to comment.