Skip to content

Commit ecbc1b9

Browse files
committed
add lwn, swn [skip ci]
1 parent 7c21b49 commit ecbc1b9

File tree

3 files changed

+170
-28
lines changed

3 files changed

+170
-28
lines changed

experiments/long_runs/data_paper_plots.jl

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function get_sim_var_dict(simdir)
5656
return sim_var_swu
5757
end
5858

59-
# Read in LWD (not to plot, but for energy balance)
59+
# Read in LWD
6060
sim_var_dict["lwd"] =
6161
() -> begin
6262
sim_var_lwd = get(simdir, short_name = "lwd") # units (W/m²)
@@ -74,6 +74,28 @@ function get_sim_var_dict(simdir)
7474
return sim_var_swd
7575
end
7676

77+
# Compute LWN = LWD - LWU
78+
sim_var_dict["lwn"] =
79+
() -> begin
80+
lwd = sim_var_dict["lwd"]()
81+
lwu = sim_var_dict["lwu"]()
82+
lwn = lwd - lwu
83+
lwn.attributes["long_name"] = "Net longwave radiation"
84+
lwn.attributes["units"] = "W m⁻²"
85+
return lwn
86+
end
87+
88+
# Compute SWN = SWD - SWU
89+
sim_var_dict["swn"] =
90+
() -> begin
91+
swd = sim_var_dict["swd"]()
92+
swu = sim_var_dict["swu"]()
93+
swn = swd - swu
94+
swn.attributes["long_name"] = "Net shortwave radiation"
95+
swn.attributes["units"] = "W m⁻²"
96+
return swn
97+
end
98+
7799
return sim_var_dict
78100
end
79101

@@ -82,8 +104,13 @@ function get_obs_var_dict()
82104
ClimaLand.Artifacts.era5_monthly_averages_2008_folder_path(),
83105
"era5_monthly_surface_fluxes_200801-200812.nc",
84106
)
85-
# era5_monthly_surface_fluxes_200801-200812.nc
86-
# era5_data_path = joinpath(ClimaLand.Artifacts.era5_monthly_averages_2008_folder_path(lowres = true), "era5_2008_1.0x1.0_lowres.nc")
107+
era5_land_forcing_data_path = joinpath(
108+
ClimaLand.Artifacts.era5_land_forcing_data2008_folder_path(
109+
lowres = false,
110+
),
111+
"era5_2008_0.9x1.25.nc",
112+
)
113+
87114
# Dict for loading in observational data
88115
obs_var_dict = Dict{String, Any}()
89116
obs_var_dict["lhf"] =
@@ -214,5 +241,90 @@ function get_obs_var_dict()
214241
return obs_var_shifted
215242
end
216243

