Skip to content

Commit

Permalink
Import landsat example from tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddelkoop committed Nov 9, 2021
1 parent d2b3b3d commit 8bf98f0
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
.venv/
.vscode/
credentials*
config*
token*
Expand Down
34 changes: 34 additions & 0 deletions landsat/ReadMe.md
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
```
5 changes: 5 additions & 0 deletions landsat/clean.sh
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*
11 changes: 11 additions & 0 deletions landsat/download.sh
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
13 changes: 13 additions & 0 deletions landsat/get-index.sh
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
6 changes: 6 additions & 0 deletions landsat/search.json
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
}
39 changes: 39 additions & 0 deletions landsat/search.py
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

0 comments on commit 8bf98f0

Please sign in to comment.