Skip to content

Instantly share code, notes, and snippets.

@WeatherGod
Created March 9, 2012 20:48
Show Gist options
  • Save WeatherGod/2008618 to your computer and use it in GitHub Desktop.
Save WeatherGod/2008618 to your computer and use it in GitHub Desktop.
test script to demonstrate nxutils leak
import numpy as np
from matplotlib.nxutils import points_inside_poly
def polar2rect(azi, r) :
# trig is reversed because this is azimuth with 0 pointing north
x = np.sin(azi) * r
y = np.cos(azi) * r
return x, y
r, az = np.meshgrid(np.arange(0.4, 400, 0.2),
np.linspace(0.0, 2*np.pi, 360, endpoint=False))
r = r.flatten()
az = az.flatten()
deltaAz = np.array([-1, -1, 1, 1]) * (np.pi / 180.0)
deltaR = np.array([-1, 1, 1, -1]) * 0.2
x, y = polar2rect(az[:, None] + deltaAz[None, :],
r[:, None] + deltaR[None, :])
x_ax = np.linspace(x.min(), x.max(), 500)
y_ax = np.linspace(y.min(), y.max(), 300)
xgrid, ygrid = np.meshgrid(x_ax, y_ax)
gridPoints = zip(xgrid.flat, ygrid.flat)
print x.shape
for idx, (tmpx, tmpy) in enumerate(zip(x, y)) :
print idx
resVol = zip(tmpx[[0, 1, 2, 3, 0]],
tmpy[[0, 1, 2, 3, 0]])
validpts = points_inside_poly(gridPoints, resVol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment