Open Source Pipeline for UAS and satellite based High Throughput Phenotyping Applications - Part 2
This notebook is designed for workshop presented at the International Plant Phenotyping Network (IPPN) conference on October 7, 2024. Click the Open in Colab button above to run this notebook interactively in the cloud. For Part 1 of the workshop, please visit this link.
Registration: https://www.plant-phenotyping.org/index.php?index=935
Earth Engine: https://earthengine.google.com
Geemap: https://geemap.org
Leafmap: https://leafmap.org
Samgeo: https://samgeo.gishub.org
Data to Science (D2S): https://ps2.d2s.org
D2S Python API: https://py.d2s.org
Acknowledgments
This training material was partially supported by the National Agricultural Producers Data Cooperative (USDA award 2023-77039-41033; Sub-award 25-6231-0428-008).
Introduction
Recent advances in sensor technology have revolutionized the assessment of crop health by providing fine spatial and high temporal resolutions at affordable costs. As plant scientists gain access to increasingly larger volumes of Unmanned Aerial Systems (UAS) and satellite High Throughput Phenotyping (HTP) data, there is a growing need to extract biologically informative and quantitative phenotypic information from the vast amount of freely available geospatial data. However, the lack of specialized software packages tailored for processing such data makes it challenging to develop transdisciplinary research collaboration around these data. This workshop aims to bridge the gap between big data and agricultural research scientists by providing training on an open-source online platform for managing big UAS HTP data known as Data to Science. Additionally, attendees will be introduced to powerful Python packages, namely leafmap and Leafmap, designed for the seamless integration and analysis of UAS and satellite images in various agricultural applications. By participating in this workshop, attendees will acquire the skills necessary to efficiently search, visualize, and analyze geospatial data within a Jupyter environment, even with minimal coding experience. The workshop provides a hands-on learning experience through practical examples and interactive exercises, enabling participants to enhance their proficiency and gain valuable insights into leveraging geospatial data for agricultural research purposes.
Agenda
The main topics to be covered in this workshop include:
Create interactive maps using leafmap
Visualize drone imagery from D2S
Segment drone imagery using samgeo
Calculate zonal statistics from drone imagery
Visualize Earth Engine data
Create timelapse animations
Environment setup
Change Colab dark theme
Currently, ipywidgets does not work well with Colab dark theme. Some of the leafmap widgets may not display properly in Colab dark theme.It is recommended that you change Colab to the light theme.
Install packages
Uncomment the following code to install the required packages.
Import libraries
Import the necessary libraries for this workshop.
Creating interactive maps
Let's create an interactive map using the ipyleaflet plotting backend. The leafmap.Map class inherits the ipyleaflet.Map class. Therefore, you can use the same syntax to create an interactive map as you would with ipyleaflet.Map.
To display it in a Jupyter notebook, simply ask for the object representation:
To customize the map, you can specify various keyword arguments, such as center ([lat, lon]), zoom, width, and height. The default width is 100%, which takes up the entire cell width of the Jupyter notebook. The height argument accepts a number or a string. If a number is provided, it represents the height of the map in pixels. If a string is provided, the string must be in the format of a number followed by px, e.g., 600px.
Adding basemaps
There are several ways to add basemaps to a map. You can specify the basemap to use in the basemap keyword argument when creating the map. Alternatively, you can add basemap layers to the map using the add_basemap method. leafmap has hundreds of built-in basemaps available that can be easily added to the map with only one line of code.
Create a map by specifying the basemap to use as follows. For example, the Esri.WorldImagery basemap represents the Esri world imagery basemap.
You can add as many basemaps as you like to the map. For example, the following code adds the OpenTopoMap basemap to the map above:
You can also add an XYZ tile layer to the map.
You can also change basemaps interactively using the basemap GUI.
Visualizing Drone Imagery from D2S
The Data to Science (D2S) platform (https://ps2.d2s.org) hosts a large collection of drone imagery that can be accessed through the D2S API (https://py.d2s.org). To visualize drone imagery from D2S, you need to sign up for a free account on the D2S platform and obtain an API key.
Login to D2S
Login and connect to your D2S workspace in one go using the d2spy.
Choose a project to work with
The Workspace get_projects method will retrieve a collection of the projects your account can currently access on the D2S instance.
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.
Now you can choose a specific project to work with. In this case, the filtered projects returned only one project, so we will use that project.
Get the project boundary
get_project_boundary method of the Project class will retrieve a GeoJSON object of the project boundary.
Get project flights
The Project get_flights method will retrieve a list of flights associated with the project.
Now, we can choose a flight from the filtered flight. Let's choose the flight on June 8, 2023.
Get data products
The Flight get_data_products method will retrieve a list of data products associated with the flight.
The data_products variable is a DataProductCollection. The collection can be filtered by data type using the method filter_by_data_type. This method will return all data products that match the requested data type.
Visualize ortho imagery
Now we can grab the ortho URL to display it using leafmap.
Add the project boundary to the map.
Add grid boundaries to the map.
Visualizing Earth Engine data
Authenticate and initialize Earth Engine
You will need to create a Google Cloud Project and enable the Earth Engine API for the project. You can find detailed instructions here.
Login to Earth Engine JavaScript Code Editor at https://code.earthengine.google.com and click on th profile icon at the top right. Remember the project ID listed in the dialog that appears. Uncomment the following code block and replace YOUR_PROJECT_ID with your project ID.
Then, run the code block to authenticate and initialize the Earth Engine Python API.