Closed gpcureton closed 6 months ago
Could you try reading as FixedAscii<16>
instead of VarLenUnicode
?
Thanks for your reply @mulimoen. For the root group attribute
let root_attr = file.attr("Mission_Name")?;
I tried
let v_reader = root_attr.as_reader();
let v = v_reader.read::<FixedAscii<4>, ndarray::Dim<[usize; 2]>>()?;
println!("\tv = {:?}", v);
and
let v = root_attr.read_2d::<FixedAscii<4>>()?;
println!("\tv = {:?}", v);
and they both gave the result
v = [["NPP"]], shape=[1, 1], strides=[1, 1], layout=CFcf (0xf), const ndim=2
and I got to the attribute payload with
if let Some(x) = v.first() {
print!("\tx = {:?}", x.to_string());
}
which is what I was after. Luckily the attributes I am interested in have fixed sizes which I know ahead of time. I'm going to check a string attribute which is a "vector" of strings, and then close this issue.
I was also able to read in a "vector" string attribute (something like a list of filenames). The filenames are of differing sizes, but as long as the argument to FixedAscii<>
is equal or greater than the longest filename, it works...
println!("\n\nReading dataset (15, 1) attribute...\n");
let dset_attr = dataset.attr("N_Anc_Filename")?;
let v = dset_attr.read_2d::<FixedAscii<104>>()?;
println!("\tv = {:?}", v);
println!("\tv.shape() = {:?}", v.shape());
println!("\tv.strides() = {:?}", v.strides());
println!("\tv.ndim() = {:?}", v.ndim());
let arr = v.iter().collect::<Vec<_>>();
let _ = arr
.iter()
.enumerate()
.map(|(idx, val)| {
println!("\tarr[{:?}] = {:?}", idx, val);
})
.collect::<Vec<_>>();
for (idx, val) in arr.iter().enumerate() {
println!("\tarr[{:?}] = {:?} ({:?})", idx, val.to_string(), val.len());
}
This basically covers the most complicated use case for the files I am reading, so I'm closing this issue. Thanks again for your tip, @mulimoen !
I've got a HDF5 file with the following structure (viewed with
h5dump
):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 isI tried the following...
at which the
.read()
method returnsError: no conversion paths found
. I get the same error if I useor
In each of these cases the variable
v
has the typeArrayBase<OwnedRepr<VarLenUnicode>, Dim<[usize; 2]>>
.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, and I suspect the stumbling block is that the attributeDATASPACE
is for something like an array rather than a scalar.