Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Land Diagnostics using ADF #354

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
51af294
Update adf_diag.py
justin-richling Feb 22, 2024
dd765c6
Update adf_diag.py
justin-richling Feb 22, 2024
c7a8a59
Update adf_diag.py
justin-richling Feb 22, 2024
79147f6
Update adf_diag.py
justin-richling Feb 22, 2024
bf4aa39
Update adf_diag.py
justin-richling Feb 22, 2024
e3d99b6
Update adf_diag.py
justin-richling Feb 22, 2024
b200a4f
Update adf_diag.py
justin-richling Feb 22, 2024
12fd449
Update adf_diag.py
justin-richling Feb 22, 2024
404ab79
Update adf_diag.py
justin-richling Feb 22, 2024
6ea5b46
Update adf_diag.py
justin-richling Feb 22, 2024
22ca8a7
Update adf_diag.py
justin-richling Feb 22, 2024
8eb4320
Update adf_diag.py
justin-richling Feb 22, 2024
9da453c
Update adf_diag.py
justin-richling Feb 22, 2024
6823bca
Update adf_diag.py
justin-richling Feb 22, 2024
9f1b25b
Update adf_diag.py
justin-richling Feb 22, 2024
fcfa3da
Update adf_diag.py
justin-richling Feb 22, 2024
be3c364
Update adf_diag.py
justin-richling Feb 22, 2024
33b09ca
Update adf_diag.py
justin-richling Feb 22, 2024
09895a8
Update adf_diag.py
justin-richling Feb 22, 2024
a4d5600
Update adf_diag.py
justin-richling Feb 22, 2024
1a891f6
modifications for LWMG plots
wwieder Jan 7, 2025
da44595
merge to main
wwieder Jan 7, 2025
15897e0
adding uxarray plotting functionality
wwieder Jan 17, 2025
ee6904b
notebook for testing uxarray plot
wwieder Jan 17, 2025
0d25ef3
conservative regridding ne30->f09
wwieder Jan 22, 2025
3917a4e
append additional variables to timeseries files
wwieder Jan 22, 2025
7494f5f
TODO for climo or ts year control
wwieder Jan 22, 2025
4b2fbec
trying to avoid conda errors
wwieder Jan 23, 2025
d3fe601
adding spatial averaging for lnd
wwieder Jan 23, 2025
bd32cf7
python environment issue: works with npl-2024a but not b
wwieder Jan 23, 2025
82e8ce7
more places to load ux.datasets
wwieder Jan 23, 2025
853a7a4
add ux function to open dataset
wwieder Jan 23, 2025
fd624d0
changes to make work for land model results
wwieder Jan 23, 2025
6369c1e
hack to get timeseries plots to work with CAM history
wwieder Jan 23, 2025
7b44d27
correcting clm config files
wwieder Jan 23, 2025
bf47cc8
need help getting this to work
wwieder Jan 23, 2025
c87b114
brainstorm for SEWG hackathon
wwieder Jan 29, 2025
00eedb1
updates for SEWG
wwieder Jan 29, 2025
5927e4b
spelling change
wwieder Jan 29, 2025
61be533
more notes on regridding notebook
wwieder Jan 30, 2025
927fcc4
Integrating land regridding into ADF workflow
slevis-lmwg Jan 30, 2025
b239e75
Attempt at using global_unstructured_latlon_map (fails at wts)
slevis-lmwg Jan 31, 2025
616ab62
updated notebook on regridding
wwieder Jan 31, 2025
2dfdc4e
Merge remote-tracking branch 'refs/remotes/wwieder/clm-test' into clm…
wwieder Jan 31, 2025
530993c
working lat-lon plots!
wwieder Jan 31, 2025
71a2388
regrid land timeseries
wwieder Feb 11, 2025
7c640d6
customize lat-lon plots
wwieder Feb 13, 2025
8bbe4a1
first attempt at polar plots
wwieder Feb 13, 2025
f237c13
corrected variable spelling
wwieder Feb 13, 2025
f9921d0
makes polar plots, overwrites lat-lon
wwieder Feb 13, 2025
2daa6e3
arctic plots working!
wwieder Feb 13, 2025
ba282f4
creating better land tables
wwieder Feb 20, 2025
36e7363
fix time errors in one place
wwieder Feb 20, 2025
08ac2c5
global timeseries for land
wwieder Feb 20, 2025
02c64e6
fixing time for climo
wwieder Feb 20, 2025
046ebce
fix time in climo files
wwieder Feb 21, 2025
9647dbb
h1 plotting test
wwieder Mar 6, 2025
d14acaa
complete notebook for h1 files
wwieder Mar 7, 2025
0e05ed9
improvements from OERO
wwieder Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 550 additions & 0 deletions config_clm_baseline_example.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/adf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import copy

