From 31cf78a4e6d68e56a28521e76bc1e34cf08d9fa1 Mon Sep 17 00:00:00 2001 From: Timothy Middelkoop Date: Wed, 10 Nov 2021 22:29:07 +0000 Subject: [PATCH] Use stdin for search and cleanup for presentation in Essentials --- landsat/ReadMe.md | 2 +- landsat/download.sh | 5 ++--- landsat/search.json | 6 ++---- landsat/search.py | 35 +++++++---------------------------- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/landsat/ReadMe.md b/landsat/ReadMe.md index 116555f..9a51147 100644 --- a/landsat/ReadMe.md +++ b/landsat/ReadMe.md @@ -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 ``` diff --git a/landsat/download.sh b/landsat/download.sh index 78feb09..133f99a 100644 --- a/landsat/download.sh +++ b/landsat/download.sh @@ -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 diff --git a/landsat/search.json b/landsat/search.json index 7bf77f2..ef3afa4 100644 --- a/landsat/search.json +++ b/landsat/search.json @@ -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" } diff --git a/landsat/search.py b/landsat/search.py index 02ca0c3..a23421b 100644 --- a/landsat/search.py +++ b/landsat/search.py @@ -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