Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
pixi-env: py313dev
- python-version: "3.14"
pixi-env: py314dev
- python-version: "3.15"
pixi-env: py315dev

steps:
- uses: actions/checkout@v7
Expand Down
79 changes: 74 additions & 5 deletions config/zppy_template_r05.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ common_snow: &common_snow
References:
- {{ livvproj_dir }}/livvkit.bib

common_river: &common_river
cmap: YlGnBu
cmap_diff: BrBG
units: m^3 s^-1
References:
- {{ livvproj_dir }}/livvkit.bib

common_energy: &common_energy
desc: Surface energy balance component {component}{comment} from {data_var_names}
references:
Expand All @@ -63,7 +70,17 @@ common_elm: &common_elm
ts_file_patterns:
model: "{_var}_{year_s:04d}01_{year_e:04d}12.nc"
masks:
model: /global/cfs/cdirs/e3sm/diagnostics/livvkit_data/grids/msk_{icesheet}_rcm_r05.nc
model: {{ livvproj_dir }}/grids/msk_{icesheet}_rcm_r05.nc

common_mosart: &common_mosart
climo_river: {{ dir_river }}/{{ case_id }}_{clim}_{sea_s}_{sea_e}_climo.nc
dataset_names: { model: MOSART }
timeseries_dirs:
model: "{{ dir_ts_river }}"
ts_file_patterns:
model: "{_var}_{year_s:04d}01_{year_e:04d}12.nc"
masks:
model: {{ livvproj_dir }}/grids/msk_{icesheet}_rcm_r05.nc

common_racmo: &common_racmo
clim_years:
Expand Down Expand Up @@ -155,8 +172,8 @@ common_modis: &common_modis
in_dirs: {dset_a: /global/cfs/cdirs/e3sm/zender/mod10cm/rgr/}
file_patterns: {dset_a: 'mod10cm_{season}_{sea_s}_{sea_e}_climo.nc'}
masks:
dset_a: /global/cfs/cdirs/e3sm/diagnostics/livvkit_data/grids/msk_{icesheet}_rcm_r05.nc
model: /global/cfs/cdirs/e3sm/diagnostics/livvkit_data/grids/msk_{icesheet}_rcm_r05.nc
dset_a: {{ livvproj_dir }}/grids/msk_{icesheet}_rcm_r05.nc
model: {{ livvproj_dir }}/grids/msk_{icesheet}_rcm_r05.nc

common_racmo_gis: &common_racmo_gis
climo_remap: {{ dir_racmo_gis }}/{{ case_id }}_{clim}_{sea_s}_{sea_e}_climo.nc
Expand Down Expand Up @@ -407,6 +424,30 @@ common_snow_cover_vars: &common_snow_cover_vars
cmax: 100
cmap: YlGnBu

common_river_vars: &common_river_vars
- title: "Total discharge to ocean: ice"
model: TOTAL_DISCHARGE_TO_OCEAN_ICE
sign: 1
scales: {model: 1}
units: "m^3 s^-1"
ac_axis: 0
cmin: 0.0
# cmax: 5000
cmap: YlGnBu
# cmin_d: -8000
# cmax_d: 8000
- title: "Total discharge to ocean: liquid"
model: TOTAL_DISCHARGE_TO_OCEAN_LIQ
sign: 1
scales: {model: 1}
units: "m^3 s^-1"
ac_axis: 0
cmin: 0.0
# cmax: 5000
cmap: YlGnBu
# cmin_d: -8000
# cmax_d: 8000

common_racmo_energy_vars: &common_racmo_energy_vars
- title: Surface temperature
dset_a: tas
Expand Down Expand Up @@ -771,7 +812,21 @@ Snow_Cover_GIS:
primary_var: FSNO
desc: "{component} snow cover from {data_var_names}"
references:
- /global/cfs/cdirs/e3sm/diagnostics/livvkit_data/livvkit.bib
- {{ livvproj_dir }}/livvkit.bib
{% endif %}

