Merging changes from life branch.

This commit is contained in:
Kasper D. Fischer 2015-10-01 15:44:23 +00:00
commit 3b5b07968e
Notes: subgit 2018-03-07 17:59:12 +01:00
r839 www/trunk
9 changed files with 65 additions and 26 deletions

View File

@ -1 +1 @@
curl -o events.xml "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?starttime=2014-08-01&orderby=time&minlat=50.92&maxlat=52.76&minlon=4.26&maxlon=9.74&minmag=1.1" curl -o events.xml "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?starttime=2015-04-01&orderby=time&minlat=50.92&maxlat=52.76&minlon=4.26&maxlon=9.74&minmag=1.1"

View File

@ -39,6 +39,8 @@ def mkGeolocationTable(file=''):
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from sys import stdin from sys import stdin
import warnings import warnings
from time import sleep
from geopy.geocoders import Photon
import urllib2 as URL import urllib2 as URL
import json as JSON import json as JSON
@ -51,6 +53,7 @@ def mkGeolocationTable(file=''):
warnings.formatwarning = simple_warning warnings.formatwarning = simple_warning
# try loading the file # try loading the file
geolocationTable = {}
if file : if file :
try: try:
jsonfile = open(file) jsonfile = open(file)
@ -62,6 +65,7 @@ def mkGeolocationTable(file=''):
# parse event.xml # parse event.xml
DOM = ET.parse(stdin).getroot() DOM = ET.parse(stdin).getroot()
geolocator = Photon()
# iterate over all events # iterate over all events
for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces): for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces):
@ -75,9 +79,32 @@ def mkGeolocationTable(file=''):
elif evaluationMode == 'automatic': elif evaluationMode == 'automatic':
warnings.warn('Skipping automatic event %s' %(publicID)) warnings.warn('Skipping automatic event %s' %(publicID))
else: else:
try:
location = geolocator.reverse("{lat}, {lng}".format(lat=lat, lng=lng))
except:
warnings.warn('Reverse Geolocation failed. Skipping event.')
continue
place = []
try:
place = location.raw['properties']['city']
except KeyError:
try:
place = location.raw['properties']['town']
except KeyError:
try:
place = location.raw['properties']['village']
except KeyError:
try:
place = location.raw['properties']['county']
except KeyError:
warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url))
geolocationTable[publicID] = place
sleep(1.1)
'''
#warnings.warn('Processing event %s' %publicID) #warnings.warn('Processing event %s' %publicID)
# send and evaluate nominatim request # send and evaluate nominatim request
url = 'https://open.mapquestapi.com/nominatim/v1/reverse.php?lat={0}&lon={1}&zoom=10&format=json'.format(lat, lng) url = 'https://open.mapquestapi.com/nominatim/v1/reverse.php?key=oE512xGQxeH1n2cueacJ6xzRv7qFlCib&lat={0}&lon={1}&zoom=10&format=json'.format(lat, lng)
response = URL.urlopen(url) response = URL.urlopen(url)
if ( response.msg == 'OK' ): if ( response.msg == 'OK' ):
data = JSON.loads(response.read()) data = JSON.loads(response.read())
@ -106,6 +133,7 @@ def mkGeolocationTable(file=''):
warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url)) warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url))
else: else:
warnings.warn('Request {0} failed'.format(url)) warnings.warn('Request {0} failed'.format(url))
'''
# dump json # dump json
print 'var geolocationTable = '+JSON.dumps(geolocationTable, sort_keys=True)+';' print 'var geolocationTable = '+JSON.dumps(geolocationTable, sort_keys=True)+';'

View File

