Skip to main content

ArrayMetadataV2

Struct ArrayMetadataV2 

Source
pub struct ArrayMetadataV2 {
    pub zarr_format: MustBeU64<2>,
    pub shape: Vec<u64>,
    pub chunks: Vec<NonZero<u64>>,
    pub dtype: DataTypeMetadataV2,
    pub compressor: Option<MetadataV2>,
    pub fill_value: FillValueMetadataV3,
    pub order: ArrayMetadataV2Order,
    pub filters: Option<Vec<MetadataV2>>,
    pub dimension_separator: ChunkKeySeparator,
    pub attributes: Map<String, Value>,
}
Expand description

Zarr V2 array metadata.

An example JSON document for a Zarr V2 array:

{
    "chunks": [
        1000,
        1000
    ],
    "compressor": {
        "id": "blosc",
        "cname": "lz4",
        "clevel": 5,
        "shuffle": 1
    },
    "dtype": "<f8",
    "fill_value": "NaN",
    "filters": [
        {"id": "delta", "dtype": "<f8", "astype": "<f4"}
    ],
    "order": "C",
    "shape": [
        10000,
        10000
    ],
    "zarr_format": 2
}

Fields§

§zarr_format: MustBeU64<2>

An integer defining the version of the storage specification to which the array adheres. Must be 2.

§shape: Vec<u64>

An array of integers providing the length of each dimension of the Zarr array.

§chunks: Vec<NonZero<u64>>

A list of integers defining the length of each dimension of a chunk of the array.

§dtype: DataTypeMetadataV2

The data type of the Zarr array.

§compressor: Option<MetadataV2>

A JSON object identifying the primary compression codec and providing configuration parameters, or null if no compressor is to be used.

§fill_value: FillValueMetadataV3

A scalar value providing the default value to use for uninitialized portions of the array, or null if no fill value is to be used.

§order: ArrayMetadataV2Order

Either “C” or “F”, defining the layout of bytes within each chunk of the array.

§filters: Option<Vec<MetadataV2>>

A list of JSON objects providing codec configurations, or null if no filters are to be applied.

§dimension_separator: ChunkKeySeparator

If present, either the string “.” or “/” defining the separator placed between the dimensions of a chunk.

§attributes: Map<String, Value>

Optional user defined attributes contained in a separate .zattrs file.

Implementations§

Source§

impl ArrayMetadataV2

Source

pub fn new( shape: Vec<u64>, chunks: Vec<NonZero<u64>>, dtype: DataTypeMetadataV2, fill_value: FillValueMetadataV3, compressor: Option<MetadataV2>, filters: Option<Vec<MetadataV2>>, ) -> ArrayMetadataV2

Create Zarr V2 array metadata.

Defaults to:

  • C order,
  • empty attributes, and
  • no additional fields.