244+
# Read in LWD
245+
obs_var_dict["lwd"] =
246+
(start_date) -> begin
247+
obs_var = ClimaAnalysis.OutputVar(
248+
era5_data_path,
249+
"msdwlwrf",
250+
new_start_date = start_date,
251+
shift_by = Dates.firstdayofmonth,
252+
) # units (W/m²)
253+
obs_var = ClimaAnalysis.replace(obs_var, missing => NaN)
254+
255+
# Copy data at lon = 0 to lon = 360 to avoid white lines
256+
push!(obs_var.dims["longitude"], 360)
257+
new_data = cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
258+
# Manually set attributes
259+
attribs = Dict(
260+
"short_name" => "lwd",
261+
"long_name" => "Downward longwave radiation",
262+
"units" => "W m⁻²",
263+
"start_date" => start_date,
264+
)
265+
266+
obs_var_shifted = ClimaAnalysis.OutputVar(
267+
attribs,
268+
obs_var.dims,
269+
obs_var.dim_attributes,
270+
new_data,
271+
)
272+
return obs_var_shifted
273+
end
274+
275+
# Read in SWD
276+
obs_var_dict["swd"] =
277+
(start_date) -> begin
278+
obs_var = ClimaAnalysis.OutputVar(
279+
era5_data_path,
280+
"msdwswrf",
281+
new_start_date = start_date,
282+
shift_by = Dates.firstdayofmonth,
283+
) # units (W/m²)
284+
obs_var = ClimaAnalysis.replace(obs_var, missing => NaN)
285+
286+
# Copy data at lon = 0 to lon = 360 to avoid white lines
287+
push!(obs_var.dims["longitude"], 360)
288+
new_data = cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
289+
# Manually set attributes
290+
attribs = Dict(
291+
"short_name" => "swd",
292+
"long_name" => "Downward shortwave radiation",
293+
"units" => "W m⁻²",
294+
"start_date" => start_date,
295+
)
296+
297+
obs_var_shifted = ClimaAnalysis.OutputVar(
298+
attribs,
299+
obs_var.dims,
300+
obs_var.dim_attributes,
301+
new_data,
302+
)
303+
return obs_var_shifted
304+
end
305+
306+
307+
# Compute LWN = LWD - LWU
308+
obs_var_dict["lwn"] =
309+
(start_date) -> begin
310+
lwd = obs_var_dict["lwd"](start_date)
311+
lwu = obs_var_dict["lwu"](start_date)
312+
lwn = lwd - lwu
313+
lwn.attributes["long_name"] = "Net longwave radiation"
314+
lwn.attributes["units"] = "W m⁻²"
315+
return lwu
316+
end
317+
318+
# Compute SWN = SWD - SWU
319+
obs_var_dict["swn"] =
320+
(start_date) -> begin
321+
swd = obs_var_dict["swd"](start_date)
322+
swu = obs_var_dict["swu"](start_date)
323+
swn = swd - swu
324+
swn.attributes["long_name"] = "Net shortwave radiation"
325+
swn.attributes["units"] = "W m⁻²"
326+
return swn
327+
end
328+
217329
return obs_var_dict
218330
end

experiments/long_runs/paper_plots.jl

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,36 @@ import ClimaLand.Parameters as LP
1414
using CairoMakie
1515
import GeoMakie
1616
using Dates
17+
using Statistics
1718

1819
root_path = joinpath(pwd(), "snowy_land_longrun_gpu")
1920
!isdir(root_path) && mkdir(root_path)
2021
# outdir = "snowy_land_longrun_gpu/output_active" # on local
2122
# Set outdir to wherever diagnostics are saved
22-
outdir = "snowy_land_longrun_gpu-3720-a_larger2_ksat_alpha/output_active" # on local
23+
# outdir = "snowy_land_longrun_gpu-3720-a_larger2_ksat_alpha/output_active" # on local
24+
# outdir = "snowy_land_longrun_gpu-3761-alpha1/output_active" # on local
25+
# outdir = "snowy_land_longrun_gpu-3771-new_default/output_active"
26+
# outdir = "snowy_land_longrun_gpu-3761-new_default/output_active" # on local
27+
outdir = "snowy_land_longrun_gpu-3777-alpha2/output_active" # on local
2328
root_path = outdir
2429

25-
short_names = ["lhf", "shf", "lwu", "swu"]
30+
short_names = ["lhf", "shf", "lwu", "swu", "lwn", "swn"]
2631
title_stubs = Dict(
2732
"lhf" => "Latent heat flux",
2833
"shf" => "Sensible heat flux",
2934
"lwu" => "Upward longwave radiation",
3035
"swu" => "Upward shortwave radiation",
36+
"lwn" => "Net longwave radiation",
37+
"swn" => "Net shortwave radiation",
3138
)
3239
# Define levels for contour colorbars
3340
levels_dict = Dict(
34-
"lhf" => collect(0:5:40),
3541
"lhf_bias" => collect(-50:10:30),
36-
"shf" => collect(-50:10:100),
3742
"shf_bias" => collect(-30:10:50),
38-
"lwu" => collect(500:10:600),
39-
"lwu_bias" => collect(-40:5:5),
40-
"swu" => collect(0:2:15),
41-
"swu_bias" => collect(-5:5:40),
43+
"lwu_bias" => collect(-40:5:20),
44+
"swu_bias" => collect(-20:5:40),
45+
"lwn_bias" => collect(-40:5:40),
46+
"swn_bias" => collect(-40:5:40),
4247
)
4348

