Belchertown: earthquake miles vs km's

623 views
Skip to first unread message

blee...@xs4all.nl

unread,
Oct 24, 2020, 1:47:03 PM10/24/20
to weewx-user
Hi Pat,

At first thanks fot the 1.2 skin with the Aeris-weather fortecast etc, working great; props!

I'm facing just a minor issue: in the skin.conf is defined 'earthquake_maxradiuskm = 2000'. Therefore I'm expecting a distance in km's, but the actual distance as well as the units are still in miles (mijl in Dutch). How to resolve this? (http://oentsjerk.eu/)

Regards, Keimpe
    

vince

unread,
Oct 24, 2020, 2:49:37 PM10/24/20
to weewx-user
On Saturday, October 24, 2020 at 10:47:03 AM UTC-7, blee...@xs4all.nl wrote:
I'm facing just a minor issue: in the skin.conf is defined 'earthquake_maxradiuskm = 2000'. Therefore I'm expecting a distance in km's, but the actual distance as well as the units are still in miles (mijl in Dutch). How to resolve this? (http://oentsjerk.eu/)


I see km when I look at your page. 

blee...@xs4all.nl

unread,
Oct 24, 2020, 3:04:04 PM10/24/20
to weewx-user
Thnx Vince, Strange, also on mobile, WLAN and 4G network, the same problem so it can't be a localization issue related to the network.


Op zaterdag 24 oktober 2020 om 20:49:37 UTC+2 schreef vince:

Arend

unread,
Oct 24, 2020, 3:46:02 PM10/24/20
to weewx-user
Hi Keimpe,

I had the same problem and created an issue about this in the repo. You can use the fix, let me know if it works for you.


Mvg, Arend

Op zaterdag 24 oktober 2020 om 21:04:04 UTC+2 schreef blee...@xs4all.nl:

vince

unread,
Oct 24, 2020, 4:30:57 PM10/24/20
to weewx-user
oops - yes I do see miles for one number there.
Sorry for the confusion.

Tim Tuck

unread,
Oct 24, 2020, 8:01:35 PM10/24/20
to weewx...@googlegroups.com

Hi Arend,

nice update to change miles to km.

In your patch you have ...

eqmag = locale.format("%g", float(eqmag) )

But you don't show what it was previously so knowing which "eqmag" to change is hard.

thanks
Tim
--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/6742394c-d258-4784-b5be-5cfbeb0584c2n%40googlegroups.com.

Arend

unread,
Oct 25, 2020, 4:57:42 AM10/25/20
to weewx-user
Hi Tim,

That was a new line of code which applied to both eqmag (quick fix). But I have changed the repository issue. It now shows which lines of code to change and apply locale formatting directly. Maybe that will make things more clear.


Regards, Arend

Op zondag 25 oktober 2020 om 02:01:35 UTC+2 schreef ti...@skybase.net:

blee...@xs4all.nl

unread,
Oct 25, 2020, 6:46:06 AM10/25/20
to weewx-user
Goedemiddag Arend,

Thnx, changes made!
At this time it says 'no recent data avilabale' so I have to wait for een eartqauke data-update.
Keep you informed.

Regards, Keimpe

Op zaterdag 24 oktober 2020 om 21:46:02 UTC+2 schreef Arend:

Tim Tuck

unread,
Oct 25, 2020, 3:45:54 PM10/25/20
to weewx...@googlegroups.com

Hi Arend,

OK, cool :)

thanks for the update

cheers

Tim

blee...@xs4all.nl

unread,
Oct 27, 2020, 2:30:46 PM10/27/20
to weewx-user
Hi Arend,