Examples found in repository?
examples/zarr_v2_to_v3.rs (lines 61-68)
22fn main() -> Result<(), Box<dyn std::error::Error>> {
23    let store = Arc::new(zarrs_storage::store::MemoryStore::new());
24
25    let serde_json::Value::Object(attributes) = serde_json::json!({
26        "foo": "bar",
27        "baz": 42,
28    }) else {
29        unreachable!()
30    };
31
32    // Create a Zarr V2 group
33    let group_metadata: GroupMetadata = GroupMetadataV2::new()
34        .with_attributes(attributes.clone())
35        .into();
36    let group = Group::new_with_metadata(store.clone(), "/group", group_metadata)?;
37
38    // Store the metadata as V2 and V3
39    let convert_group_metadata_to_v3 =
40        GroupMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
41    group.store_metadata()?;
42    group.store_metadata_opt(&convert_group_metadata_to_v3)?;
43    println!(
44        "group/.zgroup (Zarr V2 group metadata):\n{}\n",
45        key_to_str(&store, "group/.zgroup")?
46    );
47    println!(
48        "group/.zattrs (Zarr V2 group attributes):\n{}\n",
49        key_to_str(&store, "group/.zattrs")?
50    );
51    println!(
52        "group/zarr.json (Zarr V3 equivalent group metadata/attributes):\n{}\n",
53        key_to_str(&store, "group/zarr.json")?
54    );
55    // println!(
56    //     "The equivalent Zarr V3 group metadata is\n{}\n",
57    //     group.metadata_opt(&convert_group_metadata_to_v3).to_string_pretty()
58    // );
59
60    // Create a Zarr V2 array
61    let array_metadata = ArrayMetadataV2::new(
62        vec![10, 10],
63        vec![NonZeroU64::new(5).unwrap(); 2],
64        ">f4".into(), // big endian float32
65        FillValueMetadata::from(f32::NAN),
66        None,
67        None,
68    )
69    .with_dimension_separator(ChunkKeySeparator::Slash)
70    .with_order(ArrayMetadataV2Order::F)
71    .with_attributes(attributes.clone());
72    let array = zarrs::array::Array::new_with_metadata(
73        store.clone(),
74        "/group/array",
75        array_metadata.into(),
76    )?;
77
78    // Store the metadata as V2 and V3
79    let convert_array_metadata_to_v3 =
80        ArrayMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
81    array.store_metadata()?;
82    array.store_metadata_opt(&convert_array_metadata_to_v3)?;
83    println!(
84        "group/array/.zarray (Zarr V2 array metadata):\n{}\n",
85        key_to_str(&store, "group/array/.zarray")?
86    );
87    println!(
88        "group/array/.zattrs (Zarr V2 array attributes):\n{}\n",
89        key_to_str(&store, "group/array/.zattrs")?
90    );
91    println!(
92        "group/array/zarr.json (Zarr V3 equivalent array metadata/attributes):\n{}\n",
93        key_to_str(&store, "group/array/zarr.json")?
94    );
95    // println!(
96    //     "The equivalent Zarr V3 array metadata is\n{}\n",
97    //     array.metadata_opt(&convert_array_metadata_to_v3).to_string_pretty()
98    // );
99
100    array.store_chunk(&[0, 1], &[0.0f32; 5 * 5])?;
101
102    // Print the keys in the store
103    println!("The store contains keys:");
104    for key in store.list()? {
105        println!("  {}", key);
106    }
107
108    Ok(())
109}
Source

pub fn to_string_pretty(&self) -> String

Serialize the metadata as a pretty-printed String of JSON.

Source

pub fn with_dimension_separator( self, dimension_separator: ChunkKeySeparator, ) -> ArrayMetadataV2

Set the dimension separator.

Examples found in repository?
examples/zarr_v2_to_v3.rs (line 69)
22fn main() -> Result<(), Box<dyn std::error::Error>> {
23    let store = Arc::new(zarrs_storage::store::MemoryStore::new());
24
25    let serde_json::Value::Object(attributes) = serde_json::json!({
26        "foo": "bar",
27        "baz": 42,
28    }) else {
29        unreachable!()
30    };
31
32    // Create a Zarr V2 group
33    let group_metadata: GroupMetadata = GroupMetadataV2::new()
34        .with_attributes(attributes.clone())
35        .into();
36    let group = Group::new_with_metadata(store.clone(), "/group", group_metadata)?;
37
38    // Store the metadata as V2 and V3
39    let convert_group_metadata_to_v3 =
40        GroupMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
41    group.store_metadata()?;
42    group.store_metadata_opt(&convert_group_metadata_to_v3)?;
43    println!(
44        "group/.zgroup (Zarr V2 group metadata):\n{}\n",
45        key_to_str(&store, "group/.zgroup")?
46    );
47    println!(
48        "group/.zattrs (Zarr V2 group attributes):\n{}\n",
49        key_to_str(&store, "group/.zattrs")?
50    );
51    println!(
52        "group/zarr.json (Zarr V3 equivalent group metadata/attributes):\n{}\n",
53        key_to_str(&store, "group/zarr.json")?
54    );
55    // println!(
56    //     "The equivalent Zarr V3 group metadata is\n{}\n",
57    //     group.metadata_opt(&convert_group_metadata_to_v3).to_string_pretty()
58    // );
59
60    // Create a Zarr V2 array
61    let array_metadata = ArrayMetadataV2::new(
62        vec![10, 10],
63        vec![NonZeroU64::new(5).unwrap(); 2],
64        ">f4".into(), // big endian float32
65        FillValueMetadata::from(f32::NAN),
66        None,
67        None,
68    )
69    .with_dimension_separator(ChunkKeySeparator::Slash)
70    .with_order(ArrayMetadataV2Order::F)
71    .with_attributes(attributes.clone());
72    let array = zarrs::array::Array::new_with_metadata(
73        store.clone(),
74        "/group/array",
75        array_metadata.into(),
76    )?;
77
78    // Store the metadata as V2 and V3
79    let convert_array_metadata_to_v3 =
80        ArrayMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
81    array.store_metadata()?;
82    array.store_metadata_opt(&convert_array_metadata_to_v3)?;
83    println!(
84        "group/array/.zarray (Zarr V2 array metadata):\n{}\n",
85        key_to_str(&store, "group/array/.zarray")?
86    );
87    println!(
88        "group/array/.zattrs (Zarr V2 array attributes):\n{}\n",
89        key_to_str(&store, "group/array/.zattrs")?
90    );
91    println!(
92        "group/array/zarr.json (Zarr V3 equivalent array metadata/attributes):\n{}\n",
93        key_to_str(&store, "group/array/zarr.json")?
94    );
95    // println!(
96    //     "The equivalent Zarr V3 array metadata is\n{}\n",
97    //     array.metadata_opt(&convert_array_metadata_to_v3).to_string_pretty()
98    // );
99
100    array.store_chunk(&[0, 1], &[0.0f32; 5 * 5])?;
101
102    // Print the keys in the store
103    println!("The store contains keys:");
104    for key in store.list()? {
105        println!("  {}", key);
106    }
107
108    Ok(())
109}
Source

