def run(self, *args, **kwargs): meta = pyrat.data.getAnnotation(layer=self.layer) li = pyrat.query(layer=self.layer) odim = li.shape nry = odim[-2] odim[-2] //= self.suby odim[-1] //= self.subx outlayer = pyrat.data.addLayer(dtype=li.dtype, shape=odim) blockdim = odim.copy() blockdim[-2] = 1 P = pyrat.tools.ProgressBar(' ' + self.name, odim[-2]) P.update(0) for k in range(odim[-2]): arr = pyrat.getdata(block=(k * self.suby, (k + 1) * self.suby, 0, odim[-1] * self.subx), layer=self.layer) if self.decimate is True: arr = arr[..., ::self.suby, ::self.subx] else: arr = rebin(arr, tuple(blockdim)) pyrat.data.setData(arr, block=(k, k + 1, 0, 0), layer=outlayer) P.update(k + 1) del P pyrat.activate(outlayer) if "geo_ps_east" in meta and "geo_ps_north" in meta: meta['geo_ps_east'] = meta["geo_ps_east"] * self.subx meta['geo_ps_north'] = meta["geo_ps_north"] * self.suby pyrat.data.setAnnotation(meta, layer=outlayer) return outlayer
def filter(self, array, *args, **kwargs): if self.method is True: method = PIL.Image.LANCZOS else: method = PIL.Image.NEAREST odim = list(array.shape) odim[-2] //= self.suby odim[-1] //= self.subx oarr = np.empty(odim, dtype='float32') if oarr.ndim == 3: nchannel = odim[0] else: nchannel = 1 array = array[None, ...] oarr = oarr[None, ...] for k in range(nchannel): arr = array[k, ...] # workaround for PIL bug while True: # (large array crash) try: arr = PIL.Image.fromarray(arr.astype(np.float32), mode='F') except OverflowError: shp = arr.shape arr = rebin(arr[0:shp[-2] // 2 * 2, 0:shp[-1] // 2 * 2], (shp[-2] // 2, shp[-1] // 2)) else: break # arr = PIL.Image.fromarray(array[k, ...].astype(np.float32), mode='F') arr = arr.resize(odim[-2:][::-1], resample=method) oarr[k, ...] = np.asarray(arr) return np.squeeze(oarr)
def run(self, *args, **kwargs): meta = pyrat.data.getAnnotation(layer=self.layer) li = pyrat.query(layer=self.layer) odim = li.shape nry = odim[-2] odim[-2] //= self.suby odim[-1] //= self.subx outlayer = pyrat.data.addLayer(dtype=li.dtype, shape=odim) blockdim = odim.copy() blockdim[-2] = 1 P = pyrat.tools.ProgressBar(' ' + self.name, odim[-2]) P.update(0) for k in range(odim[-2]): arr = pyrat.getdata(block=(k*self.suby, (k+1)*self.suby, 0, odim[-1] * self.subx), layer=self.layer) arr = rebin(arr, tuple(blockdim)) pyrat.data.setData(arr, block=(k, k+1, 0, 0), layer=outlayer) P.update(k + 1) del P pyrat.activate(outlayer) if "geo_ps_east" in meta and "geo_ps_north" in meta: meta['geo_ps_east'] = meta["geo_ps_east"] * self.subx meta['geo_ps_north'] = meta["geo_ps_north"] * self.suby pyrat.data.setAnnotation(meta, layer=outlayer) return outlayer
def filter(self, array, *args, **kwargs): odim = list(array.shape) odim[-2] //= self.suby odim[-1] //= self.subx array = rebin(array[..., 0:odim[-2] * self.suby, 0:odim[-1] * self.subx], odim) return array
def filter(self, array, *args, **kwargs): odim = list(array.shape) odim[-2] //= self.suby odim[-1] //= self.subx array = rebin( array[..., 0:odim[-2] * self.suby, 0:odim[-1] * self.subx], odim) return array
def run(self, *args, **kwargs): li = pyrat.query(layer=self.layer) odim = li.shape nry = odim[-2] odim[-2] //= self.suby odim[-1] //= self.subx outlayer = pyrat.data.addLayer(dtype=li.dtype, shape=odim) blockdim = odim.copy() blockdim[-2] = 1 P = ProgressBar(' ' + self.name, odim[-2]) P.update(0) for k in range(odim[-2]): arr = pyrat.getdata(block=(k*self.suby, (k+1)*self.suby, 0, odim[-1] * self.subx), layer=self.layer) arr = rebin(arr, tuple(blockdim)) pyrat.data.setData(arr, block=(k, k+1, 0, 0), layer=outlayer) P.update(k + 1) del P pyrat.activate(outlayer) return outlayer
def reader(self, *args, **kwargs): fN = len(self.filenames) meta = {} if 'ppfiles' in self.__dict__: pp = Xml2Py(self.ppfiles[0]) meta['sensor'] = 'DLR F-SAR' meta['band'] = band meta['prf'] = pp.prf meta['c0'] = pp.c0 meta['rd'] = pp.rd meta['rs'] = pp.rsf/subx meta['lam'] = pp.__dict__['lam'] meta['band'] = pp.band meta['antdir'] = pp.antdir meta['v0'] = pp.v0 meta['h0'] = pp.h0 meta['terrain'] = pp.terrain meta['bw'] = pp.cbw if (len(self.rat_block) == 4): meta['rd'] += self.rat_block[0] / meta['rs'] meta['CH_pol'] = [' ']*(fN**2) pind = 0 for f1 in self.ppfiles: pp1 = Xml2Py(f1) for f2 in self.ppfiles: pp2 = Xml2Py(f2) meta['CH_pol'][pind] = pp1.polarisation+pp2.polarisation ppind += 1 file = RatFile(self.filenames[0]) if len(self.rat_block) != 4: imDim = file.dim[0:2][::-1] else: imDim = self.rat_block[2:4][::-1] imDim = np.asarray(imDim,dtype='i4') blenOut = 100 blenIn = blenOut*self.suby nBlocks = int(np.ceil(imDim[0]/float(blenIn))) sub = np.asarray([self.suby,self.subx],dtype='i4') oDim = imDim / sub meta['nrg'] = oDim[0] meta['naz'] = oDim[1] P = ProgressBar(' ' + self.name, nBlocks) P.update(0) for n in range(nBlocks): rInd = np.minimum(np.asarray([n*blenIn,(n+1)*blenIn]),imDim[0]) wInd = rInd/sub if wInd[0] >= wInd[1]: continue binInd = [(wInd[1]-wInd[0])*sub[0],oDim[1]*sub[1]] bDim = (wInd[1]-wInd[0],oDim[1]) for u in range(fN): blk = [0,rInd[0],imDim[1],rInd[1]-rInd[0]] if len(self.rat_block) == 4: blk[0] = self.rat_block[0] blk[1] += self.rat_block[1] blk[2] = self.rat_block[2] arr1 = rrat(self.filenames[u],block=blk) arr1 = arr1[0:binInd[0],0:binInd[1]] if (u == 0) and (n == 0): covar = np.empty((fN,fN)+tuple(oDim),dtype=arr1.dtype) covar[u,u,wInd[0]:wInd[1],:] = rebin(np.abs(arr1)**2,bDim) for v in range(u+1,fN): arr2 = rrat(self.filenames[v],block=blk) covar[u,v,wInd[0]:wInd[1],:] = rebin(arr1*np.conj(arr2),bDim) covar[v,u,wInd[0]:wInd[1],:] = np.conj(covar[u,v,wInd[0]:wInd[1],:]) P.update(n+1) return covar, meta