csiro-coasts / emsarray

xarray extension that supports EMS model formats
BSD 3-Clause "New" or "Revised" License
13 stars 2 forks source link

Manual format binding #45

Closed mx-moth closed 1 year ago

mx-moth commented 1 year ago

Adds a mechanism to bypass automatic format detection.

xarray accessors like dataset.ems are read only and cached. They can not be manually set. Simply doing dataset.ems = SomeFormat(dataset) does not work, and once set a format can not be swapped out. As such, an alternate mechanism to bind formats to datasets was required. The emsarray.state.State class represents this. This has attributes that are modifiable. A new Format instance can be constructed and bound to a dataset - this will set the state.format attribute. When dataset.ems is then accessed, the accessor will first check to see if a custom format has already been bound. If one has been, this will be used, else a new format will be constructed using the usual autodetection method.

This allows for greater flexibility and for overriding the format if autodetection fails.