One of the python packages I use the most is an excellent library called xarray, which is very convenient for handing multi-dimensional data. This package provides a
DataArray object which associates a n-d array with named dimensions and coordinate data, and provides convenient methods for indexing, aligning, and broadcasting. For instance, if I have two data arrays
meantemp(lat,lon), xarray allows me perform simple operations like
np.sqrt(((temp-meantemp)**2).mean('time')). This expression involves automatic broadcasting, and a reduction across the named dimension. Also, the final
sqrt call returns an
DataArray object transparently. It’s a pretty magical tool, and very useful to people involved in atmospheric science and oceanography.
I have started a implementation in julia at https://github.com/nbren12/XArray.jl. Currently,
DataArray inherits from
AbstractArray, but I am not sure if this is a good idea. My main questions are
- Should the DataArray type inherit from
AbstractArray? Or should I manually redefine all the functions like
- If I don’t subclass from
AbstractArray, how can I ensure that simple function calls like
- If I do subclass from
AbstractArray, how do I define
Base.similar(x::DataArray, dims)so that named coordinate information is passed along to the new object.
I would love your input, and would welcome anybody who is interested in contributing to this project. If there is already an equivalent package in julia please let me know.