Accessing your workspace projects, flights, and data products¶
This guide will walk you through the steps for requesting data from a Data to Science (D2S) instance.
To get started, you will need to import the Workspace
module.
# Uncomment and run the following line if working out of Google Colab
# !pip install d2spy
from datetime import date
from d2spy.workspace import Workspace
All of your D2S data can be accessed through a D2S "workspace." The Workspace
module's connect
method can be used to login to a D2S instance and connect to your workspace in one go. Behind the scenes, the Auth
module will be used to handle authenticating with D2S and requesting an authorization token. You will need to provide connect
with the URL to your D2S instance and enter your password when prompted.
# Example of connecting to a workspace for a local D2S instance
workspace = Workspace.connect("http://localhost:8000", "yourD2Semail@example.com")
The Workspace get_projects
method will retrieve a collection of the projects your account can currently access on the D2S instance.
# Get list of all your projects
projects = workspace.get_projects()
# Print title of first project (if one exists)
if len(projects) > 0:
print(projects[0])
else:
print("Please create a project before proceeding with this guide.")
The projects
variable is a ProjectCollection
. The collection can be filtered by either the project descriptions or titles using the methods filter_by_title
or filter_by_name
.
# Example of creating new collection of only projects with the keyword "Test" in the title
filtered_projects = projects.filter_by_title("Test")
print(filtered_projects)
The Project get_project_boundary
method will retrieve a GeoJSON object of the project boundary.
# Get project boundary as Python dictionary in GeoJSON structure
project_boundary = projects[0].get_project_boundary()
print(project_boundary)
The Project get_flights
method will retrieve a list of the flights associated with a project.
# Get list of all flights for a project
flights = projects[0].get_flights()
# Print first flight object (if one exists)
if len(flights) > 0:
print(flights[0])
The flights
variable is a FlightCollection
. The collection can be filtered by the acquisition date using the method filter_by_date
. This method will return all flights with an acquisition date bewteen the provided start and end dates.
# Example of creating new collection of only flights from May 2024 - June 2024
filtered_flights = flights.filter_by_date(start_date=date(2024, 5, 1), end_date=date(2024, 6, 30))
print(filtered_flights)
The Flight get_data_products
method will retrieve a list of the data products associated with a flight.
# Get list of data products from a flight
data_products = flights[0].get_data_products()
# Print the url for the first data product (if one exists)
print(data_products[0].url)
The data_products
variable is a DataProductCollection
. The collection can be filtered by the data type using the method filter_by_data_type
. This method will return all data products that match the requested data type.
# Example of creating new collection of data products with the "ortho" data type
filtered_data_products = data_products.filter_by_data_type("ortho")
print(filtered_data_products)
These are all the methods you need to know for viewing what data your account can access on a D2S instance. Once finished exploring your data, you can revoke your authorization session by logging out.
# Removes access token from future requests
workspace.logout()