spedas / pyspedas

Python-based Space Physics Environment Data Analysis Software
https://pyspedas.readthedocs.io/
MIT License
147 stars 58 forks source link

Data Management in Tplot Variables #748

Open Beforerr opened 6 months ago

Beforerr commented 6 months ago

Currently, Tplot variables are maintained globally, which, despite its convenience, diverges from recommended Pythonic practices that favor encapsulation and modular design. A more structured and Pythonic approach could involve incorporating Tplot variables into an Xarray.Dataset since “Tplot variable” is really just a fancy name for an Xarray.DataArrray object. This integration would not only streamline data management but also align with the principles of effective data structuring and accessibility.

A possible use case: Plot a time-shifted variable and its original variable in a same panel, right now it is possible but troublesome by a deep copy and renaming. In contrast, it would be very straightforward if the variables are locally encapsulated in a Xarray.Dataset.

(P.S.: furthermore, considering that a Tplot variable is fundamentally an xarray.DataArray, there is a compelling case for subclassing xr.DataArray to extend its functionality, making them more versatile and tailored to data manipulation.)