Skip to content

Commit

Permalink
Add _repr_html_ to XarrayDict
Browse files Browse the repository at this point in the history
  • Loading branch information
amarandon committed Dec 5, 2024
1 parent 4963a13 commit 2e0db81
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions eodag_cube/api/product/_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ class XarrayDict(UserDict[str, xr.Dataset]):
Dictionnary which keys are file paths and values are xarray Datasets.
"""

def _format_dims(self, ds):
return ", ".join(f"{key}: {value}" for key, value in ds.sizes.items())

def _repr_html_(self):
title = self.__class__.__name__
count = len(self)
header = f"{title} ({count})"
header_underline = "-" * len(header)

lines = ["<pre>", header, header_underline]

for key, ds in self.items():
formatted_dims = self._format_dims(ds)
line = f"> {key} : xarray.Dataset ({formatted_dims})"
lines.append(line)

lines.append("</pre>")

return "\n".join(lines)


class EOProduct(EOProduct_core):
"""A wrapper around an Earth Observation Product originating from a search.
Expand Down

0 comments on commit 2e0db81

Please sign in to comment.