I've got a HDF5 file with the following structure (viewed with h5dump
):
❯ h5dump -n GMTCO_npp_d20181005_t2022358_e2024003_b35959_c20181008035331888329_cspp_dev.h5
HDF5 "GMTCO_npp_d20181005_t2022358_e2024003_b35959_c20181008035331888329_cspp_dev.h5" {
FILE_CONTENTS {
group /
group /All_Data
group /All_Data/VIIRS-MOD-GEO-TC_All
dataset /All_Data/VIIRS-MOD-GEO-TC_All/Height
dataset /All_Data/VIIRS-MOD-GEO-TC_All/Latitude
dataset /All_Data/VIIRS-MOD-GEO-TC_All/Longitude
...
group /Data_Products
group /Data_Products/VIIRS-MOD-GEO-TC
dataset /Data_Products/VIIRS-MOD-GEO-TC/VIIRS-MOD-GEO-TC_Aggr
dataset /Data_Products/VIIRS-MOD-GEO-TC/VIIRS-MOD-GEO-TC_Gran_0
}
}
I am interested in using the hdf5-rust
crate to read string attributes of both the root group /
, and of the dataset /Data_Products/VIIRS-MOD-GEO-TC/VIIRS-MOD-GEO-TC_Gran_0
. The signature of the dataset attribute is
ATTRIBUTE "N_Granule_ID" {
DATATYPE H5T_STRING {
STRSIZE 16;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
DATASPACE SIMPLE { ( 1, 1 ) / ( 1, 1 ) }
DATA {
(0,0): "NPP002194429582"
}
}
I tried the following...
use anyhow::{Ok, Result};
use hdf5::File;
use ndarray::{Array, Array2};
use hdf5::types::VarLenUnicode;
fn main() -> Result<()> {
filename = "GMTCO_npp_d20181005_t2022358_e2024003_b35959_c20181008035331888329_cspp_dev.h5".to_string();
let file = File::open(filename)?;
let dataset = file.dataset("Data_Products/VIIRS-MOD-GEO-TC/VIIRS-MOD-GEO-TC_Gran_0")?;
let attribute = dataset.attr("N_Granule_ID")?;
let datatype = attribute.dtype()?;
let dims = attribute.ndim();
let v_reader = attribute.as_reader();
let v = v_reader.read::<VarLenUnicode, ndarray::Dim<[usize; 2]>>()?;
Ok(())
}
at which the .read()
method returns Error: no conversion paths found
. I get the same error if I use
let v = attribute.read_2d::<VarLenUnicode>()?
or
let v = attribute.read_2d::<FixedUnicode<16_usize>>()?;
Looking through the hdf5-rust
examples and tests, I haven't been able to find any examples of reading a non-scalar string attribute with anything like a hl interface. There was a previous topic about reading string attributes (Add string attribute using hdf5-rust), but I haven't been able to glean enough information from it to solve my problem, other than it looks like group and dataset attributes need to be handled separately.