Skip to content

Commit

Permalink
Fix virtual test by linking to permanent objects (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci authored Oct 15, 2024
1 parent 9c2d33d commit cc4ee75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
15 changes: 6 additions & 9 deletions icechunk-python/tests/test_virtual_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,22 @@ async def test_from_s3_public_virtual_refs(tmpdir):
)
root = zarr.Group.from_store(store=store, zarr_format=3)
depth = root.require_array(
name="depth", shape=((22, )), chunk_shape=((22,)), dtype="float64"
name="depth", shape=((10, )), chunk_shape=((10,)), dtype="float64"
)

store.set_virtual_ref(
"depth/c/0",
"s3://noaa-nos-ofs-pds/dbofs/netcdf/202410/dbofs.t00z.20241012.regulargrid.f030.nc",
offset=42499,
length=176
"s3://noaa-nos-ofs-pds/dbofs/netcdf/202410/dbofs.t00z.20241009.fields.f030.nc",
offset=119339,
length=80
)

nodes = [n async for n in store.list()]
assert "depth/c/0" in nodes

depth_values = depth[:]
assert len(depth_values) == 22
actual_values = np.array([
0., 1., 2., 4., 6., 8., 10., 12., 15., 20., 25.,
30., 35., 40., 45., 50., 60., 70., 80., 90., 100., 125.
])
assert len(depth_values) == 10
actual_values = np.array([-0.95,-0.85,-0.75,-0.65,-0.55,-0.45,-0.35,-0.25,-0.15,-0.05])
assert np.allclose(depth_values, actual_values)


Expand Down
16 changes: 8 additions & 8 deletions icechunk/tests/test_virtual_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,27 +429,27 @@ mod tests {
.await
.unwrap();

let zarr_meta = Bytes::copy_from_slice(br#"{"zarr_format":3,"node_type":"array","attributes":{"foo":42},"shape":[22],"data_type":"float64","chunk_grid":{"name":"regular","configuration":{"chunk_shape":[22]}},"chunk_key_encoding":{"name":"default","configuration":{"separator":"/"}},"fill_value": 0.0,"codecs":[{"name":"mycodec","configuration":{"foo":42}}],"storage_transformers":[],"dimension_names":["depth"]}"#);
let zarr_meta = Bytes::copy_from_slice(br#"{"zarr_format":3,"node_type":"array","attributes":{"foo":42},"shape":[10],"data_type":"float64","chunk_grid":{"name":"regular","configuration":{"chunk_shape":[10]}},"chunk_key_encoding":{"name":"default","configuration":{"separator":"/"}},"fill_value": 0.0,"codecs":[{"name":"mycodec","configuration":{"foo":42}}],"storage_transformers":[],"dimension_names":["depth"]}"#);
store.set("depth/zarr.json", zarr_meta.clone()).await.unwrap();

let ref2 = VirtualChunkRef {
location: VirtualChunkLocation::from_absolute_path(
"s3://noaa-nos-ofs-pds/dbofs/netcdf/202410/dbofs.t00z.20241012.regulargrid.f030.nc",
"s3://noaa-nos-ofs-pds/dbofs/netcdf/202410/dbofs.t00z.20241009.fields.f030.nc",
)?,
offset: 42499,
length: 176,
offset: 119339,
length: 80,
};

store.set_virtual_ref("depth/c/0", ref2).await?;

let chunk = store.get("depth/c/0", &ByteRange::ALL).await.unwrap();
assert_eq!(chunk.len(), 176);
assert_eq!(chunk.len(), 80);

let second_depth = f64::from_le_bytes(chunk[8..16].try_into().unwrap());
assert!(second_depth - 1. < 0.000001);
assert!(second_depth - -0.85 < 0.000001);

let last_depth = f64::from_le_bytes(chunk[(176 - 8)..].try_into().unwrap());
assert!(last_depth - 125. < 0.000001);
let last_depth = f64::from_le_bytes(chunk[(80 - 8)..].try_into().unwrap());
assert!(last_depth - -0.05 < 0.000001);

Ok(())
}
Expand Down

0 comments on commit cc4ee75

Please sign in to comment.