Skip to content

Commit a858bd4

Browse files
committed
cartesian spectra
1 parent 905cb99 commit a858bd4

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)
@@ -1305,6 +1329,9 @@ function make_plots(
13051329
]
13061330
short_names_xyzt = short_names_xyzt collect(keys(simdirs[1].vars))
13071331

1332+
short_names_spectra = ["wa"]
1333+
short_names_spectra = short_names_spectra collect(keys(simdirs[1].vars))
1334+
13081335
# Window average from instantaneous snapshots?
13091336
function average_t_last2hrs(var)
13101337
window_end = last(var.dims["time"])
@@ -1330,11 +1357,38 @@ function make_plots(
13301357
)
13311358

13321359
summary_file = make_plots_generic(output_paths, vcat(var_groups_tz_avg_xy...);
1360+
output_name = isempty(short_names_spectra) ? "summary" : "tmp2",
13331361
plot_fn = plot_parsed_attribute_title!,
13341362
summary_files = [tmp_file],
13351363
MAX_NUM_COLS = 2, MAX_NUM_ROWS = 4,
13361364
)
13371365

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

0 commit comments

Comments
 (0)