Skip to content
8 changes: 4 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || ( github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository )
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Log into the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: token
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for the Docker image
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push the Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install dependencies
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
matrix:
python-version: [3.9, "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -36,11 +36,11 @@ jobs:
# run: |
# make doctest
- name: Stash coverage
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage.xml
path: coverage.xml
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
3 changes: 2 additions & 1 deletion pvxarray/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def image_data_to_dataset(mesh):
def gen_coords(i):
coords = (
np.cumsum(np.insert(np.full(mesh.dimensions[i] - 1, mesh.spacing[i]), 0, 0))
+ mesh.origin[i] # noqa: W503
+ mesh.origin[i]
+ mesh.offset[i] # noqa: W503
)
return coords

Expand Down
38 changes: 33 additions & 5 deletions pvxarray/rectilinear.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, Optional
import warnings

import numpy as np
import pyvista as pv

from pvxarray.errors import DataCopyWarning
Expand All @@ -14,20 +15,47 @@ def mesh(
order: Optional[str] = "C",
component: Optional[str] = None,
scales: Optional[Dict] = None,
):
) -> pv.RectilinearGrid | pv.ImageData:
if order is None:
order = "C"
self._mesh = pv.RectilinearGrid()

ndim = 3 - (x, y, z).count(None)
if ndim < 1:
raise ValueError("You must specify at least one dimension as X, Y, or Z.")
# Construct the mesh
if x is not None:
self._mesh.x = self._get_array(x, scale=(scales and scales.get(x)) or 1)
xx = self._get_array(x, scale=(scales and scales.get(x)) or 1)
else:
xx = np.array([0.0])
if y is not None:
self._mesh.y = self._get_array(y, scale=(scales and scales.get(y)) or 1)
yy = self._get_array(y, scale=(scales and scales.get(y)) or 1)
else:
yy = np.array([0.0])
if z is not None:
self._mesh.z = self._get_array(z, scale=(scales and scales.get(z)) or 1)
zz = self._get_array(z, scale=(scales and scales.get(z)) or 1)
else:
zz = np.array([0.0])

dx = np.diff(xx)
dy = np.diff(yy)
dz = np.diff(zz)

ddx = dx[0] if len(dx) and dx[0] > 0 else 1.0
ddy = dy[0] if len(dy) and dy[0] > 0 else 1.0
ddz = dz[0] if len(dz) and dz[0] > 0 else 1.0

if np.allclose(dx, ddx) and np.allclose(dy, ddy) and np.allclose(dz, ddz):
self._mesh = pv.ImageData(
origin=(xx[0], yy[0], zz[0]),
spacing=(ddx, ddy, ddz),
dimensions=(len(xx), len(yy), len(zz)),
)
else:
self._mesh = pv.RectilinearGrid()
self._mesh.x = xx
self._mesh.y = yy
self._mesh.z = zz

# Handle data values
values = self.data
values_dim = values.ndim
Expand Down
18 changes: 9 additions & 9 deletions tests/test_dataset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ def test_read_vtr(vtr_path):

def test_read_vti(vti_path):
ds = xr.open_dataset(vti_path, engine="pyvista")
truth = ImageData(vti_path).cast_to_rectilinear_grid()
truth = ImageData(vti_path)
truth_r = truth.cast_to_rectilinear_grid()
assert np.allclose(ds["RTData"].values.ravel(), truth["RTData"].ravel())
assert np.allclose(ds["x"].values, truth.x)
assert np.allclose(ds["y"].values, truth.y)
assert np.allclose(ds["z"].values, truth.z)
assert ds["RTData"].pyvista.mesh(x="x", y="y", z="z") == truth
assert np.allclose(ds["x"].values, truth_r.x)
assert np.allclose(ds["y"].values, truth_r.y)
assert np.allclose(ds["z"].values, truth_r.z)
im = ds["RTData"].pyvista.mesh(x="x", y="y", z="z")
assert im.cast_to_rectilinear_grid() == truth_r


def test_read_vts(vts_path):
Expand Down Expand Up @@ -89,10 +91,8 @@ def test_convert_vti(vti_path):
mesh = ds["RTData"].pyvista.mesh(x="x", y="y", z="z")
assert np.array_equal(ds["RTData"].values.ravel(), truth["RTData"].ravel())
assert np.may_share_memory(ds["RTData"].values.ravel(), truth["RTData"].ravel())
assert np.array_equal(mesh.x, truth_r.x)
assert np.array_equal(mesh.y, truth_r.y)
assert np.array_equal(mesh.z, truth_r.z)
assert mesh == truth_r
# assert np.array_equal(mesh.points, truth_r.points)
assert mesh.cast_to_rectilinear_grid() == truth_r


def test_convert_vts(vts_path):
Expand Down
Loading