COSIMA / cosima-cookbook

Framework for indexing and querying ocean-sea ice model output.
https://cosima-recipes.readthedocs.io/en/latest/
Apache License 2.0
57 stars 27 forks source link

Missing bounds variable causes error in indexing #297

Closed aidanheerdegen closed 2 years ago

aidanheerdegen commented 2 years ago

There appear to be a number of files that have a bounds attribute on the time variable but the referenced variable is not present in the file, e.g. /g/data/cj50/access-om2/raw-output/access-om2-01/01deg_jra55v140_iaf_cycle4/output800/ocean/oceanbgc-3d-adic-1-monthly-mean-4-sigfig-ym_1971_01.nc

This causes an error in update_timeinfo as it doesn't check the bounds variable is present.

The check for bounds attribute is here:

https://github.com/COSIMA/cosima-cookbook/blob/master/cosima_cookbook/database.py#L574

and the code which assumes it exists:

https://github.com/COSIMA/cosima-cookbook/blob/master/cosima_cookbook/database.py#L589-L592

This change

has_bounds = hasattr(time_var, "bounds") and time_var.bounds in ds.variables

works (python short circuits logical and, so the second condition is only evaluated if the first is true)