Skip to content

Commit 7ca091b

Browse files
committed
use net radiative fluxes
1 parent 5326771 commit 7ca091b

File tree

3 files changed

+121
-61
lines changed

3 files changed

+121
-61
lines changed

bucket_restart/output_active

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output_0000

experiments/long_runs/data_paper_plots.jl

Lines changed: 115 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -74,42 +74,46 @@ 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
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+
lwn.attributes["start_date"] = lwu.attributes["start_date"]
86+
return lwn
87+
end
88+
89+
# Compute SWN = SWD - SWU
90+
sim_var_dict["swn"] =
91+
() -> begin
92+
swd = sim_var_dict["swd"]()
93+
swu = sim_var_dict["swu"]()
94+
swn = swd - swu
95+
swn.attributes["long_name"] = "Net shortwave radiation"
96+
swn.attributes["units"] = "W m⁻²"
97+
swn.attributes["start_date"] = swu.attributes["start_date"]
98+
return swn
99+
end
98100

99101
return sim_var_dict
100102
end
101103

102104
function get_obs_var_dict()
105+
# contains monthly mslhf, msshf, msuwlwrf, msuwswrf
103106
era5_data_path = joinpath(
104107
ClimaLand.Artifacts.era5_monthly_averages_2008_folder_path(),
105108
"era5_monthly_surface_fluxes_200801-200812.nc",
106109
)
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-
# )
110+
# contains hourly msdwlwrf, msdwswrf
111+
era5_land_forcing_data_path = joinpath(
112+
ClimaLand.Artifacts.era5_land_forcing_data2008_folder_path(
113+
lowres = false,
114+
),
115+
"era5_2008_1.0x1.0.nc",
116+
)
113117

114118
# Dict for loading in observational data
115119
obs_var_dict = Dict{String, Any}()
@@ -132,11 +136,11 @@ function get_obs_var_dict()
132136
)
133137

