[Nexus] 2D character arrays in python binding?
Mark Könnecke
mark.koennecke at psi.ch
Thu Jan 29 12:07:06 GMT 2009
Dear Carlos,
Am Mittwoch, den 28.01.2009, 11:16 +0100 schrieb Carlos Pascual Izarra:
> Hello,
> After reading the lists and the python binding source code I am still not
> sure: is it possible to write 2D character arrays with the python binding?
> (other than manually converting the array to "uint8" and back when reading)
>
> I've tried doing:
>
> {{{
> filenames=['bar1','longerbar2','bar3']
> ...
> f.makedata('filenames','char',[3,32])
> f.opendata('filenames')
> f.putdata(filenames)
> ...
> }}}
>
> but I get:
> {{{
> ValueError: Expected character data: foo.h5(entry/data/filenames)
> }}}
>
>
> I also tried putting the data row by row with putslab, replacing the putdata
> line with:
> {{{
> for i in range(3): f.putslab(filenames[i],[i,0],[1,32])
> }}}
>
> In which case it does not raise an exception, but:
> a) it stores the data using dtype=uint8
> b) It stores garbage from contiguous memory (i.e. it does not pad the strings
> to fill the given shape)
>
> Cheers,
>
2D character arrays are still not properly supported in the NeXus-API in
general and consequently not in the python API either. There are some
difficulties in doing that, especially in the XML-API. In HDF-4 we have
the problem that we cannot rugged shaped arrays, so we would have to
fill in the blank space sensibly.
Besides the workaround to use unit8, is to use an own separator between
entries, like newline, and store the whole lot as a long string. Which
you may append too if the string is of unlimted dimensions.
If those workarounds are a problem for you, please speak up. We might
think harder on this and be able to find a solution for the NeXus-API
release.
Best Regards
Mark Koennecke
> Carlos Pascual
>
> _______________________________________________
> NeXus mailing list
> NeXus at nexusformat.org
> http://lists.nexusformat.org/mailman/listinfo/nexus
More information about the NeXus
mailing list