[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[python #WVN-314336]: Question about QG omega example
- Subject: [python #WVN-314336]: Question about QG omega example
- Date: Thu, 30 Mar 2023 13:52:00 -0600
Hello, and thanks for reaching out!
This particular example is out of date with MetPy's progress on xarray
integration. Those particular lines can be fixed by using the `.metpy`
"accessor" to get to similar helpful methods specifically for xarray Datasets
and DataArrays, for example
...
tmpk_700s = mpcalc.smooth_n_point(tmpk_700, 9, n_reps)
# note that tmpk_700s is an xarray DataArray
tmpk_700s.metpy.convert_units('degC')
...
Check out the xarray tutorial and reference guides in our documentation for
more syntax help here
https://unidata.github.io/MetPy/latest/tutorials/xarray_tutorial.html
https://unidata.github.io/MetPy/latest/api/generated/metpy.xarray.html
Similarly, some of our functions on display in this example have out-of-date
signatures now, particularly kinematic calculations like vorticity and
advection. If you're working with well-described xarray data (has appropriate
metadata and projection information; most of the data from Siphon will try to
meet this criteria), these calculations look much simpler now:
...
vortadv_900 = mpcalc.advection(avor_900, uwnd_900s,
vwnd_900s).metpy.convert_to_base_units()
# note the simpler inputs to the function (scalar, u, v)
# and the similar change to use our `.metpy` accessor.
...
Please double-check the inputs to these functions with the python
`help(mpcalc.advection)` function or in our documentation:
https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.advection.html
These examples in our gallery will be fixed later this Spring. In the mean
time, if you run into strange errors be sure to double-check our documentation!
I hope this helps, and don't hesitate to follow up if I can help any further.
All the best,
Drew
> I have managed to
> integrate MetPy into my class this semester, thanks to all of you I would
> really like to implement the QG Omega Analysis (below) into my class, but I
> am running into two main issues.
>
> https://unidata.github.io/python-training/workshop/MetPy_Advanced/qg-analysis/
>
> *Issue #1: MetPy does not seem to like the following unit conversion in
> the code*
>
> tmpk_700s = mpcalc.smooth_n_point(tmpk_700, 9,
> n_reps)#.metpy.unit_arraytmpc_700s = tmpk_700s.to('degC') <<======
>
> AttributeError: 'DataArray' object has no attribute 'to'
>
>
> *Issue #2: MetPy does not seem to like the following unit conversion*
>
> vortadv_900 = mpcalc.advection(avor_900, (uwnd_900s, vwnd_900s), (dx,
> dy)).to_base_units()
>
> ValueError: setting an array element with a sequence. The requested
> array has an inhomogeneous shape after 1 dimensions. The detected
> shape was (2,) + inhomogeneous part.
>
>
> I tried looking through the various Unidate/GitHub search engines, but
> did not find any comments or questions about these issues.
>
Ticket Details
===================
Ticket ID: WVN-314336
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata
inquiry tracking system and then made publicly available through the web. If
you do not want to have your interactions made available in this way, you must
let us know in each email you send to us.