Skip to content

Commit

Permalink
Merge branch 'daredevil' of https://github.com/arafune/arpes into dar…
Browse files Browse the repository at this point in the history
…edevil
  • Loading branch information
arafune committed Mar 23, 2024
2 parents c5d820e + 742e2da commit fe30bd9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/arpes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ def load_data(
return load_scan(desc, **kwargs)


DATA_EXAMPLES = {
DATA_EXAMPLES: dict[str, tuple[str, str]] = {
"cut": ("ALG-MC", "cut.fits"),
"map": ("example_data", "fermi_surface.nc"),
"photon_energy": ("example_data", "photon_energy.nc"),
"nano_xps": ("example_data", "nano_xps.nc"),
"temperature_dependence": ("example_data", "temperature_dependence.nc"),
"cut2": ("SPD", "example_itx_data.itx"),
"map2": ("IF_UMCS", "BLGr_GK_example_xy_data.xy"),
}


def load_example_data(example_name: str = "cut") -> xr.Dataset:
"""Provides sample data for executable documentation.
Args:
example_name: [TODO:description]
example_name: (cut, map, photon_energy, nano_xps, temperature_dependence)
Returns:
[TODO:description]
Expand All @@ -131,6 +133,7 @@ def load_example_data(example_name: str = "cut") -> xr.Dataset:
)

location, example = DATA_EXAMPLES[example_name]
logger.debug(f"location:{location}")
file = Path(__file__).parent / "example_data" / example
return load_data(file=file, location=location)

Expand All @@ -157,6 +160,14 @@ def nano_xps(self) -> xr.Dataset:
def temperature_dependence(self) -> xr.Dataset:
return load_example_data("temperature_dependence")

@property
def cut2(self) -> xr.Dataset:
return load_example_data("cut2")

@property
def map2(self) -> xr.Dataset:
return load_example_data("map2")


example_data = ExampleData()

Expand Down
11 changes: 5 additions & 6 deletions src/arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,23 +770,22 @@ def dshape(self) -> dict[Hashable, int]:

@property
def scan_name(self) -> str:
"""[TODO:summary].
"""Return scan name.
Args:
self ([TODO:type]): [TODO:description]
Returns:
[TODO:description]
Returns: (str)
If "scan" or "file" is set in attrs, return the file name.
If they are not set, return "id" if "id" is set.
"""
for option in ["scan", "file"]:
if option in self._obj.attrs:
return Path(self._obj.attrs[option]).name

id_code = self._obj.attrs.get("id")

if id_code is None:
return "No ID"
return str(id_code)
return str(id_code) if id_code is not None else "No ID"

@property
def label(self) -> str:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def hv_map() -> xr.Dataset:
return example_data.photon_energy


@pytest.fixture()
def dataset_cut2() -> xr.Dataset:
"""A fixture for loading Dataset."""
return example_data.cut2


@pytest.fixture()
def dataarray_cut2() -> xr.DataArray:
"""A fixture for loading Dataset."""
return example_data.cut2.spectrum


class TestforProperties:
"""Test class for Array Dataset properties."""

Expand Down Expand Up @@ -298,16 +310,20 @@ def test_switch_energy_notation(
with pytest.raises(RuntimeError) as e:
hv_map.S.switch_energy_notation()
assert str(e.value) == "Not impremented yet."
with pytest.raises(RuntimeError) as e:
hv_map.spectrum.S.switch_energy_notation()
assert str(e.value) == "Not impremented yet."

def test_spectrum_type(self, dataarray_cut: xr.DataArray) -> None:
"""Test spectrum_type."""
assert dataarray_cut.S.spectrum_type == "cut"
del dataarray_cut.attrs["spectrum_type"]
assert dataarray_cut.S.spectrum_type == "cut"

def test_label(self, dataarray_cut: xr.DataArray) -> None:
def test_label(self, dataarray_cut: xr.DataArray, dataarray_cut2: xr.DataArray) -> None:
"""Test scan_name."""
assert dataarray_cut.S.label == "cut.fits"
assert dataarray_cut2.S.scan_name == "2"


class TestGeneralforDataArray:
Expand Down

0 comments on commit fe30bd9

Please sign in to comment.