New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Howto read a non-scalar string attribute using hdf5-rust #274
Comments
Could you try reading as |
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
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 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.The text was updated successfully, but these errors were encountered: