TST: start testing on Python 3.11
TST: fix a bug in bleeding-edge workflow
Merge pull request #133 from neutrinoceros/test_python_311 TST: start testing on Python 3.11
TST: don't use editable installs in CI
TST: add tests for projections
Merge pull request #135 from neutrinoceros/no_editable_install_ci TST: don't use editable installs in CI
TST: explain skip reason in more details
Merge pull request #127 from neutrinoceros/test_proj TST: add tests for projections
ENH: leverage Cython implementation for stretched grids _icoords_to_fcoords when available
Merge pull request #136 from neutrinoceros/leverage_cython_impl_stretched_grids ENH: leverage Cython implementation for stretched grids _icoords_to_fcoords when available
TST: mark unyt workaround as temporary, use unyt directly when available
TST: only filter distutils depr warnings for numpy < 1.23
Merge pull request #138 from neutrinoceros/cleanup_conftest TST: cleanup conftest.py
REL: prep release 0.13.2
Merge pull request #139 from neutrinoceros/rel_0.13.2 REL: prep release 0.13.2
@@ -11,7 +11,7 @@ on:
|
|
11 |
- main
|
12 |
pull_request:
|
13 |
paths:
|
14 |
-
- .github/workflows/
|
15 |
schedule:
|
16 |
# run this every day at 3 am UTC
|
17 |
- cron: '0 3 * * *'
|
@@ -34,7 +34,7 @@ jobs:
|
|
34 |
- name: Set up Python Dev Version
|
35 |
uses: actions/setup-python@v3
|
36 |
with:
|
37 |
-
python-version: '3.
|
38 |
|
39 |
- name: Install dependencies
|
40 |
run: |
|
11 |
- main
|
12 |
pull_request:
|
13 |
paths:
|
14 |
+
- .github/workflows/bleeding-edge.yaml
|
15 |
schedule:
|
16 |
# run this every day at 3 am UTC
|
17 |
- cron: '0 3 * * *'
|
34 |
- name: Set up Python Dev Version
|
35 |
uses: actions/setup-python@v3
|
36 |
with:
|
37 |
+
python-version: '3.11-dev'
|
38 |
|
39 |
- name: Install dependencies
|
40 |
run: |
|
@@ -35,6 +35,6 @@ jobs:
|
|
35 |
- name: Setup package
|
36 |
run: |
|
37 |
python3 -m pip install -U pip
|
38 |
-
python3 -m pip install
|
39 |
- name: run tests
|
40 |
run: pytest
|
35 |
- name: Setup package
|
36 |
run: |
|
37 |
python3 -m pip install -U pip
|
38 |
+
python3 -m pip install ".[test]"
|
39 |
- name: run tests
|
40 |
run: pytest
|
@@ -1,6 +1,6 @@
|
|
1 |
[metadata]
|
2 |
name = yt_idefix
|
3 |
-
version = 0.13.
|
4 |
description = An extension module for yt, adding a frontend for Idefix
|
5 |
long_description = file: README.md
|
6 |
long_description_content_type = text/markdown
|
1 |
[metadata]
|
2 |
name = yt_idefix
|
3 |
+
version = 0.13.2
|
4 |
description = An extension module for yt, adding a frontend for Idefix
|
5 |
long_description = file: README.md
|
6 |
long_description_content_type = text/markdown
|
@@ -1,19 +1,22 @@
|
|
1 |
from __future__ import annotations
|
2 |
|
3 |
import os
|
4 |
-
import re
|
5 |
import sys
|
|
|
6 |
from pathlib import Path
|
7 |
from typing import Any
|
8 |
|
9 |
import pytest
|
10 |
import unyt as un
|
11 |
import yaml
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
def pytest_configure(config):
|
15 |
-
if sys.version_info >= (3, 10):
|
16 |
-
# from numpy, still visible in 1.22.x
|
17 |
config.addinivalue_line(
|
18 |
"filterwarnings",
|
19 |
(
|
@@ -22,36 +25,42 @@ def pytest_configure(config):
|
|
22 |
)
|
23 |
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
DATA_DIR = Path(__file__).parent / "data"
|
1 |
from __future__ import annotations
|
2 |
|
3 |
import os
|
|
|
4 |
import sys
|
5 |
+
from importlib.metadata import version
|
6 |
from pathlib import Path
|
7 |
from typing import Any
|
8 |
|
9 |
import pytest
|
10 |
import unyt as un
|
11 |
import yaml
|
12 |
+
from packaging.version import Version
|
13 |
+
|
14 |
+
UNYT_VERSION = Version(version("unyt"))
|
15 |
+
NUMPY_VERSION = Version(version("numpy"))
|
16 |
|
17 |
|
18 |
def pytest_configure(config):
|
19 |
+
if sys.version_info >= (3, 10) and NUMPY_VERSION < Version("1.23"):
|
|
|
20 |
config.addinivalue_line(
|
21 |
"filterwarnings",
|
22 |
(
|
25 |
)
|
26 |
|
27 |
|
28 |
+
if UNYT_VERSION >= Version("2.9.0"):
|
29 |
+
|
30 |
+
def parse_quantity(s) -> un.unyt_quantity:
|
31 |
+
return un.unyt_quantity.from_string(s)
|
32 |
+
|
33 |
+
else:
|
34 |
+
|
35 |
+
def parse_quantity(s) -> un.unyt_quantity:
|
36 |
+
import re
|
37 |
+
|
38 |
+
# This is partially adapted from the following SO thread
|
39 |
+
# https://stackoverflow.com/questions/41668588/regex-to-match-scientific-notation
|
40 |
+
_NUMB_PATTERN = r"^[+/-]?((?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)|\d*\.?\d+|\d+\.?\d*|nan\s|inf\s)" # noqa: E501
|
41 |
+
# *all* greek letters are considered valid unit string elements.
|
42 |
+
# This may be an overshoot. We rely on unyt.Unit to do the actual validation
|
43 |
+
_UNIT_PATTERN = r"([α-ωΑ-Ωa-zA-Z]+(\*\*([+/-]?[0-9]+)|[*/])?)+"
|
44 |
+
_QUAN_PATTERN = rf"{_NUMB_PATTERN}\s*{_UNIT_PATTERN}"
|
45 |
+
_NUMB_REGEXP = re.compile(_NUMB_PATTERN)
|
46 |
+
_UNIT_REGEXP = re.compile(_UNIT_PATTERN)
|
47 |
+
_QUAN_REGEXP = re.compile(_QUAN_PATTERN)
|
48 |
+
|
49 |
+
v = s.strip()
|
50 |
+
match = re.fullmatch(_NUMB_PATTERN, v)
|
51 |
+
if match is not None:
|
52 |
+
return float(match.group()) * un.Unit()
|
53 |
+
if not re.match(_QUAN_REGEXP, v):
|
54 |
+
raise ValueError(f"Received invalid quantity expression '{s}'.")
|
55 |
+
res = re.search(_NUMB_REGEXP, v)
|
56 |
+
if res is None:
|
57 |
+
raise ValueError
|
58 |
+
num = res.group()
|
59 |
+
res = re.search(_UNIT_REGEXP, v[res.span()[1] :])
|
60 |
+
if res is None:
|
61 |
+
raise ValueError
|
62 |
+
unit = res.group()
|
63 |
+
return float(num) * un.Unit(unit)
|
64 |
|
65 |
|
66 |
DATA_DIR = Path(__file__).parent / "data"
|
@@ -229,6 +229,30 @@ def test_slice_plot(vtk_file):
|
|
229 |
yt.SlicePlot(ds, normal=(0, 0, 1), fields=("gas", "density"))
|
230 |
|
231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
def test_load_magic(vtk_file):
|
233 |
ds = yt.load(vtk_file["path"], geometry=vtk_file["geometry"])
|
234 |
assert isinstance(ds, IdefixVtkDataset)
|
229 |
yt.SlicePlot(ds, normal=(0, 0, 1), fields=("gas", "density"))
|
230 |
|
231 |
|
232 |
+
try:
|
233 |
+
from yt.data_objects.index_subobjects.stretched_grid import StretchedGrid
|
234 |
+
except ImportError:
|
235 |
+
HAS_STRETCHED_GRID_SUPPORT = False
|
236 |
+
else:
|
237 |
+
del StretchedGrid
|
238 |
+
HAS_STRETCHED_GRID_SUPPORT = True
|
239 |
+
|
240 |
+
|
241 |
+
@pytest.mark.skipif(
|
242 |
+
not HAS_STRETCHED_GRID_SUPPORT,
|
243 |
+
reason=(
|
244 |
+
"with yt 4.0.4, this test breaks pytest at collection because a ResourceWarning is emitted.\n"
|
245 |
+
"It is resolved upstream in yt-project/yt#3997\n"
|
246 |
+
"note that the heuristic we're using to discover if the installed version of yt is fine at runtime "
|
247 |
+
"is more restritive than this. When yt 4.1 becomes the minimal supported version this should be cleanable"
|
248 |
+
),
|
249 |
+
)
|
250 |
+
def test_projection_plot(vtk_file):
|
251 |
+
file = vtk_file
|
252 |
+
ds = yt.load(file["path"], geometry=file["geometry"], unit_system="code")
|
253 |
+
yt.ProjectionPlot(ds, normal=(0, 0, 1), fields=("gas", "density"))
|
254 |
+
|
255 |
+
|
256 |
def test_load_magic(vtk_file):
|
257 |
ds = yt.load(vtk_file["path"], geometry=vtk_file["geometry"])
|
258 |
assert isinstance(ds, IdefixVtkDataset)
|
@@ -2,4 +2,4 @@
|
|
2 |
# immediately after `import yt.extensions.idefix`
|
3 |
from yt_idefix.api import *
|
4 |
|
5 |
-
__version__ = "0.13.
|
2 |
# immediately after `import yt.extensions.idefix`
|
3 |
from yt_idefix.api import *
|
4 |
|
5 |
+
__version__ = "0.13.2"
|
@@ -63,3 +63,21 @@ def select_fcoords(self, dobj):
|
|
63 |
]
|
64 |
).T
|
65 |
return coords
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
]
|
64 |
).T
|
65 |
return coords
|
66 |
+
|
67 |
+
|
68 |
+
# a pure Python backport of a Cython routine
|
69 |
+
def _obtain_coords_and_widths(icoords, ires, cell_widths, offset):
|
70 |
+
# This function only accepts *one* axis of icoords, because we will be
|
71 |
+
# looping over the axes in python. This also simplifies cell_width
|
72 |
+
# allocation and computation.
|
73 |
+
fcoords = np.zeros(icoords.size, dtype="f8")
|
74 |
+
fwidth = np.zeros(icoords.size, dtype="f8")
|
75 |
+
cell_centers = np.zeros(cell_widths.size, dtype="f8")
|
76 |
+
pos = offset
|
77 |
+
for i in range(cell_widths.size):
|
78 |
+
cell_centers[i] = pos + 0.5 * cell_widths[i]
|
79 |
+
pos += cell_widths[i]
|
80 |
+
for i in range(icoords.size):
|
81 |
+
fcoords[i] = cell_centers[icoords[i]]
|
82 |
+
fwidth[i] = cell_widths[icoords[i]]
|
83 |
+
return fcoords, fwidth
|
@@ -29,6 +29,13 @@
|
|
29 |
except ImportError:
|
30 |
from ._vendors.streched_grids import StretchedGrid # type: ignore [no-redef]
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
# import IO classes to ensure they are properly registered,
|
33 |
# even though we don't call them directly
|
34 |
from .io import IdefixDmpIO, IdefixVtkIO, PlutoVtkIO # noqa
|
@@ -139,16 +146,16 @@ def _cell_centers(self):
|
|
139 |
|
140 |
def _icoords_to_fcoords(self, icoords, ires, axes: Sequence[int] = (0, 1, 2)):
|
141 |
# this is needed to support projections
|
142 |
-
coords =
|
143 |
-
cell_widths =
|
144 |
-
for i in
|
145 |
-
coords
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
)
|
151 |
-
return
|
152 |
|
153 |
|
154 |
class IdefixVtkHierarchy(IdefixHierarchy):
|
29 |
except ImportError:
|
30 |
from ._vendors.streched_grids import StretchedGrid # type: ignore [no-redef]
|
31 |
|
32 |
+
try:
|
33 |
+
from yt.utilities.lib.misc_utilities import _obtain_coords_and_widths
|
34 |
+
except ImportError:
|
35 |
+
from ._vendors.streched_grids import (
|
36 |
+
_obtain_coords_and_widths, # type: ignore [no-redef]
|
37 |
+
)
|
38 |
+
|
39 |
# import IO classes to ensure they are properly registered,
|
40 |
# even though we don't call them directly
|
41 |
from .io import IdefixDmpIO, IdefixVtkIO, PlutoVtkIO # noqa
|
146 |
|
147 |
def _icoords_to_fcoords(self, icoords, ires, axes: Sequence[int] = (0, 1, 2)):
|
148 |
# this is needed to support projections
|
149 |
+
coords = np.empty(icoords.shape, dtype="f8")
|
150 |
+
cell_widths = np.empty(icoords.shape, dtype="f8")
|
151 |
+
for i, ax in enumerate(axes):
|
152 |
+
coords[:, i], cell_widths[:, i] = _obtain_coords_and_widths(
|
153 |
+
icoords[:, i],
|
154 |
+
ires,
|
155 |
+
self._cell_widths[ax],
|
156 |
+
self.ds.domain_left_edge[ax].d,
|
157 |
)
|
158 |
+
return coords, cell_widths
|
159 |
|
160 |
|
161 |
class IdefixVtkHierarchy(IdefixHierarchy):
|