-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Null values in grid #49
Comments
I don't think there is a unique answer (or specification). If null corresponds to missing data, maybe it should be ignored rather than set to the min? In that case we could to set nulls to an average of the neighbors… but then what happens when all neighbors are null too. Also note that the current algorithm currently “works” with null (considered as 0, it creates a hole), but breaks with undefined or NaN, sometimes resulting in empty contours. I have a test notebook here https://observablehq.com/d/c490a61e8eef537e (not very advanced). |
@Fil thanks for the response. I am not able to reproduce the donuts like you are seeing. I thought at first it might be because i cant pass in "null". I am using a float32array this only allows for undefined. but i converted my float32array to a regular array and swapped out all the undefined for nulls. It gives me a rapid descent in the donuts down to the min range
resulting data set. with surface model EDIT: after rereading your post a couple times, i think you see what i am saying. Solution would be to have it skip the node completely? unknown is unknown do nothing |
Yes—but "do nothing" is not an option, since the marching squares algorithm needs to know which way to use if it has to cross here for value=0 in this 3x1 rectangle:
that's why I suggest doing a first pass to replace all nulls (or undefined/NaN) by neighboring values (or mean of neighboring values), if it works in this use case. I don't think this would be in the scope of d3-contour though because 1) it's costly 2) the situation can become pretty difficult (recursive) if you have many N/A values—or even only N/A 3) most importantly, the correct solution really depends on what NaNs mean in the data model. If NaN means for instance "sea vs land", then a value of -1 (or gridMin-1) might be the correct approach. If NaN means "missing data", then some kind of local interpolation might be better. |
Rather than breaking silently, throw an error? |
If you're working with non-gridded data you might want to take a look at https://github.com/Fil/d3-tricontour |
The tri-contour library does really take triangles. It takes points and Delaunay's up triangles. That wont work either because it TINs up my holes. I could make a tin by just splitting up my grid nodes, but tricontour doesn't seem to take triangles. Still searching for a solution. looks like some post process pound and ground for similar lines might be best at this point. |
Just to help the next person... I decided to go with a solution of post processing. If line vertex not on the grid then toss it. and make a new segment. Bunch of little things to deal with but pretty much:
Thanks for the help. Great lib |
We should treat null/undefined/NaN as -Infinity, i.e., a value that is lower than any possible threshold and never included in any contour. |
…es when computing the thresholds. closes #49
* null, undefined, NaN and -Infinity create holes. Ignore infinite values when computing the thresholds. closes #49 * Update src/contours.js Co-authored-by: Mike Bostock <mbostock@gmail.com> * post-review * revert unrelated style changes * nullish * extract closure * a few comments * another comment * another comment Co-authored-by: Mike Bostock <mbostock@gmail.com>
I have grids with null values. Countour does not like null or undefined in the array of values. Any solutions? I can set the nulls to gridMin-1 and then set the threshold but i still Get steps down from the Larger than min values to gridMin.
The text was updated successfully, but these errors were encountered: