use super::{Error, MeasurementArray};
use crate::{
schema::{array_uri_reference::ArrayUriReference, axes::ChannelAxis, Label},
strided_array_file::{extract_array_index, ArrayProxy, StridedArrayFile},
};
use std::{path::PathBuf, sync::Arc};
#[derive(Debug)]
pub(crate) struct StridedArrayData<'a> {
#[expect(dead_code)]
strided_array_file: StridedArrayFile<'a>,
data: ArrayProxy<'a>,
axes: Vec<ChannelAxis>,
label: Option<Label>,
}
impl<'a> StridedArrayData<'a> {
pub(crate) fn from_uri(
uri: &ArrayUriReference,
axes: Vec<ChannelAxis>,
label: Option<Label>,
) -> Result<Arc<dyn MeasurementArray<'a> + 'a>, Error> {
let path: PathBuf = (&uri.with_fragment(None)).try_into()?;
let array_index = extract_array_index(uri)?.unwrap_or(0);
let strided_array_file = StridedArrayFile::new(path);
let data = strided_array_file.try_get(array_index)?.clone();
if data.dimensions() != axes.len() {
return Err("Inconsistent data and axes dimensionality".into());
}
Ok(Arc::new(Self {
strided_array_file,
data,
axes,
label,
}))
}
}
impl<'a> MeasurementArray<'a> for StridedArrayData<'a> {
fn data(&self) -> ArrayProxy<'a> {
self.data.clone()
}
fn axes(&self) -> &Vec<ChannelAxis> {
&self.axes
}
fn label(&self) -> &Option<Label> {
&self.label
}
}