Skip to content

Commit

Permalink
⬆️ Python version should be 3.11 or above.
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Feb 26, 2024
1 parent a2f2841 commit 37fe0b2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
{ name = "Ryuichi Arafune", email = "[email protected]" },
]
readme = "README.rst"
requires-python = ">= 3.10"
requires-python = ">= 3.11"

dependencies = [
"holoviews>=1.16.0",
Expand Down
9 changes: 4 additions & 5 deletions src/arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,7 @@ def mean_other(
*,
keep_attrs: bool = False,
) -> XrTypes:
if isinstance(dim_or_dims, str):
dim_or_dims = [dim_or_dims]
assert isinstance(dim_or_dims, list)

return self._obj.mean(
[d for d in self._obj.dims if d not in dim_or_dims],
Expand Down Expand Up @@ -1726,9 +1725,9 @@ def _experimentalinfo_to_dict(conditions: EXPERIMENTINFO) -> dict[str, str]:
if isinstance(v, xr.DataArray):
min_hv = float(v.min())
max_hv = float(v.max())
transformed_dict[k] = (
f"<strong> from </strong> {min_hv} <strong> to </strong> {max_hv} eV"
)
transformed_dict[
k
] = f"<strong> from </strong> {min_hv} <strong> to </strong> {max_hv} eV"
elif isinstance(v, float) and not np.isnan(v):
transformed_dict[k] = f"{v} eV"
return transformed_dict
Expand Down
83 changes: 83 additions & 0 deletions tests/test_xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ def test_find_spectrum_energy_edges(self, dataarray_cut: xr.DataArray) -> None:
dataarray_cut.S.find_spectrum_energy_edges(indices=True),
)

def test_workfunction(self, dataarray_cut: xr.DataArray) -> None:
"""Test for S.workfunction."""
assert dataarray_cut.S.work_function == 4.3
dataarray_cut.attrs["sample_workfunction"] = 4.8
assert dataarray_cut.S.work_function == 4.8
dataarray_cut.attrs["workfunction"] = 4.5
assert dataarray_cut.S.analyzer_work_function == 4.5
dataarray_cut.attrs["inner_potential"] = 9.8
assert dataarray_cut.S.inner_potential == 9.8

def test_sum_other(self, dataarray_cut: xr.DataArray) -> None:
"""Test S.sum_other / mean_other."""
small_region = dataarray_cut.sel({"eV": slice(-0.001, 0.0), "phi": slice(0.40, 0.41)})
np.testing.assert_array_almost_equal(
small_region.S.sum_other(["phi"]),
np.array(
[467, 472, 464, 458, 438],
),
)
np.testing.assert_array_almost_equal(
small_region.S.mean_other(["phi"]),
np.array(
[467, 472, 464, 458, 438],
),
)

def test_transpose_front_back(self, dataarray_cut: xr.DataArray) -> None:
"""Test for transpose_to_front/back."""
original_ndarray = dataarray_cut.values
Expand Down Expand Up @@ -296,6 +322,63 @@ def test_G_stride(self, dataarray_cut: xr.DataArray) -> None:
"eV": 0.002325581000000021,
}

def test_G_meshgrid(self, dataarray_cut: xr.DataArray) -> None:
"""Test for G.meshgrid."""
small_region = dataarray_cut.sel({"eV": slice(-0.01, 0.0), "phi": slice(0.40, 0.42)})
meshgrid_results = small_region.G.meshgrid()
np.testing.assert_allclose(
meshgrid_results["phi"][0],
np.array(
[
0.40142573,
0.40317106,
0.40491639,
0.40666172,
0.40840704,
0.41015237,
0.4118977,
0.41364303,
0.41538836,
0.41713369,
0.41887902,
],
),
)
np.testing.assert_allclose(
meshgrid_results["eV"][-1],
np.array(
[
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
-7.7e-08,
],
),
)
meshgrid_set = small_region.G.meshgrid(as_dataset=True)
assert isinstance(meshgrid_set, xr.Dataset)

def test_G_ravel(self, dataarray_cut: xr.DataArray) -> None:
"""Test for G.ravel."""
small_region = dataarray_cut.sel({"eV": slice(-0.001, 0.0), "phi": slice(0.40, 0.41)})
ravel_ = small_region.G.ravel()
np.testing.assert_allclose(
ravel_["phi"],
np.array([0.40142573, 0.40317106, 0.40491639, 0.40666172, 0.40840704]),
)
np.testing.assert_allclose(
ravel_["eV"],
np.array([-7.7e-08, -7.7e-08, -7.7e-08, -7.7e-08, -7.7e-08]),
)
np.testing.assert_allclose(ravel_["data"], np.array([467, 472, 464, 458, 438]))


class TestAngleUnitforDataArray:
"""Test class for angle_unit for DataArray."""
Expand Down

0 comments on commit 37fe0b2

Please sign in to comment.