Skip to content

Commit

Permalink
consider 4-d variables
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 committed Jan 8, 2025
1 parent 0df7e69 commit 3a02392
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions pcmdi_metrics/mean_climate/lib/calculate_climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,31 @@ def calculate_climatology(
out_season
) # global attributes are automatically saved as well

# Plot climatology
if plot and s == "AC":
plot_climatology(
d_ac,
var,
season_to_plot="all",
output_filename=out_season.replace(".nc", ".png"),
)
# Check if variable is 4D
if is_4d_variable(d_ac[var]):
# Plot 3 levels (hPa) for 4D variables for quick check
levels_to_plot = [200, 500, 850]
else:
levels_to_plot = [None]

# Plot climatology for each level
for level in levels_to_plot:
if level is None:
output_filename = out_season.replace(".nc", ".png")
else:
output_filename = out_season.replace(".nc", f".{level}.png")

# plot climatology for each level
plot_climatology(
d_ac,
var,
level=level,
season_to_plot="all",
output_filename=output_filename,
)


def is_4d_variable(da):
return len(da.shape) == 4

0 comments on commit 3a02392

Please sign in to comment.