From 3afe3e7a2286f110f11a6829f6f458eb5c0d27a7 Mon Sep 17 00:00:00 2001 From: Richard Lindsley Date: Thu, 16 Feb 2023 17:41:20 -0800 Subject: [PATCH 1/2] Add the shuffle option to the compression method --- netcdf/src/variable.rs | 7 +++++-- netcdf/tests/group.rs | 2 +- netcdf/tests/lib.rs | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/netcdf/src/variable.rs b/netcdf/src/variable.rs index 4a8c1dc..046ac20 100644 --- a/netcdf/src/variable.rs +++ b/netcdf/src/variable.rs @@ -170,16 +170,19 @@ impl<'g> VariableMut<'g> { /// compression (good for CPU bound tasks), and 9 providing the /// highest compression level (good for memory bound tasks) /// + /// `shuffle` enables a filter to reorder bytes before compressing, which + /// can improve compression ratios + /// /// # Errors /// /// Not a `netcdf-4` file or `deflate_level` not valid - pub fn compression(&mut self, deflate_level: nc_type) -> error::Result<()> { + pub fn compression(&mut self, deflate_level: nc_type, shuffle: bool) -> error::Result<()> { unsafe { error::checked(super::with_lock(|| { nc_def_var_deflate( self.ncid, self.varid, - <_>::from(false), + shuffle.into(), <_>::from(true), deflate_level, ) diff --git a/netcdf/tests/group.rs b/netcdf/tests/group.rs index ceab0d3..210030d 100644 --- a/netcdf/tests/group.rs +++ b/netcdf/tests/group.rs @@ -64,7 +64,7 @@ fn find_variable() { for mut var in group.variables_mut() { if var.dimensions().len() > 0 { - var.compression(3).unwrap(); + var.compression(3, false).unwrap(); } if var.name() == "z" { var.chunking(&[1]).unwrap(); diff --git a/netcdf/tests/lib.rs b/netcdf/tests/lib.rs index 481fabd..eaf3718 100644 --- a/netcdf/tests/lib.rs +++ b/netcdf/tests/lib.rs @@ -854,7 +854,7 @@ fn use_compression_chunking() { file.add_dimension("x", 10).unwrap(); let var = &mut file.add_variable::("compressed", &["x"]).unwrap(); - var.compression(5).unwrap(); + var.compression(5, false).unwrap(); var.chunking(&[5]).unwrap(); let v = vec![0i32; 10]; @@ -863,7 +863,7 @@ fn use_compression_chunking() { let var = &mut file .add_variable::("compressed2", &["x", "x"]) .unwrap(); - var.compression(9).unwrap(); + var.compression(9, true).unwrap(); var.chunking(&[5, 5]).unwrap(); var.put_values(&[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10], (..10, ..1)) .unwrap(); @@ -903,7 +903,7 @@ fn set_compression_all_variables_in_a_group() { .expect("Could not create variable"); for mut var in file.variables_mut() { - var.compression(9).expect("Could not set compression level"); + var.compression(9, false).expect("Could not set compression level"); } } From f8a14868992e6b4beb6163dc8f935d0500903a8b Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 17 Feb 2023 15:53:49 +0100 Subject: [PATCH 2/2] Run cargo fmt --- netcdf/tests/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netcdf/tests/lib.rs b/netcdf/tests/lib.rs index eaf3718..9e57ae6 100644 --- a/netcdf/tests/lib.rs +++ b/netcdf/tests/lib.rs @@ -903,7 +903,8 @@ fn set_compression_all_variables_in_a_group() { .expect("Could not create variable"); for mut var in file.variables_mut() { - var.compression(9, false).expect("Could not set compression level"); + var.compression(9, false) + .expect("Could not set compression level"); } }