pub fn with_order(self, order: ArrayMetadataV2Order) -> ArrayMetadataV2

Set the order.

Examples found in repository?
examples/zarr_v2_to_v3.rs (line 70)
22fn main() -> Result<(), Box<dyn std::error::Error>> {
23    let store = Arc::new(zarrs_storage::store::MemoryStore::new());
24
25    let serde_json::Value::Object(attributes) = serde_json::json!({
26        "foo": "bar",
27        "baz": 42,
28    }) else {
29        unreachable!()
30    };
31
32    // Create a Zarr V2 group
33    let group_metadata: GroupMetadata = GroupMetadataV2::new()
34        .with_attributes(attributes.clone())
35        .into();
36    let group = Group::new_with_metadata(store.clone(), "/group", group_metadata)?;
37
38    // Store the metadata as V2 and V3
39    let convert_group_metadata_to_v3 =
40        GroupMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
41    group.store_metadata()?;
42    group.store_metadata_opt(&convert_group_metadata_to_v3)?;
43    println!(
44        "group/.zgroup (Zarr V2 group metadata):\n{}\n",
45        key_to_str(&store, "group/.zgroup")?
46    );
47    println!(
48        "group/.zattrs (Zarr V2 group attributes):\n{}\n",
49        key_to_str(&store, "group/.zattrs")?
50    );
51    println!(
52        "group/zarr.json (Zarr V3 equivalent group metadata/attributes):\n{}\n",
53        key_to_str(&store, "group/zarr.json")?
54    );
55    // println!(
56    //     "The equivalent Zarr V3 group metadata is\n{}\n",
57    //     group.metadata_opt(&convert_group_metadata_to_v3).to_string_pretty()
58    // );
59
60    // Create a Zarr V2 array
61    let array_metadata = ArrayMetadataV2::new(
62        vec![10, 10],
63        vec![NonZeroU64::new(5).unwrap(); 2],
64        ">f4".into(), // big endian float32
65        FillValueMetadata::from(f32::NAN),
66        None,
67        None,
68    )
69    .with_dimension_separator(ChunkKeySeparator::Slash)
70    .with_order(ArrayMetadataV2Order::F)
71    .with_attributes(attributes.clone());
72    let array = zarrs::array::Array::new_with_metadata(
73        store.clone(),
74        "/group/array",
75        array_metadata.into(),
76    )?;
77
78    // Store the metadata as V2 and V3
79    let convert_array_metadata_to_v3 =
80        ArrayMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
81    array.store_metadata()?;
82    array.store_metadata_opt(&convert_array_metadata_to_v3)?;
83    println!(
84        "group/array/.zarray (Zarr V2 array metadata):\n{}\n",
85        key_to_str(&store, "group/array/.zarray")?
86    );
87    println!(
88        "group/array/.zattrs (Zarr V2 array attributes):\n{}\n",
89        key_to_str(&store, "group/array/.zattrs")?
90    );
91    println!(
92        "group/array/zarr.json (Zarr V3 equivalent array metadata/attributes):\n{}\n",
93        key_to_str(&store, "group/array/zarr.json")?
94    );
95    // println!(
96    //     "The equivalent Zarr V3 array metadata is\n{}\n",
97    //     array.metadata_opt(&convert_array_metadata_to_v3).to_string_pretty()
98    // );
99
100    array.store_chunk(&[0, 1], &[0.0f32; 5 * 5])?;
101
102    // Print the keys in the store
103    println!("The store contains keys:");
104    for key in store.list()? {
105        println!("  {}", key);
106    }
107
108    Ok(())
109}
Source

