Skip to content

Commit de4f66b

Browse files
committed
cartesian spectra
1 parent beb82e2 commit de4f66b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

post_processing/ci_plots.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,30 @@ function compute_spectrum(var::ClimaAnalysis.OutputVar; mass_weight = nothing)
394394
)
395395
end
396396

397+
import ClimaCoreSpectra.FFTW
398+
function compute_average_cartesian_spectrum_1d(x::ClimaAnalysis.OutputVar)
399+
@assert length(x.dims) == 2 "Can only compute 1D or averaged 2D spectra"
400+
@assert x.dim2index["time"] == 1 "Time must be first dimension"
401+
space_name = x.index2dim[2]
402+
nt, nspace = size(x.data)
403+
Δ = only(unique(round.(Int, diff(x.dims[space_name])))) # Assume uniform grid, rounded to Int (m-scale)
404+
405+
= FFTW.rfft(x.data, 2) # FFT along non-time dim
406+
power = mean(abs2.(x̂) ./ nspace, dims = 1) |> vec
407+
408+
# ω = FFTW.rfftfreq(nspace, 1/Δ)
409+
ω = FFTW.rfftfreq(nspace, nspace) .+ 1 # wavenumber
410+
411+
attr = Dict(
412+
"short_name" => "spectrum_" * short_name(x),
413+
"long_name" => "Spectrum of " * long_name(x),
414+
"units" => "",
415+
)
416+
dims = Dict("Log10 Wavenumber" => log10.(ω))
417+
dim_attr = Dict("Log10 Wavenumber" => Dict("units" => "log(1/m)"))
418+
419+
return ClimaAnalysis.OutputVar(attr, dims, dim_attr, log10.(power))
420+
end
397421

398422
"""
399423
map_comparison(func, simdirs, args)
@@ -1310,6 +1334,9 @@ function make_plots(
13101334
]
13111335
short_names_xyzt = short_names_xyzt collect(keys(simdirs[1].vars))
13121336

1337+
short_names_spectra = ["wa"]
1338+
short_names_spectra = short_names_spectra collect(keys(simdirs[1].vars))
1339+
13131340
# Window average from instantaneous snapshots?
13141341
function average_t_last2hrs(var)
13151342
window_end = last(var.dims["time"])
@@ -1335,11 +1362,38 @@ function make_plots(
13351362
)
13361363

13371364
summary_file = make_plots_generic(output_paths, vcat(var_groups_tz_avg_xy...);
1365+
output_name = isempty(short_names_spectra) ? "summary" : "tmp2",
13381366
plot_fn = plot_parsed_attribute_title!,
13391367
summary_files = [tmp_file],
13401368
MAX_NUM_COLS = 2, MAX_NUM_ROWS = 4,
13411369
)
13421370

1371+
isempty(short_names_spectra) && return summary_file
1372+
# If spectra are available, make additional plots
1373+
1374+
var_groups_y_spectra =
1375+
map_comparison(simdirs, short_names_spectra) do simdir, short_name
1376+
var = get(simdir; short_name, reduction)
1377+
last_t = var.dims["time"][end]
1378+
var_ty = slice(var; x=50_000, z=10_000)
1379+
data_yt = window(var_ty, "time"; left = last_t - 10*3600)
1380+
compute_average_cartesian_spectrum_1d(data_yt)
1381+
end
1382+
1383+
var_groups_x_spectra =
1384+
map_comparison(simdirs, short_names_spectra) do simdir, short_name
1385+
var = get(simdir; short_name, reduction)
1386+
last_t = var.dims["time"][end]
1387+
var_tx = slice(var; y=50_000, z=10_000)
1388+
data_xt = window(var_tx, "time"; left = last_t - 10*3600)
1389+
compute_average_cartesian_spectrum_1d(data_xt)
1390+
end
1391+
1392+
make_plots_generic(
1393+
output_paths,
1394+
[var_groups_y_spectra; var_groups_x_spectra];
1395+
summary_files = [summary_file],
1396+
plot_fn = plot_spectrum_with_line!,
13431397
MAX_NUM_COLS = 2,
13441398
MAX_NUM_ROWS = 4,
13451399
)

0 commit comments

Comments
 (0)