### Async array read/write example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Example demonstrating the setup of an asynchronous storage backend for array operations. ```rust async fn async_array_write_read() -> Result<(), Box> { use std::sync::Arc; use futures::StreamExt; use zarrs::array::{ArraySubset, ZARR_NAN_F32, data_type}; use zarrs::node::Node; // Create a store let mut store: AsyncReadableWritableListableStorage = Arc::new( zarrs_object_store::AsyncObjectStore::new(object_store::memory::InMemory::new()), ); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( // std::io::BufWriter::new( std::io::stdout(), // ) )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() }); ``` -------------------------------- ### Rectilinear Array Setup Source: https://docs.rs/zarrs/latest/zarrs/group/enum.GroupMetadata.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Partial example showing the initialization of a store for rectilinear array operations. ```rust 10fn rectilinear_array_write_read() -> Result<(), Box> { 11 use rayon::prelude::{IntoParallelIterator, ParallelIterator}; 12 use zarrs::array::{ArraySubset, ZARR_NAN_F32, codec, data_type}; 13 use zarrs::node::Node; 14 use zarrs::storage::store; 15 16 // Create a store ``` -------------------------------- ### PackBitsCodecConfiguration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_bytes/packbits/index.html Example JSON configuration for the PackBitsCodec. ```json { "padding_encoding": "first_byte", "first_bit": null, "last_bit": null } ``` -------------------------------- ### Rectilinear Array Setup Source: https://docs.rs/zarrs/latest/zarrs/group/enum.GroupMetadata.html Partial example showing imports for rectilinear array operations. ```rust 10fn rectilinear_array_write_read() -> Result<(), Box> { 11 use rayon::prelude::{IntoParallelIterator, ParallelIterator}; 12 use zarrs::array::{ArraySubset, ZARR_NAN_F32, codec, data_type}; 13 use zarrs::node::Node; 14 use zarrs::storage::store; ``` -------------------------------- ### PcodecCodecConfiguration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_bytes/pcodec/index.html Example JSON configuration for the PcodecCodec, specifying compression level, mode, delta encoding, and paging parameters. ```json { "level": 5, "mode_spec": "auto", "delta_spec": "auto", "paging_spec": "equal_pages_up_to", "delta_encoding_order": null, "equal_pages_up_to": 262144 } ``` -------------------------------- ### Initialize Storage Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Setup boilerplate for creating a Zarr storage backend. ```rust fn array_write_read() -> Result<(), Box> { use std::sync::Arc; use zarrs::array::{ArraySubset, ZARR_NAN_F32, data_type}; use zarrs::node::Node; use zarrs::storage::store; // Create a store // let path = tempfile::TempDir::new()?; // let mut store: ReadableWritableListableStorage = // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); // let mut store: ReadableWritableListableStorage = Arc::new( ``` -------------------------------- ### Shuffle Codec Configuration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/bytes_to_bytes/shuffle/index.html Example configuration for the ShuffleCodec using a 2-byte element size. ```json { "elementsize": 2 } ``` -------------------------------- ### Initialize Zarr Store Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Setup code for creating a filesystem-based Zarr store. ```rust fn sharded_array_write_read() -> Result<(), Box> { use std::sync::Arc; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use zarrs::array::{ArraySubset, codec, data_type}; use zarrs::node::Node; use zarrs::storage::store; // Create a store // let path = tempfile::TempDir::new()?; // let mut store: ReadableWritableListableStorage = // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); // let mut store: ReadableWritableListableStorage = Arc::new( // zarrs::filesystem::FilesystemStore::new("zarrs/tests/data/sharded_array_write_read.zarr")?, // ); ``` -------------------------------- ### Transpose Codec Configuration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_array/transpose/index.html?search= Example JSON configuration for the TransposeCodec, specifying the permutation order of dimensions. ```json { "order": [2, 1, 0] } ``` -------------------------------- ### SqueezeCodecConfiguration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_array/squeeze/index.html Represents the default configuration for the Squeeze codec. ```json {} ``` -------------------------------- ### Array Write and Read Example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.ArraySubset.html A comprehensive example showing the creation of a Zarr array, writing chunks, and retrieving subsets. ```rust 8fn array_write_read() -> Result<(), Box> { 9 use std::sync::Arc; 10 11 use zarrs::array::{ArraySubset, ZARR_NAN_F32, data_type}; 12 use zarrs::node::Node; 13 use zarrs::storage::store; 14 15 // Create a store 16 // let path = tempfile::TempDir::new()?; 17 // let mut store: ReadableWritableListableStorage = 18 // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); 19 // let mut store: ReadableWritableListableStorage = Arc::new( 20 // zarrs::filesystem::FilesystemStore::new("zarrs/tests/data/array_write_read.zarr")?, 21 // ); 22 let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); 23 if let Some(arg1) = std::env::args().collect::>().get(1) 24 && arg1 == "--usage-log" 25 { 26 let log_writer = Arc::new(std::sync::Mutex::new( 27 // std::io::BufWriter::new( 28 std::io::stdout(), 29 // ) 30 )); 31 store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { 32 chrono::Utc::now().format("[%T%.3f] ").to_string() 33 })); 34 } 35 36 // Create the root group 37 zarrs::group::GroupBuilder::new() 38 .build(store.clone(), "/")? 39 .store_metadata()?; 40 41 // Create a group with attributes 42 let group_path = "/group"; 43 let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; 44 group 45 .attributes_mut() 46 .insert("foo".into(), serde_json::Value::String("bar".into())); 47 group.store_metadata()?; 48 49 println!( 50 "The group metadata is:\n{}\n", 51 group.metadata().to_string_pretty() 52 ); 53 54 // Create an array 55 let array_path = "/group/array"; 56 let array = zarrs::array::ArrayBuilder::new( 57 vec![8, 8], // array shape 58 vec![4, 4], // regular chunk shape 59 data_type::float32(), 60 ZARR_NAN_F32, 61 ) 62 // .bytes_to_bytes_codecs(vec![]) // uncompressed 63 .dimension_names(["y", "x"].into()) 64 // .storage_transformers(vec![].into()) 65 .build(store.clone(), array_path)?; 66 67 // Write array metadata to store 68 array.store_metadata()?; 69 70 println!( 71 "The array metadata is:\n{}\n", 72 array.metadata().to_string_pretty() 73 ); 74 75 // Write some chunks 76 (0..2).into_par_iter().try_for_each(|i| { 77 let chunk_indices: Vec = vec![0, i]; 78 let chunk_subset = array.chunk_grid().subset(&chunk_indices)?.ok_or_else(|| { 79 zarrs::array::ArrayError::InvalidChunkGridIndicesError(chunk_indices.to_vec()) 80 })?; 81 array.store_chunk( 82 &chunk_indices, 83 vec![i as f32 * 0.1; chunk_subset.num_elements() as usize], 84 ) 85 })?; 86 87 let subset_all = array.subset_all(); 88 let data_all: ArrayD = array.retrieve_array_subset(&subset_all)?; 89 println!("store_chunk [0, 0] and [0, 1]:\n{data_all:+4.1}\n"); 90 91 // Store multiple chunks 92 array.store_chunks( 93 &[1..2, 0..2], 94 &[ 95 // 96 1.0f32, 1.0, 1.0, 1.0, 1.1, 1.1, 1.1, 1.1, 1.0, 1.0, 1.0, 1.0, 1.1, 1.1, 1.1, 1.1, 97 // 98 1.0, 1.0, 1.0, 1.0, 1.1, 1.1, 1.1, 1.1, 1.0, 1.0, 1.0, 1.0, 1.1, 1.1, 1.1, 1.1, 99 ], 100 )?; 101 let data_all: ArrayD = array.retrieve_array_subset(&subset_all)?; 102 println!("store_chunks [1..2, 0..2]:\n{data_all:+4.1}\n"); 103 104 // Write a subset spanning multiple chunks, including updating chunks already written 105 array.store_array_subset( 106 &[3..6, 3..6], 107 &[-3.3f32, -3.4, -3.5, -4.3, -4.4, -4.5, -5.3, -5.4, -5.5], 108 )?; 109 let data_all: ArrayD = array.retrieve_array_subset(&subset_all)?; 110 println!("store_array_subset [3..6, 3..6]:\n{data_all:+4.1}\n"); 111 112 // Store array subset ``` -------------------------------- ### Zarr V2 Group Creation Example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Example demonstrating the initialization of a Zarr V2 group using a memory store. ```rust fn main() -> Result<(), Box> { let store = Arc::new(zarrs_storage::store::MemoryStore::new()); let serde_json::Value::Object(attributes) = serde_json::json!({ "foo": "bar", "baz": 42, }) else { unreachable!() }; // Create a Zarr V2 group ``` -------------------------------- ### Rectilinear Chunk Grid Configuration Examples Source: https://docs.rs/zarrs/latest/zarrs/array/chunk_grid/rectilinear/index.html Examples of configuring a rectilinear chunk grid using different chunk shape formats. ```json { "kind": "inline", "chunk_shapes": [10, 20] } ``` ```json { "kind": "inline", "chunk_shapes": [[5, 5, 5, 15, 15, 20, 35], [10]] } ``` ```json { "kind": "inline", "chunk_shapes": [[[5, 3], [15, 2], 20, 35], [10]] } ``` ```json { "kind": "inline", "chunk_shapes": [10, [5, 5, 5, 15, 15, 20, 35]] } ``` -------------------------------- ### ZfpyCodecConfiguration Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_bytes/zfpy/index.html?search=std%3A%3Avec Configuration examples for the ZfpyCodec, demonstrating how to set different compression modes. ```APIDOC ## ZfpyCodecConfiguration Examples ### Fixed Rate Mode Encode with 10.5 compressed bits per value. ```json { "mode": 2, "rate": 10.5 } ``` ### Fixed Precision Mode Encode with 19 uncompressed bits per value. ```json { "mode": 3, "precision": 19 } ``` ### Fixed Accuracy Mode Encode with a tolerance of 0.05. ```json { "mode": 4, "tolerance": 0.05 } ``` ``` -------------------------------- ### Initialize Storage and Create Groups Source: https://docs.rs/zarrs/latest/zarrs/group/struct.GroupBuilder.html Demonstrates setting up a storage backend, optionally with a usage log, and creating a root group or a group with custom attributes. ```rust // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( // std::io::BufWriter::new( std::io::stdout(), // ) )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; println!( "The group metadata is:\n{}\n", group.metadata().to_string_pretty() ); ``` -------------------------------- ### Configure Storage Backend and Usage Logging Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html?search=u32+-%3E+bool Initializes a storage backend using ObjectStore and optionally wraps it with a usage log adapter. ```rust let block_on = TokioBlockOn(tokio::runtime::Runtime::new()?); let mut store: ReadableStorage = match backend { Backend::ObjectStore => { let options = object_store::ClientOptions::new().with_allow_http(true); let store = object_store::http::HttpBuilder::new() .with_url(HTTP_URL) .with_client_options(options) .build()?; let store = Arc::new(zarrs_object_store::AsyncObjectStore::new(store)); Arc::new(AsyncToSyncStorageAdapter::new(store, block_on)) } }; if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( std::io::stdout(), )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } ``` -------------------------------- ### Rectilinear array write and read example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Example demonstrating the creation of a store, group, and array setup. ```rust 10fn rectilinear_array_write_read() -> Result<(), Box> { 11 use rayon::prelude::{IntoParallelIterator, ParallelIterator}; 12 use zarrs::array::{ArraySubset, ZARR_NAN_F32, codec, data_type}; 13 use zarrs::node::Node; 14 use zarrs::storage::store; 15 16 // Create a store 17 // let path = tempfile::TempDir::new()?; 18 // let mut store: ReadableWritableListableStorage = 19 // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); 20 let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); 21 if let Some(arg1) = std::env::args().collect::>().get(1) 22 && arg1 == "--usage-log" 23 { 24 let log_writer = Arc::new(std::sync::Mutex::new( 25 // std::io::BufWriter::new( 26 std::io::stdout(), 27 // ) 28 )); 29 store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { 30 chrono::Utc::now().format("[%T%.3f] ").to_string() 31 })); 32 } 33 34 // Create the root group 35 zarrs::group::GroupBuilder::new() 36 .build(store.clone(), "/")? 37 .store_metadata()?; 38 39 // Create a group with attributes 40 let group_path = "/group"; 41 let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; 42 group 43 .attributes_mut() 44 .insert("foo".into(), serde_json::Value::String("bar".into())); 45 group.store_metadata()?; 46 47 println!( 48 "The group metadata is:\n{}\n", 49 group.metadata().to_string_pretty() 50 ); 51 52 // Create an array 53 let array_path = "/group/array"; 54 let array = zarrs::array::ArrayBuilder::new( ``` -------------------------------- ### Initialize Storage and Create Groups Source: https://docs.rs/zarrs/latest/zarrs/array/builder/struct.ArrayBuilder.html Sets up a memory store and demonstrates creating a root group and a group with custom attributes. ```rust let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( std::io::stdout(), )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; ``` -------------------------------- ### Configure Storage Backend and Initialize Array Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html?search=std%3A%3Avec Sets up an ObjectStore backend with custom client options and initializes an array from the provided storage. ```rust let block_on = TokioBlockOn(tokio::runtime::Runtime::new()?); let mut store: ReadableStorage = match backend { Backend::ObjectStore => { let options = object_store::ClientOptions::new().with_allow_http(true); let store = object_store::http::HttpBuilder::new() .with_url(HTTP_URL) .with_client_options(options) .build()?; let store = Arc::new(zarrs_object_store::AsyncObjectStore::new(store)); Arc::new(AsyncToSyncStorageAdapter::new(store, block_on)) } }; if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( std::io::stdout(), )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Init the existing array, reading metadata let array = Array::open(store, ARRAY_PATH)?; ``` -------------------------------- ### Custom Fixed Size Data Type Setup Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html?search= Partial example showing the initialization of an array with a custom fixed-size data type. ```rust fn main() { let store = std::sync::Arc::new(MemoryStore::default()); let array_path = "/array"; let fill_value = CustomDataTypeFixedSizeElement { x: 1, y: 2.3 }; let array = ArrayBuilder::new( vec![4, 1], // array shape vec![2, 1], // regular chunk shape ``` -------------------------------- ### Configure Storage and Create Groups Source: https://docs.rs/zarrs/latest/zarrs/array/struct.ArraySubset.html?search= Demonstrates setting up a usage log storage adapter and creating Zarr groups with optional attributes. ```rust if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( // std::io::BufWriter::new( std::io::stdout(), // ) )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; ``` -------------------------------- ### Hierarchy tree output example Source: https://docs.rs/zarrs/latest/zarrs/node/struct.Node.html Example output format for the hierarchy_tree method. ```text a baz [10000, 1000] float64 foo [10000, 1000] float64 b ``` -------------------------------- ### HTTP array read example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html?search=std%3A%3Avec Example of reading an array from an HTTP source. ```rust 15async fn http_array_read(backend: Backend) -> Result<(), Box> { 16 const HTTP_URL: &str = 17 "https://raw.githubusercontent.com/zarrs/zarrs/main/zarrs/tests/data/array_write_read.zarr"; 18 const ARRAY_PATH: &str = "/group/array"; 19 20 // Create a HTTP store ``` -------------------------------- ### Storage Initialization Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html?search=std%3A%3Avec Setting up a memory store and optional usage logging. ```rust 22 let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); 23 if let Some(arg1) = std::env::args().collect::>().get(1) 24 && arg1 == "--usage-log" 25 { 26 let log_writer = Arc::new(std::sync::Mutex::new( 27 // std::io::BufWriter::new( 28 std::io::stdout(), 29 // ) 30 )); 31 store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { 32 chrono::Utc::now().format("[%T%.3f] ").to_string() 33 })); 34 } ``` -------------------------------- ### Initialize Zarr Storage and Groups Source: https://docs.rs/zarrs/latest/zarrs/group/struct.Group.html?search= Demonstrates setting up a storage adapter and creating a root group or a group with custom attributes. ```rust store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; ``` ```rust // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; println!( "The group metadata is:\n{}\n", group.metadata().to_string_pretty() ); ``` -------------------------------- ### Static Vec Collection Example Source: https://docs.rs/zarrs/latest/zarrs/array/type.ArrayIndices.html Example demonstrating a static mutex-protected vector of vectors. ```rust static LONG_LIVED: Mutex>> = Mutex::new(Vec::new()); ``` -------------------------------- ### TransposeCodec Usage Examples Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_array/transpose/struct.TransposeCodec.html?search= Examples demonstrating the integration of TransposeCodec within an ArrayBuilder pipeline. ```rust fn main() { let store = std::sync::Arc::new(MemoryStore::default()); let array_path = "/array"; let array = ArrayBuilder::new( vec![4, 1], // array shape vec![3, 1], // regular chunk shape Arc::new(CustomDataTypeVariableSize), [], ) .array_to_array_codecs(vec![ #[cfg(feature = "transpose")] Arc::new(zarrs::array::codec::TransposeCodec::new( zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(), )), ]) .bytes_to_bytes_codecs(vec![ #[cfg(feature = "gzip")] Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()), #[cfg(feature = "crc32c")] Arc::new(zarrs::array::codec::Crc32cCodec::new()), ]) // .storage_transformers(vec![].into()) .build(store, array_path) .unwrap(); println!("{}", array.metadata().to_string_pretty()); let data = [ CustomDataTypeVariableSizeElement::from(Some(1.0)), CustomDataTypeVariableSizeElement::from(None), CustomDataTypeVariableSizeElement::from(Some(3.0)), ]; array.store_chunk(&[0, 0], &data).unwrap(); let data: Vec = array.retrieve_array_subset(&array.subset_all()).unwrap(); assert_eq!(data[0], CustomDataTypeVariableSizeElement::from(Some(1.0))); assert_eq!(data[1], CustomDataTypeVariableSizeElement::from(None)); assert_eq!(data[2], CustomDataTypeVariableSizeElement::from(Some(3.0))); assert_eq!(data[3], CustomDataTypeVariableSizeElement::from(None)); println!("{data:#?}"); } ``` ```rust fn main() { let store = std::sync::Arc::new(MemoryStore::default()); let array_path = "/array"; let fill_value = CustomDataTypeFixedSizeElement { x: 1, y: 2.3 }; let array = ArrayBuilder::new( vec![4, 1], // array shape vec![2, 1], // regular chunk shape Arc::new(CustomDataTypeFixedSize), FillValue::new(fill_value.to_ne_bytes().to_vec()), ) .array_to_array_codecs(vec![ #[cfg(feature = "transpose")] Arc::new(zarrs::array::codec::TransposeCodec::new( zarrs::array::codec::array_to_array::transpose::TransposeOrder::new(&[1, 0]).unwrap(), )), ]) .bytes_to_bytes_codecs(vec![ #[cfg(feature = "gzip")] Arc::new(zarrs::array::codec::GzipCodec::new(5).unwrap()), #[cfg(feature = "crc32c")] Arc::new(zarrs::array::codec::Crc32cCodec::new()), ]) // .storage_transformers(vec![].into()) .build(store, array_path) .unwrap(); println!("{}", array.metadata().to_string_pretty()); let data = [ CustomDataTypeFixedSizeElement { x: 3, y: 4.5 }, CustomDataTypeFixedSizeElement { x: 6, y: 7.8 }, ]; array.store_chunk(&[0, 0], &data).unwrap(); let data: Vec = array.retrieve_array_subset(&array.subset_all()).unwrap(); assert_eq!(data[0], CustomDataTypeFixedSizeElement { x: 3, y: 4.5 }); assert_eq!(data[1], CustomDataTypeFixedSizeElement { x: 6, y: 7.8 }); assert_eq!(data[2], CustomDataTypeFixedSizeElement { x: 1, y: 2.3 }); assert_eq!(data[3], CustomDataTypeFixedSizeElement { x: 1, y: 2.3 }); println!("{data:#?}"); } ``` -------------------------------- ### Initialize Store and Manage Group Metadata Source: https://docs.rs/zarrs/latest/zarrs/group/enum.GroupMetadata.html?search=u32+-%3E+bool Shows how to set up a memory store, create a group with custom attributes, and store its metadata. ```rust 8fn array_write_read() -> Result<(), Box> { use std::sync::Arc; use zarrs::array::{ArraySubset, ZARR_NAN_F32, data_type}; use zarrs::node::Node; use zarrs::storage::store; // Create a store // let path = tempfile::TempDir::new()?; // let mut store: ReadableWritableListableStorage = // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); // let mut store: ReadableWritableListableStorage = Arc::new( // zarrs::filesystem::FilesystemStore::new("zarrs/tests/data/array_write_read.zarr")?, // ); let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( // std::io::BufWriter::new( std::io::stdout(), // ) )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; println!( "The group metadata is:\n{}\n", group.metadata().to_string_pretty() ); ``` -------------------------------- ### Array Write and Read Example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Demonstrates creating a store, defining an array, writing metadata, and storing chunks. ```rust 8fn array_write_read() -> Result<(), Box> { 9 use std::sync::Arc; 10 11 use zarrs::array::{ArraySubset, ZARR_NAN_F32, data_type}; 12 use zarrs::node::Node; 13 use zarrs::storage::store; 14 15 // Create a store 16 // let path = tempfile::TempDir::new()?; 17 // let mut store: ReadableWritableListableStorage = 18 // Arc::new(zarrs::filesystem::FilesystemStore::new(path.path())?); 19 // let mut store: ReadableWritableListableStorage = Arc::new( 20 // zarrs::filesystem::FilesystemStore::new("zarrs/tests/data/array_write_read.zarr")?, 21 // ); 22 let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); 23 if let Some(arg1) = std::env::args().collect::>().get(1) 24 && arg1 == "--usage-log" 25 { 26 let log_writer = Arc::new(std::sync::Mutex::new( 27 // std::io::BufWriter::new( 28 std::io::stdout(), 29 // ) 30 )); 31 store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { 32 chrono::Utc::now().format("[%T%.3f] ").to_string() 33 })); 34 } 35 36 // Create the root group 37 zarrs::group::GroupBuilder::new() 38 .build(store.clone(), "/")? 39 .store_metadata()?; 40 41 // Create a group with attributes 42 let group_path = "/group"; 43 let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; 44 group 45 .attributes_mut() 46 .insert("foo".into(), serde_json::Value::String("bar".into())); 47 group.store_metadata()?; 48 49 println!( 50 "The group metadata is:\n{}\n", 51 group.metadata().to_string_pretty() 52 ); 53 54 // Create an array 55 let array_path = "/group/array"; 56 let array = zarrs::array::ArrayBuilder::new( 57 vec![8, 8], // array shape 58 vec![4, 4], // regular chunk shape 59 data_type::float32(), 60 ZARR_NAN_F32, 61 ) 62 // .bytes_to_bytes_codecs(vec![]) // uncompressed 63 .dimension_names(["y", "x"].into()) 64 // .storage_transformers(vec![].into()) 65 .build(store.clone(), array_path)?; 66 67 // Write array metadata to store 68 array.store_metadata()?; 69 70 println!( 71 "The array metadata is:\n{}\n", 72 array.metadata().to_string_pretty() 73 ); 74 75 // Write some chunks 76 (0..2).into_par_iter().try_for_each(|i| { 77 let chunk_indices: Vec = vec![0, i]; 78 let chunk_subset = array.chunk_grid().subset(&chunk_indices)?.ok_or_else(|| { 79 zarrs::array::ArrayError::InvalidChunkGridIndicesError(chunk_indices.to_vec()) 80 })?; 81 array.store_chunk( 82 &chunk_indices, 83 vec![i as f32 * 0.1; chunk_subset.num_elements() as usize], 84 ) 85 })?; 86 87 let subset_all = array.subset_all(); 88 let data_all: ArrayD = array.retrieve_array_subset(&subset_all)?; 89 println!("store_chunk [0, 0] and [0, 1]:\n{data_all:+4.1}\n"); 90 91 // Store multiple chunks 92 array.store_chunks( 93 &[1..2, 0..2], ``` -------------------------------- ### BytesCodecConfiguration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_bytes/bytes/index.html Example configuration for the BytesCodec specifying little endian byte order. ```json { "endian": "little" } ``` -------------------------------- ### Initialize Storage and Groups Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Setup a memory store and create a group with custom attributes. ```rust let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( // std::io::BufWriter::new( std::io::stdout(), // ) )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; ``` -------------------------------- ### Reshape Codec Configuration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_array/reshape/index.html Example configuration for the ReshapeCodec using the ReshapeCodecConfiguration format. ```json { "shape": [[0, 1], -1, [3], 10] } ``` -------------------------------- ### fn start(&self) -> Cow<'_, [u64]> Source: https://docs.rs/zarrs/latest/zarrs/array/trait.ArraySubsetTraits.html?search=std%3A%3Avec Retrieves the starting coordinates of the array subset. ```APIDOC ## fn start(&self) -> Cow<'_, [u64]> ### Description Returns the starting coordinates of the array subset as a collection of 64-bit unsigned integers. ### Returns - **Cow<'_, [u64]>** - A copy-on-write slice containing the starting coordinates. ``` -------------------------------- ### ContiguousLinearisedIndices Iterator Output Examples Source: https://docs.rs/zarrs/latest/zarrs/array/iterators/struct.ContiguousLinearisedIndices.html Examples of the output produced by the iterator for different array subsets. ```rust [(0, 9)] ``` ```rust [(7, 2), (10, 2)] ``` -------------------------------- ### Initialize Zarr Storage and Groups Source: https://docs.rs/zarrs/latest/zarrs/group/enum.GroupMetadata.html Demonstrates setting up a memory store, optionally with a usage log, and creating a root group or a group with metadata attributes. ```rust let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( std::io::stdout(), )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; println!( "The group metadata is:\n{}\n", group.metadata().to_string_pretty() ); ``` -------------------------------- ### Initialize Storage and Group Source: https://docs.rs/zarrs/latest/zarrs/array/builder/struct.ArrayBuilder.html Setup for the storage adapter and group creation using GroupBuilder. ```rust store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; println!( "The group metadata is:\n{}\n", group.metadata().to_string_pretty() ); ``` -------------------------------- ### Zarr V2 Group Creation Example Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html?search=u32+-%3E+bool Example demonstrating the initialization of a Zarr V2 group with attributes. ```rust 22fn main() -> Result<(), Box> { 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 ``` -------------------------------- ### Zarr Group Metadata JSON Example Source: https://docs.rs/zarrs/latest/zarrs/group/index.html?search= Example of a zarr.json file structure for a Zarr V3 group. ```json { "zarr_format": 3, "node_type": "group", "attributes": { "spam": "ham", "eggs": 42, } } ``` -------------------------------- ### Initialize Zarr Storage and Group Source: https://docs.rs/zarrs/latest/zarrs/group/struct.Group.html?search=u32+-%3E+bool Demonstrates setting up a storage adapter and creating a Zarr group with custom attributes. ```rust store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; ``` -------------------------------- ### Include zarrs Metadata Example Source: https://docs.rs/zarrs/latest/zarrs/config/struct.Config.html?search= Example of the JSON structure included in array metadata when include_zarrs_metadata is enabled. ```json "_zarrs": { "description": "This array was created with zarrs", "repository": "https://github.com/zarrs/zarrs", "version": "0.15.0" } ``` -------------------------------- ### Initialize Storage and Create Zarr Structures Source: https://docs.rs/zarrs/latest/zarrs/array/builder/struct.ArrayBuilder.html?search=std%3A%3Avec Sets up a memory store, optionally with a usage log, and demonstrates creating a root group, a group with attributes, and an array with subchunking and compression. ```rust let mut store: ReadableWritableListableStorage = Arc::new(store::MemoryStore::new()); if let Some(arg1) = std::env::args().collect::>().get(1) && arg1 == "--usage-log" { let log_writer = Arc::new(std::sync::Mutex::new( std::io::stdout(), )); store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { chrono::Utc::now().format("[%T%.3f] ").to_string() })); } // Create the root group zarrs::group::GroupBuilder::new() .build(store.clone(), "/")? .store_metadata()?; // Create a group with attributes let group_path = "/group"; let mut group = zarrs::group::GroupBuilder::new().build(store.clone(), group_path)?; group .attributes_mut() .insert("foo".into(), serde_json::Value::String("bar".into())); group.store_metadata()?; // Create an array let array_path = "/group/array"; let subchunk_shape = vec![4, 4]; let array = zarrs::array::ArrayBuilder::new( vec![8, 8], // array shape vec![4, 8], // chunk (shard) shape data_type::uint16(), 0u16, ) .subchunk_shape(subchunk_shape.clone()) .bytes_to_bytes_codecs(vec![ #[cfg(feature = "gzip")] Arc::new(codec::GzipCodec::new(5)?), ]) .dimension_names(["y", "x"].into()) .build(store.clone(), array_path)?; // Write array metadata to store array.store_metadata()?; ``` -------------------------------- ### ContiguousIndices Iterator Output Examples Source: https://docs.rs/zarrs/latest/zarrs/array/iterators/struct.ContiguousIndices.html Examples showing the output of the ContiguousIndices iterator for different array subsets. ```text [((0, 0), 9)] ``` ```text [((2, 1), 2), ((3, 1), 2)] ``` -------------------------------- ### Initialize Async Storage Source: https://docs.rs/zarrs/latest/zarrs/array/struct.Array.html Setup code for creating an asynchronous storage backend and initializing the root group. ```rust 8async fn async_array_write_read() -> Result<(), Box> { 9 use std::sync::Arc; 10 11 use futures::StreamExt; 12 use zarrs::array::{ArraySubset, ZARR_NAN_F32, data_type}; 13 use zarrs::node::Node; 14 15 // Create a store 16 let mut store: AsyncReadableWritableListableStorage = Arc::new( 17 zarrs_object_store::AsyncObjectStore::new(object_store::memory::InMemory::new()), 18 ); 19 if let Some(arg1) = std::env::args().collect::>().get(1) 20 && arg1 == "--usage-log" 21 { 22 let log_writer = Arc::new(std::sync::Mutex::new( 23 // std::io::BufWriter::new( 24 std::io::stdout(), 25 // ) 26 )); 27 store = Arc::new(UsageLogStorageAdapter::new(store, log_writer, || { 28 chrono::Utc::now().format("[%T%.3f] ").to_string() 29 })); 30 } 31 32 // Create the root group 33 zarrs::group::GroupBuilder::new() 34 .build(store.clone(), "/")? 35 .async_store_metadata() 36 .await?; 37 38 // Create a group with attributes 39 let group_path = "/group"; ``` -------------------------------- ### Gzip Codec Configuration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/bytes_to_bytes/gzip/index.html Example JSON configuration for the Gzip codec, specifying the compression level. ```json { "level": 1 } ``` -------------------------------- ### Bitround Codec Configuration Example Source: https://docs.rs/zarrs/latest/zarrs/array/codec/array_to_array/bitround/index.html Example JSON configuration for the BitroundCodec, specifying the number of bits to keep. ```json { "keepbits": 10 } ```