Skip to main content

Python client for Sintetic Project. This library provides a simple interface to interact with the Sintetic API, allowing users to manage and retrieve data related to synthetic datasets. For more information, visit https://sinteticproject.eu/

Project description

Contents of README.md

Sintetic Library

Description

Python client for Sintetic Project. This library provides a simple interface to interact with the Sintetic API, allowing users to manage and retrieve data related to synthetic datasets. For more information, visit https://sinteticproject.eu/

Intallation

To install the library, use:

pip install sintetic-library

To upgrade the library, use:

pip install --upgrade sintetic-library

Use case

from sintetic_library import SinteticClient

# Create an instance of SinteticClient using your Sintetic token.
# The token is issued by your administrator with a specific scope.
#
client = SinteticClient(
        token="YOUR TOKEN",
        base_url="base URL for Sintetic GeoDB API"  # If not specified, SinteticClient will use the staging server API instead of the production one
    )

#######
# Sample #1
# Implementation sample for tree processor, forest operation and stan4d files
#######

# Call method for retrieving list of tree processors
result = client.get_list_tree_processors ()

# Retrieve list of forest properties
result = client.get_list_forest_properties () 

# Retrieve list of forest properties
result = client.get_list_forest_properties ()

# Create tree processor id for given data
data = { "name" : "Test Tree Processor",
         "type" : "harvester"    
       }        

id_tree_processor = client.create_tree_processor(data)

# Create new forest operation from given data
# 
data = { "name" : "Test Forest Operation",
                 "status" : "planned",
                 "location": {
                    "type": "Point",
                    "coordinates": [10.2, 45.2]
                    },  
                 "start_date" : "2025-06-19",
                 "end_date" : "2025-06-19", 
                 "area": 100,
                 "forest_property_id": "XXXXXXXX-YYYY-ZZZZ-XXXX-ZZZZZZZZZZZZ"
                }
        
id_forest_operation = client.create_forest_operation(data)       

# Retrieve list of Stan4D files
response = client.get_stan4d_list() 

# Save new Stan4D file
with open("./stan4d_file.hpr", "rb") as f:
    xml_content = f.read()
    
response = client.save_stan4d_object(
    filename=os.path.basename(f.name),
    xml_content=xml_content,
    tree_processor_id=id_tree_processor,
    forest_operation_id=id_forest_operation
)
    
# Extract Stan4D file ID    
stand4d_id = response.json()["id"]

# Get Stan4D file using the associated ID
response = client.get_stan4d_file(fileid=stand4d_id)

# Delete Stan4D file using the associated ID
response = client.delete_stan4d_file(fileid=stand4d_id)

# Delete Forest Operation using the associated ID
response = client.delete_forest_operation(forest_operation_id=id_forest_operation)
        
# Delete Tree Processor using the associated ID
response = client.delete_tree_processor(tree_processor_id=id_tree_processor)
##### End of Sample #1

#####
# Sample #2
# Implementation sample for climate data attachment management
#####

#Open CSV file with climate data
with open("testcsv.csv", "rb") as f:
    csv_content = f.read()

# Create new climate object
response = client.save_climate_object(
    filename="testcsv.csv",
    climate_file=csv_content,
    anomalistic=True,
    forest_operation_id="24a912c4-6a0a-4860-a163-f62e96f43d6b",
    temporal_resolution=TemporalResolution.DAILY.value,
    coverage_start_year=2025,
    coverage_end_year=2025,
    description="Test Climate Attachment"
)


climate_object_id = response   
print("Climate object saved successfully:", climate_object_id)    

# Retrieve Climate Attachment data
print("Retrieved Climate Attachment data:", client.get_climate_data(climate_object_id))   

# Retrieve Climate Attachment file
print("Retrieved Climate file contents:", client.get_climate_file(climate_object_id))

# Delete climate file and data
print("Delete climate file:", client.delete_climate_file(climate_object_id))

#### End of Sample #2

