fix timezone

This commit is contained in:
Cyberes 2024-09-03 17:54:07 -06:00
parent c77659da57
commit 4b4c4d4491
3 changed files with 10 additions and 14 deletions

View File

@ -2,7 +2,7 @@ import io
import logging import logging
import pickle import pickle
import time import time
from datetime import datetime, timedelta from datetime import datetime
import schedule import schedule
from PIL import Image from PIL import Image
@ -19,14 +19,6 @@ LON_RANGE_MIN = -180
LON_RANGE_MAX = 180 LON_RANGE_MAX = 180
def get_utc_offset():
timestamp = time.time()
local_time = datetime.fromtimestamp(timestamp)
utc_time = datetime.utcfromtimestamp(timestamp)
delta = local_time - utc_time
return delta.total_seconds() / 3600
def main(): def main():
redis = Redis(host='localhost', port=6379, db=0) redis = Redis(host='localhost', port=6379, db=0)
@ -42,7 +34,7 @@ def main():
for tecmap, epoch in ionex_data: for tecmap, epoch in ionex_data:
if epoch.hour == utc_hr: if epoch.hour == utc_hr:
plt = plot_tec_map(tecmap, [float(LON_RANGE_MIN), float(LON_RANGE_MAX)], [float(LAT_RANGE_MIN), float(LAT_RANGE_MAX)], timestamp=epoch - timedelta(hours=get_utc_offset()))[1] plt = plot_tec_map(tecmap, [float(LON_RANGE_MIN), float(LON_RANGE_MAX)], [float(LAT_RANGE_MIN), float(LAT_RANGE_MAX)], timestamp_utc=epoch)[1]
buf = io.BytesIO() buf = io.BytesIO()
plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0.1, dpi=110) plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0.1, dpi=110)
plt.close() plt.close()

View File

@ -1,9 +1,11 @@
import re import re
import time
from datetime import datetime from datetime import datetime
import cartopy.crs as ccrs import cartopy.crs as ccrs
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from dateutil.tz import tzutc, tzlocal
from mpl_toolkits.axes_grid1 import make_axes_locatable from mpl_toolkits.axes_grid1 import make_axes_locatable
""" """
@ -32,7 +34,7 @@ def get_tecmaps(ionex: str):
yield parse_map(tecmap), epoch yield parse_map(tecmap), epoch
def plot_tec_map(tecmap, lon_range: list, lat_range: list, timestamp: datetime = None): def plot_tec_map(tecmap, lon_range: list, lat_range: list, timestamp_utc: datetime = None):
proj = ccrs.PlateCarree() proj = ccrs.PlateCarree()
f, ax = plt.subplots(1, 1, subplot_kw=dict(projection=proj)) f, ax = plt.subplots(1, 1, subplot_kw=dict(projection=proj))
@ -54,8 +56,9 @@ def plot_tec_map(tecmap, lon_range: list, lat_range: list, timestamp: datetime =
# Make graph pretty # Make graph pretty
ax.coastlines() ax.coastlines()
if timestamp: if timestamp_utc:
plt.title(timestamp.strftime('%H:%M %d-%m-%Y'), fontsize=12, y=1.04) timestamp_local = timestamp_utc.replace(tzinfo=tzutc()).astimezone(tzlocal())
plt.title(timestamp_local.strftime(f'%H:%M %m-%d-%Y {time.tzname[0]}'), fontsize=12, y=1.04)
plt.suptitle('Vertical Total Electron Count', fontsize=16, y=0.87) plt.suptitle('Vertical Total Electron Count', fontsize=16, y=0.87)
divider = make_axes_locatable(ax) divider = make_axes_locatable(ax)
ax_cb = divider.new_horizontal(size='5%', pad=0.1, axes_class=plt.Axes) ax_cb = divider.new_horizontal(size='5%', pad=0.1, axes_class=plt.Axes)

View File

@ -10,4 +10,5 @@ async-timeout==4.0.3
Pillow Pillow
flask==3.0.3 flask==3.0.3
schedule==1.2.2 schedule==1.2.2
gunicorn==23.0.0 gunicorn==23.0.0
python-dateutil==2.9.0.post0