From 4843e91fef9e77711cafc13c76b2c2022cf483e2 Mon Sep 17 00:00:00 2001 From: Zhaoyi Shen <11598433+szy21@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:26:31 -0700 Subject: [PATCH] remove ncep plots --- experiments/ClimaEarth/run_amip.jl | 27 --- .../ClimaEarth/user_io/ncep_visualizer.jl | 166 ------------------ 2 files changed, 193 deletions(-) delete mode 100644 experiments/ClimaEarth/user_io/ncep_visualizer.jl diff --git a/experiments/ClimaEarth/run_amip.jl b/experiments/ClimaEarth/run_amip.jl index 562276ae7..74dea35bc 100644 --- a/experiments/ClimaEarth/run_amip.jl +++ b/experiments/ClimaEarth/run_amip.jl @@ -857,8 +857,6 @@ The postprocessing includes: - Energy and water conservation checks (if running SlabPlanet with checks enabled) - Animations (if not running in MPI) - AMIP plots of the final state of the model -- NCEP plots of reanalysis data -- Combined AMIP and NCEP plots - Error against observations - Optional additional atmosphere diagnostics plots - Plots of useful coupler and component model fields for debugging @@ -928,31 +926,6 @@ if ClimaComms.iamroot(comms_ctx) output_dir = dir_paths.artifacts, ) - ## NCEP reanalysis - @info "NCEP plots" - include("user_io/ncep_visualizer.jl") - ncep_post_spec = (; - T = (:zonal_mean,), - u = (:zonal_mean,), - q_tot = (:zonal_mean,), - toa_fluxes = (:horizontal_slice,), - precipitation_rate = (:horizontal_slice,), - T_sfc = (:horizontal_slice,), - turbulent_energy_fluxes = (:horizontal_slice,), - ) - ncep_plot_spec = plot_spec - ncep_data, fig_ncep = ncep_paperplots( - ncep_post_spec, - ncep_plot_spec, - dir_paths.output, - output_dir = dir_paths.artifacts, - month_date = cs.dates.date[1], - ) - - ## combine AMIP and NCEP plots - plot_combined = Plots.plot(fig_amip, fig_ncep, layout = (2, 1), size = (1400, 1800)) - Plots.png(joinpath(dir_paths.artifacts, "amip_ncep.png")) - ## Compare against observations if t_end > 84600 && config_dict["output_default_diagnostics"] @info "Error against observations" diff --git a/experiments/ClimaEarth/user_io/ncep_visualizer.jl b/experiments/ClimaEarth/user_io/ncep_visualizer.jl deleted file mode 100644 index e9edcbb47..000000000 --- a/experiments/ClimaEarth/user_io/ncep_visualizer.jl +++ /dev/null @@ -1,166 +0,0 @@ -import Downloads -import NCDatasets -import ClimaCoupler: Diagnostics, PostProcessor - -include("plot_helper.jl") - -""" - ncep_paperplots( - post_spec::NamedTuple, - plot_spec::NamedTuple, - files_dir::String; - month_date = Dates.DateTime(1979, 01, 01), - output_dir = ".", - fig_name = "ncep_paperplots", - ) - -Coordinates the postprocessing and plotting of sample fields (specified in `post_spec`) -of a particular monthly mean dataset (specified by `month_date`). Any plot NCEP- specific -customization should be done here. -""" -function ncep_paperplots( - post_spec::NamedTuple, - plot_spec::NamedTuple, - files_dir::String; - month_date = Dates.DateTime(1979, 01, 01), - output_dir = ".", - fig_name = "ncep_paperplots", -) - - @info month_date - - tmp_dir = joinpath(files_dir, "ncep_tmp") - isdir(tmp_dir) ? nothing : mkpath(tmp_dir) - - ncep_src = NCEPMonthlyDataSource(tmp_dir, [month_date]) - diags_vnames = propertynames(post_spec) - - all_plots = [] - all_data = (;) - for vname in diags_vnames - @info vname - - # download and read data of this month - data, coords = Diagnostics.get_var(ncep_src, Val(vname)) - raw_tag = length(size(data)) == 3 ? PostProcessor.ZLatLonData() : PostProcessor.LatLonData() - - # postprocess - post_data = - PostProcessor.postprocess(vname, data, getproperty(post_spec, vname), coords = coords, raw_tag = raw_tag) - - # create individual plots - zonal_mean_params = (; ylabel = "p (hPa)", yaxis = (;), yflip = true, getproperty(plot_spec, vname)...) # overwrite defaults - p = Plots.plot(post_data, zmd_params = zonal_mean_params, hsd_params = (; getproperty(plot_spec, vname)...)) - - push!(all_plots, p) - - # create a named tuple with data - data = post_data.data - all_data = merge(all_data, [vname => data]) - end - - # combine plots and save figure - layout = Plots.@layout([A{0.05h}; [B C D; E F G; H I J]]) - title = "NCEP Monthly Mean Fields: " * Dates.format(month_date, "mmmm yyyy") - title_plot = Plots.plot(plot_title = title, grid = false, showaxis = false, bottom_margin = -50Plots.px) - save_fig = Plots.plot( - title_plot, - all_plots..., - size = (1500, 1200), - layout = layout, - titlefont = Plots.font(12), - margin = 2Plots.mm, - ) - - Plots.png(save_fig, joinpath(output_dir, fig_name * ".png")) - - return all_data, save_fig -end - -abstract type DataSource end -struct NCEPMonthlyDataSource <: DataSource - tmp_dir::String - month_date::Array -end - -""" - download_read_nc(data_source::NCEPMonthlyDataSource, https::String, ncep_vname::String) - -Downloads and reads nc datafile of a specified NCEP variable -""" -function download_read_nc(data_source::NCEPMonthlyDataSource, https::String, ncep_vname::String) - local_file = joinpath(data_source.tmp_dir, ncep_vname * ".nc") - Downloads.download(https, local_file) - NCDatasets.NCDataset(local_file) do ds - t_i = findall(x -> Dates.yearmonth(x) == Dates.yearmonth(data_source.month_date[1]), Array(ds["time"])) # time index of month in file - d_i = length(size(Array(ds[ncep_vname]))) # index of time in the dimension list - lev = "level" in keys(ds) ? Array(ds["level"]) : [Float64(-999)] - data = dropdims(selectdim(Array(ds[ncep_vname]), d_i, t_i), dims = d_i) - if length(size(data)) == 3 - data .= data[:, end:-1:1, end:-1:1] - else - data .= data[:, end:-1:1] - end - coords = (; lon = Array(ds["lon"]), lat = Array(ds["lat"])[end:-1:1], lev = lev[end:-1:1]) - (Array(data), coords) - end -end - -# specification of variables -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:T}) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/pressure/air.mon.mean.nc" - ncep_vname = "air" - download_read_nc(data_source, https, ncep_vname) - -end - -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:u}) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/pressure/uwnd.mon.mean.nc" - ncep_vname = "uwnd" - download_read_nc(data_source, https, ncep_vname) -end - -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:q_tot}) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis/Monthlies/pressure/shum.mon.mean.nc" # Note that not ncep.reanalysis2 - ncep_vname = "shum" - download_read_nc(data_source, https, ncep_vname) -end - -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:toa_fluxes}) - https_root = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/" - https_suffix = ".ntat.mon.mean.nc" - - # sum, with upward positive. NB: dlwrf not available - # toa_tuple = download_read_nc(data_source, https_root * "uswrf" * https_suffix, "uswrf") - # toa_tuple.data .-= download_read_nc(data_source, https_root * "dswrf" * https_suffix, "dswrf").data - # toa_tuple.data .+= download_read_nc(data_source, https_root * "ulwrf" * https_suffix, "ulwrf").data - - data_uswrf, coords = download_read_nc(data_source, https_root * "uswrf" * https_suffix, "uswrf") - data_dswrf, _ = download_read_nc(data_source, https_root * "dswrf" * https_suffix, "dswrf") - data_ulwrf, _ = download_read_nc(data_source, https_root * "ulwrf" * https_suffix, "ulwrf") - - return (data_uswrf .- data_dswrf .+ data_ulwrf, coords) -end - -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:precipitation_rate}) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/prate.sfc.mon.mean.nc" - ncep_vname = "prate" - download_read_nc(data_source, https, ncep_vname) -end - -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:T_sfc}) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis/Monthlies/surface/air.sig995.mon.mean.nc" # NB: strictly speaking this is air temperature not T_sfc - ncep_vname = "air" - t_celsius, coords = download_read_nc(data_source, https, ncep_vname) - return (t_celsius .+ 273.15, coords) -end - -function Diagnostics.get_var(data_source::NCEPMonthlyDataSource, ::Val{:turbulent_energy_fluxes}) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/lhtfl.sfc.mon.mean.nc" - ncep_vname = "lhtfl" - lhtfl, coords = download_read_nc(data_source, https, ncep_vname) - https = "https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis2/Monthlies/gaussian_grid/shtfl.sfc.mon.mean.nc" - ncep_vname = "shtfl" - shtfl, coords = download_read_nc(data_source, https, ncep_vname) - return (shtfl .+ lhtfl, coords) -end