Skip to content

Commit

Permalink
Remove endianness changes in ncvar2zarr
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Mar 17, 2024
1 parent f81ea14 commit 5197701
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Various minor fixes to clap help
- `zarrs_reencode`: add `--attributes-append` to re-encoding options

### Fixed
- Correctly account for endianness of netCDF variable in `zarrs_ncvar2zarr`

## [0.3.0] - 2024-02-22

### Added
Expand Down
24 changes: 1 addition & 23 deletions src/bin/zarrs_ncvar2zarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use zarrs_tools::{get_array_builder, ZarrEncodingArgs};

use zarrs::{
array::{
codec::{
array_to_bytes::bytes::{reverse_endianness, Endianness, NATIVE_ENDIAN},
ArrayCodecTraits, CodecOptionsBuilder,
},
codec::{ArrayCodecTraits, CodecOptionsBuilder},
concurrency::RecommendedConcurrency,
Array, DimensionName,
},
Expand Down Expand Up @@ -73,7 +70,6 @@ fn ncfiles_to_array<TStore: ReadableWritableStorageTraits + ?Sized + 'static>(
variable: &str,
concat_dim: usize,
array: &Array<TStore>,
endianness: Endianness,
num_concurrent_blocks: Option<usize>,
validate: bool,
) -> usize {
Expand Down Expand Up @@ -140,10 +136,6 @@ fn ncfiles_to_array<TStore: ReadableWritableStorageTraits + ?Sized + 'static>(
// println!("Read netCDF done");
bytes_read.fetch_add(buf.len(), Ordering::Relaxed);

if !endianness.is_native() {
reverse_endianness(&mut buf, array.data_type());
}

if validate {
array
.store_array_subset_opt(&array_subset, buf.clone(), &codec_options)
Expand Down Expand Up @@ -245,13 +237,11 @@ fn main() {
// - data type
// - array shape taking into the concat dimension
// - dimension names
// - endianness
let mut array_shape: Option<Vec<u64>> = None;
let mut dimension_names: Option<Vec<String>> = None;
let mut datatype: Option<String> = None;
let mut offset: u64 = 0;
let mut offsets = Vec::with_capacity(nc_paths.len());
let mut endianness = None;
for nc_path in &nc_paths {
let nc_file = netcdf::open(nc_path).expect("Could not open netCDF file");
let nc_var = nc_file
Expand All @@ -268,16 +258,6 @@ fn main() {
}

let dims = nc_var.dimensions();
endianness = Some(
match nc_var
.endianness()
.expect("Could not get the variable endianness")
{
netcdf::Endianness::Native => NATIVE_ENDIAN,
netcdf::Endianness::Big => Endianness::Big,
netcdf::Endianness::Little => Endianness::Little,
},
);
let dim_names: Vec<_> = dims.iter().map(|dim| dim.name()).collect();
let dim_sizes: Vec<_> = dims.iter().map(|dim| dim.len() as u64).collect();

Expand All @@ -303,7 +283,6 @@ fn main() {
Some(dimension_names.iter().map(DimensionName::new).collect());
let datatype = datatype.unwrap();
let data_type = zarrs::array::DataType::from_metadata(&Metadata::new(&datatype)).unwrap();
let endianness = endianness.unwrap();
// println!("Shape: {array_shape:?}");
// println!("Datatype: {datatype}");
// println!(
Expand Down Expand Up @@ -342,7 +321,6 @@ fn main() {
&cli.variable,
cli.concat_dim,
&array,
endianness,
cli.concurrent_blocks,
cli.validate,
);
Expand Down

0 comments on commit 5197701

Please sign in to comment.