Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReNaSS new earthquake api behavior #602

Merged
merged 4 commits into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions bin/user/belchertown.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import syslog
import time
from collections import OrderedDict
from math import asin, atan2, cos, degrees, radians, sin, sqrt
from math import asin, atan2, cos, degrees, pi, radians, sin, sqrt
from re import match

import configobj
Expand Down Expand Up @@ -1620,10 +1620,24 @@ def aeris_icon(data):
% self.generator.skin_dict["Extras"]["geonet_mmi"]
)
elif self.generator.skin_dict["Extras"]["earthquake_server"] == "ReNaSS":
# Calculate min/max latitude and min/max longitude from radius and station location. https://stackoverflow.com/a/23118314
lat = float(latitude)
long = float(longitude)
radiusInKm = int(earthquake_maxradiuskm)

kmInLongitudeDegree = 111.320 * cos( lat / 180.0 * pi)

deltaLat = radiusInKm / 111.1
deltaLong = radiusInKm / kmInLongitudeDegree

minLat = lat - deltaLat
maxLat = lat + deltaLat
minLong = long - deltaLong
maxLong = long + deltaLong

earthquake_url = (
# Modify minmagnitude to suit your needs and mindepth=-1 if you want to show quarry blast
"https://renass.unistra.fr/fdsnws/event/1/query?latitude=%s&longitude=%s&maxradius=%.2f&orderby=time&format=json&limit=1&minmagnitude=2&mindepth=1"
% (latitude, longitude, int(earthquake_maxradiuskm) / 111.25)
"https://api.franceseisme.fr/fdsnws/event/1/query?eventtype=earthquake&minmagnitude=2&minlatitude=%.2f&minlongitude=%.2f&maxlatitude=%.2f&maxlongitude=%.2f&format=json&limit=1&orderby=time"
% (minLat, minLong, maxLat, maxLong)
)
earthquake_is_stale = False

Expand Down Expand Up @@ -1744,10 +1758,14 @@ def aeris_icon(data):
eqtime = int(
(eqtime - datetime.datetime(1970, 1, 1)).total_seconds()
)
equrl = eqdata["features"][0]["properties"]["url"]
eqplace = eqdata["features"][0]["properties"]["description"]
eqmag = locale.format(
"%g", float(eqdata["features"][0]["properties"]["mag"])
if match("fr_.*", system_locale):
equrl = eqdata["features"][0]["properties"]["url"]["fr"]
eqplace = eqdata["features"][0]["properties"]["description"]["fr"]
else:
equrl = eqdata["features"][0]["properties"]["url"]["en"]
eqplace = eqdata["features"][0]["properties"]["description"]["en"]
eqmag = format(
eqdata["features"][0]["properties"]["mag"], ".1f"
)
elif (
self.generator.skin_dict["Extras"]["earthquake_server"] == "GeoNet"
Expand Down