xarray-sentinel icon indicating copy to clipboard operation
xarray-sentinel copied to clipboard

Add an API to access as much original metadata as possible

Open alexamici opened this issue 4 years ago • 6 comments

Within xarray there is no easy way to expose the full XML metadata in the files inside the annotation folder.

Options:

  • add an entries into .attrs that contain the return value of xmlschema.XMLSchema(schema_path).to_dict(annotation_path) [BUT, such objects cannot be saved as netCDF]
  • add an xarray accessor with a metadata exploration API
  • provide metadata exploration API functions in xarray_sentinel

Note that the I didn't find any XSD for the manifest.safe, so we may need to keep to option to return an ElementTree representation of the XML.

alexamici avatar Apr 13 '21 05:04 alexamici

  • add an entries into .attrs that contain the return value of xmlschema.XMLSchema(schema_path).to_dict(annotation_path)

if we store a dictionary in .attrs the data will be not serializable into a netCDF.

aurghs avatar Apr 21 '21 08:04 aurghs

As already noted in https://github.com/bopen/xarray-sentinel/issues/4#issuecomment-818500175, the xarray accessor would be present in every dataset, not only those opened through xarray-sentinel.

Nonetheless I believe an accessor-like interface gives the best user experience, could we just attach a (python) attribute to the dataset? You would lose it if you dump the dataset to a netCDF (or any other format), but I think all the other options would do the same.

corrado9999 avatar Apr 26 '21 21:04 corrado9999

I agree, the accessor is the only way to go. Especially if we want to support specialised exploration APIs that perform possibly slow operations (for example when data is over the network).

alexamici avatar Apr 27 '21 09:04 alexamici

Mmm... we were probably not talking about the same thing, By "accessor-like interface" I meant something that acts as an accessor (you just call e.g. ds.sentinel1) but is not an accessor, just an attribute attached to the object. I admit it, it is not very nice, but I find having the accessor sentinel on every dataset is really a no-go.

corrado9999 avatar Apr 27 '21 11:04 corrado9999

AttributeError: cannot set attribute 'sentinel1' on a 'Dataset' object.

I just tried. You cannot add a new attribute to a Dataset. That is because you can access data variables and coordinates by attribute ds.latitude I think.

Looks like the accessor API is the only way to extend xarray objects.

alexamici avatar Apr 27 '21 12:04 alexamici

Thinking more about the accessor-interface I'm now of the opinion that there's no clean way to add the exploration API to the Dataset object because it is not the right place for it.

For what it is worth, my suggestion is to go with option 3 above:

provide metadata exploration API functions in xarray_sentinel

alexamici avatar May 03 '21 16:05 alexamici