DHI / mikeio

Read, write and manipulate dfs0, dfs1, dfs2, dfs3, dfsu and mesh files.
https://dhi.github.io/mikeio
BSD 3-Clause "New" or "Revised" License
136 stars 53 forks source link

Point incorrectly considered outside domain #685

Open coline-mathias opened 2 months ago

coline-mathias commented 2 months ago

Describe the bug Hello, I just encountered a bug in mikeio-1.7.1 when trying to extract data in specific points. All the points work fine except one of them, for which data.sel() raises OutsideDomainError. I checked on a plot, and this point is in the middle of the domain, not especially close to a boundary or anything.

I tried to uninstall and reinstall mikeio, without any change.

To Reproduce Below is an example with two points : for the first one the extraction is successful, the second one raises OutsideDomaineError. However, mesh.contains(pt) returns True.

pts = [(439166.047, 6921703.975), (439297.166, 6921728.645)] output_file= "SW.dfsu" data = mikeio.read(output_file, items=['Sign. Wave Height', 'Mean Wave Direction', 'Peak Wave Period', 'Surface elevation']) mesh = mikeio.Mesh(output_file) for pt in pts : print(mesh.contains(pt)) data_pt = data.sel(x=pt[0], y=pt[1])

Link to SW data file : https://creocean.fromsmash.com/vZre2O85U0-ct

Expected behavior I would have expected both points to be corrrectly extracted from data file.

Screenshots Position of the two points tested above : image

System information:

Thank you very much,

Coline

ecomodeller commented 2 months ago

Our current strategy to find the correct element (trying to be as fast as possible) is not correct in areas with such a mixed element sizes.

The failing point is not inside the any of the 10 closest elements and then wrongly categorized as outside the domain. image

https://github.com/DHI/mikeio/blob/08f52ac9fb6f2c91599f56a5f62a277b296c7dde/mikeio/spatial/_FM_geometry.py#L688 You can tell from the comment, that I was a bit unsure on how to handle this, but this example indicates that 10 is not enough😳

Thanks @coline-mathias for reporting.

ecomodeller commented 2 months ago

Attaching a smaller file of the AOI to make it easer to reproduce. subset.zip