Augment your data with processing algorithms.
!pip install up42-py --upgrade -q
import up42, pathlibfrom up42 import processing_templatesRun 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)
# Print the path to the fileprint(f"Credentials file is located at: {credentials_file_path}")- 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)Processes are algorithms that you can apply to STAC items in your storage. There are two types of processes:
- Enhancement processes that pre-process imagery to improve its visual quality.
- Analytics processes that extract insights from imagery.
Retrieve the class name of the process you want to run.
If you want to run the chosen process for the first time, review and accept its end-user license agreement (EULA) in one of the following ways:
If a EULA is updated, you need to re-accept it before creating your next job.
Select input STAC items and add a title to your job template.
# Add a job title, required for all processestitle = "Processing data over Berlin"
# For processes with one input item, select a single itemstac_item_id = "a32d4e56-2dd2-4094-981f-00d73edb7c45"
# Get a single item from the STAC clientstac_client = up42.stac_client()stac_item = next(stac_client.get_items(stac_item_id))
# For processes with several input items, select multiple items# stac_item1_id = "68567134-27ad-7bd7-4b65-d61adb11fc78"# stac_item2_id = "c3de9ed8-f6e5-4bb5-a157-f6430ba756da"
# Get multiple items from the STAC client# stac_client = up42.stac_client()# stac_item1 = next(stac_client.get_items(stac_item1_id))# stac_item2 = next(stac_client.get_items(stac_item2_id))Create a template by specifying the values of the input parameters for the process you have selected.
# Processes have different input parameters, but most of them only require a job title and a STAC item as DetectionAircraftOIjob_template = processing_templates.DetectionAircraftOI(title=title, item=stac_item)
# This example required 2 input STAC items# job_template = processing_templates.DetectionChangePleiadesHyperverge(# title=title,# items=[stac_item1, stac_item2]# )Check the validity of your job template.
# Assert that the job is valid, print errors if notif not job_template.is_valid: for error in job_template.errors: print(f"{error}\n")Check the cost of a valid job template.
# Verify that the template cost is less than or equal to the price you selected# This example checks the job estimation is below 100 creditsacceptable_cost = 100
if job_template.cost <= acceptable_cost: print(f"Template cost: {job_template.cost.credits} credits") print(f"Template strategy: {job_template.cost.strategy}") print(f"STAC item size: {job_template.cost.size}") print(f"Unit of measurement: {job_template.cost.unit}")
else: print(f"Template cost is higher than {acceptable_cost} credits")job = job_template.execute()
print(f"Job details for ID: {job.id}")print(f"Process ID: {job.process_id}")print(f"Status: {job.status.value}")print(f"Price: {job.credits or 'N/A'} credits")print(f"Created at: {job.created}")The track instance method allows you to track the job status until it changes to CAPTURED or RELEASED.
# This will print a status log to your console every 20 seconds# and will PAUSE the script here until the job is donejob.track(wait=20)
# This line will only run AFTER the job has finished trackingprint("\nTracking complete!")print(f"The final job status is: {job.status.value}")In a successfully completed job, get the resulting STAC collection.
if job.status == up42.JobStatus.CAPTURED: print(f"STAC collection ID: {job.collection.id}")