pypi package 'yt-idefix'

Popularity: Low
Description: An extension module for yt, adding a frontend for Idefix
Installation: pip install yt-idefix
Last version: 0.13.2 (Download)
Homepage: https://github.com/yt-project/yt
Size: 36.42 kB
License: GPL-3.0
Keywords: astronomy, astrophysics, visualization, amr, adaptivemeshrefinement

Activity

Last modified: August 5, 2022 10:00 PM (6 days ago)
Versions released in one year: 44
Weekly downloads: 9
08/22/202112/12/202103/27/2022048121602468released versions / week
  • Versions released
  • Weekly downloads

What's new in version 0.13.2

Delta between version 0.13.1 and version 0.13.2

Source: Github
Commits:
  • df94b5a0c791061244b21b2acbbc25fe50ee9972, August 1, 2022 9:21 AM:
    TST: start testing on Python 3.11
  • 9c6d39af9b5cae2dd2c14d0472bd99a3e23e1ef8, August 1, 2022 9:32 AM:
    TST: fix a bug in bleeding-edge workflow
  • 9165d4a31d025c13d1d39810b39e8af27a290ab3, August 1, 2022 10:03 AM:
    Merge pull request #133 from neutrinoceros/test_python_311
    
    TST: start testing on Python 3.11
  • 75388f6b72c41278435d4278b2e3804810a8ba6d, August 2, 2022 8:55 PM:
    TST: don't use editable installs in CI
  • fd309ff1ad2f58971fc94a7abf022d168fecd7b4, August 2, 2022 9:10 PM:
    TST: add tests for projections
  • 5d669952a0319325d443b87539b5da0f0518359f, August 2, 2022 9:23 PM:
    Merge pull request #135 from neutrinoceros/no_editable_install_ci
    
    TST: don't use editable installs in CI
  • 5896457e34ea2e213621de7f8f60a88e22ec26cd, August 3, 2022 12:20 PM:
    TST: explain skip reason in more details
  • 3bfe4d53c6fc7ec06d51373880454fac70a81e64, August 3, 2022 12:36 PM:
    Merge pull request #127 from neutrinoceros/test_proj
    
    TST: add tests for projections
  • d666ba3a97f268f47999038d1313075b15e185b2, August 5, 2022 7:47 PM:
    ENH: leverage Cython implementation for stretched grids _icoords_to_fcoords when available
  • cf4c5e4e37174d761c2a91717cf4be19e50fd090, August 5, 2022 9:28 PM:
    Merge pull request #136 from neutrinoceros/leverage_cython_impl_stretched_grids
    
    ENH: leverage Cython implementation for stretched grids _icoords_to_fcoords when available
  • 4ef3f3982df676570afba493f1fe079f34bbe93b, August 5, 2022 9:35 PM:
    TST: mark unyt workaround as temporary, use unyt directly when available
  • 8097c7649b6d72814b8a94ac477856577a45bbbd, August 5, 2022 9:42 PM:
    TST: only filter distutils depr warnings for numpy < 1.23
  • cbac00f1af27bbd11a15c305c5795a02ce6fbf4a, August 5, 2022 9:48 PM:
    Merge pull request #138 from neutrinoceros/cleanup_conftest
    
    TST: cleanup conftest.py
  • 771c762e7570e3ff6fba87e005c9575e00a9fb3b, August 5, 2022 9:49 PM:
    REL: prep release 0.13.2
  • 054eb94eddb58e3526624773c19f5da4731cf2f4, August 5, 2022 9:59 PM:
    Merge pull request #139 from neutrinoceros/rel_0.13.2
    
    REL: prep release 0.13.2
Files changed:
.github/workflows/bleeding-edge.yaml CHANGED
@@ -11,7 +11,7 @@ on:
11
  - main
12
  pull_request:
13
  paths:
14
- - .github/workflows/bleefding-edge.yaml
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.10-dev'
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: |
.github/workflows/ci.yml CHANGED
@@ -35,6 +35,6 @@ jobs:
35
  - name: Setup package
36
  run: |
37
  python3 -m pip install -U pip
38
- python3 -m pip install -e ".[test]"
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
setup.cfg CHANGED
@@ -1,6 +1,6 @@
1
  [metadata]
2
  name = yt_idefix
