From 89974426b0c7aa52438b33a65bb624fc9528fa86 Mon Sep 17 00:00:00 2001 From: Ryuichi Arafune Date: Sun, 21 Apr 2024 22:47:28 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20=20Remove=20a=20value/variable/c?= =?UTF-8?q?onstatns=20effective=20only=20for=20a=20specific=20group.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arpes/constants.py | 95 -------------------- src/arpes/endstations/__init__.py | 4 +- src/arpes/endstations/plugin/ALG_spin_ToF.py | 7 ++ src/arpes/endstations/plugin/SToF_DLD.py | 7 +- src/arpes/preparation/tof_preparation.py | 22 ++--- src/arpes/xarray_extensions.py | 21 ----- tests/test_xarray_extensions.py | 9 -- 7 files changed, 19 insertions(+), 146 deletions(-) diff --git a/src/arpes/constants.py b/src/arpes/constants.py index 1b238f95..57260464 100644 --- a/src/arpes/constants.py +++ b/src/arpes/constants.py @@ -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 @@ -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, -} diff --git a/src/arpes/endstations/__init__.py b/src/arpes/endstations/__init__.py index cc89832c..fbef66f3 100644 --- a/src/arpes/endstations/__init__.py +++ b/src/arpes/endstations/__init__.py @@ -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") diff --git a/src/arpes/endstations/plugin/ALG_spin_ToF.py b/src/arpes/endstations/plugin/ALG_spin_ToF.py index a4440879..e0ba3bf6 100644 --- a/src/arpes/endstations/plugin/ALG_spin_ToF.py +++ b/src/arpes/endstations/plugin/ALG_spin_ToF.py @@ -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",) @@ -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. @@ -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: diff --git a/src/arpes/endstations/plugin/SToF_DLD.py b/src/arpes/endstations/plugin/SToF_DLD.py index ff1eef48..ffa5c592 100644 --- a/src/arpes/endstations/plugin/SToF_DLD.py +++ b/src/arpes/endstations/plugin/SToF_DLD.py @@ -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 @@ -17,6 +17,8 @@ if TYPE_CHECKING: from _typeshed import Incomplete + from arpes._typing import Spectrometer + __all__ = ("SToFDLDEndstation",) @@ -24,6 +26,9 @@ 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. diff --git a/src/arpes/preparation/tof_preparation.py b/src/arpes/preparation/tof_preparation.py index ede3386c..cc1ae632 100644 --- a/src/arpes/preparation/tof_preparation.py +++ b/src/arpes/preparation/tof_preparation.py @@ -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") @@ -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 @@ -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] diff --git a/src/arpes/xarray_extensions.py b/src/arpes/xarray_extensions.py index 33b6e2f8..d0a6215a 100644 --- a/src/arpes/xarray_extensions.py +++ b/src/arpes/xarray_extensions.py @@ -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. @@ -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) diff --git a/tests/test_xarray_extensions.py b/tests/test_xarray_extensions.py index 359d16f3..c4172f45 100644 --- a/tests/test_xarray_extensions.py +++ b/tests/test_xarray_extensions.py @@ -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,