Reimplemented to set the mesh variables as coordinates

        Parameters
        ----------
        %(CFDecoder.decode_coords.parameters)s

        Returns
        -------
        %(CFDecoder.decode_coords.returns)s
179430
def decode_coords(ds, gridfile=None):
        
        extra_coords = set(ds.coords)
        for var in six.itervalues(ds.variables):
            if 'mesh' in var.attrs:
                mesh = var.attrs['mesh']
                if mesh not in extra_coords:
                    extra_coords.add(mesh)
                    try:
                        mesh_var = ds.variables[mesh]
                    except KeyError:
                        warn('Could not find mesh variable %s' % mesh)
                        continue
                    if 'node_coordinates' in mesh_var.attrs:
                        extra_coords.update(
                            mesh_var.attrs['node_coordinates'].split())
                    if 'face_node_connectivity' in mesh_var.attrs:
                        extra_coords.add(
                            mesh_var.attrs['face_node_connectivity'])
        if gridfile is not None and not isinstance(gridfile, xr.Dataset):
            gridfile = open_dataset(gridfile)
            ds.update({k: v for k, v in six.iteritems(gridfile.variables)
                       if k in extra_coords})
        if xr_version < (0, 11):
            ds.set_coords(extra_coords.intersection(ds.variables),
                          inplace=True)
        else:
            ds._coord_names.update(extra_coords.intersection(ds.variables))
        return ds
1244574
def locality_preserving_projections(self, coordinates, num_dims=None):
    ''''''
    X = np.atleast_2d(coordinates)  # n x d
    L = self.laplacian(normed=True)  # n x n
    u,s,_ = np.linalg.svd(X.T.dot(X))
    Fplus = np.linalg.pinv(u * np.sqrt(s))  # d x d
    n, d = X.shape
    if n >= d:  # optimized order: F(X'LX)F'
      T = Fplus.dot(X.T.dot(L.dot(X))).dot(Fplus.T)
    else:  # optimized order: (FX')L(XF')
      T = Fplus.dot(X.T).dot(L.dot(X.dot(Fplus.T)))
    L = 0.5*(T+T.T)
    return _null_space(L, num_vecs=num_dims, overwrite=True)
1152009
def _coords_conv(self, pos):
        
        px = (self.original_size[0] / 2 + pos[0]) * self.scale_factor
        py = (self.original_size[1] / 2 - pos[1]) * self.scale_factor
        return round(px, 2), round(py, 2)
636264
def set_parameters(self, parameters):
        
        if not isinstance(parameters, np.ndarray):
            parameters = np.asarray(parameters)

        # if in two dimensions, flatten with fortran ordering
        if parameters.ndim > 1:
            parameters = parameters.flatten(order='F')

        libfn = utils.get_lib_fn('setTransformParameters%s'%self._libsuffix)
        libfn(self.pointer, parameters.tolist())
113630
def getUnionLocations(encoder, x, y, r, step=1):
  
  output = np.zeros(encoder.getWidth(), dtype=defaultDtype)
  locations = set()
  for dx in range(-r, r+1, step):
    for dy in range(-r, r+1, step):
      if dx*dx + dy*dy <= r*r:
        e = encodeLocation(encoder, x+dx, y+dy, output)
        locations = locations.union(set(e))

  return locations
316177
def coordinates_inside_data(
        self,
        x,
        y
        ):

        

        return (self.min_x <= x < self.max_x) and (self.min_y <= y < self.max_y)
711225
def _add_projection_coords(ds, prod_desc, proj_var, dx, dy):
    """"""
    proj = cf_to_proj(proj_var)

    # Get projected location of lower left point
    x0, y0 = proj(prod_desc.lo1, prod_desc.la1)

    # Coordinate variable for x
    ds.createDimension('x', prod_desc.nx)
    x_var = ds.createVariable('x', np.float64, dimensions=('x',))
    x_var.units = 'm'
    x_var.long_name = 'x coordinate of projection'
    x_var.standard_name = 'projection_x_coordinate'
    x_var[:] = x0 + np.arange(prod_desc.nx) * (1000. * dx)

    # Now y
    ds.createDimension('y', prod_desc.ny)
    y_var = ds.createVariable('y', np.float64, dimensions=('y',))
    y_var.units = 'm'
    y_var.long_name = 'y coordinate of projection'
    y_var.standard_name = 'projection_y_coordinate'

    # Need to flip y because we calculated from the lower left corner, but the raster data
    # is stored with top row first.
    y_var[::-1] = y0 + np.arange(prod_desc.ny) * (1000. * dy)

    # Get the two-D lon,lat grid as well
    x, y = np.meshgrid(x_var[:], y_var[:])
    lon, lat = proj(x, y, inverse=True)
    lon_var = ds.createVariable('lon', np.float64, dimensions=('y', 'x'), wrap_array=lon)
    lon_var.long_name = 'longitude'
    lon_var.units = 'degrees_east'

    lat_var = ds.createVariable('lat', np.float64, dimensions=('y', 'x'), wrap_array=lat)
    lat_var.long_name = 'latitude'
    lat_var.units = 'degrees_north'

    ds.img_extent = (x_var[:].min(), x_var[:].max(), y_var[:].min(), y_var[:].max())
967955
def geom(self):
        
        return numpy.array([(p.x, p.y, p.z) for p in self.mesh],
                           numpy.float32)
829612
def iter_coords(obj):
    
    if isinstance(obj, (tuple, list)):
        coords = obj
    elif 'features' in obj:
        coords = [geom['geometry']['coordinates'] for geom in obj['features']]
    elif 'geometry' in obj:
        coords = obj['geometry']['coordinates']
    else:
        coords = obj.get('coordinates', obj)
    for coord in coords:
        if isinstance(coord, (float, int)):
            yield tuple(coords)
            break
        else:
            for f in iter_coords(coord):
                yield f
146355
def coords(obj):
    
    # Handle recursive case first
    if 'features' in obj:
        for f in obj['features']:
            # For Python 2 compatibility
            # See https://www.reddit.com/r/learnpython/comments/4rc15s/yield_from_and_python_27/ # noqa: E501
            for c in coords(f):
                yield c
    else:
        if isinstance(obj, (tuple, list)):
            coordinates = obj
        elif 'geometry' in obj:
            coordinates = obj['geometry']['coordinates']
        else:
            coordinates = obj.get('coordinates', obj)
        for e in coordinates:
            if isinstance(e, (float, int)):
                yield tuple(coordinates)
                break
            for f in coords(e):
                yield f
786241
def mesh_axis_to_tensor_axis(self, mesh_ndims):
    
    ta2ma = self._tensor_axis_to_mesh_axis
    return tuple(
        [ta2ma.index(mesh_axis) if mesh_axis in ta2ma else None
         for mesh_axis in xrange(mesh_ndims)])
1120384
def coordinates(self, x, y):
        ''''''
        state = self.state
        return state.mt.coord_from_area(x, y, state.lat, state.lon, state.width, state.ground_width)
20689
def _ctypes_code_parameter(lines, parameter, position):
    
    mdict = {
        'indices': _ctypes_indices,
        'variable': _ctypes_variables,
        'out': _ctypes_out,
        'regular': _ctypes_regular,
        'saved': _ctypes_saved,
        'assign': _ctypes_assign,
        'clean': _ctypes_clean
    }
    line = mdict[position](parameter)
    if line is not None:
        value, blank = line
        lines.append(value)
        if blank:
            lines.append("")
1092386
def coords(self):
        
        x, y = ("lat", "lng") if self.order == "lat" else ("lng", "lat")
        try:
            return (self["location"][x], self["location"][y])

        except KeyError:
            return None
1007455
def get_cell_node_coord(self, var, coords=None, axis='x', nans=None):
        
        if coords is None:
            coords = self.ds.coords

        idims = self.get_coord_idims(coords)

        def get_coord(coord):
            coord = coords.get(coord, self.ds.coords.get(coord))
            return coord.isel(**{d: sl for d, sl in idims.items()
                                 if d in coord.dims})

        mesh = self.get_mesh(var, coords)
        if mesh is None:
            return
        nodes = self.get_nodes(mesh, coords)
        if not len(nodes):
            raise ValueError("Could not find the nodes variables for the %s "
                             "coordinate!" % axis)
        vert = nodes[0 if axis == 'x' else 1]
        if vert is None:
            raise ValueError("Could not find the nodes variables for the %s "
                             "coordinate!" % axis)
        loc = var.attrs.get('location', 'face')
        if loc == 'node':
            # we assume a triangular grid and use matplotlibs triangulation
            from matplotlib.tri import Triangulation
            xvert, yvert = nodes
            triangles = Triangulation(xvert, yvert)
            if axis == 'x':
                bounds = triangles.x[triangles.triangles]
            else:
                bounds = triangles.y[triangles.triangles]
        elif loc in ['edge', 'face']:
            connectivity = get_coord(
                mesh.attrs.get('%s_node_connectivity' % loc, ''))
            if connectivity is None:
                raise ValueError(
                    "Could not find the connectivity information!")
            connectivity = connectivity.values
            bounds = vert.values[
                np.where(np.isnan(connectivity), connectivity[:, :1],
                         connectivity).astype(int)]
        else:
            raise ValueError(
                "Could not interprete location attribute (%s) of mesh "
                "variable %s!" % (loc, mesh.name))
        dim0 = '__face' if loc == 'node' else var.dims[-1]
        return xr.DataArray(
            bounds,
            coords={key: val for key, val in coords.items()
                    if (dim0, ) == val.dims},
            dims=(dim0, '__bnds', ),
            name=vert.name + '_bnds',  attrs=vert.attrs.copy())
34934
def coordinates(self, x, y, **kwargs):
        ''''''
        kwargs['returntype'] = 'geographies'
        fields = {
            'x': x,
            'y': y
        }

        return self._fetch('coordinates', fields, **kwargs)
603079
def mesh_axis_to_cumprod(self, tensor_shape):
    
    tensor_layout = self.tensor_layout(tensor_shape)
    ma2ta = tensor_layout.mesh_axis_to_tensor_axis(self.ndims)
    ta2cumprod = tensor_shape.cumprod
    return [None if ta is None else ta2cumprod[ta] for ta in ma2ta]