Add timestamps to SPC outlook maps
This commit is contained in:
parent
ef23e296c7
commit
5647279e2c
2 changed files with 40 additions and 5 deletions
|
@ -41,7 +41,7 @@ def render_categorical(conus: SPCOutlookMap,
|
|||
if args.dark:
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
|
||||
conus.draw_annotation(cr, f"Day {outlook.day} Categorical Severe Weather Outlook")
|
||||
conus.draw_annotation(cr, outlook, SPCOutlookType.CATEGORICAL)
|
||||
|
||||
def render_probabilistic(conus: SPCOutlookMap,
|
||||
outlook: SPCOutlook,
|
||||
|
@ -66,7 +66,7 @@ def render_probabilistic(conus: SPCOutlookMap,
|
|||
|
||||
hazard = ' '.join(map(lambda p: p.lower().capitalize(), hazard.split(' ')))
|
||||
|
||||
conus.draw_annotation(cr, f"Day {outlook.day} Probabilistic {hazard} Risk")
|
||||
conus.draw_annotation(cr, outlook, SPCOutlookType.PROBABILISTIC, hazard)
|
||||
|
||||
argparser = argparse.ArgumentParser(description='Render graphical SPC outlooks from text file')
|
||||
argparser.add_argument('db', help='Spatialite database file')
|
||||
|
|
|
@ -4,6 +4,8 @@ import shapely
|
|||
import datetime
|
||||
import cairo
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from xmet.db import Database, DatabaseTable
|
||||
from xmet.coord import COORD_SYSTEM
|
||||
from xmet.city import City
|
||||
|
@ -733,17 +735,50 @@ class SPCOutlookMap(EquirectMap):
|
|||
|
||||
cr.restore()
|
||||
|
||||
def draw_annotation(self, cr: cairo.Context, text: str):
|
||||
def draw_annotation(self,
|
||||
cr: cairo.Context,
|
||||
outlook: SPCOutlook,
|
||||
kind: SPCOutlookType,
|
||||
hazard: Optional[str]=None):
|
||||
cr.save()
|
||||
|
||||
cr.select_font_face(self.TEXT_FONT)
|
||||
cr.set_font_size(28)
|
||||
|
||||
if kind is SPCOutlookType.CATEGORICAL:
|
||||
text = f"Day {outlook.day} Categorical Severe Weather Outlook"
|
||||
elif kind is SPCOutlookType.PROBABILISTIC:
|
||||
text = f"Day {outlook.day} Probabilistic {hazard} Risk"
|
||||
|
||||
extents = cr.text_extents(text)
|
||||
|
||||
cr.move_to(self.width - extents.width - 48,
|
||||
self.height - extents.height - 16)
|
||||
x = self.width - extents.width - 48
|
||||
y = self.height - extents.height - 16
|
||||
|
||||
cr.move_to(x, y)
|
||||
cr.show_text(text)
|
||||
|
||||
#
|
||||
# Draw timestamp
|
||||
#
|
||||
cr.set_font_size(14)
|
||||
|
||||
text = "Issued %s; valid %s" % (
|
||||
outlook.timestamp_issued.strftime("%Y-%m-%d %H:%M UTC"),
|
||||
outlook.timestamp_start.strftime("%Y-%m-%d %H:%M UTC"),
|
||||
)
|
||||
|
||||
extents = cr.text_extents(text)
|
||||
|
||||
x = self.width - extents.width - 32
|
||||
y = 8 + extents.height
|
||||
|
||||
cr.set_source_rgba(1, 1, 1, 0.9)
|
||||
cr.rectangle(x - 4, y - 4, extents.width + 8, extents.height + 8)
|
||||
cr.fill()
|
||||
|
||||
cr.set_source_rgb(0, 0, 0)
|
||||
cr.move_to(x, y + extents.height)
|
||||
cr.show_text(text)
|
||||
|
||||
cr.restore()
|
||||
|
|
Loading…
Add table
Reference in a new issue