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

Update sea ice figure script #1097

Merged
merged 5 commits into from
May 13, 2024
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
12 changes: 12 additions & 0 deletions docs/metrics_sea_ice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ A `demo parameter file`_ is provided in the sea ice code.
* **obs_cell_area**: For equal area grids, the area of a single grid cell in units of km :sup:`2` . Only required if obs area file is not available.
* **pole**: Set the maximum latitude for the Central Arctic and Arctic regions to exclude ice over the pole. Default is 90.1 to include all ice.

Postprocessing
==============

A script is provided to create a multi-model bar chart using results from multiple runs of the sea ice driver. This script can be found in ./scripts/sea_ice_figures.py.

Example command: ::

python sea_ice_figures.py --filelist 'path/to/models/*/sea_ice_metrics.json' --output_path '.'


A wildcard '*' can be used to glob multiple folders of results. The final path in the --filelist parameter must be the sea_ice_metrics.json file. The --output_path parameter can be any valid path.

Reference
=========
Ivanova, D. P., P. J. Gleckler, K. E. Taylor, P. J. Durack, and K. D. Marvel, 2016: Moving beyond the Total Sea Ice Extent in Gauging Model Biases. J. Climate, 29, 8965–8987, https://doi.org/10.1175/JCLI-D-16-0026.1.
10 changes: 10 additions & 0 deletions pcmdi_metrics/sea_ice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ A [demo parameter file](https://github.com/PCMDI/pcmdi_metrics/blob/405_sic_ao/p
* **obs_cell_area**: For equal area grids, the area of a single grid cell in units of km2. Only required if obs area file is not available.
* **pole**: Set the maximum latitude for the Central Arctic and Arctic regions to exclude ice over the pole. Default is 90.1 to include all ice.

## Postprocessing

A script is provided to create a multi-model bar chart using results from multiple runs of the sea ice driver. This script can be found in `./scripts/sea_ice_figures.py`.

Example command:
```
python sea_ice_figures.py --filelist 'path/to/models/*/sea_ice_metrics.json' --output_path '.'
```

A wildcard `*` can be used to glob multiple folders of results. The final path in the `--filelist` parameter must be the sea_ice_metrics.json file. The `--output_path` parameter can be any valid path.

## Reference

Expand Down
32 changes: 13 additions & 19 deletions pcmdi_metrics/sea_ice/scripts/sea_ice_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
metrics = {"RESULTS": {}}
for metrics_file in glob.glob(filelist):
with open(metrics_file) as mf:
results = json.load(mf)["RESULTS"]
model_list.append(list(results.keys())[0])
metrics["RESULTS"].update(results)
results = json.load(mf)
for item in results["DIMENSIONS"]["model"]:
model_list.append(item)
metrics["RESULTS"].update(results["RESULTS"])

model_list.sort()
tmp = model_list[0]
reference_data_set = list(metrics["RESULTS"][tmp]["arctic"]["model_mean"].keys())[0]

Expand Down Expand Up @@ -115,27 +117,18 @@
mark_size = 1
ax7[inds].bar(ind - width / 2.0, mse_clim, width, color="b", label="Ann. Cycle")
ax7[inds].bar(ind, mse_ext, width, color="r", label="Ann. Mean")
if len(clim_err_x) > 0:
ax7[inds].scatter(
[x - width / 2.0 for x in clim_err_x],
clim_err_y,
marker="D",
s=mark_size,
color="k",
)
ax7[inds].scatter(clim_err_x, ext_err_y, marker="D", s=mark_size, color="k")
# xticks

# X axis label
if inds == len(sector_list) - 1:
ax7[inds].set_xticks(ind + width / 2.0, mlabels, rotation=90, size=7)
else:
ax7[inds].set_xticks(ind + width / 2.0, labels="")
# yticks
if len(clim_err_y) > 0:
datamax = np.max(np.array(clim_err_y))
else:
datamax = np.max(np.array(mse_clim))

# Y axis
datamax = np.nanmax(np.concatenate((np.array(mse_clim), np.array(mse_ext))))
ymax = (datamax) * 1.3
ax7[inds].set_ylim(0.0, ymax)

if ymax < 0.1:
ticks = np.linspace(0, 0.1, 6)
labels = [str(round(x, 3)) for x in ticks]
Expand All @@ -151,8 +144,8 @@
else:
ticks = range(0, round(ymax))
labels = [str(round(x, 0)) for x in ticks]

ax7[inds].set_yticks(ticks, labels, fontsize=8)

# labels etc
ax7[inds].set_ylabel("10${^1}{^2}$km${^4}$", size=8)
ax7[inds].grid(True, linestyle=":")
Expand All @@ -162,6 +155,7 @@
xycoords="axes fraction",
size=9,
)

# Add legend, save figure
ax7[0].legend(loc="upper right", fontsize=6)
plt.suptitle("Mean Square Error relative to " + reference_data_set, y=0.91)
Expand Down
Loading