-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import landsat example from tutorials
- Loading branch information
1 parent
d2b3b3d
commit 8bf98f0
Showing
7 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.DS_Store | ||
.venv/ | ||
.vscode/ | ||
credentials* | ||
config* | ||
token* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# LandSat tutorial for Essentials | ||
|
||
General data mananagement for landsat using native GCP tools. | ||
|
||
https://cloud.google.com/storage/docs/public-datasets/landsat | ||
|
||
|
||
Modeling after the Drew use-case. | ||
|
||
https://www.pnas.org/content/118/15/e2021219118#sec-6 | ||
|
||
|
||
## Stage Zero | ||
|
||
Drew has identified the products by hand and manually downloaded the data files. | ||
|
||
## Stage One | ||
|
||
Access data via command line tools. Get the index and view. | ||
|
||
``` | ||
mkdir -v data | ||
gsutil ls gs://gcp-public-data-landsat | ||
gsutil cp gs://gcp-public-data-landsat/index.csv.gz data/ | ||
gzip -d index.csv.gz | ||
``` | ||
|
||
## Stage Three | ||
|
||
Automate | ||
``` | ||
bash get-index.sh | ||
python3 search.py | bash download.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
echo "=== clean.sh" | ||
rm -v -f data/index* | ||
rm -v -rf data/L* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Read space separated URL from STDIN and download | ||
# -r do not interpret backslashes as an escape | ||
while read -r URL ; do | ||
echo "+++ $URL" | ||
# -m parallel | ||
# -n no-clobber | ||
# -r recursive | ||
gsutil -m cp -n -r "${URL}/" data/ | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
echo "=== get-index.sh" | ||
|
||
## Check connection by doing an ls | ||
gsutil ls gs://gcp-public-data-landsat | ||
|
||
## if the data is not there, get it and uncompress it | ||
if [ ! -r data/index.csv ] ; then | ||
mkdir -v data | ||
gsutil cp gs://gcp-public-data-landsat/index.csv.gz data/ | ||
gzip -d data/index.csv.gz | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"top": 38.99, | ||
"bottom":38.79, | ||
"left": -92.56, | ||
"right": -92.36 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/python3 | ||
import json | ||
import csv | ||
|
||
DEBUG=False | ||
LIMIT=1000 | ||
|
||
## Example search | ||
# Search for the Burr Oak Tree | ||
# * 38.899313,-92.464562 (Lat north+, Long west-) | ||
# * Landsat: Path 025, Row 033 | ||
|
||
config=json.load(open("search.json")) | ||
left=config['left'] | ||
right=config['right'] | ||
top=config['top'] | ||
bottom=config['bottom'] | ||
|
||
# SCENE_ID,PRODUCT_ID,SPACECRAFT_ID,SENSOR_ID,DATE_ACQUIRED,COLLECTION_NUMBER,COLLECTION_CATEGORY,SENSING_TIME,DATA_TYPE,WRS_PATH,WRS_ROW,CLOUD_COVER,NORTH_LAT,SOUTH_LAT,WEST_LON,EAST_LON,TOTAL_SIZE,BASE_URL | ||
reader=csv.reader(open("data/index.csv")) | ||
header=next(reader) | ||
count=0 | ||
|
||
# Iterate through CSV and print matching product BASE_URL | ||
for l in reader: | ||
count+=1 | ||
if DEBUG and count>=LIMIT: | ||
break | ||
|
||
# Extract data | ||
SCENE_ID,PRODUCT_ID,SPACECRAFT_ID,SENSOR_ID,DATE_ACQUIRED,COLLECTION_NUMBER,COLLECTION_CATEGORY,SENSING_TIME,DATA_TYPE,WRS_PATH,WRS_ROW,CLOUD_COVER,NORTH_LAT,SOUTH_LAT,WEST_LON,EAST_LON,TOTAL_SIZE,BASE_URL=l | ||
west,east=float(WEST_LON),float(EAST_LON) | ||
north,south=float(NORTH_LAT),float(SOUTH_LAT) | ||
if DEBUG: print(west,left,east,right,north,top,south,bottom) | ||
|
||
# Test if box is contained-ish by image | ||
if west <= left and east >= right and north >= top and south <= bottom: | ||
if DEBUG: print(west,left,east,right,north,top,south,bottom,WRS_PATH,WRS_ROW,BASE_URL) | ||
print(BASE_URL) # output BASE_URL |