aodn / python-aodntools

Repository for templates and code relating to generating standard NetCDF files for the Australia Ocean Data Network
GNU Lesser General Public License v3.0
10 stars 3 forks source link

Correct dimensionless variables & provide graceful closes when exceptions are raised #11

Closed ocehugo closed 6 years ago

ocehugo commented 6 years ago

EDIT: Sorry for the mess, I didn't give much thought before writing.

from template import DatasetTemplate as T
test=T({'one':10},{'ten':{'type':double'}})
test.to_netcdf()
#raises:
KeyError: 'dimensions'

There are several things here:

  1. if we did not provide dimensions, it's safe to write the variable as dimensionless? I think so.
  2. Despite the error, this call write a netcdf file and stop in the middle. Although this behaviour is useful for debuging, end-users will have to release the file to be able to write to it again in a new call to DatasetTemplate (say test.ncobj.close() before running again). This is clearly not optimal.

Solutions range from:

  1. Check everything before writing (a lot of boilerplate to write and new exceptions to create)
  2. Gracefully close the file when something is wrong (best). This still provide a good level of debug given the file can be inspected.