我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用numpy.ma.asarray()。
def _transform1d(plotfunc): # shift data and longitudes to map projection region, then compute # transformation to map projection coordinates. @functools.wraps(plotfunc) def with_transform(self,x,y,*args,**kwargs): x = np.asarray(x) # input coordinates are latitude/longitude, not map projection coords. if kwargs.pop('latlon', latlon_default): # shift data to map projection region for # cylindrical and pseudo-cylindrical projections. if self.projection in _cylproj or self.projection in _pseudocyl: if x.ndim == 1: x = self.shiftdata(x) elif x.ndim == 0: if x > 180: x = x - 360. # convert lat/lon coords to map projection coords. x, y = self(x,y) return plotfunc(self,x,y,*args,**kwargs) return with_transform
def detect_contour(img, level): #parameter mask = None; corner_mask = True; nchunk = 0; #prepare image data z = ma.asarray(img, dtype=np.float64); ny, nx = z.shape; x, y = np.meshgrid(np.arange(nx), np.arange(ny)); #find contour contour_generator = _contour.QuadContourGenerator(x, y, z.filled(), mask, corner_mask, nchunk) vertices = contour_generator.create_contour(level); return vertices;
def inverse(self, value): if not self.scaled(): raise ValueError("Not invertible until scaled") vmin, vmax, midpoint = self.vmin, self.vmax, self.midpoint if cbook.iterable(value): val = ma.asarray(value) val = 2 * (val-0.5) val[val>0] *= abs(vmax - midpoint) val[val<0] *= abs(vmin - midpoint) val += midpoint return val else: val = 2 * (val - 0.5) if val < 0: return val*abs(vmin-midpoint) + midpoint else: return val*abs(vmax-midpoint) + midpoint
def detect_contour(img, level): """Returns list of vertices of contours at different levels Arguments: img (array): the image array level (number): the level at which to create the contour Returns: (list of nx2 arrays): list of list of vertices of the different contours Note: The contour detection is based on matplotlib's QuadContourGenerator """ #parameter mask = None; corner_mask = True; nchunk = 0; #prepare image data z = ma.asarray(img, dtype=np.float64); ny, nx = z.shape; x, y = np.meshgrid(np.arange(nx), np.arange(ny)); #find contour contour_generator = _contour.QuadContourGenerator(x, y, z.filled(), mask, corner_mask, nchunk) vertices = contour_generator.create_contour(level); return vertices;
def _get_refvals(referent, varname, repeat, multi): try: from netCDF4 import Dataset as NetCDF except: pass refnc = NetCDF(referent) if not multi: ref_vals = refnc.variables[varname][:] else: data = refnc.variables[varname][:] new_dims = [repeat] + [x for x in data.shape] masked=False if (isinstance(data, ma.core.MaskedArray)): masked=True if not masked: ref_vals = np.zeros(new_dims, data.dtype) else: ref_vals = ma.asarray(np.zeros(new_dims, data.dtype)) for i in xrange(repeat): ref_vals[i,:] = data[:] if masked: ref_vals.mask[i,:] = data.mask[:] return ref_vals