Ordering Planet Data - porder (older)
Derived from: https://samapriya.github.io/projects/porder/
To install:
pip install planet
planet init
log in with usename/password credentials
pip install porder
Ensure you have your API KEY set up (may not be necessary if logged in as above).
Set this as a system variable
In python:
os.environ['PL_API_KEY']='12345'
In BASH:
PL_API_KEY = '12345'
Confirm quota
porder quota
Make list of scenes to order
porder idlist --input /Users/dan.sousa/Downloads/map.geojson --start 2010-01-01 --end 2019-01-01 --item PSOrthoTile --cmin 0 --cmax 10 --overlap 100 --asset analytic_sr --outfile /Users/dan.sousa/Downloads/PlanetBocaRio_2010_2019.csv
--input specifies bounding extent (vector)
--item specifies the dataset type (PSScene4Band or orthotile; 3 or 4 or 8 band)
--asset specifies the processing type (analytic_sr is surface reflectance; analytic is TOA)
--outfile is the output of the scene list
--cmin and --cmax are cloud cover (% of scene)
--overlap (% of polygon that is covered by each image)
Split the list if it's too long
porder idsplit --idlist "/Users/dan.sousa/Downloads/PlanetBocaRio_2010_2019.csv" --lines "500" --local "/Users/dan.sousa/Downloads/PlanetBocaRio_2010_2019_Split"
--local is a directory in which to write the sublists
Order the data
porder order --name "BocaRio_2010_2019_1" --idlist "/Users/dan.sousa/Downloads/PlanetBocaRio_2010_2019_Split/PlanetBocaRio_2010_2019_500.csv " --item "PSOrthoTile" --bundle "analytic_sr_udm2" --boundary "/Users/dan.sousa/Downloads/map.geojson" --op clip evi2 ndwi email
--name is the Order Name
--idlist is the path to the scene list
--item is the dataset type
--bundle is the set of files sent with each image
--boundary is the polygon with the spatial extent (if being clipped)
--op specifies the operations happening to the data before download
'clip' clips them to the spatial extent of the 'boundary'
'email' sends you an email notification once the data are ready for download
Other options include spectral indices: ndvi|gndvi|bndvi|ndwi|tvi|osavi|evi2|msavi2|sr
Or in a loop:
for i in /Users/dan.sousa/Downloads/BrianaPlanet/PM3km_B1*.geojson; do porder idlist --input ${i} --start 2016-01-01 --end 2017-12-31 --item PSOrthoTile --cmin 0 --cmax 30 --overlap 60 --asset analytic_sr --outfile ${i%????????}_list.csv; done
cd to directory
for i in *.geojson; do porder order --name "${i}" --idlist /Users/dan.sousa/Downloads/BrianaPlanet/${i%????????}_list.csv --item PSOrthoTile --bundle analytic_sr --boundary /Users/dan.sousa/Downloads/BrianaPlanet/${i} --op clip evi2 zip email; done
Once done, get the order URL
porder ostate --state success --start 2023-01-01 --end 2024-01-01
porder ostate --state partial --start 2023-01-01 --end 2024-01-01
Download the files
porder multipart --url https://api.planet.com/compute/ops/orders/v2/xxxxx --local /path/to/download/folder
Convert to common (WGS84) projection and ENVI format
for i in *math.tif; do gdalwarp -t_srs EPSG:4326 -of ENVI ${i} ${i}_e; done
Assumes files of interest end in "math.tif"
WGS-84 (lat/lon) is set using the EPSG code. Pick another if you want a different projection.
Assumes ENVI-formatted output
Pull out 1 of the bands
for i in *_e; do gdal_translate -b 1 -of ENVI ${i} ${i}EVI2; done
Assumes you want band 1. Change the number after -b to change the band
Stack all the single-band images into a single multiband timeseries
gdal_merge.py -o 2020_2021_PlanetSedg_EVI2stack -separate -of ENVI *_eEVI2