geoxarray / geoxarray

Geolocation utilities for xarray

Home Page:https://geoxarray.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `sel` and `loc` methods for selection by standard names

djhoese opened this issue · comments

One concept that came up while talking at SciPy 2019 with @dopplershift and @snowman2 was the feature in metpy to do data_arr.sel(x=slice(...), y=slice(...)) even though the dimensions of the DataArray may not be named with the preferred names.

One thing that @snowman2 talked about was a similar method he has in rioxarray that in addition to allowing the dimension name mapping it will also reorder the slices for x and y dimensions if they are "backwards". This usually happens if the data is flipped for some reason from normal +x (right) and +y (up) orientation. The method doesn't affect the data but still allows users to select a subset of the data. Without this no data would be returned.

I wanted to write this down before I forget.

Following metpy's example, I think using x, y, vertical, and time would be good names for the "preferred" dimensions of geoxarray, but these methods would allow for any other dimensions that may exist. That way you can do one slice of all dimensions in one go if needed.

That’s how the ones in MetPy work. I want to make clear that to do this in MetPy, we had to hang these off the .metpy accessor.

I don't know if there was a better issue for this (feel free to point me to it if there is), but there was discussion on whether netCDF-CF actually requires long/lats in the file. It does (cc @snowman2):

image

I see that they recommend adding the latlon, but it doesn't appear to be required. That is good to know. I think having a method to add the latlon like the one in satpy would be useful for those who want to follow the recommendation.

No, it's required:

For example, the Cartesian coordinates of a map projection should be supplied as coordinate variables in addition to the required two-dimensional latitude and longitude variables that are identified via the coordinates attribute.

(emphasis mine)

I did notice that part. They do confuse the subject by first stating: it is recommended that they by supplied in addition to .... I guess it is up to which one you prefer to take as the official requirement. Personally, I don't like them as they confuse people, make the file sizes bigger, and the mainstream GIS tools are able to read them just fine without it. So, I lean towards interpreting it as "recommended" 😃 .

I got confused by that text myself too. What it turns out is in this part:

if the coordinate variables for a horizontal grid are not longitude and latitude, it is recommended that they be supplied in addition to the required coordinates

In that sentence "they" refers to the "coordinate variables", not "longitude and latitude". Which is terrible grammar. There's also this section I have since been pointed to:

image

To be clear, I'm not arguing in favor of this, just that this is what the specification requires. And based on my conversations here at the CF meeting, this is indeed the case. You may also be interested in cf-convention/cf-conventions#133.

Ahhh, I get it now - grammar is fun :). Thanks for clarifying & sharing the link - glad to hear that they are discussing this and making steps towards latlon being optional.