pub struct ArrayMetadataOptions { /* private fields */ }Expand description
Options for writing array metadata.
Implementations§
Source§impl ArrayMetadataOptions
impl ArrayMetadataOptions
Sourcepub fn codec_metadata_options(&self) -> &CodecMetadataOptions
pub fn codec_metadata_options(&self) -> &CodecMetadataOptions
Return the codec options.
Sourcepub fn codec_metadata_options_mut(&mut self) -> &mut CodecMetadataOptions
pub fn codec_metadata_options_mut(&mut self) -> &mut CodecMetadataOptions
Return a mutable reference to the codec options.
Sourcepub fn with_codec_metadata_options(
self,
codec_metadata_options: CodecMetadataOptions,
) -> Self
pub fn with_codec_metadata_options( self, codec_metadata_options: CodecMetadataOptions, ) -> Self
Set the codec metadata options.
Sourcepub fn set_codec_metadata_options(
&mut self,
codec_metadata_options: CodecMetadataOptions,
) -> &mut Self
pub fn set_codec_metadata_options( &mut self, codec_metadata_options: CodecMetadataOptions, ) -> &mut Self
Set the codec metadata options.
Sourcepub fn metadata_convert_version(&self) -> MetadataConvertVersion
pub fn metadata_convert_version(&self) -> MetadataConvertVersion
Get the metadata convert version configuration.
Sourcepub fn with_metadata_convert_version(
self,
convert_version: MetadataConvertVersion,
) -> Self
pub fn with_metadata_convert_version( self, convert_version: MetadataConvertVersion, ) -> Self
Set the metadata convert version configuration.
Examples found in repository?
examples/zarr_v2_to_v3.rs (line 80)
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 set_metadata_convert_version(
&mut self,
convert_version: MetadataConvertVersion,
) -> &mut Self
pub fn set_metadata_convert_version( &mut self, convert_version: MetadataConvertVersion, ) -> &mut Self
Set the metadata convert version configuration.
Sourcepub fn include_zarrs_metadata(&self) -> bool
pub fn include_zarrs_metadata(&self) -> bool
Get the include zarrs metadata configuration.
Sourcepub fn with_include_zarrs_metadata(self, include_zarrs_metadata: bool) -> Self
pub fn with_include_zarrs_metadata(self, include_zarrs_metadata: bool) -> Self
Set the include zarrs metadata configuration.
Examples found in repository?
examples/data_type_optional_nested.rs (line 42)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 // Create an in-memory store
13 // let store = Arc::new(zarrs::filesystem::FilesystemStore::new(
14 // "zarrs/tests/data/v3/array_optional_nested.zarr",
15 // )?);
16 let store = Arc::new(zarrs::storage::store::MemoryStore::new());
17
18 // Build the codec chains for the optional codec
19 let array = ArrayBuilder::new(
20 vec![4, 4], // 4x4 array
21 vec![2, 2], // 2x2 chunks
22 data_type::uint8().to_optional().to_optional(), // Optional optional uint8 => Option<Option<u8>>
23 FillValue::new_optional_null().into_optional(), // Fill value => Some(None)
24 )
25 .dimension_names(["y", "x"].into())
26 .attributes(
27 serde_json::json!({
28 "description": r#"A 4x4 array of optional optional uint8 values with some missing data.
29The fill value is null on the inner optional layer, i.e. Some(None).
30N marks missing (`None`=`null`) values. SN marks `Some(None)`=`[null]` values:
31 N SN 2 3
32 N 5 N 7
33 SN SN N N
34 SN SN N N"#,
35 })
36 .as_object()
37 .unwrap()
38 .clone(),
39 )
40 .build(store.clone(), "/array")?;
41 array.store_metadata_opt(
42 &zarrs::array::ArrayMetadataOptions::default().with_include_zarrs_metadata(false),
43 )?;
44
45 println!("Array metadata:\n{}", array.metadata().to_string_pretty());
46
47 // Create some data with missing values
48 let data = ndarray::array![
49 [None, Some(None), Some(Some(2u8)), Some(Some(3u8))],
50 [None, Some(Some(5u8)), None, Some(Some(7u8))],
51 [Some(None), Some(None), None, None],
52 [Some(None), Some(None), None, None],
53 ]
54 .into_dyn();
55
56 // Write the data
57 array.store_array_subset(&array.subset_all(), data.clone())?;
58 println!("Data written to array.");
59
60 // Read back the data
61 let data_read: ArrayD<Option<Option<u8>>> = array.retrieve_array_subset(&array.subset_all())?;
62
63 // Verify data integrity
64 assert_eq!(data, data_read);
65
66 // Display the data in a grid format
67 println!(
68 "Data grid. N marks missing (`None`=`null`) values. SN marks `Some(None)`=`[null]` values"
69 );
70 println!(" 0 1 2 3");
71 for y in 0..4 {
72 print!("{} ", y);
73 for x in 0..4 {
74 match data_read[[y, x]] {
75 Some(Some(value)) => print!("{:3} ", value),
76 Some(None) => print!(" SN "),
77 None => print!(" N "),
78 }
79 }
80 println!();
81 }
82 Ok(())
83}More examples
examples/data_type_optional.rs (line 48)
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19 // Create an in-memory store
20 // let store = Arc::new(zarrs::filesystem::FilesystemStore::new(
21 // "zarrs/tests/data/v3/array_optional.zarr",
22 // )?);
23 let store = Arc::new(zarrs::storage::store::MemoryStore::new());
24
25 // Build the codec chains for the optional codec
26 let array = ArrayBuilder::new(
27 vec![4, 4], // 4x4 array
28 vec![2, 2], // 2x2 chunks
29 data_type::uint8().to_optional(), // Optional uint8
30 FillValue::new_optional_null(), // Null fill value: [0]
31 )
32 .dimension_names(["y", "x"].into())
33 .attributes(
34 serde_json::json!({
35 "description": r#"A 4x4 array of optional uint8 values with some missing data.
36N marks missing (`None`=`null`) values:
37 0 N 2 3
38 N 5 N 7
39 8 9 N N
4012 N N N"#,
41 })
42 .as_object()
43 .unwrap()
44 .clone(),
45 )
46 .build(store.clone(), "/array")?;
47 array.store_metadata_opt(
48 &zarrs::array::ArrayMetadataOptions::default().with_include_zarrs_metadata(false),
49 )?;
50
51 println!("Array metadata:\n{}", array.metadata().to_string_pretty());
52
53 // Create some data with missing values
54 let data = ndarray::array![
55 [Some(0u8), None, Some(2u8), Some(3u8)],
56 [None, Some(5u8), None, Some(7u8)],
57 [Some(8u8), Some(9u8), None, None],
58 [Some(12u8), None, None, None],
59 ]
60 .into_dyn();
61
62 // Write the data
63 array.store_array_subset(&array.subset_all(), data.clone())?;
64
65 // Read back the data
66 let data_read: ArrayD<Option<u8>> = array.retrieve_array_subset(&array.subset_all())?;
67
68 // Verify data integrity
69 assert_eq!(data, data_read);
70
71 // Display the data in a grid format
72 println!("Data grid, N marks missing (`None`=`null`) values");
73 println!(" 0 1 2 3");
74 for y in 0..4 {
75 print!("{} ", y);
76 for x in 0..4 {
77 match data_read[[y, x]] {
78 Some(value) => print!("{:2} ", value),
79 None => print!(" N "),
80 }
81 }
82 println!();
83 }
84
85 // Print the raw bytes in all chunks
86 println!("Raw bytes in all chunks:");
87 let chunk_grid_shape = array.chunk_grid_shape();
88 for chunk_y in 0..chunk_grid_shape[0] {
89 for chunk_x in 0..chunk_grid_shape[1] {
90 let chunk_indices = vec![chunk_y, chunk_x];
91 let chunk_key = array.chunk_key(&chunk_indices);
92 println!(" Chunk [{}, {}] (key: {}):", chunk_y, chunk_x, chunk_key);
93
94 if let Some(chunk_bytes) = store.get(&chunk_key)? {
95 println!(" Size: {} bytes", chunk_bytes.len());
96
97 if chunk_bytes.len() >= 16 {
98 // Parse first 8 bytes as mask size (little-endian u64)
99 let mask_size = u64::from_le_bytes([
100 chunk_bytes[0],
101 chunk_bytes[1],
102 chunk_bytes[2],
103 chunk_bytes[3],
104 chunk_bytes[4],
105 chunk_bytes[5],
106 chunk_bytes[6],
107 chunk_bytes[7],
108 ]) as usize;
109
110 // Parse second 8 bytes as data size (little-endian u64)
111 let data_size = u64::from_le_bytes([
112 chunk_bytes[8],
113 chunk_bytes[9],
114 chunk_bytes[10],
115 chunk_bytes[11],
116 chunk_bytes[12],
117 chunk_bytes[13],
118 chunk_bytes[14],
119 chunk_bytes[15],
120 ]) as usize;
121
122 // Display mask size header with raw bytes
123 print!(" Mask size: 0b");
124 for byte in &chunk_bytes[0..8] {
125 print!("{:08b}", byte);
126 }
127 println!(" -> {} bytes", mask_size);
128
129 // Display data size header with raw bytes
130 print!(" Data size: 0b");
131 for byte in &chunk_bytes[8..16] {
132 print!("{:08b}", byte);
133 }
134 println!(" -> {} bytes", data_size);
135
136 // Show mask and data sections separately
137 if chunk_bytes.len() >= 16 + mask_size + data_size {
138 let mask_start = 16;
139 let data_start = 16 + mask_size;
140
141 // Show mask as binary
142 if mask_size > 0 {
143 println!(" Mask (binary):");
144 print!(" ");
145 for byte in &chunk_bytes[mask_start..mask_start + mask_size] {
146 print!("0b{:08b} ", byte);
147 }
148 println!();
149 }
150
151 // Show data as binary
152 if data_size > 0 {
153 println!(" Data (binary):");
154 print!(" ");
155 for byte in &chunk_bytes[data_start..data_start + data_size] {
156 print!("0b{:08b} ", byte);
157 }
158 println!();
159 }
160 }
161 } else {
162 panic!(" Chunk too small to parse headers");
163 }
164 } else {
165 println!(" Chunk missing (fill value chunk)");
166 }
167 }
168 }
169 Ok(())
170}Sourcepub fn set_include_zarrs_metadata(
&mut self,
include_zarrs_metadata: bool,
) -> &mut Self
pub fn set_include_zarrs_metadata( &mut self, include_zarrs_metadata: bool, ) -> &mut Self
Set the include zarrs metadata configuration.
Sourcepub fn convert_aliased_extension_names(&self) -> bool
pub fn convert_aliased_extension_names(&self) -> bool
Return the convert aliased extension names configuration
Sourcepub fn with_convert_aliased_extension_names(
self,
convert_aliased_extension_names: bool,
) -> Self
pub fn with_convert_aliased_extension_names( self, convert_aliased_extension_names: bool, ) -> Self
Set the convert aliased extension names configuration.
Sourcepub fn set_convert_aliased_extension_names(
&mut self,
convert_aliased_extension_names: bool,
) -> &mut Self
pub fn set_convert_aliased_extension_names( &mut self, convert_aliased_extension_names: bool, ) -> &mut Self
Set the convert aliased extension names configuration.
Trait Implementations§
Source§impl Clone for ArrayMetadataOptions
impl Clone for ArrayMetadataOptions
Source§fn clone(&self) -> ArrayMetadataOptions
fn clone(&self) -> ArrayMetadataOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ArrayMetadataOptions
impl Debug for ArrayMetadataOptions
Source§impl Default for ArrayMetadataOptions
impl Default for ArrayMetadataOptions
impl Copy for ArrayMetadataOptions
Auto Trait Implementations§
impl Freeze for ArrayMetadataOptions
impl Send for ArrayMetadataOptions
impl Sync for ArrayMetadataOptions
impl RefUnwindSafe for ArrayMetadataOptions
impl Unpin for ArrayMetadataOptions
impl UnsafeUnpin for ArrayMetadataOptions
impl UnwindSafe for ArrayMetadataOptions
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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