climate-resource / input4mips_validation

Validation of input4MIPs data
https://input4mips-validation.readthedocs.io/en/latest/
Other
0 stars 1 forks source link

Handling of writing files with degree units #82

Open znichollscr opened 1 day ago

znichollscr commented 1 day ago

The motivation

If you want to write files which have "degrees" units, input4mips-validation doesn't work in all cases. Specifically, any units like "degrees_north", "degrees_n", "degrees_east" will end up as "degrees" in the written file. The underlying cause is iris' units' sanitisation (https://github.com/SciTools/iris/issues/6216), which makes sense for iris but isn't what we want here. The reason we hit this is that we go via iris to write netCDF files.

The proposed solution

One of two options:

Option 1: an automatic workaround, which puts the units back to what they were before writing the netCDF file to disk. Iris seems to be ok with updating units directly (via e.g. cube.units = "string"), even if the units aren't officially supported by udunits (like "degrees_south").

Option 2: raise a warning if we notice that the units have changed. The warning could suggest to users to either a) change their units or b) use the pattern of getting the cubes, then updating the cubes themselves, then writing (which is what I did for the MAC files, see https://github.com/climate-resource/input4mips_validation/blob/9f3462c77ebce974e2df02fbe5e45cf4f064c07a/scripts/add-input4mips-info-to-mac.py#L252).

Alternatives

Additional context

Re-riting of MAC files: https://github.com/climate-resource/input4mips_validation/blob/9f3462c77ebce974e2df02fbe5e45cf4f064c07a/scripts/add-input4mips-info-to-mac.py