-
Notifications
You must be signed in to change notification settings - Fork 1
/
atmoplots.py
197 lines (184 loc) · 4.64 KB
/
atmoplots.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Author: Florian Ladstädter
© Copyright 2021 [ Wegener Center && IGAM ] / UniGraz
"""
# Standard Library
import logging
import os
import sys
# Third party
import click
# First party
from atmoplots import vertical
mpl_logger = logging.getLogger("matplotlib")
mpl_logger.setLevel(logging.WARNING)
class GlobOptions(object):
def __init__(self, output_dir, output_format="png", debug=False, dpi=200):
if debug:
level = logging.DEBUG
else:
level = logging.INFO
logging.basicConfig(
level=level,
handlers=[
logging.FileHandler(
os.path.join(output_dir, f"{os.path.basename(sys.argv[0])}.log")
),
logging.StreamHandler(sys.stdout),
],
)
self.output_dir = output_dir
self.output_format = output_format
self.dpi = dpi
@click.group()
@click.option("--output-dir", required=True, type=click.Path(exists=True))
@click.option("--debug/--no-debug", default=False, show_default=True)
@click.option(
"--output-format",
default="png",
show_default=True,
type=click.Choice(["png", "pdf", "ps", "eps"]),
)
@click.option(
"--dpi",
default=200,
show_default=True,
type=float,
help="dpi of raster image.",
)
@click.pass_context
def atmoplots(ctx, output_dir, debug, output_format, dpi):
ctx.ensure_object(dict)
ctx.obj = GlobOptions(output_dir, output_format, debug, dpi)
logging.info(f"Command: {sys.argv[0]} {' '.join(sys.argv[1:])}")
@atmoplots.command()
@click.option(
"--data",
multiple=True,
type=click.Tuple([str, click.Path(exists=True)]),
help="Label and filepath of data to plot.",
)
@click.option(
"--var-to-plot",
required=True,
help="Base variable name to plot, e.g. 'dry_temperature_anomalies'",
)
@click.option(
"--vertical-dim",
default="altitude",
show_default=True,
type=click.Choice(["altitude", "pressure", "impact_altitude"]),
help="The coordinate to be used as y-axis.",
)
@click.option(
"--vertical-limits",
nargs=2,
type=float,
default=(0, 30000),
show_default=True,
help="Specify lower and upper limit for vertical dimension. "
"In (m) for altitude and (Pa) for pressure vertical dim. "
"Example: '0 30000' (m) or '100000 1000' (Pa).",
)
@click.option(
"--xlim",
nargs=2,
type=float,
help="Overrule x-limits for horizontal axis.",
)
@click.option(
"--mask-below",
type=float,
default=None,
help="Specify below which altitude level RO should be masked "
"(Recommendation: 8000 for tropics, 5000 outside).",
)
@click.option(
"--smooth-all",
type=float,
help="Smooth all datasets over the given value (in meters); "
"only for datasets on altitude, overrides values in the config.",
)
@click.option(
"--add-secondary-axis/--no-add-secondary-axis",
default=False,
show_default=True,
help="Add secondary axis with corresponding pressure or altitude levels.",
)
@click.option(
"--method-pres-to-alt",
default="empirical",
type=click.Choice(["empirical", "simple"]),
help="How to convert pressure grids to altitude. "
"empirical: Use RO average pres-to-alt mapping for the lat range; "
"simple: Use constant log height scale (pressure altitude)",
)
@click.option(
"--ipcc-style/--no-ipcc-style",
default=True,
show_default=True,
help="Use IPCC color scheme.",
)
@click.option(
"--errorbar/--no-errorbar",
default=False,
show_default=True,
help="Add errorbar.",
)
@click.option(
"--ncols",
type=int,
default=3,
help="Specify number of columns to be used in the legend.",
)
@click.option(
"--add-title/--no-add-title",
default=True,
show_default=True,
help="Add plot title.",
)
@click.option(
"--filename-prefix",
default="",
help="Prepend this string to the filename, to manually "
"enforce unique filenames if required.",
)
@click.pass_obj
def verticaltrends(
glob_opts,
data,
var_to_plot,
vertical_dim,
vertical_limits,
xlim,
mask_below,
smooth_all,
add_secondary_axis,
method_pres_to_alt,
ipcc_style,
errorbar,
ncols,
add_title,
filename_prefix,
):
vertical.plot_verticaltrends(
glob_opts,
data,
var_to_plot,
vertical_dim,
vertical_limits,
xlim,
mask_below,
smooth_all,
add_secondary_axis,
method_pres_to_alt,
ipcc_style,
errorbar,
ncols,
add_title,
filename_prefix,
)
if __name__ == "__main__":
atmoplots()