- open tiff seq folders with bioformats_java by finding the first tiff recursively
- make PyView serializable by skipping the ome field - fix python tests
This commit is contained in:
@@ -70,6 +70,7 @@ impl From<crate::error::Error> for PyErr {
|
||||
struct PyView {
|
||||
view: View<IxDyn, DynReader>,
|
||||
dtype: PixelType,
|
||||
#[serde(skip)]
|
||||
ome: Ome,
|
||||
index: usize,
|
||||
}
|
||||
@@ -157,9 +158,12 @@ impl PyView {
|
||||
#[pyo3(signature = (path, dtype = None, axes = "cztyx", reader = None))]
|
||||
fn new<'py>(
|
||||
py: Python<'py>,
|
||||
#[gen_stub(override_type(type_repr="str | pathlib.Path | View | bytes", imports=("pathlib")))]
|
||||
#[gen_stub(
|
||||
override_type(type_repr="str | pathlib.Path | View | bytes", imports=("pathlib"))
|
||||
)]
|
||||
path: Bound<'py, PyAny>,
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")))]
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")
|
||||
))]
|
||||
dtype: Option<Bound<'py, PyAny>>,
|
||||
axes: &str,
|
||||
reader: Option<&str>,
|
||||
@@ -167,7 +171,9 @@ impl PyView {
|
||||
if path.is_instance_of::<Self>() {
|
||||
Ok(path.cast_into::<Self>()?.extract::<Self>()?)
|
||||
} else if path.is_instance_of::<PyBytes>() {
|
||||
Ok(from_bytes(&path.extract::<Vec<u8>>()?).map_err(Error::from)?)
|
||||
let mut pyview: Self = from_bytes(&path.extract::<Vec<u8>>()?).map_err(Error::from)?;
|
||||
pyview.ome = pyview.view.metadata()?;
|
||||
Ok(pyview)
|
||||
} else {
|
||||
let builtins = PyModule::import(py, "builtins")?;
|
||||
let path = PathBuf::from(
|
||||
@@ -209,7 +215,9 @@ impl PyView {
|
||||
#[staticmethod]
|
||||
fn get_positions<'py>(
|
||||
py: Python,
|
||||
#[gen_stub(override_type(type_repr="str | pathlib.Path | View | bytes", imports=("pathlib")))]
|
||||
#[gen_stub(
|
||||
override_type(type_repr="str | pathlib.Path | View | bytes", imports=("pathlib"))
|
||||
)]
|
||||
path: Bound<'py, PyAny>,
|
||||
) -> PyResult<HashSet<usize>> {
|
||||
Self::get_available_series(py, path, None)
|
||||
@@ -337,7 +345,8 @@ impl PyView {
|
||||
fn as_type(
|
||||
&self,
|
||||
py: Python<'_>,
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")))]
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")
|
||||
))]
|
||||
dtype: Bound<'_, PyAny>,
|
||||
) -> PyResult<Self> {
|
||||
let np = PyModule::import(py, "numpy")?;
|
||||
@@ -356,7 +365,8 @@ impl PyView {
|
||||
fn astype(
|
||||
&self,
|
||||
py: Python<'_>,
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")))]
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")
|
||||
))]
|
||||
dtype: Bound<'_, PyAny>,
|
||||
) -> PyResult<Self> {
|
||||
self.as_type(py, dtype)
|
||||
@@ -510,7 +520,8 @@ impl PyView {
|
||||
fn __array__<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")))]
|
||||
#[gen_stub(override_type(type_repr = "numpy.typing.DTypeLike", imports=("numpy", "numpy.typing")
|
||||
))]
|
||||
dtype: Option<Bound<'py, PyAny>>,
|
||||
copy: Option<bool>,
|
||||
) -> PyResult<Bound<'py, PyAny>> {
|
||||
@@ -1233,7 +1244,8 @@ impl PyView {
|
||||
#[pyo3(signature = (axes = None))]
|
||||
fn transpose(
|
||||
&self,
|
||||
#[gen_stub(override_type(type_repr="typing.Optional[typing.Sequence[int | str]]", imports=("typing")))]
|
||||
#[gen_stub(override_type(type_repr="typing.Optional[typing.Sequence[int | str]]", imports=("typing")
|
||||
))]
|
||||
axes: Option<Vec<Bound<PyAny>>>,
|
||||
) -> PyResult<Self> {
|
||||
let view = if let Some(axes) = axes {
|
||||
@@ -1316,7 +1328,8 @@ impl PyView {
|
||||
/// get the maximum overall or along a given axis
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[gen_stub(skip)]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, initial=None, r#where=true), text_signature = "axis: str | int")]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, initial=None, r#where=true), text_signature = "axis: str | int"
|
||||
)]
|
||||
fn max<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
@@ -1369,7 +1382,8 @@ impl PyView {
|
||||
/// get the minimum overall or along a given axis
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[gen_stub(skip)]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, initial=Some(0), r#where=true), text_signature = "axis: str | int")]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, initial=Some(0), r#where=true), text_signature = "axis: str | int"
|
||||
)]
|
||||
fn min<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
@@ -1420,7 +1434,8 @@ impl PyView {
|
||||
}
|
||||
|
||||
#[gen_stub(skip)]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, *, r#where=true), text_signature = "axis: str | int")]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, *, r#where=true), text_signature = "axis: str | int"
|
||||
)]
|
||||
fn mean<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
@@ -1459,7 +1474,8 @@ impl PyView {
|
||||
/// get the sum overall or along a given axis
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[gen_stub(skip)]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, initial=Some(0), r#where=true), text_signature = "axis: str | int")]
|
||||
#[pyo3(signature = (axis=None, dtype=None, out=None, keepdims=false, initial=Some(0), r#where=true), text_signature = "axis: str | int"
|
||||
)]
|
||||
fn sum<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
@@ -1656,23 +1672,13 @@ impl PyView {
|
||||
py_view.view.path().to_owned()
|
||||
} else {
|
||||
let builtins = PyModule::import(py, "builtins")?;
|
||||
let mut path = PathBuf::from(
|
||||
PathBuf::from(
|
||||
builtins
|
||||
.getattr("str")?
|
||||
.call1((path,))?
|
||||
.cast_into::<PyString>()?
|
||||
.extract::<String>()?,
|
||||
);
|
||||
if path.is_dir() {
|
||||
for file in path.read_dir()?.flatten().sorted_by_key(|i| i.file_name()) {
|
||||
let p = file.path();
|
||||
if file.path().is_file() && (p.extension() == Some("tif".as_ref())) {
|
||||
path = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
path
|
||||
)
|
||||
};
|
||||
|
||||
Ok(DynReader::get_available_series_select_reader(path, reader)?)
|
||||
@@ -1693,23 +1699,13 @@ impl PyView {
|
||||
py_view.view.path().to_owned()
|
||||
} else {
|
||||
let builtins = PyModule::import(py, "builtins")?;
|
||||
let mut path = PathBuf::from(
|
||||
PathBuf::from(
|
||||
builtins
|
||||
.getattr("str")?
|
||||
.call1((path,))?
|
||||
.cast_into::<PyString>()?
|
||||
.extract::<String>()?,
|
||||
);
|
||||
if path.is_dir() {
|
||||
for file in path.read_dir()?.flatten().sorted_by_key(|i| i.file_name()) {
|
||||
let p = file.path();
|
||||
if file.path().is_file() && (p.extension() == Some("tif".as_ref())) {
|
||||
path = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
path
|
||||
)
|
||||
};
|
||||
Ok(DynReader::get_available_positions_select_reader(
|
||||
path, series, reader,
|
||||
@@ -1758,7 +1754,8 @@ impl PyView {
|
||||
|
||||
#[cfg(feature = "movie")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[pyo3(signature = (file, speed = 1.0, brightness = None, scale = 1.0, colors = None, overwrite = false, register = false, no_scaling = false))]
|
||||
#[pyo3(signature = (file, speed = 1.0, brightness = None, scale = 1.0, colors = None, overwrite = false, register = false, no_scaling = false)
|
||||
)]
|
||||
fn save_as_movie(
|
||||
&self,
|
||||
file: PathBuf,
|
||||
@@ -1813,7 +1810,8 @@ submit! {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[gen_stub_pyfunction(module = "ndbioimage.ndbioimage_rs")]
|
||||
#[pyfunction]
|
||||
#[pyo3(signature = (files_in, files_out, operations = None, colors = None, overwrite = false, bar = true, message = None))]
|
||||
#[pyo3(signature = (files_in, files_out, operations = None, colors = None, overwrite = false, bar = true, message = None)
|
||||
)]
|
||||
fn batch_to_tiff(
|
||||
py: Python,
|
||||
files_in: Vec<PathBuf>,
|
||||
@@ -1919,7 +1917,8 @@ impl PyShape {
|
||||
)
|
||||
}
|
||||
|
||||
#[gen_stub(override_return_type(type_repr="typing.Optional[int | list[int]]", imports=("typing")))]
|
||||
#[gen_stub(override_return_type(type_repr="typing.Optional[int | list[int]]", imports=("typing")
|
||||
))]
|
||||
fn __getitem__<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
|
||||
Reference in New Issue
Block a user