Add tags to STAC items in your storage to improve their discoverability.
!pip install up42-py --upgrade -q
import up42, pathlibRun the cell below to create a credentials.json file in a directory named .up42 in your home folder.
# Define the credentials file path if it doesn't existcredentials_file_path = pathlib.Path.home().joinpath(".up42/credentials.json")credentials_file_path.parent.mkdir(parents=True, exist_ok=True)credentials_file_path.touch(exist_ok=True)- Click the link above to the created file and paste the following code:
JSON {"username": "<your-email-address>","password": "<your-password>"} - Retrieve the email address and password used for logging into the console. Use them as values for
usernameandpassword. - Save the
credentials.jsonfile.
up42.authenticate(cfg_file=credentials_file_path)
# Use region if you're logging with the NSG service# up42.authenticate(cfg_file=credentials_file_path, region="sa")
UP42_client = up42.stac_client()You can make a detailed search request to find specific STAC items in your storage.
# Set up a filter to search for STAC items that contain the "ortho" tagfilter = { "op": "a_contains", "args": [ {"property": "tags"}, ["ortho"], ],}
# Perform the searchstac_items_search = UP42_client.search(filter=filter)
for item in stac_items_search.items(): properties = item.properties
# Print all results matching the search filter print(f"STAC item ID: {item.id}") print(f"Order ID: {item.up42.order_id}") print(f"User title: {item.up42.title}") print(f"User tags: {item.up42.tags}\n")# Define new tags to addnew_tags = ["ortho-done"]
# Set up a filter to search for STAC items that contain the "ortho" tagfilter = { "op": "a_contains", "args": [ {"property": "tags"}, ["ortho"], ],}
# Perform the searchstac_items_search = UP42_client.search(filter=filter)
# Iterate through each STAC item and update its tagsfor item in stac_items_search.items(): item.up42.tags = item.up42.tags + new_tags item.update() # Essential step: update change in our database
for item in stac_items_search.items(): properties = item.properties
# Print all results matching the search filter print(f"STAC item ID: {item.id}") print(f"Order ID: {item.up42.order_id}") print(f"User title: {item.up42.title}") print(f"User tags: {item.up42.tags}\n")# Define new tags to addnew_tags = ["sentinel-2"]
# Select a STAC itemitem_id = "9b919b88-8cec-42d9-b901-0b66240ba282"item = next(UP42_client.get_items(item_id))
item.up42.tags = item.up42.tags + new_tagsitem.update() # Essential step: update change in our database
# Print resultsprint(f"STAC item ID: {item.id}")print(f"Order ID: {item.up42.order_id}")print(f"User title: {item.up42.title}")print(f"User tags: {item.up42.tags}\n")