- 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:
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
pub use crate::readers::{ArrayT, PixelType, Reader};
|
||||
use crate::readers::{DynReader, Frame, Shape};
|
||||
use itertools::Itertools;
|
||||
use j4rs::{Instance, InvocationArg, Jvm, JvmBuilder};
|
||||
use std::cell::OnceCell;
|
||||
use std::collections::HashSet;
|
||||
@@ -461,6 +462,22 @@ impl Drop for BioFormatsJavaReader {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_tiff(path: PathBuf) -> Result<Option<PathBuf>, Error> {
|
||||
if let Some(ext) = path.extension()
|
||||
&& path.is_file()
|
||||
&& (["tif", "tiff"].contains(&ext.to_string_lossy().to_lowercase().as_str()))
|
||||
{
|
||||
return Ok(Some(path));
|
||||
} else if path.is_dir() {
|
||||
for file in path.read_dir()?.flatten().sorted_by_key(|i| i.file_name()) {
|
||||
if let Ok(Some(file)) = find_tiff(file.path()) {
|
||||
return Ok(Some(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
impl Reader for BioFormatsJavaReader {
|
||||
/// Create a new reader for the image file at a path, and open series #.
|
||||
fn new<P>(path: P, series: usize, _position: usize) -> Result<Self, Error>
|
||||
@@ -470,13 +487,10 @@ impl Reader for BioFormatsJavaReader {
|
||||
DebugTools::set_root_level("ERROR")?;
|
||||
let mut path = path.as_ref().to_path_buf();
|
||||
if path.is_dir() {
|
||||
for file in path.read_dir()?.flatten() {
|
||||
let p = file.path();
|
||||
if file.path().is_file() && (p.extension() == Some("tif".as_ref())) {
|
||||
path = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
let orig = path.clone();
|
||||
path = find_tiff(path)?.ok_or_else(|| {
|
||||
Error::FileDoesNotExist(orig.join("**").join("*.tif").display().to_string())
|
||||
})?;
|
||||
}
|
||||
let mut new = BioFormatsJavaReader {
|
||||
reader: ThreadLocal::default(),
|
||||
@@ -549,9 +563,16 @@ impl Reader for BioFormatsJavaReader {
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
DebugTools::set_root_level("ERROR")?;
|
||||
let mut path = path.as_ref().to_path_buf();
|
||||
if path.is_dir() {
|
||||
let orig = path.clone();
|
||||
path = find_tiff(path)?.ok_or_else(|| {
|
||||
Error::FileDoesNotExist(orig.join("**").join("*.tif").display().to_string())
|
||||
})?;
|
||||
}
|
||||
let new = BioFormatsJavaReader {
|
||||
reader: ThreadLocal::default(),
|
||||
path: path.as_ref().to_path_buf(),
|
||||
path,
|
||||
series: 0,
|
||||
shape: Shape::default(),
|
||||
pixel_type: PixelType::I8,
|
||||
@@ -594,7 +615,8 @@ mod tests {
|
||||
metadata_e: "czi/YTL1849A131_2023_05_04__13_36_36.czi",
|
||||
metadata_f: "czi/EU_UV_t=1-01.czi",
|
||||
metadata_g: "tiffseq/4-Pos_001_002/img_000000000_Cy3-Cy3_filter_000.tif",
|
||||
metadata_h: "tiffseq/20-Pos_005_005/img_000000000_Cy3-Cy3_filter_000.tif"
|
||||
metadata_h: "tiffseq/20-Pos_005_005/img_000000000_Cy3-Cy3_filter_000.tif",
|
||||
metadata_i: "tiffseq/YTL1841B2-2-1_1hr_DMSO_galinduction_1",
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user