Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to access as much original metadata as possible #7

Open
alexamici opened this issue Apr 13, 2021 · 6 comments
Open

Add an API to access as much original metadata as possible #7

alexamici opened this issue Apr 13, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@alexamici
Copy link
Member

alexamici commented Apr 13, 2021

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.

@aurghs
Copy link
Member

aurghs commented Apr 21, 2021

  • 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.

@corrado9999
Copy link
Collaborator

As already noted in #4 (comment), 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.

@alexamici
Copy link
Member Author

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).

@corrado9999
Copy link
Collaborator

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.

@alexamici
Copy link
Member Author

alexamici commented Apr 27, 2021

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
Copy link
Member Author

alexamici commented May 3, 2021

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 alexamici changed the title Add an API to access the as much original metadata as possible Add an API to access as much original metadata as possible Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants