Repository navigation
Expand file tree
/
Copy pathplot.py
More file actions
88 lines (64 loc) · 2.55 KB
/
Copy pathplot.py
File metadata and controls
88 lines (64 loc) · 2.55 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
import netCDF4 as nc
from pathlib import Path
from neoplot import figures, plots
from datarie import grids, templates
# Data settings
file = 'out/data/CLM5_detect_SP_TWS_trends.nc'
variable = 'TWS'
unit = 'mm / day'
outdir = 'out/plots/'
outfile = f'{variable}_trend_detect'
# Plot settings
plot_args = {
'fs_title': 12,
'fs_label': 10,
'TWS': {'vmax': 0.1,
'vmin': -0.1},
'SXI_SM_r': {'vmax': 0.002,
'vmin': -0.002},
'significance': 0.05,
'hatch_density': 3,
'hatch_pattern': '.'
}
if __name__ == '__main__':
data = nc.Dataset(file)
array = data.variables[f'{variable}_slope'][:]
p_val = data.variables[f'{variable}_p'][:]
EU3_grid = templates.grid(**grids.EU3)
lat, lon = EU3_grid.load_coordinates()
fig = figures.single_001(fx = 5,
fy = 4.,
projection = 'EU3').create()
ax = plots.amap(ax = fig.axs[0],
lon_extents = EU3_grid.lon_extents,
lat_extents = EU3_grid.lat_extents,
title = f'{variable}',
fs_label = plot_args['fs_label'],
fs_title = plot_args['fs_title'],
fs_ticks = plot_args['fs_label']).create()
trend = ax.colormesh(lon = lon,
lat = lat,
array = array,
cmap = 'coolwarm_r',
vmin = plot_args[variable]['vmin'],
vmax = plot_args[variable]['vmax'])
signif = ax.contourf(lon = lon,
lat = lat,
array = p_val,
levels = [0.0,
plot_args['significance']],
hatches = [plot_args['hatch_pattern']*plot_args['hatch_density'],
''],
colors = 'none',
alpha = None,
extend = 'neither')
ax.colorbar(trend,
ax = ax.ax,
label = f'Trend [{unit}]',
shrink = 0.6,
fs_label = plot_args['fs_label'])
ax.hatch_legend(fig = fig.fig,
dict_hatch = {'p ≤ 0.05': {'hatch': plot_args['hatch_pattern']*5,
'facecolor': 'none'}},
anchor = (0.1, 0.9),)
fig.save(Path(f'{outdir}/{outfile}'))