Reputation: 1
I'm new to h5py and my actual task is to create a hdf5-stack with MODIS subsets. I can create the stack with all the nice data in it but I'm not able to create or attach a spatial reference system. Goal is to load single datasets from the stack into a viewer like in ArcGIS and it should be placed at its right position.
How do I give the stack the right spatial/projection information?
Upvotes: 0
Views: 987
Reputation: 5471
You can attach spatial coordinates to an HDF5 dataset with dimension scales - these are simply other datasets that are associated with your first dataset. If you want to indicate that a particular dimension has certain physical units you can label the dimension, which is done using the HDF5 dimension scale API: H5DSset_label()
.
Dimension scales are possible in h5py, using h5py.dims.create_scale()
and h5py.dims.attach_scale()
, and h5py.dims.label
to set the label.
For example, to attach two datasets to foo.h5:/data
to specify the latitude and longitude, and that they are in degrees, you can first set their labels as follows (with f being the HDF5 file):
f['data'].dims[0].label = 'degrees'
f['data'].dims[1].label = 'degrees'
Then to actually add the coordinates, you first need to create a scale, then attach the dataset (where f['phi']
is a pre-existing dataset with your coordinates in):
f['data'].dims.create_scale(f['phi'], 'latitude')
f['data'].dims[1].attach_scale(f['phi'])
You can then access the labels with
[dim.label for dim in f['data'].dims]
and the dimension scales themselves with
f['data'].dims[1][0]
or
f['data'].dims[1]['latitude']
Upvotes: 1