Skip to content

Commit d17688e

Browse files
Merge #399
399: Enhance AMIP and NCEP paperplots r=LenkaNovak a=LenkaNovak Co-authored-by: LenkaNovak <[email protected]>
2 parents 24fb2ac + dd1b461 commit d17688e

File tree

6 files changed

+86
-38
lines changed

6 files changed

+86
-38
lines changed

experiments/AMIP/modular/coupler_driver_modular.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ dates = (; date = [date], date0 = [date0], date1 = [Dates.firstdayofmonth(date0)
353353
User can write custom diagnostics in the `user_diagnostics.jl`.
354354
=#
355355
monthly_3d_diags = init_diagnostics(
356-
(:T, :u, :q_tot),
356+
(:T, :u, :q_tot, :q_liq_ice),
357357
atmos_sim.domain.center_space;
358358
save = Monthly(),
359359
operations = (; accumulate = TimeMean([Int(0)])),
@@ -362,7 +362,7 @@ monthly_3d_diags = init_diagnostics(
362362
)
363363

364364
monthly_2d_diags = init_diagnostics(
365-
(:precipitation, :toa, :T_sfc),
365+
(:precipitation_rate, :toa_fluxes, :T_sfc, :tubulent_energy_fluxes),
366366
boundary_space;
367367
save = Monthly(),
368368
operations = (; accumulate = TimeMean([Int(0)])),
@@ -610,20 +610,24 @@ if ClimaComms.iamroot(comms_ctx)
610610
T = (:regrid, :zonal_mean),
611611
u = (:regrid, :zonal_mean),
612612
q_tot = (:regrid, :zonal_mean),
613-
toa = (:regrid, :horizontal_slice),
614-
precipitation = (:regrid, :horizontal_slice),
613+
toa_fluxes = (:regrid, :horizontal_slice),
614+
precipitation_rate = (:regrid, :horizontal_slice),
615615
T_sfc = (:regrid, :horizontal_slice),
616+
tubulent_energy_fluxes = (:regrid, :horizontal_slice),
617+
q_liq_ice = (:regrid, :zonal_mean),
616618
)
617619

618620
plot_spec = (;
619621
T = (; clims = (190, 320), units = "K"),
620622
u = (; clims = (-50, 50), units = "m/s"),
621-
q_tot = (; clims = (0, 50), units = "g/kg"),
622-
toa = (; clims = (-250, 210), units = "W/m^2"),
623-
precipitation = (clims = (0, 1e-6), units = "kg/m^2/s"),
623+
q_tot = (; clims = (0, 30), units = "g/kg"),
624+
toa_fluxes = (; clims = (-250, 250), units = "W/m^2"),
625+
precipitation_rate = (clims = (0, 1e-4), units = "kg/m^2/s"),
624626
T_sfc = (clims = (225, 310), units = "K"),
627+
tubulent_energy_fluxes = (; clims = (-250, 250), units = "W/m^2"),
628+
q_liq_ice = (; clims = (0, 10), units = "g/kg"),
625629
)
626-
amip_paperplots(
630+
amip_data = amip_paperplots(
627631
post_spec,
628632
plot_spec,
629633
COUPLER_OUTPUT_DIR,
@@ -638,12 +642,13 @@ if ClimaComms.iamroot(comms_ctx)
638642
T = (:zonal_mean,),
639643
u = (:zonal_mean,),
640644
q_tot = (:zonal_mean,),
641-
toa = (:horizontal_slice,),
642-
precipitation = (:horizontal_slice,),
645+
toa_fluxes = (:horizontal_slice,),
646+
precipitation_rate = (:horizontal_slice,),
643647
T_sfc = (:horizontal_slice,),
648+
tubulent_energy_fluxes = (:horizontal_slice,),
644649
)
645650
ncep_plot_spec = plot_spec
646-
ncep_paperplots(
651+
ncep_data = ncep_paperplots(
647652
ncep_post_spec,
648653
ncep_plot_spec,
649654
COUPLER_OUTPUT_DIR,

experiments/AMIP/modular/user_io/amip_visualizer.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ function amip_paperplots(
1919
output_dir = ".",
2020
files_root = ".hdf5",
2121
fig_name = "amip_paperplots",
22+
nlat = 180,
23+
nlon = 360,
2224
)
2325

2426
diags_names = propertynames(post_spec)
2527

2628
all_plots = []
29+
all_data = (;)
2730
for name in diags_names
2831
@info name
2932

3033
# extract data
3134
diag_data = read_latest_model_data(name, files_dir, files_root)
3235

3336
# postprocess
34-
post_data = postprocess(name, diag_data, getproperty(post_spec, name))
37+
post_data = postprocess(name, diag_data, getproperty(post_spec, name), nlat = nlat, nlon = nlon)
3538
post_data.data[1] = sum(post_data.data) == 0 ? post_data.data[1] + eps() : post_data.data[1] # avoids InexactError
3639

3740
# create individual plots
@@ -42,21 +45,25 @@ function amip_paperplots(
4245
)
4346

4447
push!(all_plots, p)
48+
49+
# create a named tuple with data
50+
data = post_data.data
51+
all_data = merge(all_data, [name => data])
4552
end
4653

4754
# combine plots and save figure
4855
save_fig = Plots.plot(
4956
all_plots...,
50-
size = (1500, 800),
51-
right_margin = 12Plots.mm,
52-
left_margin = 12Plots.mm,
53-
bottom_margin = 12Plots.mm,
54-
top_margin = 12Plots.mm,
57+
size = (1500, 1200),
58+
right_margin = 3Plots.mm,
59+
left_margin = 3Plots.mm,
60+
bottom_margin = 3Plots.mm,
61+
top_margin = 3Plots.mm,
5562
)
5663

5764
Plots.png(save_fig, joinpath(output_dir, fig_name * ".png"))
5865

59-
return all_plots
66+
return all_data
6067
end
6168

6269
"""

experiments/AMIP/modular/user_io/ncep_visualizer.jl

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ include("plot_helper.jl")
1313
fig_name = "ncep_paperplots",
1414
)
1515
16-
Coordinates the postprocessing and plotting of sample fields (specified in `post_spec`)
16+
Coordinates the postprocessing and plotting of sample fields (specified in `post_spec`)
1717
of a particular monthly mean dataset (specified by `month_date`). Any plot NCEP- specific
18-
customization should be done here.
18+
customization should be done here.
1919
"""
2020
function ncep_paperplots(
2121
post_spec::NamedTuple,
@@ -35,6 +35,7 @@ function ncep_paperplots(
3535
diags_vnames = propertynames(post_spec)
3636

3737
all_plots = []
38+
all_data = (;)
3839
for vname in diags_vnames
3940
@info vname
4041

@@ -50,21 +51,25 @@ function ncep_paperplots(
5051
p = plot(post_data, zmd_params = zonal_mean_params, hsd_params = (; getproperty(plot_spec, vname)...))
5152

5253
push!(all_plots, p)
54+
55+
# create a named tuple with data
56+
data = post_data.data
57+
all_data = merge(all_data, [vname => data])
5358
end
5459

5560
# combine plots and save figure
5661
save_fig = Plots.plot(
5762
all_plots...,
58-
size = (1500, 800),
59-
right_margin = 12Plots.mm,
60-
left_margin = 12Plots.mm,
61-
bottom_margin = 12Plots.mm,
62-
top_margin = 12Plots.mm,
63+
size = (1500, 1200),
64+
right_margin = 3Plots.mm,
65+
left_margin = 3Plots.mm,
66+
bottom_margin = 3Plots.mm,
67+
top_margin = 3Plots.mm,
6368
)
6469

6570
Plots.png(save_fig, joinpath(output_dir, fig_name * ".png"))
6671

67-
return all_plots
72+
return all_data
6873
end
6974

7075
abstract type DataSource end
@@ -116,7 +121,7 @@ function get_var(data_source::NCEPMonthlyDataSource, ::Val{:q_tot})
116121
download_read_nc(data_source, https, ncep_vname)
117122
end
118123

119-
function get_var(data_source::NCEPMonthlyDataSource, ::Val{:toa})
124+
function get_var(data_source::NCEPMonthlyDataSource, ::Val{:toa_fluxes})
120125
https_root = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/"
121126
https_suffix = ".ntat.mon.mean.nc"
122127

@@ -132,7 +137,7 @@ function get_var(data_source::NCEPMonthlyDataSource, ::Val{:toa})
132137
return (data_uswrf .- data_dswrf .+ data_ulwrf, coords)
133138
end
134139

135-
function get_var(data_source::NCEPMonthlyDataSource, ::Val{:precipitation})
140+
function get_var(data_source::NCEPMonthlyDataSource, ::Val{:precipitation_rate})
136141
https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/prate.sfc.mon.mean.nc"
137142
ncep_vname = "prate"
138143
download_read_nc(data_source, https, ncep_vname)
@@ -144,3 +149,13 @@ function get_var(data_source::NCEPMonthlyDataSource, ::Val{:T_sfc})
144149
t_celsius, coords = download_read_nc(data_source, https, ncep_vname)
145150
return (t_celsius .+ 273.15, coords)
146151
end
152+
153+
function get_var(data_source::NCEPMonthlyDataSource, ::Val{:tubulent_energy_fluxes})
154+
https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/lhtfl.sfc.mon.mean.nc"
155+
ncep_vname = "lhtfl"
156+
lhtfl, coords = download_read_nc(data_source, https, ncep_vname)
157+
https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/shtfl.sfc.mon.mean.nc"
158+
ncep_vname = "shtfl"
159+
shtfl, coords = download_read_nc(data_source, https, ncep_vname)
160+
return (shtfl .+ lhtfl, coords)
161+
end

experiments/AMIP/modular/user_io/plot_helper.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Coordinates plotting based on parsed data types.
1010
"""
1111
function plot(post_data::DataPackage; zmd_params = (;), hsd_params = (;))
1212

13-
if post_data isa ZLatData
13+
if post_data.tag isa ZLatData
1414
plot_params = zmd_params
15-
elseif post_data isa LatLonData
15+
elseif post_data.tag isa LatLonData
1616
plot_params = hsd_params
1717
else
1818
plot_params = (;)
@@ -45,7 +45,7 @@ function contourf(
4545
units = " ",
4646
)
4747
clims = clims == nothing ? extrema(p.data) : clims
48-
plot_p = Plots.contourf(
48+
Plots.contourf(
4949
p.coords.lat,
5050
p.coords.lev,
5151
p.data',

experiments/AMIP/modular/user_io/user_diagnostics.jl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,30 @@ get_var(cs::CoupledSimulation, ::Val{:u}) =
2727
"""
2828
get_var(cs::CoupledSimulation, ::Val{:q_tot})
2929
30-
Total specific humidity (kg kg⁻¹).
30+
Total specific humidity (g kg⁻¹).
3131
"""
3232
get_var(cs::CoupledSimulation, ::Val{:q_tot}) =
3333
cs.model_sims.atmos_sim.integrator.u.c.ρq_tot ./ cs.model_sims.atmos_sim.integrator.u.c.ρ .* float_type(cs)(1000)
3434

35+
36+
"""
37+
get_var(cs::CoupledSimulation, ::Val{:q_liq_ice})
38+
39+
Cloud specific humidity (g kg⁻¹).
3540
"""
36-
get_var(cs::CoupledSimulation, ::Val{:toa})
41+
function get_var(cs::CoupledSimulation, ::Val{:q_liq_ice})
42+
p = cs.model_sims.atmos_sim.integrator.p
43+
(; ᶜts, params) = p
44+
thermo_params = CAP.thermodynamics_params(params)
45+
TD.liquid_specific_humidity.(thermo_params, ᶜts) .* float_type(cs)(1000)
46+
end
47+
48+
"""
49+
get_var(cs::CoupledSimulation, ::Val{:toa_fluxes})
3750
3851
Top of the atmosphere radiation fluxes (W m⁻²).
3952
"""
40-
function get_var(cs::CoupledSimulation, ::Val{:toa})
53+
function get_var(cs::CoupledSimulation, ::Val{:toa_fluxes})
4154
atmos_sim = cs.model_sims.atmos_sim
4255
face_space = axes(atmos_sim.integrator.u.f)
4356
z = parent(Fields.coordinate_field(face_space).z)
@@ -66,11 +79,11 @@ function get_var(cs::CoupledSimulation, ::Val{:toa})
6679
end
6780

6881
"""
69-
get_var(cs::CoupledSimulation, ::Val{:precipitation})
82+
get_var(cs::CoupledSimulation, ::Val{:precipitation_rate})
7083
71-
Precipitation (m m⁻²).
84+
Precipitation rate (Kg m⁻² s⁻¹).
7285
"""
73-
get_var(cs::CoupledSimulation, ::Val{:precipitation}) =
86+
get_var(cs::CoupledSimulation, ::Val{:precipitation_rate}) =
7487
.-swap_space!(
7588
zeros(cs.boundary_space),
7689
cs.model_sims.atmos_sim.integrator.p.col_integrated_rain .+
@@ -85,4 +98,12 @@ Combined surface temperature (K).
8598
"""
8699
get_var(cs::CoupledSimulation, ::Val{:T_sfc}) = swap_space!(zeros(cs.boundary_space), cs.fields.T_S)
87100

101+
"""
102+
get_var(cs::CoupledSimulation, ::Val{:tubulent_energy_fluxes})
103+
104+
Combined aerodynamic turbulent energy surface fluxes (W m⁻²).
105+
"""
106+
get_var(cs::CoupledSimulation, ::Val{:tubulent_energy_fluxes}) =
107+
swap_space!(zeros(cs.boundary_space), cs.fields.F_turb_energy)
108+
88109
# land diagnotics

perf/flame.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ run_name_list =
1818
run_name = run_name_list[parse(Int, ARGS[2])]
1919
allocs_limit = Dict()
2020
allocs_limit["perf_default_modular_unthreaded"] = 8638304
21-
allocs_limit["perf_coarse_single_modular"] = 12671552
21+
allocs_limit["perf_coarse_single_modular"] = 18280800
2222
allocs_limit["perf_target_amip_n32_shortrun"] = 172134848
2323

2424
# number of time steps used for profiling

0 commit comments

Comments
 (0)