Generate a set of coordinates at the centers of pixels of resolutions nside across the full sky.
339090
def allSkyCoordinates(nside):
    
    lon,lat = pix2ang(nside, np.arange(0, hp.nside2npix(nside)))
    return lon, lat
1216669
function pixelToLatitude (y, zoom) {
  var latRad = Math.atan(Math.sinh(Math.PI * (1 - 2 * y / zScale(zoom))))
  return toDegrees(latRad)
}
735637
private double[] getWorldToScreenTranslation(double resolution, Coordinate position) {
		double translateX = -(position.getX() / resolution) + ((double) viewPort.getMapWidth() / 2.0);
		double translateY = (position.getY() / resolution) + ((double) viewPort.getMapHeight() / 2.0);
		return new double[] { translateX, translateY };
	}
694741
def ang2pix(nside, theta, phi, nest=False, lonlat=False):
    """"""
    lon, lat = _healpy_to_lonlat(theta, phi, lonlat=lonlat)
    return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
1112733
def pixel_bounds_based_on_center
      viewport_radius_w = @viewport_w / 2
      viewport_radius_h = @viewport_h / 2
      @pixel_bounds_based_on_center ||= {
          sw: [pixel_coords[0] + viewport_radius_h, pixel_coords[1] - viewport_radius_w],
          ne: [pixel_coords[0] - viewport_radius_h, pixel_coords[1] + viewport_radius_w]
      }
    end
910625
def pix2sky(self, pixel):
        
        pixbox = numpy.array([pixel, pixel])
        skybox = self.wcs.all_pix2world(pixbox, 1)
        return [float(skybox[0][0]), float(skybox[0][1])]
187618
def cropIndices(dims, lat, lon, depth=None, doy=None):
    
    dims_out = {}
    idx = {}
    
    yn = slice(
            np.nonzero(dims['lat'] <= lat.min())[0].max(),
            np.nonzero(dims['lat'] >= lat.max())[0].min() + 1)
    dims_out['lat'] = np.atleast_1d(dims['lat'][yn])
    idx['yn'] = yn

    lon_ext = np.array(
            (dims['lon'] - 2*360).tolist() +
            (dims['lon'] - 360).tolist() +
            dims['lon'].tolist() +
            (dims['lon'] + 360).tolist())
    xn_ext = list(4 * list(range(dims['lon'].shape[0])))
    xn_start = np.nonzero(lon_ext <= lon.min())[0].max()
    xn_end = np.nonzero(lon_ext >= lon.max())[0].min()
    xn = xn_ext[xn_start:xn_end+1]
    dims_out['lon'] = np.atleast_1d(lon_ext[xn_start:xn_end+1])
    idx['xn'] = xn

    if depth is not None:
        zn = slice(
                np.nonzero(dims['depth'] <= depth.min())[0].max(),
                np.nonzero(dims['depth'] >= min(dims['depth'].max(), depth.max())
                    )[0].min() + 1
                                                        )
        # If a higher degree interpolation system uses more than one data
        #   point in the edge, I should extend this selection one point on
        #   each side, without go beyond 0
        # if zn.start < 0:
        #    zn = slice(0, zn.stop, zn.step)
        dims_out['depth'] = np.atleast_1d(dims['depth'][zn])
        idx['zn'] = zn

    if doy is not None:
        # Source has only one time, like total mean field, or annual mean.
        if dims['time'].shape == (1,):
            dims_out['time'] = dims['time']
            idx['tn'] = [0]
        else:
            time_ext = np.array(
                    [dims['time'][-1] - 365.25] +
                            dims['time'].tolist() +
                            [dims['time'][0] + 365.25])
            tn_ext = list(range(dims['time'].size))
            tn_ext = [tn_ext[-1]] + tn_ext + [tn_ext[0]]
            tn_start = np.nonzero(time_ext <= doy.min())[0].max()
            tn_end = np.nonzero(time_ext >= doy.max())[0].min()
            dims_out['time'] = np.atleast_1d(time_ext[tn_start:tn_end+1])
            idx['tn'] = tn_ext[tn_start:tn_end+1]

    return dims_out, idx
260116
def pixels_to_ndc(pos, size=None):
    """"""
    pos = np.asarray(pos, dtype=np.float64)
    size = np.asarray(size, dtype=np.float64)
    pos = pos / (size / 2.) - 1
    # Flip y, because the origin in pixels is at the top left corner of the
    # window.
    pos[1] = -pos[1]
    return pos
1294024
def get_pixel_skydirs(self):
        

        xpix = np.linspace(0, self.npix[0] - 1., self.npix[0])
        ypix = np.linspace(0, self.npix[1] - 1., self.npix[1])
        xypix = np.meshgrid(xpix, ypix, indexing='ij')
        return SkyCoord.from_pixel(np.ravel(xypix[0]),
                                   np.ravel(xypix[1]), self.wcs)
670684
def coord_to_pixel(self, lat, lon, width, ground_width, lat2, lon2):
		''''''
		pixel_width = ground_width / float(width)

		if lat is None or lon is None or lat2 is None or lon2 is None:
			return (0,0)

		dx = mp_util.gps_distance(lat, lon, lat, lon2)
		if lon2 < lon:
			dx = -dx
		dy = mp_util.gps_distance(lat, lon, lat2, lon)
		if lat2 > lat:
			dy = -dy

		dx /= pixel_width
		dy /= pixel_width
		return (int(dx), int(dy))
