GithubHelp home page GithubHelp logo

Handle Null values in grid about d3-contour HOT 9 CLOSED

d3 avatar d3 commented on April 24, 2024
Handle Null values in grid

from d3-contour.

Comments (9)

Fil avatar Fil commented on April 24, 2024 1

If you're working with non-gridded data you might want to take a look at https://github.com/Fil/d3-tricontour

from d3-contour.

kpetrow avatar kpetrow commented on April 24, 2024 1

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:

                       (
                            isNaN(tempGrid.elevations[array_pos]) ||
                            isNaN(tempGrid.elevations[array_pos - 1]) ||
                            isNaN(tempGrid.elevations[array_pos + tempGrid.metaData.nCol + 1]) ||
                            isNaN(tempGrid.elevations[array_pos - (tempGrid.metaData.nCol + 1)]) ||
                            isNaN(tempGrid.elevations[array_pos + 1])
                        ) &&
                        (
                            tempGrid.elevations[array_pos] - 1 > myCountours[i].value
                        )

Thanks for the help. Great lib

image

from d3-contour.

Fil avatar Fil commented on April 24, 2024

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).

from d3-contour.

kpetrow avatar kpetrow commented on April 24, 2024

@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


                for(var i = min; i<max; i+= step){
			range.push(i);
		}
		var temp = Array.from(tempGrid.elevations);

		for(var i = 0;i<temp.length;i++){
			if( isNaN(temp[i]) )
				temp[i] = null ;
		};

		var myCountours = d3.contours()
		.size([tempGrid.metaData.nCol+1, tempGrid.metaData.nRow+1])
		.thresholds(range)
		(temp);

resulting data set. with surface model
image

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

from d3-contour.

Fil avatar Fil commented on April 24, 2024

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:

-1 N/A 1

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.

from d3-contour.

Fil avatar Fil commented on April 24, 2024

Rather than breaking silently, throw an error?

from d3-contour.

kpetrow avatar kpetrow commented on April 24, 2024

if not feasible i understand and will have to come up with a post process solution( could the lines be stacked vertically so i eliminate ones that have identical XY and are less than maxZ for xy combo) or something else. We are forming surface models from gps movements; so unknown means just that unknown.

If NaN means "missing data", then some kind of local interpolation might be better.
image

Sometimes its a cliff, sometimes its a gradual slope, we just cant tell what it is(its usually benches with a road).

Could you suggest an alternative method/algorithm that might work?

Rather than breaking silently, throw an error?

Yeah that might be a better solution. I still need to iterate through the flot32array to replace undefined with minRange - 1. I think throwing an error on undefined might be very helpful because it breaks the entire contour line and is confusing.

Thanks for the awesome lib.

from d3-contour.

kpetrow avatar kpetrow commented on April 24, 2024

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.

from d3-contour.

mbostock avatar mbostock commented on April 24, 2024

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.

from d3-contour.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.