Comments (9)
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.
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
from d3-contour.
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.
@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
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.
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.
Rather than breaking silently, throw an error?
from d3-contour.
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.
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.
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.
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)
- Release d3-array v2 compatible version? HOT 2
- hole issue in contour HOT 5
- Arrows using elevation value for any point(x, y) in contour chart HOT 5
- GeoJSON Geometry which is generated by d3.contour displays wrong HOT 3
- output data has index which is not exist in input data HOT 2
- Feature request: contour labels HOT 2
- smoothing removes line segements HOT 1
- Buggy input check in density size setter.
- Improve slow computations for large images HOT 2
- Dependencies HOT 3
- Some contour polygon is reverse. HOT 5
- Support fractional bandwidths. HOT 2
- [feature]: cellSize(0.5) would work well in d3.contourDensity() HOT 1
- Support curvilinear grids HOT 11
- Sometimes the lowest threshold is missing
- Bug HOT 2
- Breaking change with contour-density thresholds starting from v3.0.2 HOT 2
- isobands?
- Don’t round the corners HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-contour.