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 rich reprs to STAC objects #508

Closed
TomAugspurger opened this issue Jul 1, 2021 · 3 comments
Closed

Add rich reprs to STAC objects #508

TomAugspurger opened this issue Jul 1, 2021 · 3 comments

Comments

@TomAugspurger
Copy link
Collaborator

IPython / jupyter define a protocol where objects defining methods like _repr_html_ will have the ability to produce rich representations in a notebook. See https://ipython.readthedocs.io/en/stable/config/integrating.html.

I think this would be very useful for exploring STAC objects. dask/distributed#4857 has some designs / code that might be worth stealing. In particular the handling of nested objects would apply to catalogs, collections, and even items.

See http://matthewrocklin.com/blog/2019/07/04/html-repr for some background.

@DahnJ
Copy link
Contributor

DahnJ commented Dec 2, 2021

This seems like an immensely useful feature to have, especially given the nested structure STAC has.

PR #573 was closed since it used an extra dependency jinja2. The agreed-upon solution was to create a new package pystac-jupyter. Did that ever get made? If not, what would be needed to help it get made?

In case it didn't get made: would it perhaps be possible/convenient to only include jinja2 as an optional dependency and only attach/display the HTML representations if jinja2 is installed? I haven't thought much about this, just thought I'd mention it.

cc: @moradology

@TomAugspurger
Copy link
Collaborator Author

IMO, this would have to go in pystac itself to be worthwhile. https://ipython.readthedocs.io/en/stable/config/integrating.html#formatters-for-third-party-types mentions a way for third-party libraries to register formatters for types in other libraries, but that's not too user-friendly.

I think an optional dependency is a good compromise. The _repr_html_ would then just need a

try:
    import jinja2
except ImportError:
    return repr(self)
...

And in case it's helpful, rich.inspect can give a (verbose) repr:

image

But I think that the nested nature of STAC objects means things like HTML dropdowns / disclosure triangles will be helpful.

@duckontheweb
Copy link
Contributor

Closed by #743

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants