sun-data / named-arrays

Python library that implements named tensors with Astropy Quantity support.
https://named-arrays.readthedocs.io
4 stars 1 forks source link

What's missing from xarray? #63

Open TomNicholas opened 3 months ago

TomNicholas commented 3 months ago

Hi! I just saw this project, and I'm wondering why exactly you felt xarray wasn't suitable for your use case?

In the readme xarray is mentioned, but it's not totally clear to me what xarray doesn't offer that you need?

We even have an in-progress project in xarray to split out a lightweight version of the xr.Variable object as an xr.NamedArray, which seems to be exactly what you're trying to build here.

I would love to see more collaboration between the (awesome) astropy stack and the xarray community, so please let us know if we can help here!

byrdie commented 3 months ago

Hi @TomNicholas, and thanks for your interest in my project! I contemplate daily whether I should've just contributed to or extended xarray, but I'm afraid I've gone too far to change course at the moment for my other projects.

Apologies for the sparse documentation right now, I've been meaning to create a page which describes why I decided to go in a slightly different direction than xarray.

In short, the reasons I can remember for starting a different project (in no particular order) are as follows. Some of these issues may have been fixed by features added to xarray after I started development on this project, so please let me know if anything is incorrect or out of date.

I can certainly imagine that xarray will have all these features and more in the near future, and I would be interested in contributing what I can to xarray as soon as I'm done with my current project.

Looking forward to discussing this further, thanks again for raising this issue!

byrdie commented 3 months ago

So after perusing the xarray source this morning, I realize that a few of my points are obviously wrong.

byrdie commented 3 months ago

And regarding further collaboration with the Astropy stack, I think the planned Quantity 2.0 project, astropy/astropy-APEs#91, will make this very easy, since xr.NamedArray will be able to just wrap this new Quantity 2.0 object and probably most of the array API would just work.

TomNicholas commented 3 months ago

Thanks for the detailed response!

xarray has an AbstractArray class, much the same as my implementation, I don't know why I was under the opposite impression, apologies!

You can also subclass xarray objects, though is it rarely done and probably has some sharp edges.

No positional indexing allowed. I decided that I thought positional indexing was harmful, so named-arrays only allows indexing by name.

Yeah we do still allow it, but it's a rarely-used feature. I personally never do it. I agree with you that it might be better if xarray just forbid it entirely, but I also think it's a feature that can be ignored if you don't like it.

Vector and matrix support.

Yeah I would extend xarray if you want to add this kind of thing. Xarray is not trying to represent vector calculus - anyone who wants to do that should probably build their own project on top of xarray.

Uncertainty propagation.

This is something that hopefully could be done at the level of the wrapped array, and it would be great if someone thought seriously about how to do this with xarray.

I think the planned Quantity 2.0 project, https://github.com/astropy/astropy-APEs/pull/91, will make this very easy, since xr.NamedArray will be able to just wrap this new Quantity 2.0 object and probably most of the array API would just work.

Thanks for linking to this!