def __new__(subtype, *args, **kwargs): ''' Create new object. No default mapping - use empty dictionary. ''' values_mapping = kwargs.pop('values_mapping', {}) obj = MaskedArray.__new__(MaskedArray, *args, **kwargs) obj.__class__ = MappedArray # Must occur after class change for obj.state to update! obj.values_mapping = values_mapping return obj
def __new__(cls, *args, **kwargs): ''' Create new object. No default mapping - use empty dictionary. ''' values_mapping = kwargs.pop('values_mapping', {}) obj = MaskedArray.__new__(MaskedArray, *args, **kwargs) obj.__class__ = MappedArray # Must occur after class change for obj.state to update! obj.values_mapping = values_mapping return obj
def __new__( cls, data, yorigin, xorigin, origin, cellsize, proj=None, fill_value=None, fobj=None, mode=None, # mask=None, *args, **kwargs): # The mask will always be calculated, even if its already present or not needed at all... mask = np.zeros_like( data, np.bool) if fill_value is None else data == fill_value if origin not in ORIGINS: raise TypeError( "Argument 'origin' must be one of '{:}'".format(ORIGINS)) try: # Does this work for grids crossing the equator?? origin = "".join(("l" if cellsize[0] > 0 else "u", "l" if cellsize[1] > 0 else "r")) # iterable of len < 2, numeric value except (IndexError, TypeError): cs = abs(cellsize) cellsize = (cs if origin[0] == "l" else -cs, cs if origin[1] == "l" else -cs) obj = MaskedArray.__new__(cls, data=data, fill_value=fill_value, mask=mask, *args, **kwargs) obj.unshare_mask() obj._optinfo["yorigin"] = yorigin obj._optinfo["xorigin"] = xorigin obj._optinfo["origin"] = origin obj._optinfo["cellsize"] = tuple(cellsize) obj._optinfo["_proj"] = _Projection(proj) obj._optinfo[ "fill_value"] = fill_value #if fill_value is not None else _dtypeInfo(obj.dtype)["min"] obj._optinfo["mode"] = mode obj._optinfo["_fobj"] = fobj return obj
def __new__(cls, data, err=noerr, name='', units='', mask=nomask, dtype=None, edtype=None): """ Construct a Dvect from an input array which we try to make into a masked array as far as possible """ # Try to make a masked array out of the input #obj = masked_array(data, dtype=dtype, mask=mask, subok=True).view(cls) obj = MaskedArray.__new__(cls, data, dtype=dtype, mask=mask) if not isinstance(obj, Dvect): obj = obj.view(cls) # Add attributes if err is not noerr: obj._err = array(err, dtype=edtype) if obj._err.shape != obj.shape: raise DvectError('Dvect.__new__: errors and data are incompatible') obj._name = name obj._units = units return obj
def __new__( cls, data, geotrans=None, proj=None, fill_value=None, fobj=None, color_mode=None, # mask=None, yvalues=None, xvalues=None, mode="r", *args, **kwargs): # NOTE: The mask will always be calculated, even if its # already present or not needed at all... mask = (np.zeros_like(data, np.bool) if fill_value is None else data == fill_value) self = MaskedArray.__new__(cls, data=data, fill_value=fill_value, mask=mask, *args, **kwargs) self.unshare_mask() self.__dict__["geotrans"] = geotrans self.__dict__["proj"] = _Projection(proj) self.__dict__["color_mode"] = color_mode self.__dict__["mode"] = mode self.__dict__["_fobj"] = fobj self.__dict__["_yvalues"] = yvalues self.__dict__["_xvalues"] = xvalues return self