Skip to content

Commit

Permalink
feat(asset_mapper) : all assets available
Browse files Browse the repository at this point in the history
__update_asset_mapper_config_json.py now enable users (or best the developper of this library) to update each predefined collection assets to fasten query.
  • Loading branch information
nicolasK committed Dec 15, 2023
1 parent 2461bb7 commit e76818f
Show file tree
Hide file tree
Showing 4 changed files with 736 additions and 163 deletions.
15 changes: 10 additions & 5 deletions earthdaily/earthdatastore/cube_utils/asset_mapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from . import _asset_mapper_config
import os
import json

__pathFile = os.path.dirname(os.path.realpath(__file__))
__asset_mapper_config_path = os.path.join(
__pathFile, "asset_mapper_config.json"
)
_asset_mapper_config = json.load(open(__asset_mapper_config_path))


class AssetMapper:
def __init__(self):
self.available_collections = list(
_asset_mapper_config.asset_mapper_collections.keys()
)
self.available_collections = list(_asset_mapper_config.keys())

def collection_mapping(self, collection):
if self._collection_exists(collection, raise_warning=True):
return _asset_mapper_config.asset_mapper_collections[collection]
return _asset_mapper_config[collection]

def _collection_exists(self, collection, raise_warning=False):
exists = True if collection in self.available_collections else False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 15 09:03:08 2023
@author: nkk
"""

import earthdaily
import json

eds = earthdaily.earthdatastore.Auth()
asset_mapper_path = (
earthdaily.earthdatastore.cube_utils.asset_mapper.__asset_mapper_config_path
)
asset_mapper_config = (
earthdaily.earthdatastore.cube_utils.asset_mapper.__asset_mapper_config
)

for collection in eds.explore():
try:
assets_name = list(eds.explore(collection).item.assets.keys())
except AttributeError:
print(f"collection {collection} has no items")
continue
for asset_name in assets_name:
if asset_mapper_config.get(collection) is None:
asset_mapper_config[collection] = [{}]
if asset_name not in asset_mapper_config[collection][0].values():
asset_mapper_config[collection][0][asset_name] = asset_name

with open(asset_mapper_path, "w", encoding="utf-8") as f:
json.dump(asset_mapper_config, f, ensure_ascii=False, indent=4)

This file was deleted.

Loading

0 comments on commit e76818f

Please sign in to comment.