pub fn with_attributes(self, attributes: Map<String, Value>) -> ArrayMetadataV2

Set the user attributes.

Examples found in repository?
examples/zarr_v2_to_v3.rs (line 71)
22fn main() -> Result<(), Box<dyn std::error::Error>> {
23    let store = Arc::new(zarrs_storage::store::MemoryStore::new());
24
25    let serde_json::Value::Object(attributes) = serde_json::json!({
26        "foo": "bar",
27        "baz": 42,
28    }) else {
29        unreachable!()
30    };
31
32    // Create a Zarr V2 group
33    let group_metadata: GroupMetadata = GroupMetadataV2::new()
34        .with_attributes(attributes.clone())
35        .into();
36    let group = Group::new_with_metadata(store.clone(), "/group", group_metadata)?;
37
38    // Store the metadata as V2 and V3
39    let convert_group_metadata_to_v3 =
40        GroupMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
41    group.store_metadata()?;
42    group.store_metadata_opt(&convert_group_metadata_to_v3)?;
43    println!(
44        "group/.zgroup (Zarr V2 group metadata):\n{}\n",
45        key_to_str(&store, "group/.zgroup")?
46    );
47    println!(
48        "group/.zattrs (Zarr V2 group attributes):\n{}\n",
49        key_to_str(&store, "group/.zattrs")?
50    );
51    println!(
52        "group/zarr.json (Zarr V3 equivalent group metadata/attributes):\n{}\n",
53        key_to_str(&store, "group/zarr.json")?
54    );
55    // println!(
56    //     "The equivalent Zarr V3 group metadata is\n{}\n",
57    //     group.metadata_opt(&convert_group_metadata_to_v3).to_string_pretty()
58    // );
59
60    // Create a Zarr V2 array
61    let array_metadata = ArrayMetadataV2::new(
62        vec![10, 10],
63        vec![NonZeroU64::new(5).unwrap(); 2],
64        ">f4".into(), // big endian float32
65        FillValueMetadata::from(f32::NAN),
66        None,
67        None,
68    )
69    .with_dimension_separator(ChunkKeySeparator::Slash)
70    .with_order(ArrayMetadataV2Order::F)
71    .with_attributes(attributes.clone());
72    let array = zarrs::array::Array::new_with_metadata(
73        store.clone(),
74        "/group/array",
75        array_metadata.into(),
76    )?;
77
78    // Store the metadata as V2 and V3
79    let convert_array_metadata_to_v3 =
80        ArrayMetadataOptions::default().with_metadata_convert_version(MetadataConvertVersion::V3);
81    array.store_metadata()?;
82    array.store_metadata_opt(&convert_array_metadata_to_v3)?;
83    println!(
84        "group/array/.zarray (Zarr V2 array metadata):\n{}\n",
85        key_to_str(&store, "group/array/.zarray")?
86    );
87    println!(
88        "group/array/.zattrs (Zarr V2 array attributes):\n{}\n",
89        key_to_str(&store, "group/array/.zattrs")?
90    );
91    println!(
92        "group/array/zarr.json (Zarr V3 equivalent array metadata/attributes):\n{}\n",
93        key_to_str(&store, "group/array/zarr.json")?
94    );
95    // println!(
96    //     "The equivalent Zarr V3 array metadata is\n{}\n",
97    //     array.metadata_opt(&convert_array_metadata_to_v3).to_string_pretty()
98    // );
99
100    array.store_chunk(&[0, 1], &[0.0f32; 5 * 5])?;
101
102    // Print the keys in the store
103    println!("The store contains keys:");
104    for key in store.list()? {
105        println!("  {}", key);
106    }
107
108    Ok(())
109}

Trait Implementations§

Source§

impl Clone for ArrayMetadataV2

Source§

fn clone(&self) -> ArrayMetadataV2

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ArrayMetadataV2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ArrayMetadataV2

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ArrayMetadataV2, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ArrayMetadataV2

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<ArrayMetadataV2> for ArrayMetadata

Source§

fn from(value: ArrayMetadataV2) -> ArrayMetadata

Converts to this type from the input type.
Source§

impl PartialEq for ArrayMetadataV2

Source§

fn eq(&self, other: &ArrayMetadataV2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ArrayMetadataV2

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ArrayMetadataV2

Source§

impl StructuralPartialEq for ArrayMetadataV2

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,