简体   繁体   中英

Plot map using cartopy with hdf5 dataset

I'm curently trying to plot hdf5 files after switching them from hdf4. I got some trouble working out the longitude and latitude variables in the file, both of them have a shape (4224, 3) which I guess correspond to 1: the number of values and 2: the starting/middle/ending granule point of the satellite.

My problem is that my data 'extinction_coefficient_532' have a shape (4224, 399) which do not match with my lon/lat variables. Correct me if I'm wrong but I need to have a data file with shape (value, lon, lat) to be plotting it on a map with cartopy.

Is there a way to adapt the shape of the data to match the lon/lat variables?

f['Longitude'].shape
Out[296]: (4224, 3)

f['Latitude'].shape
Out[297]: (4224, 3)

f['Extinction_Coefficient_532'].shape
Out[298]: (4224, 399)

EDIT:

f['Extinction_Coefficient_532'].dtype
Out[122]: dtype('>f4')

Have a good day, Thomas

HDF5 is simply a data container. The specific schema/data hierarchy depends on the creator. Ideally they provide documentation, or dataset attributes you can use to interpret the data. Without details it is hard to give specific advice.

That said, I found some documentation that mentions Extinction_Coefficient_532 at NASA's website for CALIPSO Data . It describes the format of all 3 datasets mentioned above. Brief description provided here:

Latitude / Longitude
Geodetic latitude (/longitude), in degrees, of the laser footprint. For the 5 km profile products, three values are reported:

  • Footprint latitude (/longitude) for the first pulse included in the 15 shot average
  • Footprint latitude (/longitude) at the temporal midpoint (ie, at the 8th of 15 consecutive laser shots)
  • Footprint latitude (/longitude) for the final pulse.

Extinction Coefficient 532
Particulate extinction coefficients reported for each profile range bin in which the appropriate particulates (ie, clouds or aerosols) were detected; those range bins in which no particulates were detected contain fill values (-9999)

Based on this, I conclude that you have 4224 longitude and latitude locations and matching extinction coefficients. If this is correct, follow the example on this page to extract the data to create your plot: More advanced mapping with cartopy and matplotlib

It will look something like this:

import h5py
with h5py.File('yourfilename.h5','r') as h5f:
# first extract the plot data:
# 1) Latitude, 2) Longitude and 3) Extinction Coefficient           
    pulse = 0  ## to select a particular pulse, valid range 0-2
    lats = h5f['Latitude'][:,pulse]
    lons = h5f['Longitude'][:,pulse]
    bin_no = 0 ## to plot a particular profile bin, valid range 0-398
    coef = h5f['Extinction_Coefficient_532'][:, bin_no]

# lines below reference plot data extracted above
# May need to be modified to generate the plot type you want.     
    ax = plt.axes(projection=ccrs.PlateCarree())   
    plt.contourf(lons, lats, coef, 60, transform=ccrs.PlateCarree())    
    ax.coastlines()    
    plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM