[GRASS-SVN] r70695 - grass-promo/tutorials/batch_processing/earthquakes
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 27 19:01:41 PST 2017
Author: hamish
Date: 2017-02-27 19:01:41 -0800 (Mon, 27 Feb 2017)
New Revision: 70695
Modified:
grass-promo/tutorials/batch_processing/earthquakes/do_quakes_latlon.sh
grass-promo/tutorials/batch_processing/earthquakes/do_quakes_wintri.sh
Log:
adjust to USGS API changes as detailed on their announce listserv:
https://geohazards.usgs.gov/pipermail/realtime-feeds/
Modified: grass-promo/tutorials/batch_processing/earthquakes/do_quakes_latlon.sh
===================================================================
--- grass-promo/tutorials/batch_processing/earthquakes/do_quakes_latlon.sh 2017-02-27 15:35:23 UTC (rev 70694)
+++ grass-promo/tutorials/batch_processing/earthquakes/do_quakes_latlon.sh 2017-02-28 03:01:41 UTC (rev 70695)
@@ -16,8 +16,9 @@
#
# Earthquake data is downloaded from the USGS
# http://neic.usgs.gov/neis/gis/bulletin.asc (defunct)
-# new1: http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt
-# new2: http://earthquake.usgs.gov/earthquakes/feed/csv/2.5/week
+# new1: http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt (defunct)
+# new2: http://earthquake.usgs.gov/earthquakes/feed/csv/2.5/week (defunct)
+# new3: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.csv
#
if [ -z "$GISBASE" ] ; then
@@ -48,31 +49,40 @@
### download and import
-wget -nv -O "eqs7day-M2.5.csv" \
- "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt" 2>&1
+wget -nv -O "eqs7day-M2.5.raw" \
+ "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.csv" 2>&1
if [ $? -ne 0 ] ; then
echo "Failed to download data from the USGS." >&2
exit 1
fi
+# just the basics
+cut -d',' -f1-6 eqs7day-M2.5.raw > eqs7day-M2.5.csv
+rm eqs7day-M2.5.raw
+
#convert commas+quoting to pipe delims:
csv_dequote.pl eqs7day-M2.5.csv
# add a '#' at the start of the first line and remove spurious whitespace
-sed -i -e '0,/^/s//#/' \
- -e 's+| \([0-9]\)|+|\1|+' eqs7day-M2.5.psv
+# -e '1,/^/s//#/'
+mv eqs7day-M2.5.psv eqs7day-M2.5.psv.in
-# eqs7day-M2.5.txt format:
-#Src,EqId,Version,Datetime,Lat,Lon,Magnitude,Depth,NST,Region
+sed -e '0,/^/s//#/' -e 's/^Date/#Date/' \
+ -e 's+| \([0-9]\)|+|\1|+' \
+ eqs7day-M2.5.psv.in > eqs7day-M2.5.psv
-COL_DEF="data_source varchar(4), eq_id varchar(10), version varchar(3),
- eq_time varchar(50), latitude double precision, longitude double precision, \
- magnitude double precision, depth double precision, num_stations_obs integer,
- region varchar(255)"
+rm eqs7day-M2.5.psv.in
+
+# eqs7day-M2.5.csv format:
+#DateTime,Latitude,Longitude,Depth,Magnitude,MagType,NbStations,Gap,Distance,RMS,Source,EventID,Version
+#https://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php
+
+COL_DEF="eq_time varchar(50), latitude double precision, longitude double precision, \
+ depth double precision, magnitude double precision, magn_type varchar(7)"
+
INPUT="$TMPDIR/eqs7day-M2.5.psv"
-
db.connect -c
DBDRIVER=`db.connect -p | grep '^driver:' | cut -f2 -d:`
@@ -83,7 +93,7 @@
fi
v.in.ascii in="$INPUT" out=recent_earthquakes skip=1 \
- fs='|' y=5 x=6 z=8 column="$COL_DEF" --overwrite
+ fs='|' y=2 x=3 z=4 column="$COL_DEF" --overwrite
### unlog & scale magnitude
@@ -112,7 +122,7 @@
# get the timestamp
-YMD=`head -n 2 "$INPUT" | tail -n 1 | cut -f4 -d'|' | awk '{print $2,$3,$4}'`
+YMD=`head -n 3 "$INPUT" | tail -n 1 | cut -f1 -d'T' | tr '-' '/'`
if [ `echo "$YMD" | wc -c` -lt 11 ] ; then
echo "Bad timestamp ($YMD). Using system date instead." >&2
YMD=`date +%Y/%m/%d`
@@ -201,7 +211,7 @@
cp -f earthquakes.png earthquakes*.jpg "$WEBDIR/"
# Output KML file.
-# Possible todo: make fancy with Peter Loewe's more advanced v.out.kml addon script
+#TODO: make fancy with Peter Loewe's more advanced v.out.kml addon script
v.out.ogr in=recent_earthquakes dsn=recent_earthquakes.kml \
format=KML type=point
zip -q recent_earthquakes.zip recent_earthquakes.kml
@@ -215,3 +225,4 @@
# all done.
exit 0
+
Modified: grass-promo/tutorials/batch_processing/earthquakes/do_quakes_wintri.sh
===================================================================
--- grass-promo/tutorials/batch_processing/earthquakes/do_quakes_wintri.sh 2017-02-27 15:35:23 UTC (rev 70694)
+++ grass-promo/tutorials/batch_processing/earthquakes/do_quakes_wintri.sh 2017-02-28 03:01:41 UTC (rev 70695)
@@ -17,8 +17,9 @@
#
# Earthquake data is downloaded from the USGS
# http://neic.usgs.gov/neis/gis/bulletin.asc (defunct)
-# new1: http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt
-# new2: http://earthquake.usgs.gov/earthquakes/feed/csv/2.5/week
+# new1: http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt (defunct)
+# new2: http://earthquake.usgs.gov/earthquakes/feed/csv/2.5/week (defunct)
+# new3: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.csv
#
if [ -z "$GISBASE" ] ; then
@@ -49,32 +50,40 @@
### download and import
-wget -nv -O "eqs7day-M2.5.csv" \
- "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt" 2>&1
+wget -nv -O "eqs7day-M2.5.raw" \
+ "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.csv" 2>&1
if [ $? -ne 0 ] ; then
echo "Failed to download data from the USGS." >&2
exit 1
fi
+# just the basics
+cut -d',' -f1-6 eqs7day-M2.5.raw > eqs7day-M2.5.csv
+rm eqs7day-M2.5.raw
+
#convert commas+quoting to pipe delims:
csv_dequote.pl eqs7day-M2.5.csv
INPUT="$TMPDIR/eqs7day-M2.5.psv"
+mv "$INPUT" "$INPUT.in"
# add a '#' at the start of the first line and remove spurious whitespace
-sed -i -e '0,/^/s//#/' \
- -e 's+| \([0-9]\)|+|\1|+' "$INPUT"
+sed -e '0,/^/s//#/' -e 's/^Date/#Date/' \
+ -e 's+| \([0-9]\)|+|\1|+' \
+ "$INPUT.in" > "$INPUT"
-# eqs7day-M2.5.txt format:
-#Src,EqId,Version,Datetime,Lat,Lon,Magnitude,Depth,NST,Region
-
-COL_DEF="data_source varchar(4), eq_id varchar(10), version varchar(3),
- eq_time varchar(50), latitude double precision, longitude double precision, \
- magnitude double precision, depth double precision, num_stations_obs integer,
- region varchar(255)"
+rm "$INPUT.in"
-cut -f5,6 -d'|' "$INPUT" | awk -F'|' '{print $2 "\t" $1}' | \
+# eqs7day-M2.5.csv format:
+#DateTime,Latitude,Longitude,Depth,Magnitude,MagType,NbStations,Gap,Distance,RMS,Source,EventID,Version
+#https://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php
+
+COL_DEF="eq_time varchar(50), latitude double precision, longitude double precision, \
+ depth double precision, magnitude double precision, magn_type varchar(7)"
+
+
+cut -f2,3 -d'|' "$INPUT" | awk -F'|' '{print $2 "\t" $1}' | \
m.proj -ig fs='|' | cut -f1,2 -d'|' | \
awk '{if (NR!=1) {print} else {print "easting|northing"}}' \
> "$INPUT.wintri.coord"
@@ -93,7 +102,7 @@
fi
v.in.ascii in="$INPUT.wintri" out=recent_earthquakes skip=1 \
- fs='|' x=11 y=12 z=8 column="$COL_DEF" --overwrite
+ fs='|' x=7 y=8 z=4 column="$COL_DEF" --overwrite
### unlog & scale magnitude
@@ -123,7 +132,7 @@
# get the timestamp
#YMD=20`tail -n 1 "$INPUT" | cut -f1 -d,`
-YMD=`head -n 2 "$INPUT" | tail -n 1 | cut -f4 -d'|' | awk '{print $2,$3,$4}'`
+YMD=`head -n 3 "$INPUT" | tail -n 1 | cut -f1 -d'T' | tr '-' '/'`
if [ `echo "$YMD" | wc -c` -lt 11 ] ; then
echo "Bad timestamp ($YMD). Using system date instead." >&2
YMD=`date +%Y/%m/%d`
@@ -221,3 +230,4 @@
# all done.
exit 0
+
More information about the grass-commit
mailing list