Stil no recent earthquake data avilable (http://oentsjerk.eu). Can I have your URL to check the actuality?

Regards, Keimpe
 

Op zondag 25 oktober 2020 om 11:46:06 UTC+1 schreef blee...@xs4all.nl:

Arend

unread,
Oct 27, 2020, 3:51:31 PM10/27/20
to weewx-user
Goedenavond Keimpe,

You can check your earthquake file typing this into your browser:


It shows the same data as mine which means it is loaded/updated correctly, check the epoch timestamp to verify when it was downloaded/updated.
Are you sure you copied the changes the right way (without additional tabs or spaces)?
Are there no errors in your logs?
My configuration shows this:

            # Earthquake defaults
            earthquake_enabled = 1
            earthquake_maxradiuskm = 2000
            earthquake_stale = 10740
            earthquake_server = USGS

Does it match yours?

Mvg, Arend

Op dinsdag 27 oktober 2020 om 19:30:46 UTC+1 schreef blee...@xs4all.nl:

blee...@xs4all.nl

unread,
Oct 27, 2020, 4:36:04 PM10/27/20
to weewx-user
Hi Arend,

Thanks for the suggestions.

- The JSON tels me about an eartquake  6 km E of Belle-Plagne in France, and lat=53.254&lon=5.895&maxradiuskm=2000 as set in my config, seems OK to me.
- The config is same as yours
- I checked the changes in belchertown.py, the only difference with your fixes is the order of the 4 lines, they do not come across these consecutively from top to bottom as you suggested, but first 1 (line 1060), then 3 (line 1139), then 4 (line 1152) and finally 2 (line 1161). I copy/pasted the lines (again) from GitHub in the editor.

And still no data...

Regards, Keimpe   

Op dinsdag 27 oktober 2020 om 20:51:31 UTC+1 schreef Arend:

Arend

unread,
Oct 27, 2020, 5:54:22 PM10/27/20
to weewx-user
I am going to make a pull request out of this issue, hopefully Pat will incorporate this fix into the master. That way you will be able to download it from the repository.
In the mean time you could try to replace the modified file with the original from the repo and see what happens. Did you check your logs for errors?

Mvg, Arend

Op dinsdag 27 oktober 2020 om 21:36:04 UTC+1 schreef blee...@xs4all.nl:

blee...@xs4all.nl

unread,
Oct 28, 2020, 6:38:34 AM10/28/20
to weewx-user
Hoi Arend,

Thanks for your efforts.

Now changed back to the original file and (of cours) the EQ data is back, as expected in 'mijl'.
In the log there is no related error, the only recursive error is a Failed to publish record .... to WOW.
Undermentioned you may find the earthquake section of belchertown.py with the recommended changes. Between empty lines the original lines ar commented out with #25-10.1 (#date and 1 is the line-number as suggested in your GitHub post), following the line copied from GitHub.

Regards, Keimpe

 
        """
        Earthquake Data
        """
        # Only process if Earthquake data is enabled
        if self.generator.skin_dict['Extras']['earthquake_enabled'] == "1":
            earthquake_file = html_root + "/json/earthquake.json"
            earthquake_stale_timer = self.generator.skin_dict['Extras']['earthquake_stale']
            latitude = self.generator.config_dict['Station']['latitude']
            longitude = self.generator.config_dict['Station']['longitude']

#25-10.1    distance_unit = converter.group_unit_dict["group_distance"]
            distance_unit = self.generator.converter.group_unit_dict["group_distance"]

            eq_distance_label = self.generator.skin_dict['Units']['Labels'].get(distance_unit, "")
            eq_distance_round = self.generator.skin_dict['Units']['StringFormats'].get(distance_unit, "%.1f")
            earthquake_maxradiuskm = self.generator.skin_dict['Extras']['earthquake_maxradiuskm']
            if self.generator.skin_dict['Extras']['earthquake_server'] == "USGS":
                earthquake_url = "http://earthquake.usgs.gov/fdsnws/event/1/query?limit=1&lat=%s&lon=%s&maxradiuskm=%s&format=geojson&nodata=204&minmag=2" % ( latitude, longitude, earthquake_maxradiuskm )
            elif self.generator.skin_dict['Extras']['earthquake_server'] == "GeoNet":
                earthquake_url = "https://api.geonet.org.nz/quake?MMI=4"
            earthquake_is_stale = False
            
            # Determine if the file exists and get it's modified time
            if os.path.isfile( earthquake_file ):
                if ( int( time.time() ) - int( os.path.getmtime( earthquake_file ) ) ) > int( earthquake_stale_timer ):
                    earthquake_is_stale = True
            else:
                # File doesn't exist, download a new copy
                earthquake_is_stale = True
            
            # File is stale, download a new copy
            if earthquake_is_stale:
                # Download new earthquake data
                try:
                    try:
                        # Python 3
                        from urllib.request import Request, urlopen
                    except ImportError:
                        # Python 2
                        from urllib2 import Request, urlopen
                    user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3'
                    headers = { 'User-Agent' : user_agent }
                    req = Request( earthquake_url, None, headers )
                    response = urlopen( req )
                    page = response.read()
                    response.close()
                    if weewx.debug:
                        logdbg( "Downloading earthquake data using urllib2 was successful" )
                except Exception as forecast_error:
                    if weewx.debug:
                        logdbg( "Error downloading earthquake data with urllib2, reverting to curl and subprocess. Full error: %s" % forecast_error )
                    # Nested try - only execute if the urllib2 method fails
                    try:
                        import subprocess
                        command = 'curl -L --silent "%s"' % earthquake_url
                        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                        page = p.communicate()[0]
                        if weewx.debug:
                            logdbg( "Downloading earthquake data with curl was successful." )
                    except Exception as error:
                        raise Warning( "Error downloading earthquake data using urllib2 and subprocess curl. Your software may need to be updated, or the URL is incorrect. You are trying to use URL: %s, and the error is: %s" % ( earthquake_url, error ) )

                # Save earthquake data to file. w+ creates the file if it doesn't exist, and truncates the file and re-writes it everytime
                try:
                    with open( earthquake_file, 'wb+' ) as file:
                        # Python 2/3
                        try:
                            file.write( page.encode('utf-8') )
                        except:
                            file.write( page )
                        if weewx.debug:
                            logdbg( "Earthquake data saved to %s" % earthquake_file )
                except IOError as e:
                    raise Warning( "Error writing earthquake data to %s. Reason: %s" % ( earthquake_file, e) )

            # Process the earthquake file        
            with open( earthquake_file, "r" ) as read_file:
                try:
                    eqdata = json.load( read_file )
                except:
                    eqdata = ""
            
            try:
                if self.generator.skin_dict['Extras']['earthquake_server'] == "USGS":
                    eqtime = eqdata["features"][0]["properties"]["time"] / 1000
                    equrl = eqdata["features"][0]["properties"]["url"]
                    eqplace = eqdata["features"][0]["properties"]["place"]

#25-10.3            eqmag = eqdata["features"][0]["properties"]["mag"]
                    eqmag = locale.format("%g", float(eqdata["features"][0]["properties"]["mag"]) )

                elif self.generator.skin_dict['Extras']['earthquake_server'] == "GeoNet":
                    eqtime = eqdata["features"][0]["properties"]["time"]
                    #convert time to UNIX format
                    eqtime = eqtime.replace("Z","")
                    eqtime = datetime.datetime.fromisoformat(eqtime)
                    eqtime = int(eqtime.replace(tzinfo=datetime.timezone.utc).timestamp())
                    equrl = ("https://www.geonet.org.nz/earthquake/" +
                            eqdata["features"][0]["properties"]["publicID"])
                    eqplace = eqdata["features"][0]["properties"]["locality"]

#25-10.4        eqmag = round(eqdata["features"][0]["properties"]["magnitude"],1)
                eqmag = locale.format("%g", float(round(eqdata["features"][0]["properties"]["magnitude"],1)) )

                eqlat = str( round( eqdata["features"][0]["geometry"]["coordinates"][1], 4 ) )
                eqlon = str( round( eqdata["features"][0]["geometry"]["coordinates"][0], 4 ) )
                eqdistance_bearing = self.get_gps_distance((float(latitude), float(longitude)), 
                                                           (float(eqlat), float(eqlon)), 
                                                            distance_unit)

#25-10.2        eqdistance = eq_distance_round % eqdistance_bearing[0]
                eqdistance = locale.format("%g", float(eq_distance_round % eqdistance_bearing[0]) )
                
                eqbearing = eqdistance_bearing[1]
                eqbearing_raw = eqdistance_bearing[2]
            except:
                # No earthquake data
                eqtime = label_dict["earthquake_no_data"]
                equrl = ""
                eqplace = ""
                eqmag = ""
                eqlat = ""
                eqlon = ""
                eqdistance = ""
                eqbearing = ""
                eqbearing_raw = ""
            
        else:
            eqtime = ""
            equrl = ""
            eqplace = ""
            eqmag = ""
            eqlat = ""
            eqlon = ""
            eqdistance = ""
            eqbearing = ""
            eqbearing_raw = ""
            eq_distance_label = ""
            

Op dinsdag 27 oktober 2020 om 22:54:22 UTC+1 schreef Arend:

Arend

unread,
Oct 28, 2020, 10:31:29 AM10/28/20
to weewx-user
Hi Keimpe,

I have a suspicion why it didn't work out for you. Copying your code from your previous post into a text editor revealed that the changes you made were not properly alligned. The Python language is sensitive to indentation. The screenshot below shows a green and red line. The second eqmag (#25-10.4) should have been lined up to the green line like the first eqmag (#25-10.3). But instead it was lined up to the red line, probably causing an exception (error) which would result in displaying that there was no earthquake data available.

Toelichting uitlijning code.png

I have included a new version of belchertown.py that has already been modified with the correct changes. Could you be so kind to download this file and use it to replace the existing belchertown.py. If this works then I will use this file for a pull request.


Mvg, Arend


Op woensdag 28 oktober 2020 om 11:38:34 UTC+1 schreef blee...@xs4all.nl:
belchertown.py

blee...@xs4all.nl

unread,
Oct 28, 2020, 1:45:37 PM10/28/20
to weewx-user
Hallo Arend,

Yes, it's working!

Just aligning the new line after #25-10.4 solved the problem, manymany thanks! 

Best regards, Keimpe

Op woensdag 28 oktober 2020 om 15:31:29 UTC+1 schreef Arend:

moth...@gmail.com

unread,
Dec 25, 2020, 5:35:28 AM12/25/20
to weewx-user
yes, it works, thanks for the adjustment.
Ton
http://weerstationnibbixwoud.nl/

Op woensdag 28 oktober 2020 om 18:45:37 UTC+1 schreef blee...@xs4all.nl:

Colin Larsen

unread,
Dec 25, 2020, 1:40:31 PM12/25/20
to weewx-user
With the GeoNet problem I had now fixed I am also getting distances to earthquake locations in miles, when the rest of my site is km

Thanks
Colin

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

Arend

unread,
Dec 26, 2020, 7:07:00 AM12/26/20
to weewx-user
Hi Colin,

Could you please check in weewx.conf if your setting for group_distance is set to km? Like this:

    [[Defaults]]        
        [[[Units]]]            
            # The following section sets what unit to use for each unit group.
            # NB: The unit is always in the singular. I.e., 'mile_per_hour',
            # NOT 'miles_per_hour'
            [[[[Groups]]]]                
                group_altitude = meter    # Options are 'foot' or 'meter'
                group_degree_day = degree_C_day    # Options are 'degree_F_day' or 'degree_C_day'
                group_distance = km    # Options are 'mile' or 'km'
                group_pressure = hPa    # Options are 'inHg', 'mmHg', 'mbar', or 'hPa'
                group_rain = mm    # Options are 'inch', 'cm', or 'mm'
                group_rainrate = mm_per_hour    # Options are 'inch_per_hour', 'cm_per_hour', or 'mm_per_hour'
                group_speed = km_per_hour    # Options are 'mile_per_hour', 'km_per_hour', 'knot', or 'meter_per_second'
                group_speed2 = km_per_hour2    # Options are 'mile_per_hour2', 'km_per_hour2', 'knot2', or 'meter_per_second2'
                group_temperature = degree_C    # Options are 'degree_F' or 'degree_C'

Regards, Arend
Op vrijdag 25 december 2020 om 19:40:31 UTC+1 schreef colin....@gmail.com:

Colin Larsen

unread,
Dec 26, 2020, 9:19:26 PM12/26/20
to weewx-user
Arend

Great call sir! In fact even though I use all metric units with my station that unit was not set at all. Added group_distance = km to the Belchertown skin and that has solved the problem

Many thanks!

Regards and best to you.
Colin

Ian Prescott

unread,
Dec 31, 2020, 4:36:36 AM12/31/20
to weewx-user

Hi

Having been struggling with the Belchertown earthquake distance issue and so I have been following this thread with great interest.

But a warning first ....I have crashed and burned by forcing locale in the past ......make sure you can recover.


I have weewx on a VM running Belchertown and using a mysql US database but all displays are in metric.

None of the suggestions in the thread sofar would get earthquake distance to show kms only miles.

I have also been getting a lot of guidance from another weewx user.


The edits from #422 did not make any difference and a quick check of weewx.conf and skin.conf shows group_distance = km


14:18:03 pied@weewx:/etc/weewx$ grep -r group_distance*

weewx.conf.alarm.ver: group_distance = km

weewx.conf.alarm.ver: group_distance = km # Options are 'mile' or 'km'

weewx.conf.20201222111610: group_distance = km # Options are 'mile' or 'km'

weewx.conf.bak1: group_distance = km # Options are 'mile' or 'km'

weewx.conf: group_distance = km

weewx.conf: group_distance = km # Options are 'mile' or 'km'

weewx.conf.dist: group_distance = mile # Options are 'mile' or 'km'

weewx.conf.21-12-20: group_distance = km # Options are 'mile' or 'km'

skins/Belchertown/skin.conf: group_distance = km # Options are 'mile' or 'km'

skins/Belchertown/skin.conf:# group_distance = mile # Options are 'mile' or 'km'

14:18:35 pied@weewx:/etc/weewx$


What eventually solved my problem was this suggestion from my mentor...…

force belchertown to use en_AU.UTF-8


belchertown skin.conf is now

# General Site Defaults

belchertown_debug = 0

# belchertown_locale = "auto"

belchertown_locale = "en_AU.UTF-8"


Where it all fell over was during the ubuntu server install.

I paid particular attention to locale stuff during the install.

Highlighting Australia then tab to OK .......then highlighting Brisbane then tab to the OK ....and so on .......

that is why when this bit popped up during the ubuntu server install output I copy/pasted it into a text.file for later.


Change locale to Australia

Generating locales (this might take a while)...

en_AU.UTF-8... done

en_US.UTF-8... done

Generation complete.

the local is set to

LANG=en_US.UTF-8

LANGUAGE=

LC_CTYPE="en_US.UTF-8"

LC_NUMERIC="en_US.UTF-8"

LC_TIME="en_US.UTF-8"

LC_COLLATE="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_PAPER="en_US.UTF-8"

LC_NAME="en_US.UTF-8"

LC_ADDRESS="en_US.UTF-8"

LC_TELEPHONE="en_US.UTF-8"

LC_MEASUREMENT="en_US.UTF-8"

LC_IDENTIFICATION="en_US.UTF-8"

LC_ALL=

Reading package lists... Done

Building dependency tree


I thought that was strange. Why US when I selected AU ???????

but after the server install finished a check of the VM revealed this


13:16:59 pied@weewx:~$ locale

LANG=en_AU.UTF-8

LANGUAGE=

LC_CTYPE="en_AU.UTF-8"

LC_NUMERIC="en_AU.UTF-8"

LC_TIME="en_AU.UTF-8"

LC_COLLATE="en_AU.UTF-8"

LC_MONETARY="en_AU.UTF-8"

LC_MESSAGES="en_AU.UTF-8"

LC_PAPER="en_AU.UTF-8"

LC_NAME="en_AU.UTF-8"

LC_ADDRESS="en_AU.UTF-8"

LC_TELEPHONE="en_AU.UTF-8"

LC_MEASUREMENT="en_AU.UTF-8"

LC_IDENTIFICATION="en_AU.UTF-8"

LC_ALL=

14:04:09 pied@weewx:~$


I thought all was going to be good ......but no earthquake distance was in miles?????


So when the belchertown skin.conf edit fixed the distance by forcing it to use en_AU.UTF-8, and got earthquake distance in kms,

the next step was to make sure that the default locale was definitely forced to en_AU.UTF-8.


It should have been........that is what I selected .........but the server install output said otherwise ........yet a locale query said AU ??????

By forcing locale en_AU.UTF-8 it should ensure that LC_MEASUREMENT="en_US.UTF-8" would be over written. The source of "miles"


I edited skin.conf back to AUTO, then used the command locale-gen, then followed by a reboot of the server.........and distance is (still) in KMs


pied@weewx:~$ sudo locale-gen en_AU.UTF-8

[sudo] password for pied:

Generating locales (this might take a while)...

en_AU.UTF-8... done

Generation complete.

pied@weewx:~$ locale

LANG=en_AU.UTF-8

LANGUAGE=

LC_CTYPE="en_AU.UTF-8"

LC_NUMERIC="en_AU.UTF-8"

LC_TIME="en_AU.UTF-8"

LC_COLLATE="en_AU.UTF-8"

LC_MONETARY="en_AU.UTF-8"

LC_MESSAGES="en_AU.UTF-8"

LC_PAPER="en_AU.UTF-8"

LC_NAME="en_AU.UTF-8"

LC_ADDRESS="en_AU.UTF-8"

LC_TELEPHONE="en_AU.UTF-8"

LC_MEASUREMENT="en_AU.UTF-8"

LC_IDENTIFICATION="en_AU.UTF-8"

LC_ALL=

pied@weewx:~$ Connection to weewx closed by remote host.

Connection to weewx closed.

pied@XPS:~$ ssh pied@weewx


The suspicion is that the edits in #422 are probably not required in this instance.


How or why my locale could get en_US.UTF-8 when I went out of my way to select en_AU.UTF-8 during the install ......and told me it was en_AU.UTF-8 when queried after the install ......is in the lap of the gods.


Hope this may help others




Reply all
Reply to author
Forward
Message has been deleted
0 new messages