Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mean_pressure_weighted unit behavior #1635

Closed
jrleeman opened this issue Dec 27, 2020 · 1 comment · Fixed by #1639
Closed

mean_pressure_weighted unit behavior #1635

jrleeman opened this issue Dec 27, 2020 · 1 comment · Fixed by #1639
Labels
Type: Bug Something is not working like it should
Milestone

Comments

@jrleeman
Copy link
Contributor

This would product an expected value of around 19 degrees, but there appears to be a unit issue.

mpcalc.mean_pressure_weighted([1000, 900, 800] * units.hPa,
                              [20, 18, 16] * units.degC,
                              height=[10, 1000, 2000] * units.meters)

produces 292.2026315789474 <Unit('degree_Celsius')>

Now if we try

mpcalc.mean_pressure_weighted([1000, 900, 800] * units.hPa,
                              [20, 18, 16] * units.kelvin,
                              height=[10, 1000, 2000] * units.meters)

produces 19.05263157894737 <Unit('kelvin')>

so it appears that for temperatures this is potentially broken as inappropriate units are being reattached after the calculation is done correctly in base units.

@jrleeman jrleeman added the Type: Bug Something is not working like it should label Dec 27, 2020
@kgoebber
Copy link
Collaborator

kgoebber commented Dec 28, 2020

Doing a bit of testing, this appears to be an issue with the use of temperature units. If you substitute in different units (e.g., m/s) then you get the expected result. Due to differences being taken in the process, that is likely where something is going awry. What is coming out is the average value in Kelvin (likely getting to Kelvin somewhere in the process to get to a base unit), but then just attaching the original units to this.

It appears that the trapz function accepts units at this point and removing the magnitude calls in the function yields the following results:

mpcalc.mean_pressure_weighted([1000, 900, 800] * units.hPa,
                              [20, 18, 16] * units.degC,
                              height=[10, 1000, 2000] * units.meters)

produces 292.2026315789474 <Unit('kelvin')>

Whether we wish have the result return the original units can be open to discussion, although with this current behavior it would act similarly to the parcel_profile function to return the temperatures in Kelvin. An initial PR fixing this issue will be submitted shortly.

@kgoebber kgoebber mentioned this issue Dec 28, 2020
3 tasks
@dopplershift dopplershift added this to the 1.0.1 milestone Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants