Idea: functionally-derived non-dimensional coordinates
See original GitHub issue@Cadair and I are from the solar and astrophysics communities, respectively (particularly SunPy and Astropy). In our fields, we have a concept of something called “World Coordinate Systems” (WCS) which basically are arbitrary mappings from pixel coordinates (which is often but not necessarily the same as the index) to physical coordinates. (For more on this and associated Python/Astropy APIs, see this document). If we are reading correctly, this concept maps roughly onto the xarray concept of “Non-dimension coordinates”.
However, a critical difference is this: WCS are usually expressed as arbitrary complex mathematical functions, rather than coordinate arrays, as it is crucial to some of the science cases to carry sub-pixel or other coordinate-related metadata around along with the WCS.
So our question is: is it in-scope for xarray
non-dimensional coordinates to be extended to be functional instead of having to be arrays? I.e., have the coordinate arrays be generated on-the-fly from some function instead of being realized as arrays at creation-time. We have thought about several ways this might be specified and are willing to do some trial implementations, but are first asking here if it is likely to be
- Easy
- Hard
- Impossible
- PR will immediately be rejected on philosophical grounds, regardless?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:15 (14 by maintainers)
Top GitHub Comments
This looks like a nice use case for the forthcoming Xarray’s custom index feature.
How I see CRS/WCS-aware Xarray datasets with custom indexes:
A set of coordinate(s) and their attributes hold data or metadata relevant for public use and that could be easily (de)serialized
A custom index (
CRSIndex
orWCSIndex
) provides CRS/WCS-aware implementations of common Xarray operations such as alignment (merge/concat) and data selection (sel), viaXarray.Index
’sequals
,union
,intersection
andquery
methods added in #5102 and #5322 (not yet ready for use outside of Xarray). Such custom index may also be used to hold some data that is tricky to propagate by other means, e.g., some internal information like “functional” coordinate parameters or acrs
object. Xarray indexes should definitely provide more flexibility than coordinate data or attributes or accessor attributes for propagating this kind of information.Xarray accessors may be used to extend Dataset/DataArray public API. They could use the information stored in the
CRSIndex
/WCSIndex
, e.g., add acrs
read-only property that returns thecrs
object stored in CRSIndex, or add some someextract_crs_parameters
method to extract the parameters and store them in Dataset/DataArray attributes similarly to what @djhoese suggests in his comment above.For this use case a possible workflow would then be something like this:
@djhoese not yet but hopefully soon! Most of the work on explicit indexes is currently happening in #5692, which once merged (probably after the next release) will provide all the infrastructure for custom indexes. This is quite a big internal refactoring (bigger than I initially thought) that we cannot avoid as we’re changing Xarray’s core data model. After that, we’ll need to update some public API (Xarray object constructors,
.set_index()
, etc.) so that Xarray will accept custom index classes. This should take much less work than #5692, though.