{ "cells": [ { "cell_type": "markdown", "id": "4546538a-bbfe-4ddd-a121-db773e2dd676", "metadata": {}, "source": [ "# Search and Download\n", "\n", "This example notebook walks through the steps for searching and downloading PlanetScope imagery using the planetsca library.\n", "\n", "You will need a user account with Planet, and your own [API key](https://developers.planet.com/quickstart/apis/#find-your-api-key) to use these functions." ] }, { "cell_type": "code", "execution_count": 1, "id": "3235db75-6bed-4c70-af0b-3a0372c78499", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/jovyan/envs/planetenv/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import planetsca as ps" ] }, { "cell_type": "code", "execution_count": 2, "id": "b4790b25-1b72-4b98-b912-3215123ae4f6", "metadata": {}, "outputs": [], "source": [ "api_key = \"YOUR_API_KEY_HERE\" # provide you Planet API key here" ] }, { "cell_type": "markdown", "id": "cdef64b0-9021-4f41-99a8-443304acc059", "metadata": {}, "source": [ "## Searching for Planet imagery" ] }, { "cell_type": "markdown", "id": "9c8939e5-9cc2-4fed-9adb-c44b876e45b4", "metadata": {}, "source": [ "Set up a filter to search a specific time range and region, and to avoid cloudy images:" ] }, { "cell_type": "code", "execution_count": 3, "id": "a9567970-258b-44b1-92de-805879b79e65", "metadata": {}, "outputs": [], "source": [ "# filter images acquired in a certain date range\n", "date_range_filter = ps.search.make_date_range_filter(\n", " \"2024-01-15T00:00:00.000Z\", \"2024-01-31T00:00:00.000Z\"\n", ")" ] }, { "cell_type": "markdown", "id": "64e5598f-dfc8-490d-a368-627cbf5f470d", "metadata": {}, "source": [ "There are two options for specifying a region to search: creating a \"geometry filter\" from lat and lon bounding coordinates, or creating a \"geometry filter\" from a geojson file." ] }, { "cell_type": "code", "execution_count": 4, "id": "a1f0a035-299a-4eb5-ba92-eea1813399d0", "metadata": {}, "outputs": [], "source": [ "# Example for defining an area of interest from bounds\n", "minLon = -105.88\n", "minLat = 40.51\n", "maxLon = -105.87\n", "maxLat = 40.52\n", "\n", "# make a geometry filter with these bounding coordinates\n", "geometry_filter = ps.search.make_geometry_filter_from_bounds(\n", " [minLon, minLat, maxLon, maxLat]\n", ")\n", "\n", "\n", "# Alternatively, define area of interest from a geojson file\n", "# geometry_filter = ps.search.make_geometry_filter_from_geojson('my_study_area.geojson')" ] }, { "cell_type": "markdown", "id": "59875ef5-ff8b-4a37-afd2-94b355f94766", "metadata": {}, "source": [ "Add a cloud cover percentage filter" ] }, { "cell_type": "code", "execution_count": 5, "id": "f94679ad-4a58-4c23-a51b-40328405d53a", "metadata": {}, "outputs": [], "source": [ "cloud_filter = ps.search.make_cloud_cover_filter(\n", " 0.05\n", ") # filter any images which are more than 5% clouds" ] }, { "cell_type": "markdown", "id": "8901d0ec-105b-47cf-a3a5-0932aa29d7fb", "metadata": {}, "source": [ "Finally, create a filter that combines our geometry, date, and cloud filters" ] }, { "cell_type": "code", "execution_count": 6, "id": "1e41c858-e7aa-4391-a5bb-aa5c43599c46", "metadata": {}, "outputs": [], "source": [ "filter = ps.search.combine_filters([date_range_filter, geometry_filter, cloud_filter])" ] }, { "cell_type": "markdown", "id": "be6ee4e9-41b7-4aed-8f47-3b695aae0380", "metadata": {}, "source": [ "Submit our search to the Planet API. This returns a geopandas.GeoDataFrame with information about the images that match our filter criteria" ] }, { "cell_type": "code", "execution_count": 7, "id": "cd2f612d-7570-4a33-9c9c-9f98a9a9b724", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search returned 8 items.\n" ] } ], "source": [ "search_results_gdf = ps.search.search(api_key, filter)" ] }, { "cell_type": "code", "execution_count": 8, "id": "c5fd449e-e110-4421-b7e1-3a9ad831d870", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | geometry | \n", "acquired | \n", "anomalous_pixels | \n", "clear_confidence_percent | \n", "clear_percent | \n", "cloud_cover | \n", "cloud_percent | \n", "ground_control | \n", "gsd | \n", "heavy_haze_percent | \n", "... | \n", "strip_id | \n", "sun_azimuth | \n", "sun_elevation | \n", "updated | \n", "view_angle | \n", "visible_confidence_percent | \n", "visible_percent | \n", "intersection_area | \n", "overlap_percentage | \n", "id | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "POLYGON ((-106.19821 40.69052, -106.24418 40.5... | \n", "2024-01-30T17:48:24.24349Z | \n", "0 | \n", "66 | \n", "14 | \n", "0.00 | \n", "0 | \n", "True | \n", "3.5 | \n", "0 | \n", "... | \n", "7075747 | \n", "156.3 | \n", "28.4 | \n", "2024-02-01T03:58:16Z | \n", "5.0 | \n", "65 | \n", "100 | \n", "0.000051 | \n", "50.644997 | \n", "20240130_174824_24_2484 | \n", "
1 | \n", "POLYGON ((-105.94697 40.5751, -105.99321 40.41... | \n", "2024-01-27T17:49:51.954811Z | \n", "0 | \n", "65 | \n", "29 | \n", "0.01 | \n", "1 | \n", "True | \n", "3.5 | \n", "0 | \n", "... | \n", "7068597 | \n", "157.0 | \n", "27.9 | \n", "2024-01-28T06:11:48Z | \n", "2.0 | \n", "61 | \n", "99 | \n", "0.000100 | \n", "100.000000 | \n", "20240127_174951_95_247d | \n", "
2 | \n", "POLYGON ((-105.88645 40.55067, -105.93283 40.3... | \n", "2024-01-27T17:42:51.03811Z | \n", "0 | \n", "64 | \n", "29 | \n", "0.03 | \n", "3 | \n", "True | \n", "3.6 | \n", "0 | \n", "... | \n", "7068561 | \n", "155.6 | \n", "27.5 | \n", "2024-01-28T06:09:20Z | \n", "5.0 | \n", "60 | \n", "97 | \n", "0.000100 | \n", "100.000000 | \n", "20240127_174251_03_227a | \n", "
3 | \n", "POLYGON ((-105.85123 40.6801, -105.89698 40.51... | \n", "2024-01-27T17:42:48.998661Z | \n", "0 | \n", "63 | \n", "23 | \n", "0.00 | \n", "0 | \n", "True | \n", "3.6 | \n", "0 | \n", "... | \n", "7068561 | \n", "155.7 | \n", "27.4 | \n", "2024-01-28T06:09:20Z | \n", "5.0 | \n", "59 | \n", "100 | \n", "0.000100 | \n", "100.000000 | \n", "20240127_174248_99_227a | \n", "
4 | \n", "POLYGON ((-106.1921 40.68607, -106.24563 40.50... | \n", "2024-01-23T17:07:24.191323Z | \n", "0 | \n", "56 | \n", "17 | \n", "0.03 | \n", "3 | \n", "True | \n", "3.9 | \n", "0 | \n", "... | \n", "7060077 | \n", "146.6 | \n", "22.8 | \n", "2024-01-24T06:13:56Z | \n", "4.0 | \n", "58 | \n", "97 | \n", "0.000100 | \n", "100.000000 | \n", "20240123_170724_19_24bc | \n", "
5 | \n", "POLYGON ((-106.03646 40.70049, -106.09005 40.5... | \n", "2024-01-16T17:07:00.243012Z | \n", "0 | \n", "40 | \n", "1 | \n", "0.03 | \n", "3 | \n", "True | \n", "3.9 | \n", "0 | \n", "... | \n", "7045035 | \n", "147.8 | \n", "21.6 | \n", "2024-01-17T09:58:34Z | \n", "5.0 | \n", "56 | \n", "97 | \n", "0.000100 | \n", "100.000000 | \n", "20240116_170700_24_24b0 | \n", "
6 | \n", "POLYGON ((-105.84943 40.62474, -105.89752 40.4... | \n", "2024-01-16T17:49:47.733879Z | \n", "0 | \n", "47 | \n", "12 | \n", "0.04 | \n", "4 | \n", "True | \n", "3.5 | \n", "0 | \n", "... | \n", "7045173 | \n", "158.1 | \n", "25.5 | \n", "2024-01-17T05:31:17Z | \n", "5.0 | \n", "54 | \n", "96 | \n", "0.000100 | \n", "100.000000 | \n", "20240116_174947_73_2483 | \n", "
7 | \n", "POLYGON ((-105.8839 40.65978, -105.93455 40.47... | \n", "2024-01-16T17:01:56.418635Z | \n", "0 | \n", "50 | \n", "6 | \n", "0.00 | \n", "0 | \n", "True | \n", "3.9 | \n", "0 | \n", "... | \n", "7045016 | \n", "147.5 | \n", "21.7 | \n", "2024-01-17T05:37:04Z | \n", "3.5 | \n", "53 | \n", "100 | \n", "0.000100 | \n", "100.000000 | \n", "20240116_170156_41_24c1 | \n", "
8 rows × 32 columns
\n", "\n", " | geometry | \n", "acquired | \n", "anomalous_pixels | \n", "clear_confidence_percent | \n", "clear_percent | \n", "cloud_cover | \n", "cloud_percent | \n", "ground_control | \n", "gsd | \n", "heavy_haze_percent | \n", "... | \n", "strip_id | \n", "sun_azimuth | \n", "sun_elevation | \n", "updated | \n", "view_angle | \n", "visible_confidence_percent | \n", "visible_percent | \n", "intersection_area | \n", "overlap_percentage | \n", "id | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "POLYGON ((-106.19821 40.69052, -106.24418 40.5... | \n", "2024-01-30T17:48:24.24349Z | \n", "0 | \n", "66 | \n", "14 | \n", "0.00 | \n", "0 | \n", "True | \n", "3.5 | \n", "0 | \n", "... | \n", "7075747 | \n", "156.3 | \n", "28.4 | \n", "2024-02-01T03:58:16Z | \n", "5.0 | \n", "65 | \n", "100 | \n", "0.000051 | \n", "50.644997 | \n", "20240130_174824_24_2484 | \n", "
1 | \n", "POLYGON ((-105.94697 40.5751, -105.99321 40.41... | \n", "2024-01-27T17:49:51.954811Z | \n", "0 | \n", "65 | \n", "29 | \n", "0.01 | \n", "1 | \n", "True | \n", "3.5 | \n", "0 | \n", "... | \n", "7068597 | \n", "157.0 | \n", "27.9 | \n", "2024-01-28T06:11:48Z | \n", "2.0 | \n", "61 | \n", "99 | \n", "0.000100 | \n", "100.000000 | \n", "20240127_174951_95_247d | \n", "
2 | \n", "POLYGON ((-105.88645 40.55067, -105.93283 40.3... | \n", "2024-01-27T17:42:51.03811Z | \n", "0 | \n", "64 | \n", "29 | \n", "0.03 | \n", "3 | \n", "True | \n", "3.6 | \n", "0 | \n", "... | \n", "7068561 | \n", "155.6 | \n", "27.5 | \n", "2024-01-28T06:09:20Z | \n", "5.0 | \n", "60 | \n", "97 | \n", "0.000100 | \n", "100.000000 | \n", "20240127_174251_03_227a | \n", "
3 | \n", "POLYGON ((-105.85123 40.6801, -105.89698 40.51... | \n", "2024-01-27T17:42:48.998661Z | \n", "0 | \n", "63 | \n", "23 | \n", "0.00 | \n", "0 | \n", "True | \n", "3.6 | \n", "0 | \n", "... | \n", "7068561 | \n", "155.7 | \n", "27.4 | \n", "2024-01-28T06:09:20Z | \n", "5.0 | \n", "59 | \n", "100 | \n", "0.000100 | \n", "100.000000 | \n", "20240127_174248_99_227a | \n", "
4 | \n", "POLYGON ((-106.1921 40.68607, -106.24563 40.50... | \n", "2024-01-23T17:07:24.191323Z | \n", "0 | \n", "56 | \n", "17 | \n", "0.03 | \n", "3 | \n", "True | \n", "3.9 | \n", "0 | \n", "... | \n", "7060077 | \n", "146.6 | \n", "22.8 | \n", "2024-01-24T06:13:56Z | \n", "4.0 | \n", "58 | \n", "97 | \n", "0.000100 | \n", "100.000000 | \n", "20240123_170724_19_24bc | \n", "
5 | \n", "POLYGON ((-106.03646 40.70049, -106.09005 40.5... | \n", "2024-01-16T17:07:00.243012Z | \n", "0 | \n", "40 | \n", "1 | \n", "0.03 | \n", "3 | \n", "True | \n", "3.9 | \n", "0 | \n", "... | \n", "7045035 | \n", "147.8 | \n", "21.6 | \n", "2024-01-17T09:58:34Z | \n", "5.0 | \n", "56 | \n", "97 | \n", "0.000100 | \n", "100.000000 | \n", "20240116_170700_24_24b0 | \n", "
6 | \n", "POLYGON ((-105.84943 40.62474, -105.89752 40.4... | \n", "2024-01-16T17:49:47.733879Z | \n", "0 | \n", "47 | \n", "12 | \n", "0.04 | \n", "4 | \n", "True | \n", "3.5 | \n", "0 | \n", "... | \n", "7045173 | \n", "158.1 | \n", "25.5 | \n", "2024-01-17T05:31:17Z | \n", "5.0 | \n", "54 | \n", "96 | \n", "0.000100 | \n", "100.000000 | \n", "20240116_174947_73_2483 | \n", "
7 | \n", "POLYGON ((-105.8839 40.65978, -105.93455 40.47... | \n", "2024-01-16T17:01:56.418635Z | \n", "0 | \n", "50 | \n", "6 | \n", "0.00 | \n", "0 | \n", "True | \n", "3.9 | \n", "0 | \n", "... | \n", "7045016 | \n", "147.5 | \n", "21.7 | \n", "2024-01-17T05:37:04Z | \n", "3.5 | \n", "53 | \n", "100 | \n", "0.000100 | \n", "100.000000 | \n", "20240116_170156_41_24c1 | \n", "
8 rows × 32 columns
\n", "