Compare commits

..

3 commits

4 changed files with 62 additions and 7 deletions

51
bin/xmet-sounding-graph Executable file
View file

@ -0,0 +1,51 @@
#! /usr/bin/env python3
import argparse
import cairo
import shapely
from xmet.db import Database
from xmet.sounding import Sounding
from xmet.skew_t import SkewTGraph, SkewTLegend
IMAGE_WIDTH = 800
IMAGE_HEIGHT = 800
GRAPH_WIDTH = 800 - 128
GRAPH_HEIGHT = 800 - 128
parser = argparse.ArgumentParser(
description = 'Graph most recent valid sounding for location'
)
parser.add_argument('db', help='XMET SQLite3 database')
parser.add_argument('lat', help='Latitude')
parser.add_argument('lon', help='Longitude')
parser.add_argument('timestamp', help='Timestamp in YYYY-MM-DD HH:MM:SS (UTC)')
parser.add_argument('output', help='Output SVG file')
args = parser.parse_args()
db = Database.connect(args.db)
location = shapely.Point(float(args.lon), float(args.lat))
sounding = Sounding.valid_by_location(db, location, args.timestamp)
print(f"Graphing {sounding.station} sounding at {sounding.timestamp_observed}")
skew_t = SkewTGraph(GRAPH_WIDTH, GRAPH_HEIGHT)
with cairo.SVGSurface(args.output, IMAGE_WIDTH, IMAGE_HEIGHT) as surface:
cr = cairo.Context(surface)
cr.set_source_rgb(1, 1, 1)
cr.rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)
cr.fill()
skew_t.draw(cr, 64, 64, sounding.samples)
cr.set_source_rgb(0, 0, 0)
cr.rectangle(64, 64, GRAPH_WIDTH, GRAPH_HEIGHT)
cr.stroke()
SkewTLegend.draw_for_graph(cr, skew_t, 64, 64)

View file

@ -114,9 +114,10 @@ class IGRAReader():
sounding.station = match['id']
date = datetime.datetime(
year = int(match['year']),
month = int(match['month']),
day = int(match['day'])
year = int(match['year']),
month = int(match['month']),
day = int(match['day']),
tzinfo = datetime.UTC
)
timestamp = date.astimezone(datetime.UTC)

View file

@ -112,6 +112,9 @@ class SkewTGraph():
first = True
for sample in samples:
if sample.pressure < 0 or sample.pressure is None:
continue
if sample.pressure < PRESSURE_MIN:
break

View file

@ -131,9 +131,9 @@ class Sounding(DatabaseTable):
xmet_sounding
where
station = :station
and timestamp_released <= :timestamp
and timestamp_observed <= :timestamp
order by
timestamp_released desc
timestamp_observed desc
limit 1
"""
@ -167,10 +167,10 @@ class Sounding(DatabaseTable):
from
xmet_sounding
where
timestamp_released <= :timestamp
timestamp_observed <= :timestamp
order by
distance asc,
timestamp_released desc
timestamp_observed desc
limit 1
""".format(crs=COORD_SYSTEM)