Skip to content

Commit bc701fd

Browse files
committed
format
1 parent 0659f0b commit bc701fd

File tree

2 files changed

+72
-28
lines changed

2 files changed

+72
-28
lines changed

experiments/ClimaEarth/hierarchy/climate_plots.jl

+31-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DelimitedFiles: writedlm, readdlm
88

99
include("plot_helper.jl")
1010

11-
for job_id in ["dry_held_suarez", "moist_held_suarez",]
11+
for job_id in ["dry_held_suarez", "moist_held_suarez"]
1212
if isinteractive()
1313
DATA_DIR = "experiments/ClimaEarth/$job_id/$job_id/clima_atmos/output_active/"
1414
else
@@ -24,7 +24,16 @@ for job_id in ["dry_held_suarez", "moist_held_suarez",]
2424
# SUPPLEMENTAL: animation of surface temperature
2525
ta_sfc, lat, lon, z, time = get_nc_data_all("ta", reduction, DATA_DIR)
2626
anim = Plots.@animate for i in 1:size(ta_sfc, 1)
27-
Plots.contourf(lon, lat, ta_sfc[i, :, :, 1]', xlabel="Longitude", ylabel="Latitude", title="$var", color=:viridis, clims=(260, 315))
27+
Plots.contourf(
28+
lon,
29+
lat,
30+
ta_sfc[i, :, :, 1]',
31+
xlabel = "Longitude",
32+
ylabel = "Latitude",
33+
title = "$var",
34+
color = :viridis,
35+
clims = (260, 315),
36+
)
2837
end
2938
Plots.mp4(anim, joinpath(PLOT_DIR, "anim_ta_sfc.mp4"), fps = 10)
3039

@@ -39,29 +48,41 @@ for job_id in ["dry_held_suarez", "moist_held_suarez",]
3948

4049
# F4: storm track diagnostics: time mean maps
4150
lev_st = 6
42-
ta_zm, ta_sfc,lat, lon, z = mean_climate_data("ta", reduction, DATA_DIR, lev_i = lev_st)
43-
va_zm, va_sfc,lat, lon, z = mean_climate_data("va", reduction, DATA_DIR, lev_i = lev_st)
44-
vT_zm, vT_sfc,lat, lon, z = mean_climate_data("vt", reduction, DATA_DIR, lev_i = lev_st)
51+
ta_zm, ta_sfc, lat, lon, z = mean_climate_data("ta", reduction, DATA_DIR, lev_i = lev_st)
52+
va_zm, va_sfc, lat, lon, z = mean_climate_data("va", reduction, DATA_DIR, lev_i = lev_st)
53+
vT_zm, vT_sfc, lat, lon, z = mean_climate_data("vt", reduction, DATA_DIR, lev_i = lev_st)
4554
heat_flux_zm = vT_zm .- va_zm .* ta_zm
4655

47-
pa_zm, ~,~,~,~ = mean_climate_data("pfull", reduction, DATA_DIR)
56+
pa_zm, ~, ~, ~, ~ = mean_climate_data("pfull", reduction, DATA_DIR)
4857
pa_zm = pa_zm ./ 100 # convert to hPa
4958
pa_grid = [950, 800, 700, 600, 500, 400, 300, 200, 50]
5059

5160
heat_flux_int_zm = interpolate_to_pressure_coord_2d(heat_flux_zm, pa_zm, pa_grid)
52-
Plots.contourf(lat, -pa_grid, heat_flux_int_zm', xlabel="Latitude (deg N)", ylabel="Pressure (hPa)", title="Heat flux", color=:viridis, ylims = (-pa_grid[1], -pa_grid[end]), yticks = (-pa_grid, pa_grid))# , clims=(-1e10, 1e10))
61+
Plots.contourf(
62+
lat,
63+
-pa_grid,
64+
heat_flux_int_zm',
65+
xlabel = "Latitude (deg N)",
66+
ylabel = "Pressure (hPa)",
67+
title = "Heat flux",
68+
color = :viridis,
69+
ylims = (-pa_grid[1], -pa_grid[end]),
70+
yticks = (-pa_grid, pa_grid),
71+
)# , clims=(-1e10, 1e10))
5372
png(joinpath(PLOT_DIR, "$(job_id)_heat_flux.png"))
5473

5574
# F5: storm track diagnostics: timeseries
5675
lev_i, lat_s_i, lat_n_i, lon_w_i, lon_e_i = lev_st, 60, 75, 1, 30
57-
println("Sectorial selevtion for timeseries: \n level: $(z[lev_i]), lat: $(lat[lat_s_i]) to $(lat[lat_n_i]), lon: $(lon[lon_w_i]) to $(lon[lon_e_i])")
76+
println(
77+
"Sectorial selevtion for timeseries: \n level: $(z[lev_i]), lat: $(lat[lat_s_i]) to $(lat[lat_n_i]), lon: $(lon[lon_w_i]) to $(lon[lon_e_i])",
78+
)
5879

5980
egr_all, lat, lon, z, time = get_nc_data_all("egr", reduction, DATA_DIR)
60-
egr_t = point_timeseries_data(egr_all, [lon_w_i, lon_e_i], [lat_s_i, lat_n_i],lev_i)
81+
egr_t = point_timeseries_data(egr_all, [lon_w_i, lon_e_i], [lat_s_i, lat_n_i], lev_i)
6182

6283
vT_all, lat, lon, z, time = get_nc_data_all("vt", reduction, DATA_DIR)
6384
va_all, lat, lon, z, time = get_nc_data_all("va", reduction, DATA_DIR)
6485
ta_all, lat, lon, z, time = get_nc_data_all("ta", reduction, DATA_DIR)
6586
heat_flux_all = vT_all .- va_all .* ta_all
6687
heat_flux_t = point_timeseries_data(heat_flux_all, [lon_w_i, lon_e_i], [lat_s_i, lat_n_i], lev_i)
67-
end
88+
end

experiments/ClimaEarth/hierarchy/plot_helper.jl

+41-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Reads the netcdf file for the variable `var` and reduction `red` from the direct
77
"""
88
get_nc_data_all = (var, red, DATA_DIR) -> begin
99
ds = NCDataset("$DATA_DIR/$(var)_$red.nc")
10-
var = ds["$var"][:,:,:,:]
10+
var = ds["$var"][:, :, :, :]
1111
lat = ds["lat"][:]
1212
lon = ds["lon"][:]
1313
z = ds["z"][:]
@@ -21,28 +21,30 @@ end
2121
2222
Postprocesses the climate data for the variable `var` and reduction `red` from the directory `DATA_DIR`. Returns the zonal mean and horizontal surface slice mean of the variable.
2323
"""
24-
mean_climate_data = (varname, reduction, DATA_DIR; lev_i = 2, spinup=160) -> begin
24+
mean_climate_data =
25+
(varname, reduction, DATA_DIR; lev_i = 2, spinup = 160) -> begin
2526

26-
var, lat, lon, z, time = get_nc_data_all(varname, reduction, DATA_DIR)
27-
@assert spinup < size(var, 1)
27+
var, lat, lon, z, time = get_nc_data_all(varname, reduction, DATA_DIR)
28+
@assert spinup < size(var, 1)
2829

29-
var_time_zonal_mean = mean(var[spinup:end,:,:,:], dims=(1,2))[1, 1, :, :]
30-
var_time_mean_sfc = mean(var[spinup:end,:,:,:], dims=(1))[1, :, :, lev_i]
30+
var_time_zonal_mean = mean(var[spinup:end, :, :, :], dims = (1, 2))[1, 1, :, :]
31+
var_time_mean_sfc = mean(var[spinup:end, :, :, :], dims = (1))[1, :, :, lev_i]
3132

32-
return var_time_zonal_mean, var_time_mean_sfc, lat, lon, z
33-
end
33+
return var_time_zonal_mean, var_time_mean_sfc, lat, lon, z
34+
end
3435

3536
"""
3637
point_timeseries_data(variable, lon_i, lat_i, lev_i)
3738
3839
Returns the time series data for the variable `variable` at the indices `lon_i`, `lat_i`, and `lev_i`.
3940
"""
40-
point_timeseries_data = (variable, lon_i, lat_i, lev_i) -> begin
41+
point_timeseries_data =
42+
(variable, lon_i, lat_i, lev_i) -> begin
4143

42-
variable_time_mean = mean(variable[:, lon_i[1]:lon_i[2], lat_i[1]:lat_i[2], lev_i], dims=(2,3))[:,1,1]
44+
variable_time_mean = mean(variable[:, lon_i[1]:lon_i[2], lat_i[1]:lat_i[2], lev_i], dims = (2, 3))[:, 1, 1]
4345

44-
return variable_time_mean
45-
end
46+
return variable_time_mean
47+
end
4648

4749
"""
4850
plot_climate(var, DATA_DIR, PLOT_DIR; reduction = "inst")
@@ -55,22 +57,43 @@ function plot_climate(var, DATA_DIR, PLOT_DIR, job_id; reduction = "inst", inter
5557

5658
# vertical-lat plot of zonal and time mean
5759
if interpolate_to_pressure
58-
pa_zm, ~,~,~,~ = mean_climate_data("pfull", reduction, DATA_DIR)
60+
pa_zm, ~, ~, ~, ~ = mean_climate_data("pfull", reduction, DATA_DIR)
5961
pa_zm = pa_zm ./ 100 # convert to hPa
6062
pa_grid = [950, 800, 700, 600, 500, 400, 300, 200, 50]
6163
strf_zm = interpolate_to_pressure_coord_2d(strf_zm, pa_zm, pa_grid)
62-
Plots.contourf(lat, -pa_grid, strf_zm', xlabel="Latitude (deg N)", ylabel="Pressure (hPa)", title="$var", color=:viridis, ylims = (-pa_grid[1], -pa_grid[end]), yticks = (-pa_grid, pa_grid))# , clims=(-1e10, 1e10))
64+
Plots.contourf(
65+
lat,
66+
-pa_grid,
67+
strf_zm',
68+
xlabel = "Latitude (deg N)",
69+
ylabel = "Pressure (hPa)",
70+
title = "$var",
71+
color = :viridis,
72+
ylims = (-pa_grid[1], -pa_grid[end]),
73+
yticks = (-pa_grid, pa_grid),
74+
)# , clims=(-1e10, 1e10))
6375
png(joinpath(PLOT_DIR, "$(job_id)_$(var)_pa.png"))
6476
else
65-
Plots.contourf(lat, z, strf_zm', xlabel="Latitude", ylabel="Height (km)", title="$var", color=:viridis, ylims = (0, 3e4), yscale=:log10, yticks = ([1e3,5e3,10e3,20e3,30e3], ["1", "5", "10", "20", "30"]))# , clims=(-1e10, 1e10)
77+
Plots.contourf(
78+
lat,
79+
z,
80+
strf_zm',
81+
xlabel = "Latitude",
82+
ylabel = "Height (km)",
83+
title = "$var",
84+
color = :viridis,
85+
ylims = (0, 3e4),
86+
yscale = :log10,
87+
yticks = ([1e3, 5e3, 10e3, 20e3, 30e3], ["1", "5", "10", "20", "30"]),
88+
)# , clims=(-1e10, 1e10)
6689
png(joinpath(PLOT_DIR, "$(job_id)_$var.png"))
6790
end
6891

6992
# horizontal slices
70-
Plots.contourf(lon, lat, strf_sfc', xlabel="Longitude", ylabel="Latitude", title="$var", color=:viridis)#, clims=(-1e10, 1e10))
93+
Plots.contourf(lon, lat, strf_sfc', xlabel = "Longitude", ylabel = "Latitude", title = "$var", color = :viridis)#, clims=(-1e10, 1e10))
7194
png(joinpath(PLOT_DIR, "$(job_id)_$(var)_sfc.png"))
7295

73-
Plots.contourf(lon, lat, strf_upper', xlabel="Longitude", ylabel="Latitude", title="$var", color=:viridis)#, clims=(-1e10, 1e10))
96+
Plots.contourf(lon, lat, strf_upper', xlabel = "Longitude", ylabel = "Latitude", title = "$var", color = :viridis)#, clims=(-1e10, 1e10))
7497
png(joinpath(PLOT_DIR, "$(job_id)_$(var)_10km.png"))
7598
end
7699

@@ -93,4 +116,4 @@ function interpolate_to_pressure_coord_2d(var_zm, pa, pa_grid)
93116
end
94117
end
95118
return var_on_pa
96-
end
119+
end

0 commit comments

Comments
 (0)