MetPy icon indicating copy to clipboard operation
MetPy copied to clipboard

Fix for skewt subroutines ignoring x axis units

Open jibbals opened this issue 6 years ago • 10 comments

Wet and dry adiabats, along with mixing lines, do not correctly plot unless everything is in degrees celcius. This is especially a problem when the plots show the wrong values without giving any sort of warning. This fix makes the subroutines plot onto units matching the xaxis or input temperature. Checklist

Closes #1155 test added

Description Of Changes

Checklist

  • [x] Closes #xxxx
  • [x] Tests added
  • [x] Fully documented

jibbals avatar Oct 24 '19 01:10 jibbals

This follows on from the closed unimplemented pull request #1168

jibbals avatar Oct 24 '19 01:10 jibbals

When I run the pytest --mpl -k test_skewt.py, there is a warning. I don't know what this warning is or if it applies to my changes?

TestWarning

jibbals avatar Oct 29 '19 21:10 jibbals

Let me look locally. Some of the other most recent builds don't show this, so I'm guessing something that's tweaked in this PR is causing it.

dopplershift avatar Oct 29 '19 22:10 dopplershift

Ok, so the error is caused by the fact that we're now doing a little bit of computing, so our this line:

ref_pressure < pressure.max()

ends up returning true, even though both are nominally 1000. Mind if I upload a commit to fix?

dopplershift avatar Oct 30 '19 20:10 dopplershift

Actually, on second thought I'll do a separate PR for that issue, since I'll need some tests for that. We can ignore the warning in your PR.

dopplershift avatar Oct 30 '19 20:10 dopplershift

You should be able to add the blank line and do:

git commit —amend
git push —force

dopplershift avatar Oct 31 '19 00:10 dopplershift

As far as the other tests, I can take a look and see what’s going on.

dopplershift avatar Oct 31 '19 00:10 dopplershift

Thanks @dopplershift.

jibbals avatar Oct 31 '19 00:10 jibbals

@jibbals Apologies on this languishing for so long. I took the liberty of rebasing this on current main and making sure everything works with how the code is now structured. I'm expecting this to pass now.

Regarding the warnings from lsoda, I've figured them out completely, it's pretty dumb. Essentially:

units.Quantity(1000., 'mbar') - units.Quantity(1000., 'hPa')

gives -2.2737367544323206e-13 millibar rather than 0 thanks to the wonder that is floating point arithmetic.

dopplershift avatar Dec 03 '21 20:12 dopplershift

So with cf734e38 deciding default units for the xaxis, and underlying calculations (e.g. dry_lapse) having unit handling since, the original behavior in #1155 no longer happens, and these tests (with units specified, even if mixed) pass as-is on 1.1 and on current main. Passing un-united arrays as t0 to e.g. plot_dry_adiabats does currently fail with a unit error per the underlying calculation. I'm fine with that. As far as I can tell, the only thing we gain here right now is the hidden t > 150 assumption, which does avoid unit errors, but (imo) incorrectly so. We do need some of this more flexible axis unit handling in the future, so let's leave this open but punt for now. Thanks all!

dcamron avatar Jan 21 '22 22:01 dcamron