Skip to content

Commit

Permalink
Use stdin for search and cleanup for presentation in Essentials
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddelkoop committed Nov 10, 2021
1 parent ca580df commit 31cf78a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion landsat/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ sudo apt install --yes git
git clone https://github.internet2.edu/CLASS/CLASS-Examples.git
cd CLASS-Examples/landsat/
bash get-index.sh
python3 search.py | bash download.sh
cat data/index.csv | python3 search.py | bash download.sh
```
5 changes: 2 additions & 3 deletions landsat/download.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/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
# -n no-clobber (do not re-download data)
# -r recursive (download all the data in the specified URL)
gsutil -m cp -n -r "${URL}/" data/
done
6 changes: 2 additions & 4 deletions landsat/search.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"top": 38.99,
"bottom":38.79,
"left": -92.56,
"right": -92.36,
"lat": 38.899313,
"lon": -92.464562,
"landsat": "LANDSAT_8"
}
35 changes: 7 additions & 28 deletions landsat/search.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
#!/usr/bin/python3
import json
import csv
import sys

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

# Example: 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']
lat,lon=config['lat'],config['lon']
landsat=config['landsat']

# 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
reader=csv.reader(sys.stdin)
header=next(reader) # skip header
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 and SPACECRAFT_ID==landsat:
if DEBUG: print(west,left,east,right,north,top,south,bottom,WRS_PATH,WRS_ROW,BASE_URL)
if SPACECRAFT_ID==landsat and north >= lat and south <= lat and west <= lon and east >= lon:
print(BASE_URL) # output BASE_URL

0 comments on commit 31cf78a

Please sign in to comment.