Skip to content

Accessor

No due date 75% complete

Instead of creating a subclass of Xarray's Dataset, use an accessor.

To what extent do we actually need the DataStore class as subclass of Xarray's Dataset?
What about instead of subclassing to add a dts accessor that holds the calibration functions? https://docs.xarray.dev/en/stable/internals/extending-xarray.html

  • ds.dts.single_ended_calibration()
  • ds.dt…

Instead of creating a subclass of Xarray's Dataset, use an accessor.

To what extent do we actually need the DataStore class as subclass of Xarray's Dataset?
What about instead of subclassing to add a dts accessor that holds the calibration functions? https://docs.xarray.dev/en/stable/internals/extending-xarray.html

  • ds.dts.single_ended_calibration()
  • ds.dts.double_ended_calibration()
  • ds.dts.sections and its values are still stored in ds.attrs["_sections"]
  • ds.dts.variance_stokes()
  • ds.dts.__repr__()

Taking your code it would look as follows:

from dtscalibration.calibration_routines import double_ended, single_ended

@xr.register_dataset_accessor("dts")
class DataStore:
    ...
    def calibration_single_ended(self, **kwargs):
        single_ended.calibrate(self, **kwargs)

    def calibration_double_ended(self, **kwargs):
        double_ended.calibrate(self, **kwargs)

This entire overhaul is much bigger than what you propose.. Maybe leave it at your proposal for now. I am doing this thing with the accessor with pandas object and it works really neat! Keeps everything tidy and allows for combining different accessors simultaneously.

Loading