csiro-coasts / emsarray

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

Fix generated bounds for 'river' cells in CFGrid2D datasets #154

Closed mx-moth closed 2 months ago

mx-moth commented 2 months ago

Some CFGrid2D datasets contain 'river' geometry - single cell wide stretches surrounded by nans. CFGrid2D datasets can contain cell bounds, but in instances where the dataset does not contain cell bounds the polygons generated by emsarray were invalid along river cells.

Example of a 'river' geometry with cell bounds. Red circles are the cell centres described by the longitude/latitude variables. Blue polygons are the cell geometry described by the cell bounds: river-with-bounds

Without bounds, emsarray previously generated geometry that looked like. Red circles are the cell centres described by the longitude/latitude variables. Blue polygons are the polygons constructed by emsarray. The polygons extending along the river are invalid as they contain multiple overlapping points, and in total describe a line segment not a polygon: river-without-bounds-old

For a real world example, consider the following river track: tasse

When reconstructing geometry emsarray now does not attempt to create geometry for 'river' cells. There is no viable way of reconstructing the geometry in all cases, as the river itself could curve and vary in width. No data is lost along river cells. Data can still be queried at these indices, and other geometric properties like Convention.face_centres might have data: river-without-bounds-new