-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_flutter_animations_temp.py
More file actions
119 lines (90 loc) · 2.84 KB
/
export_flutter_animations_temp.py
File metadata and controls
119 lines (90 loc) · 2.84 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
import xarray as xr
import cartopy.crs as ccrs
from pathlib import Path
import flutter
## Directories
dir_data = Path("data/reduced")
dir_fig = Path("data/fig")
dir_vid = dir_fig/ "vid"
#%% Shared parameters
## Variable to animate
var = "2t"
Es=[50,100]
timesteps = 5
Ts = range(0,11,11//timesteps)
n_repetitions = 2
shuffle = True
params_temp = dict(vmin=250, vmax=290, cmap="viridis")
threshold_op = "lt"
tight_layout=False
#%% Plumbing
## Mapping between two different variable naming schemes
var_map = {
"2t":"t2m",
"msl":"msl",
"10fg":"fg10",
"tp":"tp"
}
var2 = var_map[var]
## generating filenames
f_var_fun = lambda var : f"hundred_members_{var}_pf.nc"
f_var = {var:f_var_fun(var) for var in
["2t",
"msl",
"10fg",
"tp"]}
## Load data set
filename = dir_data/f_var[var]
da = xr.load_dataset(filename)
da = da.assign_coords({"longitude": [ i if i <= 180 else i-360 for i in da.longitude.values]})
# reduce spatial range
da = da.sel(longitude=slice(-20,20),latitude=slice(65,35))
#%% Animation
## evolving timesteps
## temperature - no threshold
temp_threshold = None
for E in Es:
flutter.export_flutter(da,var2,Ts,E,
filename=dir_vid/f"ensembles_time_temp_T{timesteps}_{E}.mp4",
projection= ccrs.PlateCarree(),
transform = ccrs.PlateCarree(),
plot_params=params_temp,
threshold=temp_threshold,
threshold_op=threshold_op,
n_repetitions=n_repetitions, shuffle=shuffle,
title=f"Temperatures N_ens:{E:3}",
tight_layout=tight_layout
)
#%% Animation
## evolving timesteps
## threshold temperature - freezing
temp_threshold = 273.15
## loop through parameters and export
for E in Es:
flutter.export_flutter(da,var2,Ts,E,
filename=dir_vid/f"ensembles_time_freezing_T{timesteps}_{E}.mp4",
projection= ccrs.PlateCarree(),
transform = ccrs.PlateCarree(),
plot_params=params_temp,
threshold=temp_threshold,
threshold_op=threshold_op,
n_repetitions=n_repetitions, shuffle=shuffle,
title=f"Temperatures <0⁰C N_ens:{E:3}",
tight_layout=tight_layout
)
# %% Animation
## evolving timesteps
## threshold temperature - subfreezing
temp_threshold = 268
for E in Es:
flutter.export_flutter(da,var2,Ts,E,
filename=dir_vid/f"ensembles_time_subfreezing_T{timesteps}_{E}.mp4",
projection= ccrs.PlateCarree(),
transform = ccrs.PlateCarree(),
plot_params=params_temp,
threshold=temp_threshold,
threshold_op=threshold_op,
n_repetitions=n_repetitions, shuffle=shuffle,
title=f"Temperatures <-5⁰C N_ens:{E:3}",
tight_layout=tight_layout
)