@@ -42,7 +42,6 @@ class Catalog(STACObject):
42
42
43
43
See: https://github.com/radiantearth/stac-spec/blob/v0.8.0/catalog/catalog-spec.md
44
44
"""
45
-
46
45
"""Default file name that will be given to this STAC item in a cononical format."""
47
46
DEFAULT_FILE_NAME = "catalog.json"
48
47
@@ -63,8 +62,8 @@ def __repr__(self):
63
62
64
63
def set_root (self , root , link_type = LinkType .ABSOLUTE ):
65
64
STACObject .set_root (self , root , link_type )
66
- root ._resolved_objects = ResolvedObjectCache .merge (root . _resolved_objects ,
67
- self ._resolved_objects )
65
+ root ._resolved_objects = ResolvedObjectCache .merge (
66
+ root . _resolved_objects , self ._resolved_objects )
68
67
69
68
def add_child (self , child , title = None ):
70
69
child .set_root (self .get_root ())
@@ -180,16 +179,16 @@ def make_all_asset_hrefs_absolute(self):
180
179
for item in items :
181
180
item .make_asset_hrefs_absolute ()
182
181
183
- def normalize_and_save (self ,
184
- root_href ,
185
- catalog_type ):
182
+ def normalize_and_save (self , root_href , catalog_type ):
186
183
self .normalize_hrefs (root_href )
187
184
self .save (catalog_type )
188
185
189
186
def normalize_hrefs (self , root_href ):
190
187
# Normalizing requires an absolute path
191
188
if not is_absolute_href (root_href ):
192
- root_href = make_absolute_href (root_href , os .getcwd (), start_is_dir = True )
189
+ root_href = make_absolute_href (root_href ,
190
+ os .getcwd (),
191
+ start_is_dir = True )
193
192
194
193
# Fully resolve the STAC to avoid linking issues.
195
194
# This particularly can happen with unresolved links that have
@@ -230,23 +229,27 @@ def save(self, catalog_type):
230
229
else :
231
230
self .make_all_links_relative ()
232
231
233
- include_self_link = catalog_type in [CatalogType .ABSOLUTE_PUBLISHED ,
234
- CatalogType .RELATIVE_PUBLISHED ]
232
+ include_self_link = catalog_type in [
233
+ CatalogType .ABSOLUTE_PUBLISHED , CatalogType .RELATIVE_PUBLISHED
234
+ ]
235
235
236
236
if catalog_type == CatalogType .RELATIVE_PUBLISHED :
237
237
child_catalog_type = CatalogType .SELF_CONTAINED
238
238
else :
239
239
child_catalog_type = catalog_type
240
240
241
- items_include_self_link = catalog_type in [CatalogType .ABSOLUTE_PUBLISHED ]
241
+ items_include_self_link = catalog_type in [
242
+ CatalogType .ABSOLUTE_PUBLISHED
243
+ ]
242
244
243
245
for child_link in self .get_child_links ():
244
246
if child_link .is_resolved ():
245
247
child_link .target .save (catalog_type = child_catalog_type )
246
248
247
249
for item_link in self .get_item_links ():
248
250
if item_link .is_resolved ():
249
- item_link .target .save_object (include_self_link = items_include_self_link )
251
+ item_link .target .save_object (
252
+ include_self_link = items_include_self_link )
250
253
251
254
self .save_object (include_self_link = include_self_link )
252
255
@@ -270,8 +273,9 @@ def map_items(self, item_mapper):
270
273
"""Creates a copy of a catalog, with each item passed through the item_mapper function.
271
274
272
275
Args:
273
- item_mapper: A function that takes in an item, and returns either an item or list of items.
274
- The item that is passed into the item_mapper is a copy, so the method can mutate it safetly.
276
+ item_mapper: A function that takes in an item, and returns either
277
+ an item or list of items. The item that is passed into the item_mapper
278
+ is a copy, so the method can mutate it safetly.
275
279
"""
276
280
277
281
new_cat = self .full_copy ()
@@ -290,9 +294,9 @@ def process_catalog(catalog):
290
294
item_links .append (item_link )
291
295
else :
292
296
for i in mapped :
293
- l = item_link .clone ()
294
- l .target = i
295
- item_links .append (l )
297
+ new_link = item_link .clone ()
298
+ new_link .target = i
299
+ item_links .append (new_link )
296
300
catalog .clear_items ()
297
301
catalog .add_links (item_links )
298
302
@@ -304,9 +308,10 @@ def map_assets(self, asset_mapper):
304
308
through the asset_mapper function.
305
309
306
310
Args:
307
- asset_mapper: A function that takes in an key and an Asset, and returns
308
- either an Asset, a (key, Asset), or a dictionary of Assets with unique keys.
309
- The Asset that is passed into the item_mapper is a copy, so the method can mutate it safetly.
311
+ asset_mapper: A function that takes in an key and an Asset, and returns
312
+ either an Asset, a (key, Asset), or a dictionary of Assets with unique keys.
313
+ The Asset that is passed into the item_mapper is a copy, so the method can
314
+ mutate it safetly.
310
315
"""
311
316
def apply_asset_mapper (tup ):
312
317
k , v = tup
@@ -324,8 +329,10 @@ def apply_asset_mapper(tup):
324
329
return assets
325
330
326
331
def item_mapper (item ):
327
- new_assets = [x for result in map (apply_asset_mapper , item .assets .items ())
328
- for x in result ]
332
+ new_assets = [
333
+ x for result in map (apply_asset_mapper , item .assets .items ())
334
+ for x in result
335
+ ]
329
336
item .assets = dict (new_assets )
330
337
return item
331
338
@@ -337,9 +344,9 @@ def describe(self, indent=0, include_hrefs=False):
337
344
s += ' {}' .format (self .get_self_href ())
338
345
print (s )
339
346
for child in self .get_children ():
340
- child .describe (indent = indent + 4 , include_hrefs = include_hrefs )
347
+ child .describe (indent = indent + 4 , include_hrefs = include_hrefs )
341
348
for item in self .get_items ():
342
- s = '{}* {}' .format (' ' * (indent + 2 ), item )
349
+ s = '{}* {}' .format (' ' * (indent + 2 ), item )
343
350
if include_hrefs :
344
351
s += ' {}' .format (item .get_self_href ())
345
352
print (s )
@@ -350,9 +357,7 @@ def from_dict(d):
350
357
description = d ['description' ]
351
358
title = d .get ('title' )
352
359
353
- cat = Catalog (id = id ,
354
- description = description ,
355
- title = title )
360
+ cat = Catalog (id = id , description = description , title = title )
356
361
357
362
for l in d ['links' ]:
358
363
if not l ['rel' ] == 'root' :
0 commit comments