- silence java warnings

- renam View -> Imread in Python
This commit is contained in:
w.pomp
2026-08-07 15:26:12 +02:00
parent a0d2359e55
commit b950f4a39d
4 changed files with 82 additions and 87 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ os.environ["RUST_BACKTRACE"] = "full"
os.environ["COLORBT_SHOW_HIDDEN"] = "1" os.environ["COLORBT_SHOW_HIDDEN"] = "1"
from . import ndbioimage_rs as rs # noqa from . import ndbioimage_rs as rs # noqa
from .ndbioimage_rs import View as Imread from .ndbioimage_rs import Imread
from .transforms import Transform, Transforms # noqa: F401 from .transforms import Transform, Transforms # noqa: F401
try: try:
+64 -64
View File
@@ -10,53 +10,13 @@ import numpy
import numpy.typing import numpy.typing
__all__ = [ __all__ = [
"Imread",
"Shape", "Shape",
"View",
"batch_to_tiff", "batch_to_tiff",
"main", "main",
] ]
class Shape: class Imread:
@property
def c(self) -> builtins.int: ...
@property
def z(self) -> builtins.int: ...
@property
def t(self) -> builtins.int: ...
@property
def y(self) -> builtins.int: ...
@property
def x(self) -> builtins.int: ...
@property
def axes(self) -> builtins.str: ...
def __new__(
cls,
order: builtins.str,
c: builtins.int = 1,
z: builtins.int = 1,
t: builtins.int = 1,
y: builtins.int = 1,
x: builtins.int = 1,
) -> Shape: ...
def __str__(self) -> builtins.str: ...
def __repr__(self) -> builtins.str: ...
def __getnewargs__(
self,
) -> tuple[
builtins.str,
builtins.int,
builtins.int,
builtins.int,
builtins.int,
builtins.int,
]: ...
def __getitem__(
self, idx: str | int | None | Ellipsis | slice | list[int] | tuple[int]
) -> typing.Optional[int | list[int]]: ...
def __len__(self) -> builtins.int: ...
def to_list(self) -> builtins.list[builtins.int]: ...
class View:
r""" r"""
class to read image files, while taking good care of important metadata, class to read image files, while taking good care of important metadata,
currently optimized for .czi files, but can open anything that bioformats can handle currently optimized for .czi files, but can open anything that bioformats can handle
@@ -123,7 +83,7 @@ class View:
the number of dimensions in the view the number of dimensions in the view
""" """
@property @property
def T(self) -> View: ... def T(self) -> Imread: ...
@property @property
def dtype(self) -> numpy.dtype: ... def dtype(self) -> numpy.dtype: ...
@property @property
@@ -174,17 +134,17 @@ class View:
def tube_lens_name(self) -> typing.Optional[builtins.str]: ... def tube_lens_name(self) -> typing.Optional[builtins.str]: ...
def __new__( def __new__(
cls, cls,
path: str | pathlib.Path | View | bytes, path: str | pathlib.Path | Imread | bytes,
dtype: numpy.typing.DTypeLike = None, dtype: numpy.typing.DTypeLike = None,
axes: builtins.str = "cztyx", axes: builtins.str = "cztyx",
reader: typing.Optional[builtins.str] = None, reader: typing.Optional[builtins.str] = None,
) -> View: ) -> Imread:
r""" r"""
new view on a file at path, open series #, open as dtype: (u)int(8/16/32) or float(32/64) new view on a file at path, open series #, open as dtype: (u)int(8/16/32) or float(32/64)
""" """
@staticmethod @staticmethod
def get_positions( def get_positions(
path: str | pathlib.Path | View | bytes, path: str | pathlib.Path | Imread | bytes,
) -> builtins.set[builtins.int]: ... ) -> builtins.set[builtins.int]: ...
@staticmethod @staticmethod
def kill_vm() -> None: def kill_vm() -> None:
@@ -198,17 +158,17 @@ class View:
drift: builtins.bool = False, drift: builtins.bool = False,
file: typing.Optional[typing.Any] = None, file: typing.Optional[typing.Any] = None,
bead_files: typing.Optional[typing.Any] = None, bead_files: typing.Optional[typing.Any] = None,
) -> View: ... ) -> Imread: ...
def squeeze(self) -> numpy.ndarray | int | float: ... def squeeze(self) -> numpy.ndarray | int | float: ...
def close(self) -> None: def close(self) -> None:
r""" r"""
close the file: does nothing as this is handled automatically close the file: does nothing as this is handled automatically
""" """
def as_type(self, dtype: numpy.typing.DTypeLike) -> View: def as_type(self, dtype: numpy.typing.DTypeLike) -> Imread:
r""" r"""
change the data type of the view: (u)int(8/16/32) or float(32/64) change the data type of the view: (u)int(8/16/32) or float(32/64)
""" """
def astype(self, dtype: numpy.typing.DTypeLike) -> View: def astype(self, dtype: numpy.typing.DTypeLike) -> Imread:
r""" r"""
change the data type of the view: (u)int(8/16/32) or float(32/64) change the data type of the view: (u)int(8/16/32) or float(32/64)
""" """
@@ -256,7 +216,7 @@ class View:
def __pos__(self) -> typing.Any: ... def __pos__(self) -> typing.Any: ...
def __abs__(self) -> typing.Any: ... def __abs__(self) -> typing.Any: ...
def __invert__(self) -> typing.Any: ... def __invert__(self) -> typing.Any: ...
def __enter__(self) -> View: ... def __enter__(self) -> Imread: ...
def __exit__( def __exit__(
self, self,
exc_type: typing.Optional[typing.Any] = None, exc_type: typing.Optional[typing.Any] = None,
@@ -264,10 +224,10 @@ class View:
exc_tb: typing.Optional[typing.Any] = None, exc_tb: typing.Optional[typing.Any] = None,
) -> None: ... ) -> None: ...
def __getnewargs__(self) -> tuple[builtins.list[builtins.int]]: ... def __getnewargs__(self) -> tuple[builtins.list[builtins.int]]: ...
def __copy__(self) -> View: ... def __copy__(self) -> Imread: ...
def __deepcopy__(self) -> View: ... def __deepcopy__(self) -> Imread: ...
def copy(self) -> View: ... def copy(self) -> Imread: ...
def __iter__(self) -> View: ... def __iter__(self) -> Imread: ...
def __next__(self) -> typing.Optional[typing.Any]: ... def __next__(self) -> typing.Optional[typing.Any]: ...
def __len__(self) -> builtins.int: ... def __len__(self) -> builtins.int: ...
def __repr__(self) -> builtins.str: ... def __repr__(self) -> builtins.str: ...
@@ -285,13 +245,13 @@ class View:
r""" r"""
find the position of an axis find the position of an axis
""" """
def swap_axes(self, ax0: int | str, ax1: int | str) -> View: def swap_axes(self, ax0: int | str, ax1: int | str) -> Imread:
r""" r"""
swap two axes swap two axes
""" """
def transpose( def transpose(
self, axes: typing.Optional[typing.Sequence[int | str]] = None self, axes: typing.Optional[typing.Sequence[int | str]] = None
) -> View: ) -> Imread:
r""" r"""
permute the order of the axes permute the order of the axes
""" """
@@ -317,14 +277,14 @@ class View:
""" """
@staticmethod @staticmethod
def get_available_series( def get_available_series(
path: str | pathlib.Path | View, reader: typing.Optional[builtins.str] = None path: str | pathlib.Path | Imread, reader: typing.Optional[builtins.str] = None
) -> builtins.set[builtins.int]: ) -> builtins.set[builtins.int]:
r""" r"""
get all series contained in the file get all series contained in the file
""" """
@staticmethod @staticmethod
def get_available_positions( def get_available_positions(
path: str | pathlib.Path | View, path: str | pathlib.Path | Imread,
series: builtins.int, series: builtins.int,
reader: typing.Optional[builtins.str] = None, reader: typing.Optional[builtins.str] = None,
) -> builtins.set[builtins.int]: ) -> builtins.set[builtins.int]:
@@ -355,13 +315,13 @@ class View:
""" """
def __pow__( def __pow__(
self, self,
other: View | numpy.typing.NDArray | int | float, other: Imread | numpy.typing.NDArray | int | float,
mod: typing.Any = None, mod: typing.Any = None,
/, /,
) -> numpy.typing.NDArray: ... ) -> numpy.typing.NDArray: ...
def __rpow__( def __rpow__(
self, self,
other: View | numpy.typing.NDArray | int | float, other: Imread | numpy.typing.NDArray | int | float,
mod: typing.Any = None, mod: typing.Any = None,
/, /,
) -> numpy.typing.NDArray: ... ) -> numpy.typing.NDArray: ...
@@ -373,7 +333,7 @@ class View:
keepdims: bool = False, keepdims: bool = False,
initial: int | float = None, initial: int | float = None,
where: bool = True, where: bool = True,
) -> View | numpy.typing.NDArray | int | float: ) -> Imread | numpy.typing.NDArray | int | float:
r""" r"""
Return the maximum along a given axis. Arguments beyond axis are not implemented Return the maximum along a given axis. Arguments beyond axis are not implemented
""" """
@@ -385,7 +345,7 @@ class View:
keepdims: bool = False, keepdims: bool = False,
initial: int | float = None, initial: int | float = None,
where: bool = True, where: bool = True,
) -> View | numpy.typing.NDArray | int | float: ) -> Imread | numpy.typing.NDArray | int | float:
r""" r"""
Return the minimum along a given axis. Arguments beyond axis are not implemented Return the minimum along a given axis. Arguments beyond axis are not implemented
""" """
@@ -395,7 +355,7 @@ class View:
dtype: numpy.typing.DTypeLike = None, dtype: numpy.typing.DTypeLike = None,
out: typing.Any = None, out: typing.Any = None,
keepdims: bool = False, keepdims: bool = False,
) -> View | numpy.typing.NDArray | int | float: ) -> Imread | numpy.typing.NDArray | int | float:
r""" r"""
Return the mean along a given axis. Arguments beyond axis are not implemented Return the mean along a given axis. Arguments beyond axis are not implemented
""" """
@@ -407,11 +367,51 @@ class View:
keepdims: bool = False, keepdims: bool = False,
initial: int | float = None, initial: int | float = None,
where: bool = True, where: bool = True,
) -> View | numpy.typing.NDArray | int | float: ) -> Imread | numpy.typing.NDArray | int | float:
r""" r"""
Return the sum along a given axis. Arguments beyond axis are not implemented Return the sum along a given axis. Arguments beyond axis are not implemented
""" """
class Shape:
@property
def c(self) -> builtins.int: ...
@property
def z(self) -> builtins.int: ...
@property
def t(self) -> builtins.int: ...
@property
def y(self) -> builtins.int: ...
@property
def x(self) -> builtins.int: ...
@property
def axes(self) -> builtins.str: ...
def __new__(
cls,
order: builtins.str,
c: builtins.int = 1,
z: builtins.int = 1,
t: builtins.int = 1,
y: builtins.int = 1,
x: builtins.int = 1,
) -> Shape: ...
def __str__(self) -> builtins.str: ...
def __repr__(self) -> builtins.str: ...
def __getnewargs__(
self,
) -> tuple[
builtins.str,
builtins.int,
builtins.int,
builtins.int,
builtins.int,
builtins.int,
]: ...
def __getitem__(
self, idx: str | int | None | Ellipsis | slice | list[int] | tuple[int]
) -> typing.Optional[int | list[int]]: ...
def __len__(self) -> builtins.int: ...
def to_list(self) -> builtins.list[builtins.int]: ...
def batch_to_tiff( def batch_to_tiff(
files_in: typing.Sequence[builtins.str | os.PathLike | pathlib.Path], files_in: typing.Sequence[builtins.str | os.PathLike | pathlib.Path],
files_out: typing.Sequence[builtins.str | os.PathLike | pathlib.Path], files_out: typing.Sequence[builtins.str | os.PathLike | pathlib.Path],
+13 -13
View File
@@ -80,7 +80,7 @@ impl From<crate::error::Error> for PyErr {
#[pyclass( #[pyclass(
subclass, subclass,
from_py_object, from_py_object,
name = "View", name = "Imread",
module = "ndbioimage.ndbioimage_rs" module = "ndbioimage.ndbioimage_rs"
)] )]
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@@ -176,7 +176,7 @@ impl PyView {
fn new<'py>( fn new<'py>(
py: Python<'py>, py: Python<'py>,
#[gen_stub( #[gen_stub(
override_type(type_repr="str | pathlib.Path | View | bytes", imports=("pathlib")) override_type(type_repr="str | pathlib.Path | Imread | bytes", imports=("pathlib"))
)] )]
path: Bound<'py, PyAny>, 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")
@@ -233,7 +233,7 @@ impl PyView {
fn get_positions<'py>( fn get_positions<'py>(
py: Python, py: Python,
#[gen_stub( #[gen_stub(
override_type(type_repr="str | pathlib.Path | View | bytes", imports=("pathlib")) override_type(type_repr="str | pathlib.Path | Imread | bytes", imports=("pathlib"))
)] )]
path: Bound<'py, PyAny>, path: Bound<'py, PyAny>,
) -> PyResult<HashSet<usize>> { ) -> PyResult<HashSet<usize>> {
@@ -761,7 +761,7 @@ impl PyView {
) -> PyResult<Bound<'py, PyAny>> { ) -> PyResult<Bound<'py, PyAny>> {
if r#mod.is_some() { if r#mod.is_some() {
return Err(PyNotImplementedError::new_err( return Err(PyNotImplementedError::new_err(
"cannot use pow or ** on View with mod != None", "cannot use pow or ** on Imread with mod != None",
)); ));
} }
let np = PyModule::import(py, "numpy")?; let np = PyModule::import(py, "numpy")?;
@@ -779,7 +779,7 @@ impl PyView {
) -> PyResult<Bound<'py, PyAny>> { ) -> PyResult<Bound<'py, PyAny>> {
if r#mod.is_some() { if r#mod.is_some() {
return Err(PyNotImplementedError::new_err( return Err(PyNotImplementedError::new_err(
"cannot use pow or ** on View with mod != None", "cannot use pow or ** on Imread with mod != None",
)); ));
} }
let np = PyModule::import(py, "numpy")?; let np = PyModule::import(py, "numpy")?;
@@ -1681,7 +1681,7 @@ impl PyView {
#[pyo3(signature = (path, reader = None))] #[pyo3(signature = (path, reader = None))]
fn get_available_series<'py>( fn get_available_series<'py>(
py: Python<'py>, py: Python<'py>,
#[gen_stub(override_type(type_repr="str | pathlib.Path | View", imports=("pathlib")))] #[gen_stub(override_type(type_repr="str | pathlib.Path | Imread", imports=("pathlib")))]
path: Bound<'py, PyAny>, path: Bound<'py, PyAny>,
reader: Option<&str>, reader: Option<&str>,
) -> PyResult<HashSet<usize>> { ) -> PyResult<HashSet<usize>> {
@@ -1707,7 +1707,7 @@ impl PyView {
#[pyo3(signature = (path, series, reader = None))] #[pyo3(signature = (path, series, reader = None))]
fn get_available_positions<'py>( fn get_available_positions<'py>(
py: Python<'py>, py: Python<'py>,
#[gen_stub(override_type(type_repr="str | pathlib.Path | View", imports=("pathlib")))] #[gen_stub(override_type(type_repr="str | pathlib.Path | Imread", imports=("pathlib")))]
path: Bound<'py, PyAny>, path: Bound<'py, PyAny>,
series: usize, series: usize,
reader: Option<&str>, reader: Option<&str>,
@@ -1810,19 +1810,19 @@ submit! {
import numpy.typing import numpy.typing
class PyView: class PyView:
def __pow__(other: View | numpy.typing.NDArray | int | float, mod: typing.Any = None, /) -> numpy.typing.NDArray: ... def __pow__(other: Imread | numpy.typing.NDArray | int | float, mod: typing.Any = None, /) -> numpy.typing.NDArray: ...
def __rpow__(other: View | numpy.typing.NDArray | int | float, mod: typing.Any = None, /) -> numpy.typing.NDArray: ... def __rpow__(other: Imread | numpy.typing.NDArray | int | float, mod: typing.Any = None, /) -> numpy.typing.NDArray: ...
def max(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False, initial: int | float = None, where: bool = True) -> View | numpy.typing.NDArray | int | float: def max(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False, initial: int | float = None, where: bool = True) -> Imread | numpy.typing.NDArray | int | float:
""" Return the maximum along a given axis. Arguments beyond axis are not implemented """ """ Return the maximum along a given axis. Arguments beyond axis are not implemented """
def min(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False, initial: int | float = None, where: bool = True) -> View | numpy.typing.NDArray | int | float: def min(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False, initial: int | float = None, where: bool = True) -> Imread | numpy.typing.NDArray | int | float:
""" Return the minimum along a given axis. Arguments beyond axis are not implemented """ """ Return the minimum along a given axis. Arguments beyond axis are not implemented """
def mean(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False) -> View | numpy.typing.NDArray | int | float: def mean(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False) -> Imread | numpy.typing.NDArray | int | float:
""" Return the mean along a given axis. Arguments beyond axis are not implemented """ """ Return the mean along a given axis. Arguments beyond axis are not implemented """
def sum(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False, initial: int | float = None, where: bool = True) -> View | numpy.typing.NDArray | int | float: def sum(axis: int | str = None, dtype: numpy.typing.DTypeLike = None, out: typing.Any = None, keepdims: bool = False, initial: int | float = None, where: bool = True) -> Imread | numpy.typing.NDArray | int | float:
""" Return the sum along a given axis. Arguments beyond axis are not implemented """ """ Return the sum along a given axis. Arguments beyond axis are not implemented """
"# "#
} }
+4 -9
View File
@@ -108,16 +108,11 @@ fn jvm() -> Rc<Jvm> {
let j = JvmBuilder::new() let j = JvmBuilder::new()
.skip_setting_native_lib() .skip_setting_native_lib()
.with_base_path(class_path.to_str().unwrap()) .with_base_path(class_path.to_str().unwrap())
.java_opt(JavaOpt::new("-XX:+IgnoreUnrecognizedVMOptions"))
.java_opt(JavaOpt::new("--enable-native-access=ALL-UNNAMED")) .java_opt(JavaOpt::new("--enable-native-access=ALL-UNNAMED"))
.build(); .java_opt(JavaOpt::new("--sun-misc-unsafe-memory-access=allow"))
let j = match j { .build()
Ok(j) => j, .expect("Failed to build JVM");
Err(_) => JvmBuilder::new()
.skip_setting_native_lib()
.with_base_path(class_path.to_str().unwrap())
.build()
.expect("Failed to build JVM"),
};
if let Ok(e) = InvocationArg::try_from("ERROR") { if let Ok(e) = InvocationArg::try_from("ERROR") {
let _ = j.invoke_static( let _ = j.invoke_static(
"loci.common.DebugTools", "loci.common.DebugTools",