#+++++++++++++++++++++++++++++++++++++++++++++++++
#import non-standard python modules, including ADF
#import non-standard python modules, including ADF:
#+++++++++++++++++++++++++++++++++++++++++++++++++

import yaml
Expand Down
45 changes: 36 additions & 9 deletions lib/adf_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import xarray as xr
import uxarray as ux

import warnings # use to warn user about missing files

Expand Down Expand Up @@ -47,7 +48,7 @@ class AdfData:
def __init__(self, adfobj):
self.adf = adfobj # provides quick access to the AdfDiag object
# paths
self.model_rgrid_loc = adfobj.get_basic_info("cam_regrid_loc", required=True)
self.model_rgrid_loc = adfobj.get_basic_info("cam_climo_regrid_loc", required=True)

# variables (and info for unit transform)
# use self.adf.diag_var_list and self.adf.self.adf.variable_defaults
Expand Down Expand Up @@ -185,15 +186,30 @@ def load_climo_da(self, case, variablename):
return self.load_da(fils, variablename, add_offset=add_offset, scale_factor=scale_factor)


def load_climo_file(self, case, variablename):
"""Return Dataset for climo of variablename"""
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
uses grid flag to determine if reading in a regular or unstructured grid
returns a xarry or uxarray dataset, respectively
"""
fils = self.get_climo_file(case, variablename)
if not fils:
warnings.warn(f"WARNING: Did not find climo file for variable: {variablename}. Will try to skip.")
return None
return self.load_dataset(fils)

if grid == 'regular':
return self.load_dataset(fils)
elif grid == 'unstructured':
return self.load_ux_dataset(fils)


def get_climo_file(self, case, variablename):
"""Retrieve the climo file path(s) for variablename for a specific case."""
a = self.adf.get_cam_info("cam_climo_loc", required=True) # list of paths (could be multiple cases)
Expand All @@ -209,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 All @@ -223,14 +248,13 @@ def get_reference_climo_file(self, var):

#------------------


# Regridded files
#------------------

# Test case(s)
def get_regrid_file(self, case, field):
"""Return list of test regridded files"""
model_rg_loc = Path(self.adf.get_basic_info("cam_regrid_loc", required=True))
model_rg_loc = Path(self.adf.get_basic_info("cam_climo_regrid_loc", required=True))
rlbl = self.ref_labels[field] # rlbl = "reference label" = the name of the reference data that defines target grid
return sorted(model_rg_loc.glob(f"{rlbl}_{case}_{field}_regridded.nc"))

Expand Down Expand Up @@ -264,7 +288,7 @@ def get_ref_regrid_file(self, case, field):
else:
fils = []
else:
model_rg_loc = Path(self.adf.get_basic_info("cam_regrid_loc", required=True))
model_rg_loc = Path(self.adf.get_basic_info("cam_climo_regrid_loc", required=True))
fils = sorted(model_rg_loc.glob(f"{case}_{field}_baseline.nc"))
return fils

Expand Down Expand Up @@ -296,6 +320,8 @@ def load_reference_regrid_da(self, case, field):

# DataSet and DataArray load
#---------------------------
# TODO, make uxarray options fo all of these fuctions.
# What's the most robust way to handle this?

# Load DataSet
def load_dataset(self, fils):
Expand All @@ -310,7 +336,8 @@ def load_dataset(self, fils):
if not Path(sfil).is_file():
warnings.warn(f"Expecting to find file: {sfil}")
return None
ds = xr.open_dataset(sfil)
mesh = '/glade/campaign/cesm/cesmdata/inputdata/share/meshes/ne30pg3_ESMFmesh_cdf5_c20211018.nc'
ds = ux.open_dataset(mesh, sfil)
if ds is None:
warnings.warn(f"invalid data on load_dataset")
return ds
Expand Down
50 changes: 48 additions & 2 deletions lib/adf_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@
print("Please install module, e.g. 'pip install Cartopy'.")
sys.exit(1)

# Check if "uxarray" is present in python path:
try:
import uxarray as ux
except ImportError:
print("uxarray module does not exist in python path.")
print("Please install module, e.g. 'pip install uxarray'.")
sys.exit(1)

# Check if "esmpy" is present in python path:
try:
import esmpy as esmpy
except ImportError:
print("xesmf module does not exist in python path.")
print("Please install module, e.g. 'pip install esmpy'.")
sys.exit(1)

# Check if "xesmf" is present in python path:
try:
import xesmf as xesmf
except ImportError:
print("xesmf module does not exist in python path.")
print("Please install module, e.g. 'pip install xesmf'.")
sys.exit(1)

# pylint: enable=unused-import

# +++++++++++++++++++++++++++++
Expand Down Expand Up @@ -714,19 +738,41 @@ def call_ncrcat(cmd):
ts_outfil_str
]

# Step 3: Create the ncatted command to remove the history attribute
# Step 3a: Optional, add additional variables to clm2.h0 files
cmd_add_clm_h0_fields = [
"ncks", "-A", "-v", "area,landfrac,landmask",
hist_files[0],
ts_outfil_str
]

# Step 3b: Optional, add additional variables to clm2.h1 files
cmd_add_clm_h1_fields = [
"ncrcat", "-A", "-v", "pfts1d_ixy,pfts1d_jxy,pfts1d_itype_veg,lat,lon",
hist_files,
ts_outfil_str
]

# Step 3c: Create the ncatted command to remove the history attribute
cmd_remove_history = [
"ncatted", "-O", "-h",
"-a", "history,global,d,,",
ts_outfil_str
]



# Add to command list for use in multi-processing pool:
# -----------------------------------------------------
# generate time series files
list_of_commands.append(cmd)
# Add global attributes: user, original hist file loc(s) and all filenames
list_of_ncattend_commands.append(cmd_ncatted)

# TODO, add some logic to control if these are done
# add time invariant information to clm2.h0 fields
list_of_hist_commands.append(cmd_add_clm_h0_fields)
# add time varrying information to clm2.h1 fields
#list_of_hist_commands.append(cmd_add_clm_h1_fields)

# Remove the `history` attr that gets tacked on (for clean up)
# NOTE: this may not be best practice, but it the history attr repeats
# the files attrs so the global attrs become obtrusive...
Expand Down
18 changes: 18 additions & 0 deletions lib/adf_variable_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,24 @@ RESTOM:
pct_diff_contour_levels: [-100,-75,-50,-40,-30,-20,-10,-8,-6,-4,-2,0,2,4,6,8,10,20,30,40,50,75,100]
pct_diff_colormap: "PuOr_r"

SNOWDP:
colormap: "Blues"
contour_levels_range: [-150, 50, 10]
diff_colormap: "BrBG"
diff_contour_range: [-20, 20, 2]
scale_factor: 1
add_offset: 0
new_unit: "Wm$^{-2}$"
mpl:
colorbar:
label : "Wm$^{-2}$"
obs_file: "CERES_EBAF_Ed4.1_2001-2020.nc"
obs_name: "CERES_EBAF_Ed4.1"
obs_var_name: "toa_cre_sw_mon"
obs_scale_factor: 1
obs_add_offset: 0
category: "TOA energy flux"

SWCF:
colormap: "Blues"
contour_levels_range: [-150, 50, 10]
Expand Down
Loading