- test ome reading from some example files

This commit is contained in:
Wim Pomp
2026-01-04 15:13:35 +01:00
parent 8db873c425
commit b1f8dd998b
3 changed files with 45 additions and 4 deletions

View File

@@ -47,6 +47,9 @@ optional = true
[dev-dependencies] [dev-dependencies]
rayon = "1" rayon = "1"
downloader = "0.2"
regex = "1"
reqwest = { version = "0.13", features = ["blocking"] }
[build-dependencies] [build-dependencies]
j4rs = "0.24" j4rs = "0.24"

View File

@@ -50,10 +50,7 @@ pub fn download_bioformats(gpl_formats: bool) -> Result<(), Error> {
let path = crate::py::ndbioimage_file(); let path = crate::py::ndbioimage_file();
#[cfg(not(feature = "python"))] #[cfg(not(feature = "python"))]
let path = std::env::current_exe()? let path = std::env::current_exe()?.parent().unwrap().to_path_buf();
.parent()
.unwrap()
.to_path_buf();
let class_path = path.parent().unwrap(); let class_path = path.parent().unwrap();
let jassets = class_path.join("jassets"); let jassets = class_path.join("jassets");

View File

@@ -26,6 +26,7 @@ mod tests {
use crate::reader::{Frame, Reader}; use crate::reader::{Frame, Reader};
use crate::stats::MinMax; use crate::stats::MinMax;
use crate::view::Item; use crate::view::Item;
use downloader::{Download, Downloader};
use ndarray::{Array, Array4, Array5, NewAxis}; use ndarray::{Array, Array4, Array5, NewAxis};
use ndarray::{Array2, s}; use ndarray::{Array2, s};
use rayon::prelude::*; use rayon::prelude::*;
@@ -38,6 +39,46 @@ mod tests {
Reader::new(&path, 0) Reader::new(&path, 0)
} }
#[test]
fn read_ome() -> Result<(), Box<dyn std::error::Error>> {
let path = std::env::current_dir()?.join("tests/files/ome");
std::fs::create_dir_all(&path)?;
let url =
"https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/";
let page = reqwest::blocking::get(url)?.text()?;
let pat = regex::Regex::new(
r#"<a\s+href\s*=\s*"([^"<>]+)">[^<>]+</a>\s+\d{2}-\w{3}-\d{4}\s+\d{2}:\d{2}\s+(\d+)"#,
)?;
let mut downloads = Vec::new();
let mut files = Vec::new();
for line in page.lines() {
if let Some(cap) = pat.captures(line) {
let link = cap[1].trim().to_string();
let size = cap[2].trim().parse::<usize>()?;
if size < 10 * 1024usize.pow(2) {
if !path.join(&link).exists() {
downloads.push(Download::new(&format!("{}{}", url, link)));
}
files.push(path.join(link));
}
}
}
if !downloads.is_empty() {
let mut downloader = Downloader::builder().download_folder(&path).build()?;
downloader.download(&downloads)?;
}
let mut count = 0;
for file in files {
if let Ok(reader) = Reader::new(&file, 0) {
let _ome = reader.get_ome()?;
count += 1;
}
}
println!("count: {}", count);
assert!(count > 30);
Ok(())
}
fn get_pixel_type(file: &str) -> Result<String, Error> { fn get_pixel_type(file: &str) -> Result<String, Error> {
let reader = open(file)?; let reader = open(file)?;
Ok(format!( Ok(format!(