134138
# Copy data at lon = 0 to lon = 360 to avoid white lines
135-
push!(obs_var.dims["longitude"], 360)
139+
push!(obs_var.dims[ClimaAnalysis.longitude_name(obs_var)], 360)
136140
new_data =
137141
-1 * cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
138142
# # relabel longitude values from [0, 359] to [-180, 179]
139-
# obs_var.dims["longitude"] = obs_var.dims["longitude"] .- 180
143+
# obs_var.dims[ClimaAnalysis.longitude_name(obs_var)] = obs_var.dims[ClimaAnalysis.longitude_name(obs_var)] .- 180
140144
obs_var_pos = ClimaAnalysis.OutputVar(
141145
attribs,
142146
obs_var.dims,
@@ -165,7 +169,7 @@ function get_obs_var_dict()
165169
"start_date" => start_date,
166170
)
167171
# Copy data at lon = 0 to lon = 360 to avoid white lines
168-
push!(obs_var.dims["longitude"], 360)
172+
push!(obs_var.dims[ClimaAnalysis.longitude_name(obs_var)], 360)
169173
new_data =
170174
-1 * cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
171175
obs_var_pos = ClimaAnalysis.OutputVar(
@@ -190,7 +194,7 @@ function get_obs_var_dict()
190194
obs_var = ClimaAnalysis.replace(obs_var, missing => NaN)
191195

192196
# Copy data at lon = 0 to lon = 360 to avoid white lines
193-
push!(obs_var.dims["longitude"], 360)
197+
push!(obs_var.dims[ClimaAnalysis.longitude_name(obs_var)], 360)
194198
new_data = cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
195199

196200
# Manually set attributes
@@ -222,7 +226,7 @@ function get_obs_var_dict()
222226
obs_var = ClimaAnalysis.replace(obs_var, missing => NaN)
223227

224228
# Copy data at lon = 0 to lon = 360 to avoid white lines
225-
push!(obs_var.dims["longitude"], 360)
229+
push!(obs_var.dims[ClimaAnalysis.longitude_name(obs_var)], 360)
226230
new_data = cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
227231
# Manually set attributes
228232
attribs = Dict(
@@ -245,15 +249,15 @@ function get_obs_var_dict()
245249
obs_var_dict["lwd"] =
246250
(start_date) -> begin
247251
obs_var = ClimaAnalysis.OutputVar(
248-
era5_data_path,
252+
era5_land_forcing_data_path,
249253
"msdwlwrf",
250254
new_start_date = start_date,
251255
shift_by = Dates.firstdayofmonth,
252256
) # units (W/m²)
253257
obs_var = ClimaAnalysis.replace(obs_var, missing => NaN)
254258

255259
# Copy data at lon = 0 to lon = 360 to avoid white lines
256-
push!(obs_var.dims["longitude"], 360)
260+
push!(obs_var.dims[ClimaAnalysis.longitude_name(obs_var)], 360)
257261
new_data = cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
258262
# Manually set attributes
259263
attribs = Dict(
@@ -276,15 +280,15 @@ function get_obs_var_dict()
276280
obs_var_dict["swd"] =
277281
(start_date) -> begin
278282
obs_var = ClimaAnalysis.OutputVar(
279-
era5_data_path,
283+
era5_land_forcing_data_path,
280284
"msdwswrf",
281285
new_start_date = start_date,
282286
shift_by = Dates.firstdayofmonth,
283287
) # units (W/m²)
284288
obs_var = ClimaAnalysis.replace(obs_var, missing => NaN)
285289

286290
# Copy data at lon = 0 to lon = 360 to avoid white lines
287-
push!(obs_var.dims["longitude"], 360)
291+
push!(obs_var.dims[ClimaAnalysis.longitude_name(obs_var)], 360)
288292
new_data = cat(obs_var.data, obs_var.data[[1], :, :], dims = 1)
289293
# Manually set attributes
290294
attribs = Dict(
@@ -304,27 +308,81 @@ function get_obs_var_dict()
304308
end
305309

306310

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
311+
# Compute LWN = LWD - LWU
312+
obs_var_dict["lwn"] =
313+
(start_date) -> begin
314+
# LWD is very large because it's hourly, so it takes a while to load
315+
lwd = obs_var_dict["lwd"](start_date)
316+
lwu = obs_var_dict["lwu"](start_date)
317+
318+
monthly_times = lwu.dims["time"]
319+
lwd_monthly_data = similar(lwu.data)
320+
# average hourly LWD data to monthly so we can compare with monthly LWU
321+
for (idx, time) in enumerate(monthly_times)
322+
# collect all hourly time indices in this month
323+
time_idxs = findall(x -> (x == time), lwd.dims["time"])
324+
325+
# average hourly data to monthly
326+
lwd_monthly_data[:, :, idx] =
327+
mean(lwd.data[:, :, time_idxs], dims = 3)
328+
end
329+
330+
# Compute LWN = LWD - LWU
331+
lwn_data = lwd_monthly_data - lwu.data
332+
333+
attribs = Dict(
334+
"short_name" => "lwn",
335+
"long_name" => "Net longwave radiation",
336+
"units" => "W m⁻²",
337+
"start_date" => start_date,
338+
)
339+
340+
lwn = ClimaAnalysis.OutputVar(
341+
attribs,
342+
lwu.dims,
343+
lwu.dim_attributes,
344+
lwn_data,
345+
)
346+
return lwn
347+
end
348+
349+
# Compute SWN = SWD - SWU
350+
obs_var_dict["swn"] =
351+
(start_date) -> begin
352+
# SWD is very large because it's hourly, so it takes a while to load
353+
swd = obs_var_dict["swd"](start_date)
354+
swu = obs_var_dict["swu"](start_date)
355+
356+
monthly_times = swu.dims["time"]
357+
swd_monthly_data = similar(swu.data)
358+
# average hourly SWD data to monthly so we can compare with monthly SWU
359+
for (idx, time) in enumerate(monthly_times)
360+
# collect all hourly time indices in this month
361+
time_idxs = findall(x -> (x == time), swd.dims["time"])
362+
363+
# average hourly data to monthly
364+
swd_monthly_data[:, :, idx] =
365+
mean(swd.data[:, :, time_idxs], dims = 3)
366+
end
367+
368+
# Compute SWN = SWD - SWU
369+
swn_data = swd_monthly_data - swu.data
370+
371+
attribs = Dict(
372+
"short_name" => "swn",
373+
"long_name" => "Net shortwave radiation",
374+
"units" => "W m⁻²",
375+
"start_date" => start_date,
376+
)
377+
378+
swn = ClimaAnalysis.OutputVar(
379+
attribs,
380+
swu.dims,
381+
swu.dim_attributes,
382+
swn_data,
383+
)
384+
return swn
385+
end
328386

329387
return obs_var_dict
330388
end

experiments/long_runs/paper_plots.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ root_path = joinpath(pwd(), "snowy_land_longrun_gpu")
2727
outdir = "snowy_land_longrun_gpu-3785"
2828
root_path = outdir
2929

30-
short_names = ["lhf", "shf", "lwu", "swu"]#, "lwn", "swn"]
30+
short_names = ["lhf", "shf", "lwn", "swn"]#, "lwu", "swu"]
3131
title_stubs = Dict(
3232
"lhf" => "LE",#"Latent heat flux",
3333
"shf" => "H",#"Sensible heat flux",
3434
"lwu" => "LWᵤ",#"Upward longwave radiation",
3535
"swu" => "SWᵤ",#"Upward shortwave radiation",
36+
"lwn" => "LWₙ",#"Net longwave radiation",
37+
"swn" => "SWₙ",#"Net shortwave radiation",
3638
)
3739
# Define levels for contour colorbars
3840
levels_dict = Dict(
@@ -92,8 +94,6 @@ function make_paper_figures(
9294

9395
obs_var = obs_var_dict[short_name](sim_var.attributes["start_date"])
9496

95-
96-
9797
sim_var_global_average = zeros(12)
9898
obs_var_global_average = zeros(12)
9999
for i in 1:12
@@ -510,7 +510,8 @@ function make_paper_figures(
510510
end
511511
save_name = joinpath(root_path, "combined_figures.png")
512512
save_name =
513-
plot_bias ? joinpath(root_path, "combined_figures_bias.png") : save_name
513+
plot_bias ? joinpath(root_path, "combined_figures_net-rad_bias.png") :
514+
save_name
514515
save_name =
515516
plot_seasonal ? joinpath(root_path, "combined_figures_seasonal.png") :
516517
save_name

0 commit comments

Comments
 (0)