def fromfile(self,varname,iind=slice(None),jind=slice(None),kind=slice(None),\ tind=slice(None),maskandscale=True, dtype=sp.float32): ''' Reads subset of the field. To be overloaded in the derived class. ''' ii, jj, kk, tt = scalar2slice(iind, jind, kind, tind) var = self.subset(iind, jind, kind, tind, dtype=dtype) var.name = self.name + ' ' + varname for i, mm in enumerate(self.fmap[tt]): find = mm[0] recind, = scalar2slice(mm[1]) fname = self.flist[find] print 'Reading ' + varname + ' from ', fname try: f = nc.Dataset(fname) x = f.variables[varname] x.set_auto_maskandscale(maskandscale) x = x[recind] f.close() except (RuntimeError, IOError), err: print err x = sp.ma.masked_array(sp.ones(self.grid.dims) * self.undef, mask=True) if len(x.shape) < 4: x = x[:] x = x[sp.newaxis, ...] var.data[i] = x[:, kk][:, :, jj][:, :, :, ii]
def fromfile(self,varname,iind=slice(None),\ jind=slice(None),kind=slice(None),tind=slice(None),dtype=sp.float32): ''' Reads subset of the field. To be overloaded in the derived class. ''' ii, jj, kk, tt = scalar2slice(iind, jind, kind, tind) var = self.subset(iind, jind, kind, tind) var.name = self.name + ' ' + varname for i, mm in enumerate(self.fmap[tt]): find = mm[0] recind = scalar2slice(mm[1]) print 'Reading ' + varname + ' from ', self.flist[find] if self.files[find] is not None: var.data[i] = sp.ma.masked_values( self.files[find][varname][recind][:, kk][:, :, jj][:, :, :, ii], self.undef) else: print 'File does not exist, values are set to missing' var.data[i] = self.undef var.data[i] = sp.ma.masked return var
def subset(self, iind=slice(None), jind=slice(None), kind=slice(None)): """ Make a subset according to indices """ i, j, k = scalar2slice(iind, jind, kind) lon = self['lon'][j][:, i] lat = self['lat'][j][:, i] lev = self['lev'][k] return Grid(lon, lat, lev)
def subset(self,iind=slice(None),\ jind=slice(None),kind=slice(None),tind=slice(None), dtype=sp.float32): ''' Creates empty field from dataset with dimentions (tind,kind,jind,iind) ''' g = self.grid.subset(iind=iind, jind=jind, kind=kind) t, = scalar2slice(tind) time = self.time[t] sh = time.shape + g.dims data = sp.ma.masked_array(sp.zeros(sh), dtype=dtype, fill_value=self.undef) return Field(data, time, g, self.name)
def subset(self, iind=slice(None), jind=slice(None), kind=slice(None), tind=slice(None)): ''' Returns slice of the field. Indices should be valid for array indexing. If no indices are given, returns a copy. ''' g = self.grid.subset(iind, jind, kind) i, j, k, t = utl.scalar2slice(iind, jind, kind, tind) time = self.time[t].copy() data = self.data[t][:, k][:, :, j][:, :, :, i].copy() out = Field(data, time, g, self.name) return out