4449
include("data_paper_plots.jl")
@@ -50,7 +55,7 @@ function compute_global_average(masked_var)
5055
land_data = ClimaAnalysis.apply_oceanmask(masked_var).data
5156
lat_data = masked_var.dims[latitude_name]
5257
mask = .~isnan.(land_data)
53-
nlon = length(masked_var.dims[lon_name])
58+
nlon = length(masked_var.dims[lon_name])µ
5459
resized_lat_data = transpose(repeat(lat_data, 1, nlon))
5560

5661
return sum(land_data[mask] .* cosd.(resized_lat_data[mask])) /
@@ -96,12 +101,12 @@ function make_paper_figures(
96101
for i in 1:12
97102
sim_slice_args =
98103
ClimaAnalysis.has_altitude(sim_var) ?
99-
Dict(:z => 1, :time => sim_var_times[i + 12]) :
100-
Dict(:time => sim_var_times[i + 12]) # if has altitude, take first layer
104+
Dict(:z => 1, :time => sim_var_times[i]) :
105+
Dict(:time => sim_var_times[i]) # if has altitude, take first layer
101106
obs_slice_args =
102107
ClimaAnalysis.has_altitude(sim_var) ?
103108
Dict(:z => 1, :time => sim_var_times[i]) :
104-
Dict(:time => sim_var_times[i + 12]) # if has altitude, take first layer
109+
Dict(:time => sim_var_times[i]) # if has altitude, take first layer
105110

106111
sim_var_sliced = ClimaAnalysis.slice(sim_var; sim_slice_args...)
107112
sim_var_masked = ClimaAnalysis.apply_oceanmask(sim_var_sliced)
@@ -112,7 +117,7 @@ function make_paper_figures(
112117
obs_var_global_average[i] = compute_global_average(obs_var_masked)
113118
end
114119

115-
i = 2 # use second year of simulation
120+
i = 1 # use first year of simulation
116121
kwarg_z = ClimaAnalysis.has_altitude(sim_var) ? Dict(:z => 1) : Dict() # if has altitude, take first layer
117122
sim_var_sliced = ClimaAnalysis.slice(sim_var; kwarg_z...)
118123
sim_var_window = ClimaAnalysis.window(
@@ -144,14 +149,30 @@ function make_paper_figures(
144149
t = sim_var_times[1]
145150

146151
# Get colorbar limits to share between heatmaps
147-
# sim_var_no_nans = deepcopy(sim_var_annual_average.data)
148-
# sim_var_no_nans[isnan.(sim_var_no_nans)] .= 0 # TODO this is a hacky way to remove NaNs in data
152+
sim_var_no_nans = deepcopy(sim_var_annual_average.data)
153+
sim_var_no_nans[isnan.(sim_var_no_nans)] .= 0 # TODO this is a hacky way to remove NaNs in data
149154
# sim_extrema = extrema(sim_var_no_nans)
150155
# obs_extrema = extrema(obs_var_annual_average.data)
151-
# we MUST pass the same clims to the sim plot, obs plot, AND colorbars
152-
levels = levels_dict[short_name]
156+
157+
combined_data =
158+
vcat(vec(sim_var_no_nans), vec(obs_var_annual_average.data))
159+
min = Int(round(quantile(combined_data, 0.05); digits = -1))
160+
max = Int(round(quantile(combined_data, 0.95); digits = -1))
161+
diff = max - min
162+
step_size = diff < 150 ? 10 : 40
163+
164+
# Increase max to be a multiple of step_size
165+
max =
166+
(diff % step_size != 0) ? max + step_size - (diff % step_size) : max
167+
clims = (min, max)
168+
levels = collect(min:step_size:max)
153169
nlevels = length(levels)
154-
clims = (levels[1], levels[end])
170+
171+
# extrema = (min(sim_extrema[1], obs_extrema[1]), max(sim_extrema[2], obs_extrema[2]))
172+
# we MUST pass the same clims to the sim plot, obs plot, AND colorbars
173+
# levels = levels_dict[short_name]
174+
# nlevels = length(levels)
175+
# clims = (levels[1], levels[end])
155176

156177
# make colorbar tick labels
157178
ticklabels = map(x -> string(x), levels)#; digits = digits_to_round)), levels)
@@ -210,7 +231,7 @@ function make_paper_figures(
210231
rev = false,
211232
)
212233
colors = colormap.colors.colors
213-
viz.contour2D_on_globe!(
234+
contour = viz.contour2D_on_globe!(
214235
fig,
215236
sim_var_annual_average,
216237
# ylabel = "$(sim_var.attributes["long_name"]) $units_label", # plot variable label on y-axis for leftmost column (sim)
@@ -223,7 +244,9 @@ function make_paper_figures(
223244
rasterize = true,
224245
# colorrange = clims,
225246
colormap = colormap,
226-
# levels = levels,
247+
levels = levels,
248+
extendhigh = :auto,
249+
extendlow = :auto,
227250
),
228251
:axis => ClimaAnalysis.Utils.kwargs(
229252
title = sim_title,
@@ -235,6 +258,7 @@ function make_paper_figures(
235258
ylabel = "$(sim_var.attributes["long_name"]) $units_label", # plot variable label on y-axis for leftmost column (sim)
236259
ylabelpadding = -5,
237260
ylabelvisible = true,
261+
# limits = clims,
238262
),
239263
),
240264
)
@@ -318,7 +342,9 @@ function make_paper_figures(
318342
rasterize = true,
319343
# colorrange = clims,
320344
colormap = colormap,
321-
# levels = levels,
345+
levels = levels,
346+
extendhigh = :auto,
347+
extendlow = :auto,
322348
),
323349
:axis => ClimaAnalysis.Utils.kwargs(
324350
title = obs_title,
@@ -486,7 +512,7 @@ function make_paper_figures(
486512
end
487513
save_name = joinpath(root_path, "combined_figures.pdf")
488514
save_name =
489-
plot_bias ? joinpath(root_path, "combined_figures_bias_contour-clims.pdf") : save_name
515+
plot_bias ? joinpath(root_path, "combined_figures_bias.pdf") : save_name
490516
save_name =
491517
plot_seasonal ? joinpath(root_path, "combined_figures_seasonal.pdf") :
492518
save_name

experiments/long_runs/seasonal_paper_plots.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ using Dates
1818
root_path = joinpath(pwd(), "snowy_land_longrun_gpu")
1919
!isdir(root_path) && mkdir(root_path)
2020
# Set outdir to wherever diagnostics are saved
21-
outdir = "snowy_land_longrun_gpu-3720-a_larger2_ksat_alpha/output_active" # on local
21+
# outdir = "snowy_land_longrun_gpu-3720-a_larger2_ksat_alpha/output_active" # on local
22+
# outdir = "snowy_land_longrun_gpu-3771-new_default/output_active"
23+
# outdir = "snowy_land_longrun_gpu-3761-new_default/output_active" # on local
24+
# outdir = "snowy_land_longrun_gpu-3761-alpha1/output_active" # on local
25+
outdir = "snowy_land_longrun_gpu-3777-alpha2/output_active" # on local
2226
root_path = outdir
2327

2428
short_names = ["lhf", "shf", "lwu", "swu"]
@@ -107,8 +111,8 @@ function make_seasonal_cycle_figure(root_path, outdir, short_names, title_stubs)
107111
for i in 1:12
108112
sim_slice_args =
109113
ClimaAnalysis.has_altitude(sim_var) ?
110-
Dict(:z => 1, :time => sim_var_times[i + 12]) :
111-
Dict(:time => sim_var_times[i + 12]) # if has altitude, take first layer
114+
Dict(:z => 1, :time => sim_var_times[i]) :
115+
Dict(:time => sim_var_times[i]) # if has altitude, take first layer
112116
obs_slice_args =
113117
ClimaAnalysis.has_altitude(sim_var) ?
114118
Dict(:z => 1, :time => obs_var_times[i]) :

0 commit comments

Comments
 (0)