-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
209 lines (158 loc) · 6.15 KB
/
plotting.py
File metadata and controls
209 lines (158 loc) · 6.15 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
# ===============================================================================
# Copyright 2019 ross
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
from itertools import groupby
from operator import itemgetter
import matplotlib.colors as colors
import matplotlib.cm as cmx
import matplotlib.pyplot as plt
import os
from matplotlib.backends.backend_pdf import PdfPages
from numpy import arange
from message import log
def make_dtdz(count, cfg, xs, zs, ts):
log('making dt/dz plot')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('dt/dz')
dz = zs - cfg.base_elevation
dt = ts[:len(xs)] - ts[-len(xs):]
plt.plot(xs, dt / dz)
save(os.path.join(cfg.output_root, 'dtdz_{}.pdf'.format(count)))
def make_section(count, cfg, xs, ys, ks):
log('making section plot')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
for ki, data in groupby(zip(xs, ys, ks), key=itemgetter(2)):
xis, yis, kis = zip(*data)
# plt.fill_between(xis, yis)
plt.plot(xis, yis)
save(os.path.join(cfg.output_root, 'section_{}.pdf'.format(count)))
def make_combined_temperature_vector(count, cfg, xs, ys, vs, vectors):
log('making temperature+vector')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
x, y, u, v = vectors.T
plt.contourf(xs, ys, vs, levels=cfg.levels, cmap=cfg.colormap)
add_colorbar(cfg)
plt.quiver(x, y, u, v, color=cfg.vector_color, width=0.002)
save(os.path.join(cfg.output_root, 'combined_temperature_vector_{}.pdf'.format(count)))
def make_combined_temperature_position(count, cfg, xs, ys, vs, sxs, sys):
log('making temperature+position')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
sxs, sys = zip(*sorted(zip(sxs, sys)))
plt.plot(sxs, sys)
plt.contourf(xs, ys, vs, levels=cfg.levels, cmap=cfg.colormap)
add_colorbar(cfg)
save(os.path.join(cfg.output_root, 'combined_temperature_position_{}.pdf'.format(count)))
def make_forward(cfg, xs, ys):
log('making forward')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Age (Ma)')
plt.title('Sample Forward')
plt.plot(xs, ys)
save(os.path.join(cfg.output_root, 'sample_forward.pdf'))
def make_sample_positions(count, cfg, xs, ys):
log('making sample positions')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
plt.title('Sample Position')
xs, ys = zip(*sorted(zip(xs, ys)))
plt.plot(xs, ys)
save(os.path.join(cfg.output_root, 'sample_position_{}.pdf'.format(count)))
def make_topography(count, cfg, xs, ys):
log('making topography')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
plt.title('Topography')
plt.plot(xs, ys)
save(os.path.join(cfg.output_root, 'topography_{}.pdf'.format(count)))
def make_isotherms(count, cfg, xs, ys, vs):
log('making isotherms')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
plt.title('Isotherms (C)')
ax = plt.contour(xs, ys, vs, levels=cfg.isotherms, colors='red')
if cfg.label_isotherms:
plt.clabel(ax, fmt='%0.0f (C)')
save(os.path.join(cfg.output_root, 'isotherms_{}.pdf'.format(count)))
def make_temperature_plot(count, cfg, xs, ys, vs):
log('making temperature')
plt.rcParams.update(cfg.fontdict)
plt.xlabel('X Distance Along Model Space (km)')
plt.ylabel('Elevation (km)')
plt.title('Temperature (C)')
plt.contourf(xs, ys, vs, levels=cfg.levels, cmap=cfg.colormap)
add_colorbar(cfg)
save(os.path.join(cfg.output_root, 'temperature_{}.pdf'.format(count)))
def add_colorbar(cfg):
bar = plt.colorbar(pad=0.01)
bar.mappable.set_clim(cfg.colormap_min, cfg.colormap_max)
bar.ax.invert_yaxis()
bar.set_label('Temperature (C)')
def make_coolhistory(config, tis, tes, color, label):
plt.plot(tis, tes, color=color, label=label)
def format_coolhistory(config):
ax = plt.gca()
ch = config.ch
xr = ch['xrange']
yr = ch['yrange']
xmi, xma = xr['min'], xr['max']
ymi, yma = yr['min'], yr['max']
plt.xlim(xmi, xma)
plt.ylim(ymi, yma)
for a in ('x', 'y'):
try:
if ch['grid'][a]:
plt.grid(axis=a)
except KeyError:
pass
for i, lims, axis in ((xr['interval'], ax.get_xlim, ax.xaxis),
(yr['interval'], ax.get_ylim, ax.yaxis)):
try:
if i:
start, end = lims()
if start > end:
start, end = end, start
axis.set_ticks(arange(start, end + i, i))
except KeyError:
pass
ax.set_facecolor(ch.get('bgcolor', 'lightgrey'))
plt.xlabel('Time (Ma)')
plt.ylabel('Temperature (C)')
plt.title(ch['title'])
plt.legend(loc=ch['legend_location'])
def make_line_color_mapper(cmap, start, end):
jet = cm = plt.get_cmap(cmap)
cNorm = colors.Normalize(vmin=start, vmax=end)
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)
def func(v):
return scalarMap.to_rgba(v)
return func
def save(opath):
plt.tight_layout()
pp = PdfPages(opath)
pp.savefig()
pp.close()
plt.clf()
# ============= EOF =============================================