Help with Skew-t plots that require units in variables #2279
Replies: 13 comments 16 replies
-
Per the error message:
I think you need to add units to Pressure, TempC, and Td before using them in the call to
Please make sure the units I added are actually the units you're using. |
Beta Was this translation helpful? Give feedback.
-
Dan:
Thanks, but the error message is the same after adding the units as you
prescribed.
I inserted the following into each variable:
TempC = units.Quantity(TempC, "degC")
Td = units.Quantity(Td,"degC")
Pressure = units.Quantity(Pressure,"hectopascals")
with the following error:
TypeError Traceback (most recent call
last)~\AppData\Local\Temp\11/ipykernel_14660/4184182665.py in <module>
23 24 # COnvert parameters into units---> 25 TempC =
units.Quantity(TempC, "degC") 26 Td = units.Quantity(Td,"degC")
27 Pressure = units.Quantity(Pressure,"hectopascals")
~\Anaconda3\lib\site-packages\pint\quantity.py in __new__(cls, value,
units) 255 def __new__(cls, value, units=None): 256
if is_upcast_type(type(value)):--> 257 raise
TypeError(f"Quantity cannot wrap upcast type {type(value)}") 258
259 if units is None and isinstance(value, str) and value ==
"":
TypeError: Quantity cannot wrap upcast type <class 'pandas.core.series.Series'>
Should I assign the units into the variables before I read them in?
Arunas
Arunas Kuciauskas
***@***.***
831-261-4342
…On Thu, Dec 30, 2021 at 7:09 AM Dan Adriaansen ***@***.***> wrote:
Per the error message:
Any variable x can be assigned a unit as follows:
from metpy.units import units
x = units.Quantity(x, "m/s")
I think you need to add units to Pressure, TempC, and Td before using them
in the call to parcel_profile(). You can do this in various places in the
code, but something like:
from metpy.units import units
TempC = units.Quantity(TempC,"degC")
Td = units.Quantity(Td,"degC")
Pressure = units.Quantity(Pressure,"hectopascals")
parcel_path = mpcalc.parcel_profile(Pressure, TempC[0], Td[0])
Please make sure the units I added are actually the units you're using.
—
Reply to this email directly, view it on GitHub
<#2279 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQL3QFPSKNRPV24GLRXF43TUTRY23ANCNFSM5K7BY3JQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Dan:
Sorry that it took me so long to respond, I was ill.
Using your approach above, please see below for the code and subsequent
errors.
I can't find a way in working on variables with units.
Thanks,
Arunas
BTW: I'm new at this...If there's a more efficient way of presenting my
issue, please let me know.
```python
# I couldn't perform an df.column name assignment, e.g., Lat = df['Lat'],
so I applied indexing for each column
Hgt = df.iloc[:,1]
# Pressure = df.iloc[:,2]*units('hPa')
Pressure = df.iloc[:,2]*units.hectopascal
TempC = df.iloc[:,3]*units.celsius
RH = df.iloc[:,4]*units.percent
Lat = df.iloc[:,7]*units.degree_north
Lon = df.iloc[:,8]*units.degrees_E
# Calculate dew pt temp
Td = TempC - ((100-RH/5.))
wnd_dir = df.iloc[:,5]*units('degree')
wnd_spd = df.iloc[:,6]*units('knots')
rad = 4.0*np.arctan(1)/180.
u_new = -wnd_spd*np.sin(rad*wnd_dir)
v_new = -wnd_spd*np.cos(rad*wnd_dir)
# Convert parameters into units
Pressure = units.Quantity(Pressure.to_numpy(),"hectopascals")
TempC = units.Quantity(TempC.to_numpy(),"degC")
Td = units.Quantity(Td.to_numpy(),"degC")
print('Press, TempC, Td:', Pressure.dtype, TempC.dtype, Td.dtype)
Press, TempC, Td: float64 float64 float64
# Change default to be better for skew-T
fig = plt.figure(figsize=(9, 11))
# Initiate the skew-T plot type from MetPy class loaded earlier
skew = SkewT(fig, rotation=45)
# Plot the data using normal plotting functions, in this case using
# log scaling in Y, as dictated by the typical meteorological plot
skew.plot(Pressure, TempC, 'r')
skew.plot(Pressure, Td, 'g')
# Set some appropriate axes limits for x and y
skew.ax.set_xlim(-30, 40)
skew.ax.set_ylim(1020, 100)
print(Pressure)
# mask = Pressure * hectopascal >= 100
mask = Presssure * hectopascal
# Add the relevant special lines to plot throughout the figure
skew.plot_dry_adiabats(t0=np.arange(233, 533, 10) * units.K,
alpha=0.25, color='orangered')
skew.plot_moist_adiabats(t0=np.arange(233, 400, 5) * units.K,
alpha=0.25, color='tab:green')
skew.plot_barbs(Pressure[mask][::75], u_new[mask][::75], v_new[mask][::75])
# skew.plot_mixing_lines(Pressure=np.arange(1000, 99, -20) * units.hPa,
# linestyle='dotted', color='tab:blue')
# Add some descriptive titles
SHIP = 'Ron Brown: ', Lat[1], Lon[1]
month=int(month)
day = int(day)
year = int(year)
dtg = month,'/',day,'/',year
table = str.maketrans(dict.fromkeys("()"))
# dtg.translate(table)
plt.title(format(SHIP), loc='left')
plt.title(format(dtg), loc='right')
plt.xlabel('Temperature (C)')
plt.ylabel('Pressure hPa')
plt.show()
```
`[1024.3 1022.4 1022.2 ... 98.2 98.1 98.1] hectopascal`
```pytb
NameError Traceback (most recent call
last)~\AppData\Local\Temp\12/ipykernel_13020/989837325.py in <module>
16 print(Pressure) 17 # mask = Pressure * hectopascal >=
100---> 18 mask = Presssure * hectopascal 19 20 # Add the
relevant special lines to plot throughout the figure
NameError: name 'Presssure' is not defined
```
[image: image.png]
|
Beta Was this translation helpful? Give feedback.
-
Dan:
I fixed the spelling after sending this last code to you. However, I still
get an error message after trying to calculate for 'mask'
Arunas
Code:
print(Pressure)
mask = Pressure * hectopascal >= 100
Error:
[1024.3 1022.4 1022.2 ... 98.2 98.1 98.1] hectopascal
…---------------------------------------------------------------------------NameError
Traceback (most recent call
last)~\AppData\Local\Temp\12/ipykernel_13020/737877772.py in <module>
16 print(Pressure)---> 17 mask = Pressure * hectopascal >= 100
18
NameError: name 'hectopascal' is not defined
Arunas Kuciauskas
***@***.***
831-261-4342
On Mon, Jan 3, 2022 at 4:52 PM Dan Adriaansen ***@***.***> wrote:
You have a typo. Fix the spelling of "pressure" and try again and see if
it works.
—
Reply to this email directly, view it on GitHub
<#2279 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQL3QFMUPEZ7NGSBDO7G473UUJAD5ANCNFSM5K7BY3JQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Dan:
Yes, I tried it without the unit, but I still received an error. I’ll start up again tomorrow morning, thanks
…Sent from my iPhone
On Jan 3, 2022, at 6:03 PM, Dan Adriaansen ***@***.***> wrote:
Since you have already converted Pressure to have the units "hectopascal", you don't need to specify the units again. As you see from printing Pressure:
print(Pressure)
[1024.3 1022.4 1022.2 ... 98.2 98.1 98.1] hectopascal
It already has units of hectopascals. So I think you can just use your original code of:
mask = Pressure >= 100
Try that and see if it works.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
Dan:
Here's the latest that I tried...
I am able to properly plot a Skew-T profile, BUT,
when I try to insert the Pressure, TempC[0] and Td[0]
as in the following lne of code:
parcel_path = mpcalc.parcel_profile(Pressure, TempC[0], Td[0])
it comes back with the below. I need help in trying to provide the Pressure
(with units of hectopascal)
in reverse order.
Any help?
Thanks,
Arunas
…---------------------------------------------------------------------------InvalidSoundingError
Traceback (most recent call
last)~\AppData\Local\Temp\13/ipykernel_11964/2429310348.py in <module>
5 #parcel_path = mpcalc.parcel_profile(Pressure, TempC[0], Td[0])
6 ----> 7 parcel_path = mpcalc.parcel_profile(Pressure, TempC[0],
Td[0])
~\Anaconda3\lib\site-packages\metpy\xarray.py in wrapper(*args,
**kwargs) 1214 1215 # Evaluate inner calculation->
1216 result = func(*bound_args.args, **bound_args.kwargs)
1217 1218 # Wrap output based on match and match_unit
~\Anaconda3\lib\site-packages\metpy\units.py in wrapper(*args,
**kwargs) 244 'that the function is
being called properly.\n') + msg 245 raise
ValueError(msg)--> 246 return func(*args, **kwargs) 247
248 return wrapper
~\Anaconda3\lib\site-packages\metpy\calc\thermo.py in
parcel_profile(pressure, temperature, dewpoint) 742 743
"""--> 744 _, _, _, t_l, _, t_u = _parcel_profile_helper(pressure,
temperature, dewpoint) 745 return concatenate((t_l, t_u))
746
~\Anaconda3\lib\site-packages\metpy\calc\thermo.py in
_parcel_profile_helper(pressure, temperature, dewpoint) 899
Pressure does not decrease monotonically in your sounding. 900
Using scipy.signal.medfilt may fix this."""--> 901 raise
InvalidSoundingError(msg) 902 903 # Find the LCL
InvalidSoundingError:
Pressure does not decrease monotonically in your sounding.
Using scipy.signal.medfilt may fix this.
Arunas Kuciauskas
***@***.***
831-261-4342
On Mon, Jan 3, 2022 at 6:14 PM Dan Adriaansen ***@***.***> wrote:
Sounds good. I will review your code sample closer also and see if I
notice anything else.
—
Reply to this email directly, view it on GitHub
<#2279 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQL3QFKOMZ7NBYNTBXY36A3UUJJYTANCNFSM5K7BY3JQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Dan: can you repeat your message? My Gmail server could not provide me with your content. It might be best to respond to my work email;
***@***.***
Thanks
…Sent from my iPhone
On Jan 3, 2022, at 6:14 PM, Dan Adriaansen ***@***.***> wrote:
Sounds good. I will review your code sample closer also and see if I notice anything else.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
I am able to use your code to compute parcel_path without getting that error. Have you made any other modifications to your code since this reply: ? |
Beta Was this translation helpful? Give feedback.
-
Dan: I’m coming back from a doc visit. Yes, I made a few of what I thought were insignificant changes. I can provide you with my updated code shortly. Thanks
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Dan Adriaansen ***@***.***>
Sent: Tuesday, January 4, 2022 2:25:43 PM
To: Unidata/MetPy ***@***.***>
Cc: arunaskuciauskas ***@***.***>; Author ***@***.***>
Subject: Re: [Unidata/MetPy] Help with Skew-t plots that require units in variables (Discussion #2279)
I am able to use your code to compute parcel_path without getting that error. Have you made any other modifications to your code since this reply:
#2279<#2279> (comment)
?
—
Reply to this email directly, view it on GitHub<#2279 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AQL3QFJXVKH24UAKUBLLRETUUNXWPANCNFSM5K7BY3JQ>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Dan:
I attached the code. But just to convince you my problem area:
parcel_path = mpcalc.parcel_profile(Pressure, TempC[0], Td[0])
error:
…---------------------------------------------------------------------------InvalidSoundingError
Traceback (most recent call
last)~\AppData\Local\Temp\13/ipykernel_11964/3710001079.py in <module>
1 print(P, T1, dewpt)----> 2 parcel_path =
mpcalc.parcel_profile(Pressure, TempC[0], Td[0])
~\Anaconda3\lib\site-packages\metpy\xarray.py in wrapper(*args,
**kwargs) 1214 1215 # Evaluate inner calculation->
1216 result = func(*bound_args.args, **bound_args.kwargs)
1217 1218 # Wrap output based on match and match_unit
~\Anaconda3\lib\site-packages\metpy\units.py in wrapper(*args,
**kwargs) 244 'that the function is
being called properly.\n') + msg 245 raise
ValueError(msg)--> 246 return func(*args, **kwargs) 247
248 return wrapper
~\Anaconda3\lib\site-packages\metpy\calc\thermo.py in
parcel_profile(pressure, temperature, dewpoint) 742 743
"""--> 744 _, _, _, t_l, _, t_u = _parcel_profile_helper(pressure,
temperature, dewpoint) 745 return concatenate((t_l, t_u))
746
~\Anaconda3\lib\site-packages\metpy\calc\thermo.py in
_parcel_profile_helper(pressure, temperature, dewpoint) 899
Pressure does not decrease monotonically in your sounding. 900
Using scipy.signal.medfilt may fix this."""--> 901 raise
InvalidSoundingError(msg) 902 903 # Find the LCL
InvalidSoundingError:
Pressure does not decrease monotonically in your sounding.
Using scipy.signal.medfilt may fix this.
Arunas Kuciauskas
***@***.***
831-261-4342
On Tue, Jan 4, 2022 at 2:28 PM Arunas Kuciauskas ***@***.***> wrote:
Dan: I’m coming back from a doc visit. Yes, I made a few of what I thought
were insignificant changes. I can provide you with my updated code shortly.
Thanks
Get Outlook for iOS <https://aka.ms/o0ukef>
------------------------------
*From:* Dan Adriaansen ***@***.***>
*Sent:* Tuesday, January 4, 2022 2:25:43 PM
*To:* Unidata/MetPy ***@***.***>
*Cc:* arunaskuciauskas ***@***.***>; Author <
***@***.***>
*Subject:* Re: [Unidata/MetPy] Help with Skew-t plots that require units
in variables (Discussion #2279)
I am able to use your code to compute parcel_path without getting that
error. Have you made any other modifications to your code since this reply:
#2279 <#2279> (comment)
?
—
Reply to this email directly, view it on GitHub
<#2279 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQL3QFJXVKH24UAKUBLLRETUUNXWPANCNFSM5K7BY3JQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Ryan:
Do you suggest that I provide the entire code in my email back to Dan. I’m still learning the ropes…sorry
|
Beta Was this translation helpful? Give feedback.
-
Ryan:
Thanks, I'm still not sure where (link) in github (MetPy) that I should go
to, i.e., Is there a particular protocol in doing back and forth messaging?
Thanks,
Arunas
Arunas Kuciauskas
***@***.***
831-261-4342
…On Tue, Jan 4, 2022 at 4:11 PM Ryan May ***@***.***> wrote:
My suggestion would be if you're going to use email, don't use the github
emails that are being used right now when you reply in your email
client--you'll need to exchange your proper email addresses.
If you're going to use GitHub, don't reply to emails, but use the GitHub
web interface so you can properly format your code
<https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks>
to make it much easier to read. GitHub has the bare minimum support that's
good for quick replies, but isn't good for sharing things.
—
Reply to this email directly, view it on GitHub
<#2279 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQL3QFJJ7A2LX37F2FK5XGDUUOEEBANCNFSM5K7BY3JQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your responses. I’ll work on it later today. Currently, I’m moving out of my old place.
Arunas
…Sent from my iPhone
On Jan 5, 2022, at 9:47 AM, Ryan May ***@***.***> wrote:
Thanks for digging in @DanielAdriaansen. I'll note that the next release of MetPy will relax the monotonic requirement to also allow adjacent points to be equal. I'll note that for most data, points don't actually have equal points, but this is merely an artifact of rounding to 1 decimal place.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
HI:
I am working on developing a Skew-T plot where I want to include shading for CINH and CAPE. Using your MetPy Mondays #19 session, I am trying to calculate parcel_path:
parcel_path = mpcalc.parcel_profile(Pressure, TempC[0], Td[0])
At the bottom of this discussion is the error message that I receive, asking for units that I are not there. How do I provide the proper parameters for the parcel_path calculation? Thanks...
The attachment shows my progress. I am also working off of a Sounding file that is also attached.
WTEC_20190325_042301_edt.txt
Beta Was this translation helpful? Give feedback.
All reactions