{% if river %}
River_Discharge_GIS:
module: /global/homes/m/mek/livvext/livvext/river/river.py
data_vars: *common_river_vars
icesheet: gis
<<: [*common, *common_river, *common_mosart]
scales:
{ model: 1,}
primary_var: TOTAL_DISCHARGE_TO_OCEAN_LIQ
desc: "{component} river discharge from {data_var_names}"
references:
- {{ livvproj_dir }}/livvkit.bib
{% endif %}

{% if energy_racmo %}
Expand Down Expand Up @@ -856,7 +911,21 @@ Snow_Cover_AIS:
desc: "{component} snow storage from {data_var_names}"
icesheet: ais
references:
- /global/cfs/cdirs/e3sm/diagnostics/livvkit_data/livvkit.bib
- {{ livvproj_dir }}/livvkit.bib
{% endif %}

{% if river %}
River_Discharge_AIS:
module: /global/homes/m/mek/livvext/livvext/river/river.py
data_vars: *common_river_vars
icesheet: ais
<<: [*common, *common_mosart, *common_river,]
scales:
{ model: 1,}
primary_var: TOTAL_DISCHARGE_TO_OCEAN_LIQ
desc: "{component} river discharge from {data_var_names}"
references:
- {{ livvproj_dir }}/livvkit.bib
{% endif %}