1185280
def getZoom(self, resolution):
        ""
        assert resolution in self.RESOLUTIONS
        return self.RESOLUTIONS.index(resolution)
860567
private Coordinate[] getCenterPoints( double[][][] houghValues, int maxCircles ) {

        Coordinate[] centerPoints = new Coordinate[maxCircles];
        int xMax = 0;
        int yMax = 0;
        int rMax = 0;

        pm.beginTask("Search for circles...", maxCircles);
        for( int c = 0; c < maxCircles; c++ ) {
            double counterMax = -1;
            for( int radius = radiusMinPixel; radius <= radiusMaxPixel; radius = radius + radiusIncPixel ) {

                int indexR = (radius - radiusMinPixel) / radiusIncPixel;
                for( int y = 0; y < height; y++ ) {
                    for( int x = 0; x < width; x++ ) {
                        if (houghValues[x][y][indexR] > counterMax) {
                            counterMax = houghValues[x][y][indexR];
                            xMax = x;
                            yMax = y;
                            rMax = radius;
                        }
                    }

                }
            }
            centerPoints[c] = new Coordinate(xMax, yMax, rMax);
            clearNeighbours(houghValues, xMax, yMax, rMax);
            pm.worked(1);
        }
        pm.done();
        return centerPoints;
    }
319911
def map_pixel(self, point_x, point_y):
        '''
        
        '''
        row, col = map_pixel(point_x, point_y,
                             self.x_cell_size, self.y_cell_size, self.xmin, self.ymax)
        try:
            return self.raster[row, col]
        except:
            raise RasterGeoError('Make sure the point belongs to the raster coverage \
                                 and it is in the correct geographic coordinate system.')
1321115
def nside2pixarea(nside, degrees=False):
    """"""
    area = nside_to_pixel_area(nside)
    if degrees:
        return area.to(u.deg ** 2).value
    else:
        return area.to(u.sr).value
1098644
def _get_nadir_pixel(earth_mask, sector):
        
        if sector == FULL_DISC:
            logger.debug('Computing nadir pixel')

            # The earth is not centered in the image, compute bounding box
            # of the earth disc first
            rmin, rmax, cmin, cmax = bbox(earth_mask)

            # The nadir pixel is approximately at the centre of the earth disk
            nadir_row = rmin + (rmax - rmin) // 2
            nadir_col = cmin + (cmax - cmin) // 2

            return nadir_row, nadir_col

        return None, None
1335915
def ang2pix(nside, theta, phi):
    
    """
    nside, theta, phi = numpy.lib.stride_tricks.broadcast_arrays(nside, theta, phi)

    def equatorial(nside, tt, z):
        t1 = nside * (0.5 + tt)
        t2 = nside * z * 0.75
        jp = (t1 - t2).astype('i8')
        jm = (t1 + t2).astype('i8')
        ir = nside + 1 + jp - jm # in {1, 2n + 1}
        kshift = 1 - (ir & 1) # kshift=1 if ir even, 0 odd

        ip = (jp + jm - nside + kshift + 1) // 2 # in {0, 4n - 1}

        ip = ip % (4 * nside)
        return nside * (nside - 1) * 2 + (ir - 1) * 4 * nside + ip

    def polecaps(nside, tt, z, s):
        tp = tt - numpy.floor(tt)
        za = numpy.abs(z)
        tmp = nside * s / ((1 + za) / 3) ** 0.5
        mp = za > 0.99
        tmp[mp] = nside[mp] * (3 *(1-za[mp])) ** 0.5
        jp = (tp * tmp).astype('i8')
        jm = ((1 - tp) * tmp).astype('i8')
        ir = jp + jm + 1
        ip = (tt * ir).astype('i8')
        ip = ip % (4 * ir)

        r1 = 2 * ir * (ir - 1)
        r2 = 2 * ir * (ir + 1)

        r = numpy.empty_like(r1)

        r[z > 0] = r1[z > 0] + ip[z > 0]
        r[z < 0] = 12 * nside[z < 0] * nside[z < 0] - r2[z < 0] + ip[z < 0]
        return r

    z = numpy.cos(theta)
    s = numpy.sin(theta)

    tt = (phi / (0.5 * numpy.pi) ) % 4 # in [0, 4]

    result = numpy.zeros(z.shape, dtype='i8')
    mask = (z < 2. / 3) & (z > -2. / 3)

    result[mask] = equatorial(nside[mask], tt[mask], z[mask])
    result[~mask] = polecaps(nside[~mask], tt[~mask], z[~mask], s[~mask])
    return result
866400
def for_meters(cls, meter_x, meter_y, zoom):
        """"""
        point = Point.from_meters(meter_x=meter_x, meter_y=meter_y)
        pixel_x, pixel_y = point.pixels(zoom=zoom)
        return cls.for_pixels(pixel_x=pixel_x, pixel_y=pixel_y, zoom=zoom)