Working on Cross Sections in MetPy with xarray

Jon Thielen
Jon Thielen

During this past summer at Unidata, I worked primarily on MetPy by implementing cross section functionality and improving xarray integration. The ability to work with cross sections in MetPy has been frequently requested by users, and it was one of the major features present in GEMPAK but still missing from MetPy. Also, since MetPy is moving towards having xarray DataArrays and Datasets as its primary data structures, the development team thought it best to implement the new cross section interpolation and supporting calculations using xarray.

TDS Catalog
Cross section plot (click to enlarge)

And so, one of my first major tasks of the summer was preparing for the cross section implementation by refactoring the existing gridding/interpolation in MetPy. This allowed for the interpolation functionality already in place for gridding irregularly-spaced data to exist alongside other interpolation functions such as vertical interpolation and cross sections. Another prerequisite task was extending our xarray enhancements to include systematic coordinate identification. While xarray itself provides useful features for selecting data along named dimensions and utilizing coordinate metadata, it is not able to identify which dimension coordinate belongs to which spatiotemporal coordinate type (such as vertical or time). By parsing the coordinate attributes according to the the recommended and optional criteria of the Climate and Forecast (CF) conventions (and a few regular expressions for backup), we are now able to identify the spatiotemporal coordinates that exist in a dataset, which makes it easy to apply operations in a specific direction.

TDS Catalog
Xarray tutorial in the MetPy documentation
(click to enlarge)

Once these details were in place, we were actually able to include the cross section functionality. The interpolation itself takes place in a function that takes the data and an arbitrary path, to allow flexibility for users who need it, but is also wrapped by a function that takes the data and start and end points, to provide a simple interface as well. The calculations relating to cross sections (such as tangential and normal components of a vector field) utilize the coordinate information attached to the data to simply the interface as well.

This new functionality, along with examples and documentation, will be included in version 0.9 of MetPy.

Overall, I have learned much this summer and I am very thankful to have had this opportunity to work full-time on MetPy, both on my previously mentioned main projects and on all the little side tasks along the way. I hope that these new features I’ve worked on will help move MetPy along in its development roadmap and will, most importantly, be useful to users in the community.

Comments:

Post a Comment:
Comments are closed for this entry.
Unidata Developer's Blog
A weblog about software development by Unidata developers*
Unidata Developer's Blog
A weblog about software development by Unidata developers*

Welcome

FAQs

News@Unidata blog

Take a poll!

What if we had an ongoing user poll in here?

Browse By Topic
Browse by Topic
« December 2024
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    
       
Today