3
- version = 0.13.1
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
tests/conftest.py CHANGED
@@ -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
- def parse_quantity(s) -> un.unyt_quantity:
26
- # FUTURE: use unyt.unyt_quantity.from_string instead
27
- # https://github.com/yt-project/unyt/pull/191
28
-
29
- # This is partially adapted from the following SO thread
30
- # https://stackoverflow.com/questions/41668588/regex-to-match-scientific-notation
31
- _NUMB_PATTERN = r"^[+/-]?((?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)|\d*\.?\d+|\d+\.?\d*|nan\s|inf\s)" # noqa: E501
32
- # *all* greek letters are considered valid unit string elements.
33
- # This may be an overshoot. We rely on unyt.Unit to do the actual validation
34
- _UNIT_PATTERN = r"([α-ωΑ-Ωa-zA-Z]+(\*\*([+/-]?[0-9]+)|[*/])?)+"
35
- _QUAN_PATTERN = rf"{_NUMB_PATTERN}\s*{_UNIT_PATTERN}"
36
- _NUMB_REGEXP = re.compile(_NUMB_PATTERN)
37
- _UNIT_REGEXP = re.compile(_UNIT_PATTERN)
38
- _QUAN_REGEXP = re.compile(_QUAN_PATTERN)
39
-
40
- v = s.strip()
41
- match = re.fullmatch(_NUMB_PATTERN, v)
42
- if match is not None:
43
- return float(match.group()) * un.Unit()
44
- if not re.match(_QUAN_REGEXP, v):
45
- raise ValueError(f"Received invalid quantity expression '{s}'.")
46
- res = re.search(_NUMB_REGEXP, v)
47
- if res is None:
48
- raise ValueError
49
- num = res.group()
50
- res = re.search(_UNIT_REGEXP, v[res.span()[1] :])
51
- if res is None:
52
- raise ValueError
53
- unit = res.group()
54
- return float(num) * un.Unit(unit)
 
 
 
 
 
 
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"
tests/test_vtk.py CHANGED
@@ -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)
yt_idefix/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
  # immediately after `import yt.extensions.idefix`
3
  from yt_idefix.api import *
4
 
5
- __version__ = "0.13.1"
2
  # immediately after `import yt.extensions.idefix`
3
  from yt_idefix.api import *
4
 
5
+ __version__ = "0.13.2"
yt_idefix/_vendors/streched_grids.py CHANGED
@@ -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
yt_idefix/data_structures.py CHANGED
@@ -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 range(icoords.shape[0]):
145
- coords.append(
146
- [self._cell_centers[ax][icoords[i, _]] for _, ax in enumerate(axes)]
147
- )
148
- cell_widths.append(
149
- [self._cell_widths[ax][icoords[i, _]] for _, ax in enumerate(axes)]
150
  )
151
- return np.array(coords).T, np.array(cell_widths).T
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):

Readme

yt_idefix

<!--- Tests and style ---> [![CI](https://github.com/neutrinoceros/yt_idefix/actions/workflows/ci.yml/badge.svg)](https://github.com/neutrinoceros/yt_idefix/actions/workflows/ci.yml) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/neutrinoceros/yt_idefix/main.svg)](https://results.pre-commit.ci/latest/github/neutrinoceros/yt_idefix/main) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) A maturing yt frontend for Idefix and Pluto (vtk), packaged as an extension for yt. This frontend is a candidate for integration in the core yt code base. ## Installation ```shell pip install yt_idefix ``` ## Usage After importing `yt` itself, make sure to activate the extension ```python import yt import yt_idefix ``` Now `yt.load` will be able to read Pluto/Idefix `.vtk` output files, as well as Idefix `.dmp` dump files. ## Strecthed grids support ### yt_idefix 0.12.0 and newer version 0.12.0 brings experimental *native* support for streched grids, which is under active development upstream, in yt itself. Slices should now work seamlessly even with older versions of yt, however yt 4.1 (to be released) will be required to perform projections correctly. In the meantime, I recommend installing yt from source. At the time of writing, the branch attached to the following pull request is required for projections with stretched grids: https://github.com/yt-project/yt/pull/2998 ### yt_idefix 0.11 and older (deprecated) yt_idefix ships a specialized loader function for datasets with streched grids `yt_idefix.load_stretched`. This function is only provided as a workaround 4.0.x limitations, but it's highly limited itself: - no field magic (no aliasing, or dimensionalization, or automatic derived field generation) - no lazy loading (all data has to reside in memory) - projections are not supported - only supports vtk outputs (not dumps)