forked from astoeckel/pydwdapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.py
executable file
·81 lines (73 loc) · 2.95 KB
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Simple REST HTTP Weather Server using DWD weather data for Germany
# Copyright (C) 2016 Andreas Stöckel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import sys
# Fetch the logger
import logging
logger = logging.getLogger("pydwdapi")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Renders a map with interpolated weather data')
parser.add_argument('--user',
dest='user',
type=str,
help='DWD FTP Username')
parser.add_argument('--password',
dest='password',
type=str,
help='DWD FTP Password')
parser.add_argument('--modality',
dest='modality',
required=True,
type=str,
help='Modality to plot.')
parser.add_argument('--bare',
dest='bare',
action="store_true",
default=False,
help='If set, does not plot any descriptive overlay')
parser.add_argument('--resolution',
dest='resolution',
type=int,
default=256,
help='Map resolution in pixels')
parser.add_argument('--format',
dest='format',
type=str,
default="pdf",
help='Output format')
args = parser.parse_args()
# Setup logging
logging.basicConfig(
stream=sys.stderr,
level=logging.DEBUG,
format='%(filename)s:%(lineno)s %(levelname)s:%(message)s')
# Map extents -- min_lat, max_lat, min_lon, max_lon
extents = [47.0, 55.1, 5.8, 15.1]
# Create the API and plot the map
import pydwdapi
api = pydwdapi.PyDWDApi(args.user, args.password)
api.update()
api.render_map(args.modality,
extents,
resolution=args.resolution,
bare=args.bare).savefig(
args.modality + "." + args.format,
format=args.format,
bbox_inches='tight',
pad_inches=(0.0 if args.bare else 0.1))