Skip to content

Commit

Permalink
Merge pull request #1357 from opendatacube/grid-spec-for-list
Browse files Browse the repository at this point in the history
add grid spec to list_products
  • Loading branch information
pindge authored Nov 17, 2022
2 parents 64ef235 + 88e51b3 commit 54491c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions datacube/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def list_products(self, with_pandas=True, dataset_count=False):
'name'
'description'
'license'
'default_crs'
'default_resolution'
'default_crs' or 'grid_spec.crs'
'default_resolution' or 'grid_spec.crs'
'dataset_count' (optional)
:param bool with_pandas:
Expand All @@ -121,8 +121,16 @@ def list_products(self, with_pandas=True, dataset_count=False):
'default_crs',
'default_resolution',
]
rows = [[getattr(pr, col, None) for col in cols]
for pr in self.index.products.get_all()]
rows = [[
getattr(pr, col, None)
# if 'default_crs' and 'default_resolution' are not None
# return 'default_crs' and 'default_resolution'
if getattr(pr, col, None) and 'default' not in col
# else try 'grid_spec.crs' and 'grid_spec.resolution'
# as per output_geobox() handling logic
else getattr(pr.grid_spec, col.replace('default_', ''), None)
for col in cols]
for pr in self.index.products.get_all()]

# Optionally compute dataset count for each product and add to row/cols
# Product lists are sorted by product name to ensure 1:1 match
Expand Down Expand Up @@ -870,7 +878,10 @@ def output_geobox(like=None, output_crs=None, resolution=None, align=None,
resolution = grid_spec.resolution
align = align or grid_spec.alignment
else:
raise ValueError("Product has no default CRS. Must specify 'output_crs' and 'resolution'")
raise ValueError(
"Product has no default CRS. \n"
"Must specify 'output_crs' and 'resolution'"
)

# Try figuring out bounds
# 1. Explicitly defined with geopolygon
Expand Down
2 changes: 2 additions & 0 deletions docs/about/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ What's New
v1.8.next
=========

- Add `grid_spec` to `list_products` (:pull:`1357`)

v1.8.9 (17 November 2022)
=========================

Expand Down

0 comments on commit 54491c4

Please sign in to comment.