# -*- coding: utf-8 -*-
# Created on Tue May 12 21:49:49 2015
"""Plot a wind chart. Wind in knots. Wind barbs with the common interpretation
lower than 2.5 knots indicated without barns, calms are circles.
Input is read from a parameter file. - VERSION 2: with HR-DEM-Dat
Necessary parameters:
* sqlite-database pathname: dbname
* outputdirectory: outputdir
* start and end date and time as integer (yyyymoddhhmi):
startdattim , enddattim
* time-delta in minutes: timedelta
* Title of the map as ASCII-String (no Umlaute etc..): maptitle
* Map limits: max. longitude; min. latitude; max. latitude (deci. degrees):
maplimits
* Map pickle directory: mappickledir
* Path to HR-DEM data file: dempath"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import sys
import numpy as np
import os.path as op
try:
import nobotouls.noboinout as inout
except:
import noboinout as inout
DESCRIPTION = __doc__
PARAMHELP = u"""File with parameters for wind map plotting"""
MOVIEHELP = u"""If set it produces a movie and deletes the output images.
Otherwise only images are produced without a movie"""
KEEPHELP = u"""If set the images are also kept after a movie has
been produced"""
SEPARATOR1 = 79 * "-"
[docs]def calc_maplimits(lonctr=14.,
latctr=47.,
width=50,
height=30):
"""Calculate map boundaries from center-ccord., width and height"""
DEG2KM = 40000 / 360 # : km/lat.degree
DLAT = height / DEG2KM # : y-width in degrees
DLON = width / DEG2KM / np.cos(np.deg2rad(latctr)) # : x-width in degrees
LATMIN = latctr - DLAT / 2 # : min. latitude
LATMAX = latctr + DLAT / 2 # : max. latitude
LONMIN = lonctr - DLON / 2 # : min. longitude
LONMAX = lonctr + DLON / 2 # : min. longitude
return LONMIN, LONMAX, LATMIN, LATMAX
[docs]def main():
"""Main routine"""
# Imput paramters and options
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('paramfile', help=PARAMHELP)
parser.add_argument('-m', '--movie', action='store_true', help=MOVIEHELP)
parser.add_argument('-k', '--keep', action='store_true', help=KEEPHELP)
parser.add_argument('--version', action='version', version=inout.version())
args = parser.parse_args()
# read and parse parameter files
params = inout.read_inputparms(args.paramfile)
dbfile = params['dbname']
outputdir = params['outputdir']
starttime = params['startdattim']
endtime = params['enddattim']
delta = params['timedelta']
maptitle = params['maptitle']
lonmin, lonmax, latmin, latmax = params['maplimits']
pickledir = params['mappickledir']
dempath = params['dempath']
# Output log
inout.version()
print(SEPARATOR1)
print("Input paramters: ")
print("NOBO-Data-Base : ", dbfile)
print("Output-Directory : ", outputdir)
print("Start-Date-Time : ", starttime)
print("End-Date-Time : ", endtime)
print("Time-Delta (min) : ", delta)
print("Map title : ", maptitle)
print("Map: Left-Lon : {:8.5f} Right-Lon : {:8.5f}".format(lonmin,
lonmax))
print(" Lower-Lat : {:8.5f} Upper-Lat : {:8.5f}".format(latmin,
latmax))
print("Map pickle directory : ", pickledir)
print("Path to HR-DEM file : ", dempath)
print(SEPARATOR1)
print("Output Log:")
picklefilen = \
inout.makepicklefilename(pickledir,
(lonmin, lonmax, latmin, latmax)) + \
'_dm'
# Plotting
if not os.path.exists(picklefilen):
print('MAP-Pickle not yet exist, to be generated:')
print(picklefilen)
inout.make_mercator_map_and_pickle_dm(
lonmin,
lonmax,
latmin,
latmax,
picklefilen,
dempath=dempath,
resolution='c')
print('MAP-Pickle exists: \n ', picklefilen)
start = inout.yymoddhhmi2pydatetime(starttime)
end = inout.yymoddhhmi2pydatetime(endtime)
inout.windplot_dm(dbfile, picklefilen, outputdir,
start, end, delta,
maptitle=maptitle,
dempath=dempath)
if args.movie: # Movie
print(SEPARATOR1)
print("Make a movie")
fm = '%Y%m%d'
moviefilename = op.join(outputdir,
start.strftime(fm) + '_' + end.strftime(fm))
inout.moviemaker(outputdir, moviefilename)
if not args.keep:
print(SEPARATOR1)
print("Delete images")
inout.deletefiles(op.join(outputdir, '*.png'))
print(SEPARATOR1)
print("Ready - Enjoy the output!")
return
if __name__ == '__main__':
sys.exit(main())