@ -41,15 +41,18 @@ function addTableRow(row, table) {
/* do reverse geolocation lookup */ /* do reverse geolocation lookup */
function getGeolocation(id, lat, lng) { function getGeolocation(id, lat, lng) {
if ( !geolocationTable[id] ) { if ( !geolocationTable[id] ) {
$.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng, zoom: 10, format: "json" } ) $.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng } )
.done(function( json ) { .done(function( json ) {
var city = json.address["city"]; var city = json.address["city"];
if ( ~city ) { city = json.address["town"]; }; if ( ~city ) { city = json.address["town"]; };
if ( ~city ) { city = json.address["village"]; }; if ( ~city ) { city = json.address["village"]; };
var country = json.address["country"]; var country = json.address["country"];
var countryCode = json.address["country_code"].toUpperCase(); var countryCode = json.address["country_code"].toUpperCase();
var city = json.features[0].properties.city;
var countryCode = json.features[0].properties.country;
geolocationTable[id] = city; geolocationTable[id] = city;
( countryCode != "DE" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; ( countryCode != "DE" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null;
( countryCode != "Germany" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null;
if ( city ) { if ( city ) {
$("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]); $("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]);
var sort = [[0,1],[1,1],[2,1]]; var sort = [[0,1],[1,1],[2,1]];
@ -120,12 +123,10 @@ function ajaxLoadEvents(stime, etime, eventid, url, target) {
var evaluationStatus = $(this).find('origin > evaluationStatus').text(); var evaluationStatus = $(this).find('origin > evaluationStatus').text();
var type = $(this).find('type').last().text(); var type = $(this).find('type').last().text();
var location var location
// get location, try this in order:
// regional map name, given value, cached value, or nominatim lookup
geolocationTable[id] ? null : getGeolocation(id, lat, lng); // do AJAX lookup if not cached, location will be updated later
location = ( geolocationTable[id] || getLocation(lat, lng)[0] || $(this).find('description > text').text() );
// create table row: Date, Time, Mag, Location // create table row: Date, Time, Mag, Location
if ( !eventTable[id] && $.inArray(type, config['event']['typeWhitelist'] )+1 && $.inArray(evaluationStatus, config['event']['evaluationBlacklist'])<0 && Number(mag)+0.05 >= config['event']['minMag'] ) { if ( !eventTable[id] && $.inArray(type, config['event']['typeWhitelist'] )+1 && $.inArray(evaluationStatus, config['event']['evaluationBlacklist'])<0 && Number(mag)+0.05 >= config['event']['minMag'] ) {
geolocationTable[id] ? null : getGeolocation(id, lat, lng); // do AJAX lookup if not cached, location will be updated later
location = ( geolocationTable[id] || getLocation(lat, lng)[0] || $(this).find('description > text').text() );
// general event info (1st line) // general event info (1st line)
var row = '<tr class="tablesorter-hasChildRow">' var row = '<tr class="tablesorter-hasChildRow">'
+ '<td class="utctime-date">'+otime.split('.')[0]+'Z</td>' + '<td class="utctime-date">'+otime.split('.')[0]+'Z</td>'

View File

@ -41,15 +41,18 @@ function addTableRow(row, table) {
/* do reverse geolocation lookup */ /* do reverse geolocation lookup */
function getGeolocation(id, lat, lng) { function getGeolocation(id, lat, lng) {
if ( !geolocationTable[id] ) { if ( !geolocationTable[id] ) {
$.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng, zoom: 10, format: "json" } ) $.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng } )
.done(function( json ) { .done(function( json ) {
var city = json.address["city"]; var city = json.address["city"];
if ( ~city ) { city = json.address["town"]; }; if ( ~city ) { city = json.address["town"]; };
if ( ~city ) { city = json.address["village"]; }; if ( ~city ) { city = json.address["village"]; };
var country = json.address["country"]; var country = json.address["country"];
var countryCode = json.address["country_code"].toUpperCase(); var countryCode = json.address["country_code"].toUpperCase();
var city = json.features[0].properties.city;
var countryCode = json.features[0].properties.country;
geolocationTable[id] = city; geolocationTable[id] = city;
( countryCode != "DE" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; ( countryCode != "DE" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null;
( countryCode != "Germany" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null;
if ( city ) { if ( city ) {
$("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]); $("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]);
var sort = [[0,1],[1,1],[2,1]]; var sort = [[0,1],[1,1],[2,1]];
@ -121,11 +124,9 @@ function ajaxLoadEvents(stime, etime, eventid, url, target) {
var type = $(this).find('type').last().text(); var type = $(this).find('type').last().text();
var location var location
// get location, try this in order: // get location, try this in order:
// regional map name, given value, cached value, or nominatim lookup
geolocationTable[id] ? null : getGeolocation(id, lat, lng); // do AJAX lookup if not cached, location will be updated later
location = ( geolocationTable[id] || getLocation(lat, lng)[0] || $(this).find('description > text').text() );
// create table row: Date, Time, Mag, Location
if ( !eventTable[id] && $.inArray(type, config['event']['typeWhitelist'] )+1 && $.inArray(evaluationStatus, config['event']['evaluationBlacklist'])<0 && Number(mag)+0.05 >= config['event']['minMag'] ) { if ( !eventTable[id] && $.inArray(type, config['event']['typeWhitelist'] )+1 && $.inArray(evaluationStatus, config['event']['evaluationBlacklist'])<0 && Number(mag)+0.05 >= config['event']['minMag'] ) {
geolocationTable[id] ? null : getGeolocation(id, lat, lng); // do AJAX lookup if not cached, location will be updated later
location = ( geolocationTable[id] || getLocation(lat, lng)[0] || $(this).find('description > text').text() );
// general event info (1st line) // general event info (1st line)
var row = '<tr class="tablesorter-hasChildRow">' var row = '<tr class="tablesorter-hasChildRow">'
+ '<td class="utctime-date">'+otime.split('.')[0]+'Z</td>' + '<td class="utctime-date">'+otime.split('.')[0]+'Z</td>'

View File

@ -115,7 +115,7 @@
<span id="events-type">Symbole:</span> <span id="events-type">Symbole:</span>
</p> </p>
<p class="table-caption"> <p class="table-caption">
Nominatim Search Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img alt="Mapquest Logo" src="//developer.mapquest.com/content/osm/mq_logo.png" /> Reverse Geolocation courtesy of <a href="http://photon.komoot.de/" target="_blank">Photon by Komoot</a>
</p> </p>
</div> </div>
<!-- Stations --> <!-- Stations -->
@ -176,7 +176,7 @@
</div> </div>
<!-- Logo --> <!-- Logo -->
<div class="rublogo"><a href="http://www.gmg.ruhr-uni-bochum.de/geophysik/seisobs"><img class="rublogo" src="logo_RUB_155x30.png" alt="Ruhr-Universität Bochum" title="Ruhr-Universität Bochum" border="0"/></a></div> <div class="rublogo"><a href="http://www.gmg.ruhr-uni-bochum.de/geophysik/seisobs"><img class="rublogo" src="logo_RUB_155x30.png" alt="Ruhr-Universität Bochum" title="Ruhr-Universität Bochum" border="0"/></a></div>
<!-- Map --> <!-- Map -->
<div id="map" class="map"></div> <div id="map" class="map"></div>
<div id="spinner" class="spinner" style="display:none;"><img id="img-spinner" src="spinner.gif" alt="Loading"/><br />Loading ...</div> <div id="spinner" class="spinner" style="display:none;"><img id="img-spinner" src="spinner.gif" alt="Loading"/><br />Loading ...</div>
</body> </body>

View File

@ -15,7 +15,7 @@
<link rel="stylesheet" href="external/leaflet.css" /> <link rel="stylesheet" href="external/leaflet.css" />
<!-- link rel="stylesheet" href="external/css/dvf.css" type="text/css" media="screen" / --> <!-- link rel="stylesheet" href="external/css/dvf.css" type="text/css" media="screen" / -->
<link rel="stylesheet" href="external/css/leaflet.label.css" type="text/css" media="screen" /> <link rel="stylesheet" href="external/css/leaflet.label.css" type="text/css" media="screen" />
<!-- <link rel="stylesheet" href="external/easyPrint.css"/> --> <link rel="stylesheet" href="external/easyPrint.css"/>
<!-- jQuery & jQueryUI --> <!-- jQuery & jQueryUI -->
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
@ -37,8 +37,8 @@
<script type="text/javascript" src="external/TileLayer.Grayscale.js"></script> <script type="text/javascript" src="external/TileLayer.Grayscale.js"></script>
<script type="text/javascript" src="external/leaflet-dvf.markers.min.js"></script> <script type="text/javascript" src="external/leaflet-dvf.markers.min.js"></script>
<script type="text/javascript" src="external/leaflet.label.js"></script> <script type="text/javascript" src="external/leaflet.label.js"></script>
<!-- <script src="external/jQuery.print.js"></script> --> <script src="external/jQuery.print.js"></script>
<!-- <script src="external/leaflet.easyPrint.js"></script> --> <script src="external/leaflet.easyPrint.js"></script>
<!-- Map, Events & Stations --> <!-- Map, Events & Stations -->
<script type="text/javascript" src="misc.js"></script> <script type="text/javascript" src="misc.js"></script>
@ -96,7 +96,6 @@
<col width="50" /> <col width="50" />
<col width="50" /> <col width="50" />
<col /> <col />
<col width="30" />
</colgroup> </colgroup>
<thead> <thead>
<tr> <tr>

View File

@ -24,7 +24,7 @@
/* add station marker */ /* add station marker */
function addStationMarker(id, lat, lng, station) { function addStationMarker(id, lat, lng, station) {
var marker = L.triangleMarker(L.latLng(lat, lng), var marker = L.triangleMarker(L.latLng(lat, lng),
{ {
gradient: true, gradient: true,
fillColor: config['station']['markerColor'], fillColor: config['station']['markerColor'],
@ -38,7 +38,7 @@ function addStationMarker(id, lat, lng, station) {
marker.bindLabel('Station '+station); marker.bindLabel('Station '+station);
stationLayer.addLayer(marker); stationLayer.addLayer(marker);
stationTable[id] = marker; stationTable[id] = marker;
}; };
/* add event marker */ /* add event marker */
function addEventMarker(id, lat, lng, mag, type) { function addEventMarker(id, lat, lng, mag, type) {
@ -79,7 +79,7 @@ function addEventMarker(id, lat, lng, mag, type) {
eventTable[id] = marker; eventTable[id] = marker;
return marker; return marker;
}; };
}; };
/* handle to show events on map */ /* handle to show events on map */
function initMapLink() { function initMapLink() {
@ -158,6 +158,12 @@ $(document).ready(function() {
attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
}).addTo(map); }).addTo(map);
break; break;
case 'komoot': // add OpenStreetMap.DE tile layer
L.tileLayer('//www.komoot.de/tiles/{s}/{z}/{x}/{y}.png',
{
attribution: 'Map data &copy; <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | Tiles Courtesy of <a href="http://www.komoot.de/">Komoot</a>',
}).addTo(map);
break;
case 'mapquestgray': // add MapQuestOSM tile layer case 'mapquestgray': // add MapQuestOSM tile layer
L.tileLayer.grayscale('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', L.tileLayer.grayscale('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg',
{ {

View File

@ -158,6 +158,12 @@ $(document).ready(function() {
attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
}).addTo(map); }).addTo(map);
break; break;
case 'komoot': // add OpenStreetMap.DE tile layer
L.tileLayer('//www.komoot.de/tiles/{s}/{z}/{x}/{y}.png',
{
attribution: 'Map data &copy; <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | Tiles Courtesy of <a href="http://www.komoot.de/">Komoot</a>',
}).addTo(map);
break;
case 'mapquestgray': // add MapQuestOSM tile layer case 'mapquestgray': // add MapQuestOSM tile layer
L.tileLayer.grayscale('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', L.tileLayer.grayscale('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg',
{ {
@ -216,6 +222,5 @@ $(document).ready(function() {
}); });
// print icon // print icon
// L.easyPrint().addTo(map); L.easyPrint().addTo(map);
}); });

View File

@ -95,9 +95,8 @@ var config = {
dlsvURL: 'dlsv', dlsvURL: 'dlsv',
mseedURL: '/fdsnws/dataselect/1/query', mseedURL: '/fdsnws/dataselect/1/query',
stationURL: '/fdsnws/station/1/query', stationURL: '/fdsnws/station/1/query',
nominatimURL: '//open.mapquestapi.com/nominatim/v1/reverse.php', nominatimURL: 'https://photon.komoot.de/reverse',
// nominatimURL: '//nominatim.openstreetmap.org/reverse', timespan: 180,
timespan: 60,
}, },
event: { event: {
evaluationBlacklist: ['automatic', 'preliminary', 'rejected'], evaluationBlacklist: ['automatic', 'preliminary', 'rejected'],