20
20
except ImportError :
21
21
from datacube .index .abstract import default_metadata_type_docs # type: ignore
22
22
23
- from datacube .model import Dataset , DatasetType , metadata_from_doc
23
+ from datacube .model import Dataset , Product , metadata_from_doc
24
24
from odc .geo import CRS
25
25
from odc .geo .geobox import GeoBox
26
26
from toolz import dicttoolz
60
60
)
61
61
62
62
63
- def _to_product (md : RasterCollectionMetadata ) -> DatasetType :
63
+ def _to_product (md : RasterCollectionMetadata ) -> Product :
64
64
def make_band (
65
65
band_key : BandKey ,
66
66
band : RasterBandMetadata ,
@@ -95,11 +95,11 @@ def make_band(
95
95
for band_key , band in md .meta .bands .items ()
96
96
],
97
97
}
98
- return DatasetType (_eo3 , doc )
98
+ return Product (_eo3 , doc )
99
99
100
100
101
101
@singledispatch
102
- def infer_dc_product (x : Any , cfg : Optional [ConversionConfig ] = None ) -> DatasetType :
102
+ def infer_dc_product (x : Any , cfg : Optional [ConversionConfig ] = None ) -> Product :
103
103
"""Overloaded function."""
104
104
raise TypeError (
105
105
"Invalid type, must be one of: pystac.item.Item, pystac.collection.Collection"
@@ -109,7 +109,7 @@ def infer_dc_product(x: Any, cfg: Optional[ConversionConfig] = None) -> DatasetT
109
109
@infer_dc_product .register (pystac .item .Item )
110
110
def infer_dc_product_from_item (
111
111
item : pystac .item .Item , cfg : Optional [ConversionConfig ] = None
112
- ) -> DatasetType :
112
+ ) -> Product :
113
113
"""
114
114
Infer Datacube product object from a STAC Item.
115
115
@@ -164,7 +164,7 @@ def _to_dataset(
164
164
item : ParsedItem ,
165
165
properties : Dict [str , Any ],
166
166
ds_uuid : uuid .UUID ,
167
- product : DatasetType ,
167
+ product : Product ,
168
168
) -> Dataset :
169
169
# pylint: disable=too-many-locals
170
170
@@ -227,7 +227,7 @@ def _to_dataset(
227
227
228
228
229
229
def _item_to_ds (
230
- item : pystac .item .Item , product : DatasetType , cfg : Optional [ConversionConfig ] = None
230
+ item : pystac .item .Item , product : Product , cfg : Optional [ConversionConfig ] = None
231
231
) -> Dataset :
232
232
"""
233
233
Construct Dataset object from STAC Item and previously constructed Product.
@@ -251,7 +251,7 @@ def _item_to_ds(
251
251
def stac2ds (
252
252
items : Iterable [pystac .item .Item ],
253
253
cfg : Optional [ConversionConfig ] = None ,
254
- product_cache : Optional [Dict [str , DatasetType ]] = None ,
254
+ product_cache : Optional [Dict [str , Product ]] = None ,
255
255
) -> Iterator [Dataset ]:
256
256
"""
257
257
STAC :class:`~pystac.item.Item` to :class:`~datacube.model.Dataset` stream converter.
@@ -276,7 +276,7 @@ def stac2ds(
276
276
277
277
:param product_cache:
278
278
Input/Output parameter, contains mapping from collection name to deduced product definition,
279
- i.e. :py:class:`datacube.model.DatasetType ` object.
279
+ i.e. :py:class:`datacube.model.Product ` object.
280
280
281
281
.. rubric: Sample Configuration
282
282
@@ -312,7 +312,7 @@ def stac2ds(
312
312
warnings: ignore
313
313
314
314
"""
315
- products : Dict [str , DatasetType ] = {} if product_cache is None else product_cache
315
+ products : Dict [str , Product ] = {} if product_cache is None else product_cache
316
316
for item in items :
317
317
collection_id = _collection_id (item )
318
318
product = products .get (collection_id )
@@ -321,14 +321,18 @@ def stac2ds(
321
321
if product is None :
322
322
product = infer_dc_product (item , cfg )
323
323
products [collection_id ] = product
324
+ # if product_cache was provided, the products within may not have the custom _md attr
325
+ if not hasattr (product , "_md" ): # pylint: disable=protected-access
326
+ md = extract_collection_metadata (item , cfg )
327
+ setattr (product , "_md" , md ) # pylint: disable=protected-access
324
328
325
329
yield _item_to_ds (item , product , cfg )
326
330
327
331
328
332
@infer_dc_product .register (pystac .collection .Collection )
329
333
def infer_dc_product_from_collection (
330
334
collection : pystac .collection .Collection , cfg : Optional [ConversionConfig ] = None
331
- ) -> DatasetType :
335
+ ) -> Product :
332
336
"""
333
337
Construct Datacube Product definition from STAC Collection.
334
338
0 commit comments