{% if energy_racmo %}
Expand Down
2 changes: 1 addition & 1 deletion livvext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
Storage for global variables. These are set upon startup in the options module
"""

__version_info__ = (1, 2, 0)
__version_info__ = (1, 3, 0)
__version__ = ".".join(str(vi) for vi in __version_info__)
65 changes: 46 additions & 19 deletions livvext/compare_gridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,20 @@ def annotate_plot(
_text = f"Avg.\n{cnrtxt}"
elif stats is not None:
_text = ""
for _stat in ["min", "max", "avg"]:
if "tot" in stats:
_text += f"Tot: {stats['tot']:.3g}\n{stats.get('aavg_units')}\n"
else:
_text += f"Avg: {stats['avg']:.3g}\n"

for _stat in ["min", "max"]:
_text += f"{_stat.capitalize()}: {stats[_stat]:.3g}\n"

if "units" in stats:
_text += stats["units"]
else:
_text = _text[:-1]
else:
_text = ""

plt.figtext(
0.98,
Expand Down Expand Up @@ -246,11 +253,14 @@ def main(args: argparse.Namespace, config: dict, sea: str | int = "ANN"):
all_data["model"] = xr.open_dataset(
lxc.proc_climo_file(config, "climo_remap", sea)
)
elif "climo_river" in config:
all_data["model"] = xr.open_dataset(
lxc.proc_climo_file(config, "climo_river", sea)
)
else:
all_data["model"] = xr.open_dataset(
lxc.proc_climo_file(config, "climo", sea)
)

for _vers in all_data:
all_data[_vers] = lxc.check_longitude(all_data[_vers])

Expand Down Expand Up @@ -352,18 +362,20 @@ def main(args: argparse.Namespace, config: dict, sea: str | int = "ANN"):
sum_out=_do_sum,
land_only=config.get("mask_ocean", {}).get(_vers, False),
)
all_stats[_vers] = {
"min": np.nanmin(_plt_data[_vers]),
"max": np.nanmax(_plt_data[_vers]),
"avg": all_aavg[_vers],
}

all_aavg[_vers] *= _aavg_scale
for _stat in all_stats[_vers]:
all_stats[_vers][_stat] *= _aavg_scale
if _do_sum:
_avgkey = "tot"
else:
_avgkey = "avg"
# Sometimes area average, sometimes area sum is the "mean" measure
all_stats[_vers] = {_avgkey: all_aavg[_vers]}

# for _stat in all_stats[_vers]:
# all_stats[_vers][_stat] *= _aavg_scale

if all_stats.get("aavg_units"):
all_stats[_vers]["units"] = all_stats.get("aavg_units")
all_stats[_vers]["aavg_units"] = all_stats.get("aavg_units")
all_stats[_vers]["units"] = _units

aavg_out[data_var["title"]] = {
config["dataset_names"][_vers]: all_aavg[_vers] for _vers in all_aavg
Expand All @@ -379,17 +391,20 @@ def main(args: argparse.Namespace, config: dict, sea: str | int = "ANN"):
sum_out=_do_sum,
land_only=config.get("mask_ocean", {}).get(_ds2, False),
)
diffs_stats[_diffname] = {
"min": np.nanmin(diffs[_diffname]),
"max": np.nanmax(diffs[_diffname]),
"avg": diffs_aavg[_diffname],
}

if _do_sum:
_avgkey = "tot"
else:
_avgkey = "avg"
diffs_aavg[_diffname] *= _aavg_scale
for _stat in diffs_stats[_diffname]:
diffs_stats[_diffname][_stat] *= _aavg_scale
diffs_stats[_diffname] = {_avgkey: diffs_aavg[_diffname]}

# for _stat in diffs_stats[_diffname]:
# diffs_stats[_diffname][_stat] *= _aavg_scale

if diffs_stats.get("aavg_units"):
diffs_stats[_diffname]["units"] = diffs_stats.get("aavg_units")
diffs_stats[_diffname]["aavg_units"] = diffs_stats.get("aavg_units")
diffs_stats[_diffname]["units"] = _units

_longname = (
f"{config['dataset_names'][_ds1]} - {config['dataset_names'][_ds2]}"
Expand Down Expand Up @@ -483,6 +498,12 @@ def main(args: argparse.Namespace, config: dict, sea: str | int = "ANN"):
ndsets = len(dsets)
_comment = ""
for idx, _vers in enumerate(dsets_to_plot):
all_stats[_vers].update(
{
"min": np.nanmin(_plt_data[_vers]),
"max": np.nanmax(_plt_data[_vers]),
}
)
_cf = axes[idx].pcolormesh(
all_data[_vers]["lon"],
all_data[_vers]["lat"],
Expand Down Expand Up @@ -533,6 +554,12 @@ def main(args: argparse.Namespace, config: dict, sea: str | int = "ANN"):
else:
cnrtxt = f"{diffs_aavg[_diffnm]:.2f}"

diffs_stats[_diffnm].update(
{
"min": np.nanmin(diffs[_diffnm]),
"max": np.nanmax(diffs[_diffnm]),
}
)
_cfd = axes[n_dsets_to_plot + idx].pcolormesh(
all_data[_ds1]["lon"],
all_data[_ds1]["lat"],
Expand Down
6 changes: 3 additions & 3 deletions livvext/energy/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def run(name, config):

elements = []
if "meta" in config:
run_summary = el.Table(
title="Case Summary", data=config["meta"], transpose=True
)
meta = utils.climo_meta_update(config)

run_summary = el.Table(title="Case Summary", data=meta, transpose=True)
else:
run_summary = el.RawHTML("<h3>Case Summary</h3>")

Expand Down
6 changes: 6 additions & 0 deletions livvext/generate_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def main():
_ts_dir = _grid_dir.replace("/clim/", "/ts/monthly/")
climo_dirs[f"dir_{_grid}"] = Path(_grid_dir)
ts_dirs[f"dir_ts_{_grid}"] = Path(_ts_dir)
climo_dirs["dir_river"] = Path(
str(climo_dirs["dir_native"]).replace("lnd", "rof")
)
ts_dirs["dir_ts_river"] = Path(
str(ts_dirs["dir_ts_native"]).replace("lnd", "rof")
)

case_dir = Path(cl_args.casedir)

Expand Down
1 change: 1 addition & 0 deletions livvext/river/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module for analyzing river discharge over an ice sheet"""
Loading
Loading