如何将 hdf 中的网格化卫星条带数据转换为 NASA GPM 卫星可用的 netcdf4?

How to convert gridded satellite swath data in hdf to netcdf4 which is available from the NASA GPM satellite?

我正在尝试从 https://disc.gsfc.nasa.gov/datasets?keywords=LATENT%20HEATING&page=1 访问 hdf 中可用的网格化卫星条带数据 您可以看到我正在尝试使用的任何 3 级数据。熟悉ferret等netcdf可视化库,cdo、nco等netcdf操作软件。我想将此条带网格化数据转换为 netcdf,以便使用 cdo 和 nco 进行平滑分析。

我从您共享的 link 下载了文件 3B-ORBIT.GPM.DPRGMI.3GCSHv6-0.20190626-S064516-E081748.030252.V06A.HDF5 并创建了一个采用文件名的程序作为参数并生成一个包含变量 latentHeating、surfacePrecipRate 和 stratiformFraction 的 netcdf 文件。让我澄清一下,这个文件是一个网格化的卫星条带数据。您可能需要做一些其他事情来从像素方向的条带数据中制作网格数据

import h5py
import numpy as np
import datetime as dt
import xarray as xr
import sys

input_file = sys.argv[1]
f = h5py.File(input_file, 'r')

yy = np.max(f['Grid']['GridTime']['Year'][:])
mm = np.max(f['Grid']['GridTime']['Month'][:])
dd = np.max(f['Grid']['GridTime']['DayOfMonth'][:])

time_ = dt.datetime(yy, mm, dd)
lat = np.linspace(-67+0.25/2,67-0.25/2,536)
lon = np.linspace(-180+0.25/2,180-0.25/2,1440)
lev = np.arange(0.125,0.125+0.25*80,0.25)

lh = f['Grid']['latentHeating'][:]
spr = f['Grid']['surfacePrecipRate'][:]
stratfrac = f['Grid']['stratiformFraction'][:]
lh[lh==-9999.9] = np.nan
spr[spr==-9999.9] = np.nan
stratfrac[stratfrac==-9999.9] = np.nan

stratfrac = stratfrac.T
spr = spr.T
lh = lh.swapaxes(1,2)
lh = lh[np.newaxis,...]

stratfrac = stratfrac[np.newaxis,...]
spr = spr[np.newaxis,...]

df = xr.Dataset(
        data_vars={'latentHeating':    (('time', 'level', 'latitude', 
'longitude' ), lh),
                   'surfacePrecipRate':    (('time', 'latitude', 
'longitude' ), spr),
                   'stratiformFraction':    (('time', 'latitude', 
'longitude'), stratfrac)},
        coords={ 'time':np.atleast_1d((time_- 
dt.datetime(1,1,1)).days+2),
            'level': lev,
            'longitude': lon,
            'latitude': lat,
        })
df.latentHeating.attrs['long_name'] = 'Latent Heating'
df.surfacePrecipRate.attrs['long_name'] = 'Surface Precipitation Rate'
df.stratiformFraction.attrs['long_name'] = 'Stratiform Fraction'

df.time.attrs['units'] = 'days since 01-01-01 00:00:00'
df.time.attrs['standard_name'] = 'time'
df.time.attrs['long_name'] = 'Year AD'
df.time.attrs['calendar'] = 'standard'

df.longitude.attrs['standard_name'] = 'longitude'
df.longitude.attrs['long_name'] = 'longitude'
df.longitude.attrs['units'] = 'degrees_east'
df.longitude.attrs['axis'] = 'X'

df.latitude.attrs['standard_name'] = 'latitude'
df.latitude.attrs['long_name'] = 'latitude'
df.latitude.attrs['units'] = 'degrees_north'
df.latitude.attrs['axis'] = 'Y'

df.level.attrs['standard_name'] = 'air_pressure'
df.level.attrs['long_name'] = 'pressure_level'
df.level.attrs['units'] = 'km' 
df.level.attrs['axis'] = 'Z'
df.level.attrs['positive'] = 'up'
df.to_netcdf(input_file[:-4]+'nc')

您可以将其保存为 python 文件并将 hdf 文件作为参数传递。

来自此处发布的答案:

最简单的方法是:

nccopy in.h5 out.nc