Skip to content

Commit ea9f7de

Browse files
committed
Py: Fix tests, fix bugs
1 parent c3ee74f commit ea9f7de

File tree

6 files changed

+229
-156
lines changed

6 files changed

+229
-156
lines changed

pysplashsurf/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import pysplashsurf
4848
# Load particles from mesh file
4949
mesh = meshio.read("input.vtk")
5050
particles = np.array(mesh.points, dtype=np.float64)
51+
5152
# Reconstruct the points/particles with some post-processing
5253
mesh_with_data, reconstruction = pysplashsurf.reconstruction_pipeline(
5354
particles,
@@ -66,7 +67,8 @@ mesh_with_data, reconstruction = pysplashsurf.reconstruction_pipeline(
6667
subdomain_num_cubes_per_dim=64,
6768
output_mesh_smoothing_weights=True
6869
)
69-
# Write the mesh with attributes to a file using meshio
70+
71+
# Write the mesh with attributes to file using meshio
7072
mesh_with_data.write_to_file("surface.vtk")
7173
```
7274
The `reconstruction_pipeline` method provides (mostly) the same arguments as the splashsurf binary CLI.

pysplashsurf/pysplashsurf/pysplashsurf.pyi

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ from __future__ import annotations
66
import builtins
77
import numpy
88
import numpy.typing
9+
import os
10+
import pathlib
911
import typing
1012
from enum import Enum
1113

@@ -112,9 +114,9 @@ class MeshWithData:
112114
113115
There has to be exactly one attribute value per vertex in the mesh.
114116
As attribute data, the following numpy array types are supported:
115-
- 1D array with shape (N,) of `np.uint64`
116-
- 1D array with shape (N,) of the mesh scalar type (`np.float32` or `np.float64`)
117-
- 2D array with shape (N,3) of the mesh scalar type (`np.float32` or `np.float64`)
117+
- 1D array with shape (N,) of ``np.uint64``
118+
- 1D array with shape (N,) of the mesh scalar type (``np.float32`` or ``np.float64``)
119+
- 2D array with shape (N,3) of the mesh scalar type (``np.float32`` or ``np.float64``)
118120
The data is copied into the mesh object.
119121
"""
120122
def add_cell_attribute(self, name:builtins.str, attribute:numpy.typing.NDArray[typing.Any]) -> None:
@@ -123,12 +125,12 @@ class MeshWithData:
123125
124126
There has to be exactly one attribute value per cell in the mesh.
125127
As attribute data, the following numpy array types are supported:
126-
- 1D array with shape (N,) of `np.uint64`
127-
- 1D array with shape (N,) of the mesh scalar type (`np.float32` or `np.float64`)
128-
- 2D array with shape (N,3) of the mesh scalar type (`np.float32` or `np.float64`)
128+
- 1D array with shape (N,) of ``np.uint64``
129+
- 1D array with shape (N,) of the mesh scalar type (``np.float32`` or ``np.float64``)
130+
- 2D array with shape (N,3) of the mesh scalar type (``np.float32`` or ``np.float64``)
129131
The data is copied into the mesh object.
130132
"""
131-
def write_to_file(self, path:builtins.str, *, file_format:typing.Optional[builtins.str]='vtk42') -> None:
133+
def write_to_file(self, path:builtins.str | os.PathLike | pathlib.Path, *, file_format:typing.Optional[builtins.str]='vtk42') -> None:
132134
r"""
133135
Writes the mesh and its attributes to a file using `meshio.write_points_cells`
134136
"""
@@ -159,7 +161,7 @@ class MixedTriQuadMesh3d:
159161
r"""
160162
Returns a copy of all quad cells of the mesh as an `Nx4` array of vertex indices
161163
"""
162-
def write_to_file(self, path:builtins.str, *, file_format:typing.Optional[builtins.str]='vtk42') -> None:
164+
def write_to_file(self, path:builtins.str | os.PathLike | pathlib.Path, *, file_format:typing.Optional[builtins.str]='vtk42') -> None:
163165
r"""
164166
Writes the mesh to a file using `meshio.write_points_cells`
165167
"""
@@ -259,7 +261,7 @@ class TriMesh3d:
259261
r"""
260262
Computes the vertex-vertex connectivity of the mesh
261263
"""
262-
def write_to_file(self, path:builtins.str, *, file_format:typing.Optional[builtins.str]='vtk42') -> None:
264+
def write_to_file(self, path:builtins.str | os.PathLike | pathlib.Path, *, file_format:typing.Optional[builtins.str]='vtk42') -> None:
263265
r"""
264266
Writes the mesh to a file using `meshio.write_points_cells`
265267
"""

pysplashsurf/src/aabb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl PyAabb3d {
3838
points: &Bound<'py, PyArray2<R>>,
3939
) -> PyResult<Self> {
4040
let points = points.try_readonly()?;
41-
let points_vec: &[Vector3<f32>] = bytemuck::cast_slice(points.as_slice()?);
41+
let points_vec: &[Vector3<R>] = bytemuck::cast_slice(points.as_slice()?);
4242
Ok(Self::from(Aabb3d::par_from_points(points_vec)))
4343
}
4444
}

pysplashsurf/src/mesh.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use crate::NumpyUsize;
2+
use crate::utils;
3+
use crate::utils::{enum_impl_from, enum_wrapper_impl_from};
14
use bytemuck::{NoUninit, Pod};
25
use ndarray::Array2;
36
use numpy as np;
@@ -6,7 +9,7 @@ use numpy::{Element, PyArray, PyArray1, PyArray2, PyArrayDescr, PyUntypedArray};
69
use pyo3::IntoPyObjectExt;
710
use pyo3::exceptions::{PyTypeError, PyValueError};
811
use pyo3::prelude::*;
9-
use pyo3::types::{IntoPyDict, PyDict, PyTuple};
12+
use pyo3::types::{IntoPyDict, PyDict};
1013
use pyo3_stub_gen::derive::*;
1114
use splashsurf_lib::mesh::TriangleCell;
1215
use splashsurf_lib::{
@@ -18,10 +21,7 @@ use splashsurf_lib::{
1821
nalgebra::{Unit, Vector3},
1922
};
2023
use std::ops::Deref;
21-
22-
use crate::NumpyUsize;
23-
use crate::utils;
24-
use crate::utils::{enum_impl_from, enum_wrapper_impl_from};
24+
use std::path::PathBuf;
2525

2626
fn view_triangles_generic<'py>(
2727
triangles: &[TriangleCell],
@@ -209,7 +209,7 @@ impl PyTriMesh3d {
209209
#[pyo3(signature = (path, *, file_format = Some("vtk42")))]
210210
pub fn write_to_file<'py>(
211211
this: Bound<'py, Self>,
212-
path: &str,
212+
path: PathBuf,
213213
file_format: Option<&str>,
214214
) -> PyResult<()> {
215215
let py = this.py();
@@ -308,7 +308,7 @@ impl PyMixedTriQuadMesh3d {
308308
#[pyo3(signature = (path, *, file_format = Some("vtk42")))]
309309
pub fn write_to_file<'py>(
310310
this: Bound<'py, Self>,
311-
path: &str,
311+
path: PathBuf,
312312
file_format: Option<&str>,
313313
) -> PyResult<()> {
314314
let py = this.py();
@@ -727,9 +727,9 @@ impl PyMeshWithData {
727727
///
728728
/// There has to be exactly one attribute value per vertex in the mesh.
729729
/// As attribute data, the following numpy array types are supported:
730-
/// - 1D array with shape (N,) of `np.uint64`
731-
/// - 1D array with shape (N,) of the mesh scalar type (`np.float32` or `np.float64`)
732-
/// - 2D array with shape (N,3) of the mesh scalar type (`np.float32` or `np.float64`)
730+
/// - 1D array with shape (N,) of ``np.uint64``
731+
/// - 1D array with shape (N,) of the mesh scalar type (``np.float32`` or ``np.float64``)
732+
/// - 2D array with shape (N,3) of the mesh scalar type (``np.float32`` or ``np.float64``)
733733
/// The data is copied into the mesh object.
734734
pub fn add_point_attribute<'py>(
735735
&mut self,
@@ -763,9 +763,9 @@ impl PyMeshWithData {
763763
///
764764
/// There has to be exactly one attribute value per cell in the mesh.
765765
/// As attribute data, the following numpy array types are supported:
766-
/// - 1D array with shape (N,) of `np.uint64`
767-
/// - 1D array with shape (N,) of the mesh scalar type (`np.float32` or `np.float64`)
768-
/// - 2D array with shape (N,3) of the mesh scalar type (`np.float32` or `np.float64`)
766+
/// - 1D array with shape (N,) of ``np.uint64``
767+
/// - 1D array with shape (N,) of the mesh scalar type (``np.float32`` or ``np.float64``)
768+
/// - 2D array with shape (N,3) of the mesh scalar type (``np.float32`` or ``np.float64``)
769769
/// The data is copied into the mesh object.
770770
pub fn add_cell_attribute<'py>(
771771
&mut self,
@@ -799,7 +799,7 @@ impl PyMeshWithData {
799799
#[pyo3(signature = (path, *, file_format = Some("vtk42")))]
800800
pub fn write_to_file<'py>(
801801
this: Bound<'py, Self>,
802-
path: &str,
802+
path: PathBuf,
803803
file_format: Option<&str>,
804804
) -> PyResult<()> {
805805
let py = this.py();

pysplashsurf/tests/main.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)