4

I have a HDF5 file with a field of radar observations. I'd like to read this data and produce a GeoTiff that contains the spatial metadata. I can access the data, but I can't access the geographical metadata (which I assume it must be inside the file).

The file is one of these that can be freely downloaded here.

The code I have is:

import h5py
filename = 'RAD_NL25_PCP_NA_202103111340.h5'
f = h5py.File(filename, 'r')

data = f['image1']['image_data'][:,:]

This works to get a numpy array with the data. Now, the metadata seems to be in the group f['geographic']['map_projection'] but this seems to be an empty without dataset.

Do you know how to inspect this file to get the metadata, or how to assert that it is really an empty group?

5

f['geographic']['map_projection'] is a group. It returns this: <HDF5 group "/geographic/map_projection" (0 members)>. 0 members means it is really an empty group.

But a group has attributes. You can get atrributes using attrs which gives you an AttributeManager object. It has items() method.

To get map_projection info, use this:

proj_info = dict(f['geographic']['map_projection'].attrs.items())
print(proj_info)

Output:

{'projection_indication': b'Y',
 'projection_name': b'STEREOGRAPHIC',
 'projection_proj4_params': b'+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.14 +b=6356.75 +x_0=0 y_0=0'}

You can use the script in this post to see all structure of the h5 file, then use attrs.items() for other groups/datasets to get other metadata.

For example: dict(f['geographic'].attrs.items()) returns

{'geo_column_offset': array([0.], dtype=float32),
 'geo_dim_pixel': b'KM,KM',
 'geo_number_columns': array([700], dtype=int32),
 'geo_number_rows': array([765], dtype=int32),
 'geo_par_pixel': b'X,Y',
 'geo_pixel_def': b'LU',
 'geo_pixel_size_x': array([1.0000035], dtype=float32),
 'geo_pixel_size_y': array([-1.0000048], dtype=float32),
 'geo_product_corners': array([ 0., 49.362064, 0., 55.973602, 10.856453, 55.388973, 9.0093, 48.8953 ], dtype=float32),
 'geo_row_offset': array([3649.982], dtype=float32)}

I used RAD_NL25_PCP_NA_201910281110.h5 file for testing.

2
  • Thanks. One side question... this is not sufficient to know the coordinates, right? The affine transformation has to be known yet
    – Onturenio
    Mar 12 at 18:48
  • @Onturenio dict(f['geographic'].attrs.items()) gives some other metadata. I've added additional information. Mar 12 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.