OpenSenseAction / poligrain

Simplify common tasks for working with point, line and gridded sensor data, focusing on rainfall observations.
https://poligrain.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2 stars 10 forks source link

Use xarray Accessors for easy access to functionality #28

Open cchwala opened 3 months ago

cchwala commented 3 months ago

Because we use xarray.Dataset and xarray.DataArray as our data container it would be best and most convenient to make as much functionality as possible accessible via custom xarray Accessors so that we can e.g. plot the CML paths like this

ds_cmls.plg.plot_cmls()

where plg is our custom accessor.

If we go this step, we could also make some basics functions that work in the background more general regarding their input, e.g. allow plotting colored lines by passing the coordinates and values as numpy arrays and not rely on xarray.Dataset in these "low-level functions" because one can call the functions via the xarray Accessor. The only question would where to put the detailed doc string, in the low-level function or in the accessor method.

cchwala commented 3 months ago

29 implements the xarray Accessors for plotting the CML paths. IMO it works great.

Things we should do/discuss now:

  1. Decide if we want to keep functions like plot_map.plot_lines(cmls, ...) which take a xarray.Dataset as input or if we consider these functions redundant because the exact same thing can be achieved with ds_cmls.plg.plot_cmls(...). This currently calls plot_map.plot_lines but it could also call the lower-level function plot_map.scatter_lines which does not require a xarray.Dataset as input and which can also serve as basis for plotting for SMLs.
  2. Implement xarray Accessors for other functions, e.g. spatial distance, finding nearest neigbor, projecting coordinates.