mod open;
use std::sync::Arc;
use anyhow::Result;
use ndarray::ArrayD;
use zarrs::storage::ReadableListableStorage;
pub use open::open_product;
#[cfg(feature = "safe")]
use crate::safe::SafeStore;
use crate::zarr::{ZarrStore, tree::ZarrTree};
#[derive(Clone)]
pub enum Product {
Zarr(ZarrStore),
#[cfg(feature = "safe")]
Safe(SafeStore),
}
impl Product {
pub fn root_path(&self) -> &str {
match self {
Self::Zarr(store) => &store.root_path,
#[cfg(feature = "safe")]
Self::Safe(store) => &store.root_path,
}
}
pub fn tree(&self) -> &ZarrTree {
match self {
Self::Zarr(store) => &store.tree,
#[cfg(feature = "safe")]
Self::Safe(store) => &store.tree,
}
}
pub fn zarr_storage(&self) -> Option<&ReadableListableStorage> {
match self {
Self::Zarr(store) => Some(&store.storage),
#[cfg(feature = "safe")]
Self::Safe(_) => None,
}
}
#[cfg(feature = "safe")]
pub fn as_safe(&self) -> Option<&SafeStore> {
match self {
Self::Safe(store) => Some(store),
Self::Zarr(_) => None,
}
}
pub fn read_array_subset_f64(
&self,
path: &str,
ranges: &[std::ops::Range<u64>],
) -> Result<ArrayD<f64>> {
match self {
Self::Zarr(store) => store.read_array_subset_f64(path, ranges),
#[cfg(feature = "safe")]
Self::Safe(store) => store.read_array_subset_f64(path, ranges),
}
}
}
impl std::fmt::Debug for Product {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Product")
.field("root_path", &self.root_path())
.field(
"format",
&match self {
Self::Zarr(_) => "zarr",
#[cfg(feature = "safe")]
Self::Safe(_) => "safe",
},
)
.finish()
}
}
pub type ProductHandle = Arc<Product>;