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: DataTypeMetadataV2The 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: FillValueMetadataV3A 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: ArrayMetadataV2OrderEither “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: ChunkKeySeparatorIf 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
impl ArrayMetadataV2
Sourcepub fn new(
shape: Vec<u64>,
chunks: Vec<NonZero<u64>>,
dtype: DataTypeMetadataV2,
fill_value: FillValueMetadataV3,
compressor: Option<MetadataV2>,
filters: Option<Vec<MetadataV2>>,
) -> ArrayMetadataV2
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?
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}Sourcepub fn to_string_pretty(&self) -> String
pub fn to_string_pretty(&self) -> String
Serialize the metadata as a pretty-printed String of JSON.
Sourcepub fn with_dimension_separator(
self,
dimension_separator: ChunkKeySeparator,
) -> ArrayMetadataV2
pub fn with_dimension_separator( self, dimension_separator: ChunkKeySeparator, ) -> ArrayMetadataV2
Set the dimension separator.
Examples found in repository?
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}Sourcepub fn with_order(self, order: ArrayMetadataV2Order) -> ArrayMetadataV2
pub fn with_order(self, order: ArrayMetadataV2Order) -> ArrayMetadataV2
Set the order.
Examples found in repository?
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}Sourcepub fn with_attributes(self, attributes: Map<String, Value>) -> ArrayMetadataV2
pub fn with_attributes(self, attributes: Map<String, Value>) -> ArrayMetadataV2
Set the user attributes.
Examples found in repository?
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
impl Clone for ArrayMetadataV2
Source§fn clone(&self) -> ArrayMetadataV2
fn clone(&self) -> ArrayMetadataV2
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ArrayMetadataV2
impl Debug for ArrayMetadataV2
Source§impl<'de> Deserialize<'de> for ArrayMetadataV2
impl<'de> Deserialize<'de> for ArrayMetadataV2
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ArrayMetadataV2, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ArrayMetadataV2, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for ArrayMetadataV2
impl Display for ArrayMetadataV2
Source§impl From<ArrayMetadataV2> for ArrayMetadata
impl From<ArrayMetadataV2> for ArrayMetadata
Source§fn from(value: ArrayMetadataV2) -> ArrayMetadata
fn from(value: ArrayMetadataV2) -> ArrayMetadata
Source§impl PartialEq for ArrayMetadataV2
impl PartialEq for ArrayMetadataV2
Source§impl Serialize for ArrayMetadataV2
impl Serialize for ArrayMetadataV2
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for ArrayMetadataV2
impl StructuralPartialEq for ArrayMetadataV2
Auto Trait Implementations§
impl Freeze for ArrayMetadataV2
impl Send for ArrayMetadataV2
impl Sync for ArrayMetadataV2
impl RefUnwindSafe for ArrayMetadataV2
impl Unpin for ArrayMetadataV2
impl UnsafeUnpin for ArrayMetadataV2
impl UnwindSafe for ArrayMetadataV2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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