####
# Sample #3
# Implementation sample for subcompartments and vegetation file management
####

#create a new forest operation for subcompartment
data = { "name" : "Test Leandro for Subcompartment",
                "status" : "planned",
                "location": {
                "type": "Point",
                "coordinates": [10.2, 45.2]
                },  
                "start_date" : "2025-06-19",
                "end_date" : "2025-06-19", 
                "area": 100,
                "forest_property_id": "8a0febff-e133-44fd-8e15-bfa11b40f620"
            }
    
forest_id = client.create_forest_operation(data)
print("Risposta creazione forest operation: ", forest_id)

# Create a new subcompartment
response = client.create_subcompartment("Test subcompartment Leandro", SubcompartmentType.FOREST_OPERATION.value, 
                            forest_id, 10.0, 10.0, 20.0, 20.0)

print(f"Subcompartment created successfully with UUID: {response}")
subcomp_id = response
# Retrieve the list of subcompartments
response = client.get_subcompartments_list()
print(f"List of subcompartments: {response}")

# Retrieve the subcompartment by UUID   
response = client.get_subcompartment(subcomp_id)
print(f"Retrieved subcompartment info: {response}")

# Create new vegetation object
# open ndvi file in binary mode
with open("ndvi_july.csv", "rb") as f:
    csv_content = f.read()

response = client.save_vegetation_object(
    filename="ndvi_july.csv",
    vegetation_file=csv_content,
    subcompartment_id=subcomp_id,
)

print(f"Vegetation object saved successfully with ID: {response}")

# Retrieve the vegetation data
response = client.get_vegetation_data(subcomp_id)
print(f"Retrieved vegetation file contents: {response}")
    
# Retrieve vegetation attachments list
response = client.get_vegetation_list()
print(f"Retrieved vegetation attachments list: {response}")

# Retrieve the vegetation object
response = client.get_vegetation_file(subcomp_id)
print(f"Retrieved vegetation file contents: {response}")
    
#Append new vegetation file
#open ndvi file in binary mode
with open("ndvi_august.csv", "rb") as f:
    csv_content = f.read()

response = client.save_vegetation_object(
    filename="ndvi_august.csv",
    vegetation_file=csv_content,
    subcompartment_id=subcomp_id,
)

print(f"Vegetation object saved successfully with ID: {response}")

# Retrieve the updated vegetation object 
response = client.get_vegetation_file(subcomp_id)
print(f"Retrieved updated file contents: {response}")

# Delete vegetation file
#  file type contains "csv" or "png" value
response = client.delete_vegetation_file(subcomp_id, file_type)
print(f"Vegetation file deleted successfully: {response}")

# Delete subcompartment
response = client.delete_subcompartment(subcomp_id)
print(f"Subcompartment deleted successfully: {response}")

# Delete forest operation
response = client.delete_forest_operation(forest_id)
print(f"Subcompartment deleted successfully: {response}")

License

This library is freely provided for use within the Sintetic project

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sintetic_library-0.5.4.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sintetic_library-0.5.4-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file sintetic_library-0.5.4.tar.gz.

File metadata

  • Download URL: sintetic_library-0.5.4.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sintetic_library-0.5.4.tar.gz
Algorithm Hash digest
SHA256 c3b43319ae7230f1a8d918c4fd1c43ca51ce71c3f5a34782cfef0505825c7490
MD5 8b88d1969abaf88d54da5ce6d819f787
BLAKE2b-256 5e34bfa215157c71bb80b518534bc0b3c5085a8c2ea622060b892b7fa1db77c2

See more details on using hashes here.

File details

Details for the file sintetic_library-0.5.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sintetic_library-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 eac5879c5167e5520942b18fd3be8ae3e6118e354d15997a6cc74ff5ed9074e8
MD5 7775bbecc9d93a98c093ad7a6abb66c9
BLAKE2b-256 bde96a447988db7cafc644837682e1e06caebff17f3625572df9b162de5fe6f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page