Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
output : :class:`numpy:numpy.ndarray`
(num volume bins, 3)
Examples
--------
See :ref:`/notebooks/workflow/recipe2.ipynb`.
"""
# make sure that elevs is an array
elevs = np.array([elevs]).ravel()
# create polar grid
el, az, r = util.meshgrid_n(elevs, azimuths, ranges)
# get projected coordinates
coords = georef.spherical_to_proj(r, az, el, sitecoords, proj=proj)
coords = coords.reshape(-1, 3)
return coords
# but first adapt input arrays to this task
if onerange4all:
ranges = np.array([ranges for i in range(len(elevs))])
if oneaz4all:
azimuths = np.array([azimuths for i in range(len(elevs))])
# and second create the corresponding polar volume grid
el = np.array([])
az = np.array([])
r = np.array([])
for i, elev in enumerate(elevs):
az_tmp, r_tmp = np.meshgrid(azimuths[i], ranges[i])
el = np.append(el, np.repeat(elev, len(azimuths[i]) * len(ranges[i])))
az = np.append(az, az_tmp.ravel())
r = np.append(r, r_tmp.ravel())
# get projected coordinates
coords = georef.spherical_to_proj(r, az, el, sitecoords, proj=proj)
coords = coords.reshape(-1, 3)
return coords
# use simple trigonometry to calculate coordinates
nsewx, nsewy = (psite[0] + rr * np.cos(np.radians(90 - az)),
psite[1] + rr * np.sin(np.radians(90 - az)))
# mark the site, just in case nothing else would be drawn
ax.plot(*psite[:2], marker='+', **linekw)
# draw the lines
for i in range(len(angles)):
ax.add_line(lines.Line2D(nsewx[i, :], nsewy[i, :], **linekw))
# draw the range circles
if proj:
# produce an approximation of the circle
x, y = np.meshgrid(ranges, np.arange(360))
poly = georef.spherical_to_proj(ranges, np.arange(360), elev, site,
proj=proj)[..., :2]
poly = np.swapaxes(poly, 0, 1)
for p in poly:
ax.add_patch(patches.Polygon(p, **circkw))
else:
# in the unprojected case, we may use 'true' circles.
for r in ranges:
ax.add_patch(patches.Circle(psite, r, **circkw))
# there should be not much wrong, setting the axes aspect to equal
# by default
ax.set_aspect('equal')
# return the axes object for later use
return ax
# set default circle keywords
circkw = dict(edgecolor='gray', linestyle='dashed', facecolor='none')
# update with user settings
circkw.update(kwargs.get('circle', {}))
# determine coordinates for 'straight' lines
if proj:
# projected
# reproject the site coordinates
psite = georef.reproject(*site, projection_target=proj)
# these lines might not be straigt so we approximate them with 10
# segments. Produce polar coordinates
rr, az = np.meshgrid(np.linspace(0, ranges[-1], 10), angles)
# convert from spherical to projection
coords = georef.spherical_to_proj(rr, az, elev, site, proj=proj)
nsewx = coords[..., 0]
nsewy = coords[..., 1]
else:
# no projection
psite = site
rr, az = np.meshgrid(np.linspace(0, ranges[-1], 2), angles)
# use simple trigonometry to calculate coordinates
nsewx, nsewy = (psite[0] + rr * np.cos(np.radians(90 - az)),
psite[1] + rr * np.sin(np.radians(90 - az)))
# mark the site, just in case nothing else would be drawn
ax.plot(*psite[:2], marker='+', **linekw)
# draw the lines
for i in range(len(angles)):
ax.add_line(lines.Line2D(nsewx[i, :], nsewy[i, :], **linekw))