Welp, it looks like it’s been longer since I tried tweaking basic code than I thought. I’m having trouble just trying to adjust the box’s range to be from −124 to −71 and 25 to 53 (ie, longitude and latitude) instead of 1-10/1-10. I’m going to keep puzzling away, but anyone reading this, feel free to offer advice. :)
(I have some TV to watch later with the fam, so I won’t mind doing some drudge work during the shows of typing out the city-list into an array of X/Y coordinates and population/weight, to paste into the Python script in place of randomly-generated points. … Once I figure out how to get the script to accept a fixed array instead of randomly-generated points.)
The range is specified by the box argument to the compute_2d_voronoi function, in form [[min_x, max_x], [min_y, max_y]]. Points and weights can be specified as 2d and 1d arrays, e.g., as np.array([[x1,y1], [x2, y2], [x3, y3], ..., [xn, yn]]) and np.array([w1, w2, w3, ..., wn]). Here’s an example that takes specified points, and also allows you to plot point radii for debugging purposes: http://pastebin.com/h2fDLXRD
I started entering the live city data, and everything was going fine. Had to tweak the weights a bit to avoid some initial problems… then I got to Washington DC, and nothing I try seems to get it to work again. http://pastebin.com/q1JhUpSp is what I’ve ended up with; if I comment out DC’s lines, I get a plot, if I put it back in, python just errors out, no matter what I set the weight divisor to. Any thoughts?
all other points have a negative x coordinate, and the x range passed to the tessellation algorithm is [-124, −71]. You probably forgot the minus sign for that point’s x coordinate.
as mentioned above, the algorithm fails to converge because the weights are poorly scaled. For a better graphical representation, you will want to scale them to the range between one and one half of the nearest point distance, but to make it run, just increase the division constant.
Welp, it looks like it’s been longer since I tried tweaking basic code than I thought. I’m having trouble just trying to adjust the box’s range to be from −124 to −71 and 25 to 53 (ie, longitude and latitude) instead of 1-10/1-10. I’m going to keep puzzling away, but anyone reading this, feel free to offer advice. :)
(I have some TV to watch later with the fam, so I won’t mind doing some drudge work during the shows of typing out the city-list into an array of X/Y coordinates and population/weight, to paste into the Python script in place of randomly-generated points. … Once I figure out how to get the script to accept a fixed array instead of randomly-generated points.)
The range is specified by the box argument to the
compute_2d_voronoi
function, in form[[min_x, max_x], [min_y, max_y]]
. Points and weights can be specified as 2d and 1d arrays, e.g., asnp.array([[x1,y1], [x2, y2], [x3, y3], ..., [xn, yn]])
andnp.array([w1, w2, w3, ..., wn])
. Here’s an example that takes specified points, and also allows you to plot point radii for debugging purposes: http://pastebin.com/h2fDLXRDThank you kindly for your help so far. :)
I started entering the live city data, and everything was going fine. Had to tweak the weights a bit to avoid some initial problems… then I got to Washington DC, and nothing I try seems to get it to work again. http://pastebin.com/q1JhUpSp is what I’ve ended up with; if I comment out DC’s lines, I get a plot, if I put it back in, python just errors out, no matter what I set the weight divisor to. Any thoughts?
Two things:
all other points have a negative x coordinate, and the x range passed to the tessellation algorithm is [-124, −71]. You probably forgot the minus sign for that point’s x coordinate.
as mentioned above, the algorithm fails to converge because the weights are poorly scaled. For a better graphical representation, you will want to scale them to the range between one and one half of the nearest point distance, but to make it run, just increase the division constant.