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

Convert SHGrid class to a subclass of xarray.DataArray #260

Open
MarkWieczorek opened this issue Sep 29, 2020 · 0 comments
Open

Convert SHGrid class to a subclass of xarray.DataArray #260

MarkWieczorek opened this issue Sep 29, 2020 · 0 comments

Comments

@MarkWieczorek
Copy link
Member

Desired feature

The SHGrid class is a custom class that was initially designed to support grids of data for use with spherical harmonic transforms, metadata, standard arithemetic operations, spherical harmonic transforms, and simple plotting. Most of these operations are currently supported by the xarray package using the DataArray class. Though SHGrid class instances can be converted to an xarray DataArray, for simplicity, and for additional features that are included in the DataArray class, it might instead be best to do away with the custom SHGrid class, and simply make SHGrid a subclass of DataArray.

Problems to resolve

There are two ways of doing this.

First, you could subclass DataArray, add the custom method .expand() for spherical harmonic transforms, add the metadata in the DataArray attributes, and override the xarray .plot() routine with the custom pyshtools .plot() routine.

Second, as opposed to overriding the xarray .plot() routine, one could instead create a custom shtools dataset accessor that would allow the new routines to be called as

grid.shtools.plot()
grid.shtools.plotgmt()
coeffs = grid.shtools.expand()

The benefit of using an accessor is that the original xarray function remains untouched. The drawback is that the notation is rather heavy, and the user is certain to call grid.plot() many times by accident. At some point in the future DataArray.plot() might do everything that SHGrid.plot() does, but we are not yet to that point.

Lastly, thought should be given to remaining backward compatible with the original SHGrid class. For example, with an xarray DataArray, it will no longer be necessary to have the .lats() and .lons() methods, as the latitudes and longitudes are stored directly in the DataArray class. The choice is thus either to deprecate these old functions or to keep them for backwards compatibility (perhaps without providing documentation to keep this hidden).

If this feature is implemented, this would be released as pyshtools 5.0 if backward compatibility could not be assured.

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

No branches or pull requests

1 participant