1
$\begingroup$

I want to extract relative humidity at a specific pressure level (850 hPa) using metpy. Earlier, I tried with wrf-python function 'wrf.interplevel' and it worked successfully. But, I was getting some NaN values over high mountains like over the Himalaya region. Therefore, it is difficult to compare between the ERA-5 reanalysis data and model output as values are present over the high mountains in case of ERA-5 data.Therefore, I tried another approach using metpy function metpy.interpolate.interpolate_to_isosurface for the inetrpolation of relative humidity data at 850 hPa level.

But, I am getting the follwoing error: IndexError: Unlabeled multi-dimensional array cannot be used for indexing: bottom_top

For your convenience, my python code is given in the following:

from netCDF4 import Dataset
import xarray as xr
import numpy as np
from wrf import (getvar, interplevel, interpz3d, vertcross, 
                 CoordPair, ALL_TIMES, to_np,
                 get_cartopy, latlon_coords,
                 cartopy_xlim, cartopy_ylim)
import metpy.calc as mpcalc
from metpy.interpolate import interpolate_to_isosurface
from metpy.units import units    
input_path = "wrfout_d02_2017-10-26_00_00_00"
output_path = "/data/RelativeHumidity850hPa_d02.nc"
ncfile = Dataset(input_path, 'r')
ds = xr.open_dataset(input_path)
lat = np.nanmean(ds.XLAT, axis=(0, 2))
lon = np.nanmean(ds.XLONG, axis=(0, 1))
time_var = ncfile.variables['XTIME']
new_t = time_var[72:]
p = getvar(ncfile, "pressure")
l = np.nanmean(p,axis=(1,2))
p_da = xr.DataArray(p, dims=('bottom_top', 'south_north',     'west_east'),coords=[('level', l), ('lat', lat), ('lon', lon)])
p_da=p_da * units.hPa
rh = getvar(ncfile, "rh", timeidx=0)
rh = rh * units.percent
rh_da = xr.DataArray(rh, dims=('bottom_top', 'south_north', 'west_east'),coords=[('level', l), ('lat', lat), ('lon', lon)])
target_level = 850.0
target_level_hpa = target_level * units.hPa
rh_850 = interpolate_to_isosurface(p_da, rh_da, target_level_hpa)

Can anyone please help me to solve the error? That will be very helpful for me. Thank you for your time. With regards, Ankan

$\endgroup$
1
  • $\begingroup$ Maybe better off by opening an issue on MetPy or on the gitter channel $\endgroup$ Commented Sep 23, 2023 at 8:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.