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

xarray parcel functions #1968

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

traupach
Copy link

Description Of Changes

Here are suggested xarray-enabled implementations of air parcel functions that can be run over 3D data much faster than looping existing functions over 1D profiles. The functions are not yet integrated with the rest of MetPy and notably do not use any Pint quantities. Unit tests are provided but aren't yet integrated properly with the testing framework.

For performance, moist lapse rates are not exactly calculated but rather are approximated using a lookup table. For more information about these functions and their use, including a demonstration in a Jupyter notebook, see xarray_parcel.

Checklist

  • Closes #xxxx
  • Tests added
  • Fully documented

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Timothy Raupach seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jthielen
Copy link
Collaborator

This is an impressive rewrite of the thermodynamic parcel calculations! While I wouldn't foresee this as likely to be included in MetPy as-is (see below discussion), this PR will be a tremendous asset as progress is made on MetPy's parcel calculations for vectorizability and performance improvements. Thank you for putting forward your work here!


While the following points may sound critical, please don't take them as anything against what you've done. Instead, these are just my thoughts on where this implementation (which I assume was built to meet your needs rather than be fully generalized) differs from MetPy's usual philosophy, so as to set the stage for later incorporation of approaches used here into MetPy itself.

  • Here, datasets are often taken as input, with assumed names corresponding to physical variables. Until we have a robust way to identify variables from a dataset, MetPy has been taking the approach of just accepting DataArrays when a particular physical variable is needed, so that the user doesn't have to rename variables to fit naming assumptions. This also makes it easier to handle non-xarray use cases.
  • As you've mentioned, this PR as-is does not fully handle units. While using Pint Quantities internally is not required, assuring unit correctness on input and output (rather than assuming particular units) is a key feature of MetPy.
  • Xarray functionality is used internally throughout the functions here. Since MetPy prioritizes working with both xarray DataArrays and Pint Quantities, MetPy's functions right now typically just work with Quantities internally, with xarray handled in an external wrapper. However, seeing how useful some of xarray's API is for these calculations, it may be worth investigating if a flipped approach (wrapping Quantities in coordinate-less DataArrays) or split internal implementations are worthwhile in some cases.
  • The approximate lookup table for moist_lapse is definitely a novel approach for speeding up these calculations. However, we'd want to maintain the direct formulation (or future evolutions of it) as an option as well for accuracy's sake, so adding such an alternative path would likely require waiting on having the capability for pluggable/alternative calculations.
  • Unless I missed it in my cursory review, this implementation does not handle the various options for when there are multiple EL/LFC candidates (i.e., _multiple_el_lfc_options), which would be important for a release-ready implementation.

@traupach
Copy link
Author

This is an impressive rewrite of the thermodynamic parcel calculations! While I wouldn't foresee this as likely to be included in MetPy as-is (see below discussion), this PR will be a tremendous asset as progress is made on MetPy's parcel calculations for vectorizability and performance improvements. Thank you for putting forward your work here!

Thanks for the kind comments Jon!

While the following points may sound critical, please don't take them as anything against what you've done. Instead, these are just my thoughts on where this implementation (which I assume was built to meet your needs rather than be fully generalized) differs from MetPy's usual philosophy, so as to set the stage for later incorporation of approaches used here into MetPy itself.

Yes exactly, I built this because I needed to calculate some values more quickly and that's why it differs from the usual MetPy philosophy in several areas. It's also why, as you noted, there is no multiple EL/LFC functionality.

You're correct on all the points you raise and I agree that they will need to be addressed before this code could be considered for inclusion in MetPy. I hope that in the meantime it will serve as a useful resource/source of ideas for what an xarray implantation of parcel functions could look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants