Return slew the telescope and return the corners of the modules
        as Polygon objects.

        If a projection is supplied, the ras and
        decs are mapped onto x, y using that projection
552279
def getAllChannelsAsPolygons(self, maptype=None):
        
        polyList = []
        for ch in self.origin[:, 2]:
            poly = self.getChannelAsPolygon(ch, maptype)
            polyList.append(poly)
        return polyList
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
807590
def to_polygon(self):
        
        x,y = self.corners.T
        vertices = PixCoord(x=x, y=y)
        return PolygonPixelRegion(vertices=vertices, meta=self.meta,
                                  visual=self.visual)
299168
function getShapeFour(x,y,options,modules,mod_matrix){

  var EOL = '\r\n';
  var width = options.width;
  var height = options.height;
  var length = modules.length;
  var style = options.style;
  var xsize = width / (length + 2 * options.padding);
  var ysize = height / (length + 2 * options.padding);
  var px = (x * xsize + options.padding * xsize);
  var py = (y * ysize + options.padding * ysize);

  //Else in the center of a horizontal-vertical cross
  var orientation = 0;

  switch(options.style){
    case 'square':
      return '<rect transform="rotate('+orientation+' '+(px+xsize/2)+' '+(py+ysize/2)+')"  x="' + px + '" y="' + py + '" width="' + xsize + '" height="' + ysize + '" style="fill:' + options.color + ';shape-rendering:crispEdges;"/>' + EOL;
    case 'circle':
      return '<rect transform="rotate('+orientation+' '+(px+xsize/2)+' '+(py+ysize/2)+')"  rx="'+xsize+'" x="' + px + '" y="' + py + '" width="' + xsize + '" height="' + ysize + '" style="fill:' + options.color + ';shape-rendering:crispEdges;"/>' + EOL;
    case 'sharp-edge':
      return '<rect transform="rotate('+orientation+' '+(px+xsize/2)+' '+(py+ysize/2)+')" x="' + px + '" y="' + py + '" width="' + xsize + '" height="' + ysize + '" style="fill:' + options.color + ';shape-rendering:crispEdges;"/>' + EOL;
  }
}
35877
def downsample_mesh(mesh, tol=1.0):
    
    idx = _find_turning_points(mesh, tol)
    if mesh.depths is not None:
        return RectangularMesh(lons=mesh.lons[:, idx],
                               lats=mesh.lats[:, idx],
                               depths=mesh.depths[:, idx])
    else:
        return RectangularMesh(lons=mesh.lons[:, idx],
                               lats=mesh.lats[:, idx])
553881
def projection_to_raster_coords(self, lat, lon):
        
        r_px_py = np.array([1, lon, lat])
        tg = inv(np.array([[1, 0, 0], self.geotransform[0:3], self.geotransform[3:6]]))
        return np.inner(tg, r_px_py)[1:]
1203847
def coords_for_computations(self):
        

        # TODO: need to subtract the position offset if a Mesh (in orbit)
        if self._compute_at_vertices:
            if self.pvertices is not None:
                return self.pvertices - self._pos_center
            else:
                return self.vertices - self._pos_center
        else:
            return self.centers - self._pos_center
638433
function getRandomPointOnSphere(r) {
  var u = THREE.Math.randFloat(0, 1);
  var v = THREE.Math.randFloat(0, 1);
  var theta = 2 * Math.PI * u;
  var phi = Math.acos(2 * v - 1);
  var x = r * Math.sin(theta) * Math.sin(phi);
  var y = r * Math.cos(theta) * Math.sin(phi);
  var z = r * Math.cos(phi);
  return {
    x,
    y,
    z,
  };
}
1101101
def from_points(cls, list_of_lists):
        
        result = []
        for l in list_of_lists:
            curve = []
            for point in l:
                curve.append((point.lon, point.lat))
            result.append(curve)
        return Polygon(result)
983860
def mesh_nmasked(self):
        

        return self._make_2d_array(
            np.ma.count_masked(self._data_sigclip, axis=1))
1301951
def geometry(self):
        """"""
        if arcpyFound:
            if self._geom is None:
                if 'feature' in self._dict:
                    self._geom = arcpy.AsShape(self._dict['feature']['geometry'], esri_json=True)
                elif 'geometry' in self._dict:
                    self._geom = arcpy.AsShape(self._dict['geometry'], esri_json=True)
            return self._geom
        return None
1310374
def ds_cT(ds, x, y, xy_srs=wgs_srs):
    
    #Convert lat/lon to projected srs
    ds_srs = get_ds_srs(ds)
    #If xy_srs is undefined, assume it is the same as ds_srs
    mX = x
    mY = y
    if xy_srs is not None:
        if not ds_srs.IsSame(xy_srs):
            mX, mY, mZ = cT_helper(x, y, 0, xy_srs, ds_srs)
    return mX, mY
449720
def unit_poly_verts(theta):
    
    x0, y0, r = [0.5] * 3
    verts = [(r*np.cos(t) + x0, r*np.sin(t) + y0) for t in theta]
    return verts
454110
def process_parsed_coords(coords):
    
    geometry = np.zeros(shape=(len(coords), 3), dtype=float)
    for ii, entry in enumerate(coords):
        for jj in range(3):
            geometry[ii, jj] = float(entry[jj])
    return geometry
179152
def _spherical_to_cartesian(cls, coord, center):
        
        r, theta, phi, r_dot, theta_dot, phi_dot = coord
        x = r * cos(phi) * cos(theta)
        y = r * cos(phi) * sin(theta)
        z = r * sin(phi)

        vx = r_dot * x / r - y * theta_dot - z * phi_dot * cos(theta)
        vy = r_dot * y / r + x * theta_dot - z * phi_dot * sin(theta)
        vz = r_dot * z / r + r * phi_dot * cos(phi)

        return np.array([x, y, z, vx, vy, vz], dtype=float)
683541
def _create_and_rotate_coordinate_arrays(self, x, y, p):
        

        if p.aspect_ratio == 0 or p.size == 0:
            x = x * 0.0
            y = y * 0.0
        else:
            x = (x*10.0) / (p.size*p.aspect_ratio)
            y = (y*10.0) / p.size

        offset = np.exp(p.size)
        pattern_x = np.add.outer(np.sin(p.orientation)*y, np.cos(p.orientation)*x) + offset
        pattern_y = np.subtract.outer(np.cos(p.orientation)*y, np.sin(p.orientation)*x) + offset

        np.clip(pattern_x, 0, np.Infinity, out=pattern_x)
        np.clip(pattern_y, 0, np.Infinity, out=pattern_y)

        return pattern_x, pattern_y
278933
def grid_from_coordinate_transform(numPix, Mpix2coord, ra_at_xy_0, dec_at_xy_0):
    
    a = np.arange(numPix)
    matrix = np.dstack(np.meshgrid(a, a)).reshape(-1, 2)
    x_grid = matrix[:, 0]
    y_grid = matrix[:, 1]
    ra_grid = x_grid * Mpix2coord[0, 0] + y_grid * Mpix2coord[0, 1] + ra_at_xy_0
    dec_grid = x_grid * Mpix2coord[1, 0] + y_grid * Mpix2coord[1, 1] + dec_at_xy_0
    return ra_grid, dec_grid