On Tuesday, January 18, 2022 at 5:15:49 p.m. UTC-4 vince wrote:
> Very cool - I had to spin up a gnome desktop lightsail instance and VNC in
> from my Mac mini but I got there. Is there a way to run this one headless
> to generate the image for viewing on a different computer ?
Easiest is just to comment out the "plt.show()" at the end. I've attached
a version which does that, and pretties up the output a bit.
> FWIW - on ubuntu you need to: "sudo apt-get install python3-matplotlib
> python3-numpy python3-geopy" for the requisite pieces of the puzzle.
>
> My data => distance 9195.8 km arrival at 1642248822 (2022-01-15 04:13:41)
> here about 3 km from the water between Seattle+Tacoma
>
It looks like your pressure was fairly flat. Maybe expand the time range,
so that's obvious?
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/a6ebe634-6940-4fd4-aa6e-71d122fbe9fbn%40googlegroups.com.
import time
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import sqlite3
from geopy import distance
# change as needed
home = (44.80321621050904, -63.62038361172844)
hunga_tonga = (-20.5452074472518, -175.38715105641674)
speed_of_sound = 0.32 # km/s
eruption_time = 1642220085 # 2022-01-15 04:14:45 UTC
hour_lead = 6
hour_lag = 6
distance = distance.distance(hunga_tonga, home).km
travel_time = distance / speed_of_sound
arrival_time = eruption_time + travel_time
start_time = 3600*(arrival_time // 3600 - hour_lead) # start at an even hour
print("distance to eruption %0.1f km arrival at %.0f (%s)" % (distance, arrival_time, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(arrival_time))))
connection = sqlite3.connect('weewx.sdb')
cursor = connection.cursor()
query = "select datetime, barometer from archive where datetime > %.0f and datetime < %.0f order by dateTime;" % (start_time, arrival_time + hour_lag*3600)
print(query)
cursor.execute(query).fetchall
result = cursor.fetchall()
connection.close()
xdata = []
ydata = []
tdata = []
for row in result:
xdata.append(row[0])
tdata.append(mdates.datestr2num(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))))
ydata.append(row[1])
# remove any linear trend
coeff = np.polyfit(xdata, ydata, 2)
trend = np.polyval(coeff, xdata)
fig, ax = plt.subplots()
plt.text(tdata[1], np.max(ydata), "location: %0.2f, %0.2f" % home)
date_formatter = mdates.DateFormatter('%m-%d %H:%M')
ax.tick_params(axis="x", rotation=90)
ax.xaxis.set_major_locator(mdates.HourLocator(interval = 1))
ax.xaxis.set_major_formatter(date_formatter)
ax.xaxis.set_minor_locator(mdates.MinuteLocator(interval = 10))
#ax.set_xlim(xmin=tdata[0]//1) # start at a round hour
fig.subplots_adjust(bottom=0.2)
ax.plot(tdata, ydata, color="paleturquoise", linewidth=3)
ax.plot(tdata, trend, color="lightgrey", linewidth=1)
ax2=ax.twinx()
ax2.plot(tdata, ydata - trend, linewidth=1)
# save the plot as a file
fig.savefig('./hunga_tonga.png', format='png', dpi=100, bbox_inches='tight')
#plt.show()