-
I am trying to calculate potential vorticity at isentropic level, I am successful in calculating the potential vorticity at pressure level, but as I am trying to interpolate it to isentropic level I am getting the error as : Input In [12] in <cell line: 2>
isent_data = mpcalc.isentropic_interpolation_as_dataset(
File ~/miniconda3/lib/python3.8/site-packages/metpy/calc/thermo.py:2767 in isentropic_interpolation_as_dataset
all_args[0].metpy.vertical,
File ~/miniconda3/lib/python3.8/site-packages/metpy/xarray.py:486 in vertical
return self._axis('vertical')
File ~/miniconda3/lib/python3.8/site-packages/metpy/xarray.py:418 in _axis
raise AttributeError(axis + ' attribute is not available.')
AttributeError: vertical attribute is not available. I am also giving the code which I am using for the calculation: import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import metpy.calc as mpcalc
from metpy.units import units
import numpy as np
import xarray as xr
#############################
data1 = xr.open_dataset("/mnt/h/MPAS/HICS/VAR/ERA/AMPHAN/AMPHAN.uzonal.nc").metpy.parse_cf()
data2 = xr.open_dataset("/mnt/h/MPAS/HICS/VAR/ERA/AMPHAN/AMPHAN.umeridional.nc").metpy.parse_cf()
data3 = xr.open_dataset("/mnt/h/MPAS/HICS/VAR/ERA/AMPHAN/AMPHAN.temperature.nc").metpy.parse_cf()
data1 = data1.metpy.parse_cf('u',
coordinates={'T': 'time', 'Z': 'level',
'Y': 'lat', 'X': 'lon'})
data2 = data2.metpy.parse_cf('v',
coordinates={'T': 'time', 'Z': 'level',
'Y': 'lat', 'X': 'lon'})
data3 = data3.metpy.parse_cf('atmp',
coordinates={'T': 'time', 'Z': 'level',
'Y': 'lat', 'X': 'lon'})
############################################
lats = data1.lat.values
lons = data1.lon.values
#########################################
pres = data1['level'].values[:] * units('Pa')
##########################################
tmpk_var = data3.isel(time=10).squeeze()
tmpk = mpcalc.smooth_n_point(tmpk_var, 9, 2)
thta = mpcalc.potential_temperature(pres[:, None, None], tmpk)
############################################
uwnd_var = data1.isel(time=10).squeeze()
vwnd_var = data2.isel(time=10).squeeze()
uwnd = mpcalc.smooth_n_point(uwnd_var, 9, 2)
vwnd = mpcalc.smooth_n_point(vwnd_var, 9, 2)
######Compute dx and dy spacing for use in vorticity calculation################
dx, dy = mpcalc.lat_lon_grid_deltas(lons, lats)
###############Comput the PV on all isobaric surfaces##################
pv = mpcalc.potential_vorticity_baroclinic(thta, pres[:, None, None], uwnd, vwnd,
dx[None, :, :], dy[None, :, :],
lats[None, :, None] * units('degrees'))
isentlevs = [320.] * units.kelvin
isent_data = mpcalc.isentropic_interpolation_as_dataset(
isentlevs,
tmpk,
pv,
) |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
That error indicates that MetPy's xarray machinery isn't able to discern what the vertical coordinate/dimension is from the available metadata on the input data. I don't have access to the data, so I'm not sure what that problem is exactly. Could you share the output of A work-around is to skip the xarray-aware isentropical inteprolation and just use |
Beta Was this translation helpful? Give feedback.
-
Thanks for the solution. Let me try, and I see. Also, I have posted below
the output of `print(data1.level)`:
```
<xarray.DataArray 'level' (level: 6)>
array([200, 250, 500, 700, 850, 925])
Coordinates:
* level (level) int64 200 250 500 700 850 925
metpy_crs object Projection: latitude_longitude
Attributes:
_metpy_axis: Z
```
…On Mon, Aug 21, 2023 at 3:20 AM Ryan May ***@***.***> wrote:
That error indicates that MetPy's xarray machinery isn't able to discern
what the vertical coordinate/dimension is from the available metadata on
the input data. I don't have access to the data, so I'm not sure what that
problem is exactly. Could you share the output of print(data1.level)?
A work-around is to skip the xarray-aware isentropical inteprolation and
just use isentropic_interpolation
<https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.isentropic_interpolation.html>
directly.
—
Reply to this email directly, view it on GitHub
<#3160 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASYYLPK65S3VVJMBXLKR6VLXWKBCLANCNFSM6AAAAAA3XIFD5Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
tmpk is 4 dimensional having dimensions time x level x lat x lon
(49,6,300,350)
…On Tue, 22 Aug, 2023, 5:11 am Ryan May, ***@***.***> wrote:
What about print(tmpk)?
—
Reply to this email directly, view it on GitHub
<#3160 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASYYLPPTYG5V4ZSMVFUSHJTXWPW3TANCNFSM6AAAAAA3XIFD5Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Data. Please go to this link for the data. |
Beta Was this translation helpful? Give feedback.
-
Hi! The core of the issue is that your vertical coordinate (here You were on the right track by specifying import xarray as xr
import metpy.calc as mpcalc
from metpy.units import units
air_temp = xr.open_dataarray("AMPHAN.air_temp.nc")
potential_vorticity = xr.open_dataarray("AMPHAN.pot_vort.nc")
air_temp.metpy.assign_coordinates({"vertical": "lev"})
air_temp["lev"].attrs["units"] = "hPa"
potential_vorticity.metpy.assign_coordinates({"vertical": "lev"})
potential_vorticity["lev"].attrs["units"] = "hPa"
isentlevs = [320.] * units.kelvin
mpcalc.isentropic_interpolation_as_dataset(isentlevs, d1, d2) |
Beta Was this translation helpful? Give feedback.
-
Yes, the solution worked. Thanks
*Debashis Paul*
|
Beta Was this translation helpful? Give feedback.
Hi! The core of the issue is that your vertical coordinate (here
lev
andlevel
in some of your examples) is not compliant with CF conventions. MetPy tries to understand relevant metadata and even match common names, but we your coordinates are lacking any metadata and we don't currently check for "lev" or "level" (@jthielen should we?).You were on the right track by specifying
parse_cf(coordinates = {'Z': 'level'})
in your earlier example, but the MetPy internal coordinate identifier is'vertical'
, not'Z'
(an alias we could consider adding.) You are also missing unit information. The following should work with your data with those two fixes: