Skip to content

Commit

Permalink
working lat-lon plots!
Browse files Browse the repository at this point in the history
  • Loading branch information
wwieder committed Jan 31, 2025
1 parent 2dfdc4e commit 530993c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config_clm_baseline_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# Note that the string 'USER-NAME-NOT-SET' is used in the jupyter script
# to check for a failure to customize
#
user: 'slevis'
user: 'wwieder'


#This first set of variables specify basic info used by all diagnostic runs:
Expand Down
17 changes: 17 additions & 0 deletions lib/adf_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ def load_climo_da(self, case, variablename):
return self.load_da(fils, variablename, add_offset=add_offset, scale_factor=scale_factor)


def load_climo_dataset(self, case, field):
"""Return a data set to be used as reference (aka baseline) for variable field."""
fils = self.get_climo_file(case, field)
if not fils:
warnings.warn(f"WARNING: Did not find climo file(s) for case: {case}, variable: {field}")
return None
return self.load_dataset(fils)

def load_climo_file(self, case, variablename, grid='regular'):
"""
Return Dataset for climo of variablename
Expand Down Expand Up @@ -217,6 +225,15 @@ def load_reference_climo_da(self, case, variablename):
fils = self.get_reference_climo_file(variablename)
return self.load_da(fils, variablename, add_offset=add_offset, scale_factor=scale_factor)

def load_reference_climo_dataset(self, case, field):
"""Return a data set to be used as reference (aka baseline) for variable field."""
fils = self.get_reference_climo_file(self, field)
if not fils:
warnings.warn(f"WARNING: Did not find climo file(s) for case: {case}, variable: {field}")
return None
return self.load_dataset(fils)


def get_reference_climo_file(self, var):
"""Return a list of files to be used as reference (aka baseline) for variable var."""
if self.adf.compare_obs:
Expand Down
11 changes: 9 additions & 2 deletions lib/plotting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ def seasonal_mean(data, season=None, is_climo=None):
if "month" in data.dims:
data = data.rename({"month":"time"})
has_time = True
if isinstance(data, ux.UxDataset):
has_time = 'time' in data.dims
if not has_time:
if "month" in data.dims:
data = data.rename({"month":"time"})
has_time = True
if not has_time:
# this might happen if a pure numpy array gets passed in
# --> assumes ordered January to December.
Expand Down Expand Up @@ -1604,7 +1610,8 @@ def plot_unstructured_map_and_save(wks, case_nickname, base_nickname,
if i > 0:
cbar = plt.colorbar(ac, ax=axs[i], orientation='vertical',
pad=0.05, shrink=0.8, **cp_info['colorbar_opt'])
cbar.set_label(wrap_fields[i].attrs['units'])
#TODO keep variable attributes on dataarrays
#cbar.set_label(wrap_fields[i].attrs['units'])
#Set stats: area_avg
axs[i].set_title(f"Mean: {area_avg[i].item():5.2f}\nMax: {wrap_fields[i].max().item():5.2f}\nMin: {wrap_fields[i].min().item():5.2f}",
loc='right', fontsize=tiFontSize)
Expand Down Expand Up @@ -2829,4 +2836,4 @@ def square_contour_difference(fld1, fld2, **kwargs):
return fig

#####################
#END HELPER FUNCTIONS
#END HELPER FUNCTIONS
11 changes: 7 additions & 4 deletions scripts/plotting/global_unstructured_latlon_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def global_unstructured_latlon_map(adfobj):

# Gather reference variable data
odata = adfobj.data.load_reference_climo_da(base_name, var)
#odata = odata[var] # now just read in the data array, but don't modify anything

if odata is None:
dmsg = f"No regridded test file for {base_name} for variable `{var}`, global lat/lon mean plotting skipped."
Expand All @@ -209,9 +210,11 @@ def global_unstructured_latlon_map(adfobj):
plot_loc.mkdir(parents=True)

#Load climo model files:
mdata = adfobj.data.load_climo_da(case_name, var)
area = adfobj.data.load_climo_da(case_name, 'area') # THIS AND NEXT LINE DO NOT WORK, YET
landfrac = adfobj.data.load_climo_da(case_name, 'landfrac')
mdata = adfobj.data.load_climo_dataset(case_name, var) # read in dataset for area & landfrac
area = mdata.area.isel(time=0)
landfrac = mdata.landfrac.isel(time=0)
mdata = mdata[var] # now just read in the data array
odata.attrs = mdata.attrs # copy attributes back to base case

#Skip this variable/case if the climo file doesn't exist:
if mdata is None:
Expand Down Expand Up @@ -476,7 +479,7 @@ def aod_latlon(adfobj):

for case in test_case_names:
#Load re-gridded model files:
ds_case = adfobj.data.load_climo_da(case, var)
ds_case = adfobj.data.load_climo_dataset(case, var)

#Skip this variable/case if the climo file doesn't exist:
if ds_case is None:
Expand Down

0 comments on commit 530993c

Please sign in to comment.