def getdelay(self, dataobj, inc=0.0, wvl=4 * np.pi): '''Write delay to a matrix / HDF5 object or a file directly. Bilinear interpolation at each elevation level is used. Args: * dataobj (str or HDF5 or np.array): Final output. If str, output is written to file. Kwargs: * inc (np.float): Incidence angle in degrees. Default is vertical. * wvl (np.float): Wavelength in meters. Default output results in delay in meters. .. note:: If dataobj is string, output is written to the file. If np.array or HDF5 object, it should be of size (ny,nx).''' minAltp = self.dict['minAltP'] # Reading in the DEM if self.verb: print 'PROGRESS: READING DEM' fin = open(self.hfile, 'rb') if self.fmt in ('HGT'): dem = np.fromfile(file=fin, dtype=self.demtype, count=self.nx * self.ny).reshape( self.ny, self.nx) elif self.fmt in ('RMG'): dem = np.fromfile(file=fin, dtype=self.demtype, count=2 * self.nx * self.ny).reshape( self.ny, 2 * self.nx) dem = dem[:, self.nx:] dem = np.round(dem).astype(np.int) fin.close() # check output, and open file if necessary outFile = isinstance(dataobj, str) if outFile: fout = open(dataobj, 'wb') dout = np.zeros((self.ny, self.nx)) else: assert ((dataobj.shape[0] == self.ny) & (dataobj.shape[1] == self.nx)), 'PyAPS: Not a valid data object.' dout = dataobj # Incidence cinc = np.cos(inc * np.pi / 180.0) # Create the 1d interpolator if self.verb: print 'PROGRESS: FINE INTERPOLATION OF HEIGHT LEVELS' intp_1d = si.interp1d(self.hgt, self.Delfn, kind='cubic', axis=-1) # Interpolate the delay function every meter dem[dem < minAltp] = minAltp minH = dem.min() maxH = dem.max() + 1 kh = np.arange(minH, maxH) Delfn_1m = intp_1d(kh) self.Delfn_interp = Delfn_1m.copy() self.alti = kh # Reshape Delfn Lonu = np.unique(self.lonlist) Latu = np.unique(self.latlist) nLon = len(Lonu) nLat = len(Latu) Delfn_1m = np.reshape(Delfn_1m.T, (len(kh), nLat, nLon)) self.Delfn_1m = Delfn_1m # build the x array xarr = np.arange(1., self.nx + 1.) # Create the cube interpolator for the bilinear method if self.verb: print 'PROGRESS: CREATE THE BILINEAR INTERPOLATION FUNCTION' bilicube = processor.Bilinear2DInterpolator(Lonu, Latu, Delfn_1m, cube=True) # Loop on the lines if self.verb: toto = utils.ProgressBar(maxValue=self.ny) print 'PROGRESS: MAPPING THE DELAY' for m in xrange(self.ny): if self.verb: toto.update(m, every=5) # Transfert (range,azimuth) to (lon,lat) yarr = (m + 1) * np.ones((xarr.shape)) [loni, lati] = utils.rdr2glob(self.nx, self.ny, self.lat, self.lon, xarr, yarr) # Make the bilinear interpolation D = dem[m, :] - minH val = bilicube(loni, lati, D) * np.pi * 4.0 / (cinc * wvl) if outFile: resy = val.astype(np.float32) resy.tofile(fout) else: dataobj[m, :] = val if self.verb: toto.close() # Close if outfile if outFile: fout.close()
def merisfactor(self, dataobj, inc=0.0, wvl=np.pi * 4.): ''' Write pi-factor from Li et al 2012 to a matrix / HDF5 object or a file directly. This is used when no lat/lon file is known. Bilinear Interpolation is used. Args: * dataobj (str or HDF5 or np.array): Final output. If str, output is written to file. Kwargs: * inc (np.float) : Incidence angle in degrees. * wvl (np.float) : Wavelength in meters. Default output results in delay in meters. .. note:: If dataobj is string, output is written to the file. If np.array or HDF5 object, it should be of size (ny,nx).''' minAltp = self.dict['minAltP'] # Incidence cinc = np.cos(inc * np.pi / 180.0) # Compute the two integrals WonT = self.Vi / self.Ti WonT2 = WonT / self.Ti S1 = intg.cumtrapz(WonT, x=self.hgt, axis=-1) val = 2 * S1[:, -1] - S1[:, -2] val = val[:, None] S1 = np.concatenate((S1, val), axis=-1) del WonT S2 = intg.cumtrapz(WonT2, x=self.hgt, axis=-1) val = 2 * S2[:, -1] - S2[:, -2] val = val[:, None] S2 = np.concatenate((S2, val), axis=-1) del WonT2 Tm = S1 / S2 self.Tm = Tm # Reading in the DEM if self.verb: print 'PROGRESS: READING DEM' fin = open(self.hfile, 'rb') if self.fmt in ('HGT'): dem = np.fromfile(file=fin, dtype=self.demtype, count=self.nx * self.ny).reshape( self.ny, self.nx) elif self.fmt in ('RMG'): dem = np.fromfile(file=fin, dtype=self.demtype, count=2 * self.nx * self.ny).reshape( self.ny, 2 * self.nx) dem = dem[:, self.nx:] dem = np.round(dem).astype(np.int) fin.close() # check output, and open file if necessary outFile = isinstance(dataobj, str) if outFile: fout = open(dataobj, 'wb') dout = np.zeros((self.ny, self.nx)) else: assert ((dataobj.shape[0] == self.ny) & (dataobj.shape[1] == self.nx)), 'PyAPS: Not a valid data object.' dout = dataobj # Create the 1d interpolator if self.verb: print 'PROGRESS: FINE INTERPOLATION OF HEIGHT LEVELS' intp_1d = si.interp1d(self.hgt, Tm, kind='cubic', axis=1) # Interpolate the Tm variable every meter dem[dem < minAltp] = minAltp minH = dem.min() maxH = dem.max() + 1 kh = np.arange(minH, maxH) Tm_1m = intp_1d(kh) self.alti = kh # Reshape Tm Lonu = np.unique(self.lonlist) Latu = np.unique(self.latlist) nLon = len(Lonu) nLat = len(Latu) Tm_1m = np.reshape(Tm_1m.T, (len(kh), nLat, nLon)) self.Tm_1m = Tm_1m # build the x array xarr = np.arange(1., self.nx + 1.) # Create the cube interpolator for the bilinear method if self.verb: print 'PROGRESS: CREATE THE BILINEAR INTERPOLATION FUNCTION' bilicube = processor.Bilinear2DInterpolator(Lonu, Latu, Tm_1m, cube=True) # Get the values from the dictionnary k1 = self.dict['k1'] k2 = self.dict['k2'] k3 = self.dict['k3'] mmO = self.dict['mmO'] mmH = self.dict['mmH'] mma = self.dict['mma'] w = (2 * mmH + mmO) / mma Rv = self.dict['Rv'] Rho = self.dict['Rho'] # Loop on the lines if self.verb: toto = utils.ProgressBar(maxValue=self.ny) print 'PROGRESS: MAPPING THE DELAY' for m in xrange(self.ny): if self.verb: toto.update(m, every=5) # Transfert (range,azimuth) to (lon,lat) yarr = (m + 1) * np.ones((xarr.shape)) [loni, lati] = utils.rdr2glob(self.nx, self.ny, self.lat, self.lon, xarr, yarr) # Make the bilinear interpolation D = dem[m, :] - minH val = bilicube(loni, lati, D) val = 0.000001 * Rho * Rv * (k3 / val + k2 - w * k1) * np.pi * 4.0 / (cinc * wvl) if outFile: resy = val.astype(np.float32) resy.tofile(fout) else: dataobj[m, :] = val if self.verb: toto.close() # Close if outfile if outFile: fout.close()
def getlindelay(self, dataobj, inc=0.0, wvl=4 * np.pi): '''Write delay to a matrix / HDF5 object or a file directly. LinearNDInterpolator is used, and is not really stable. Args: * dataobj (str or HDF5 or np.array): Final output. If str, output is written to file. Kwargs: * inc (np.float): Incidence angle in degrees. Default is vertical. * wvl (np.float): Wavelength in meters. Default output results in delay in meters. .. note:: If dataobj is string, output is written to the file. If np.array or HDF5 object, it should be of size (ny,nx).''' self.rdrfnc = processor.make3dintp(self.Delfn, self.lonlist, self.latlist, self.hgt, self.hgtscale) minAltp = self.dict['minAltP'] xarr = np.arange(1., self.nx + 1.) fin = open(self.hfile, 'rb') outFile = isinstance(dataobj, str) if outFile: fout = open(dataobj, 'wb') else: assert ((dataobj.shape[0] == self.ny) & (dataobj.shape[1] == self.nx)), 'PyAPS: Not a valid data object.' cinc = np.cos(inc * np.pi / 180.0) toto = utils.ProgressBar(maxValue=self.ny) for m in range(self.ny): if self.fmt in ('HGT'): dem = np.fromfile(file=fin, dtype=self.demtype, count=self.nx) elif self.fmt in ('RMG'): dem = np.fromfile(file=fin, dtype=self.demtype, count=2 * self.nx) dem = dem[self.nx:] dem[dem < minAltp] = minAltp demy = dem.astype(np.float64) llh = np.zeros((self.nx, 3)) yarr = (m + 1) * np.ones((xarr.shape)) [xin, yin] = utils.rdr2glob(self.nx, self.ny, self.lat, self.lon, xarr, yarr) llh[:, 0] = xin llh[:, 1] = yin llh[:, 2] = demy / self.hgtscale res = self.rdrfnc(llh) res = res * np.pi * 4.0 / (cinc * wvl) res = res.flatten() if outFile: resy = res.astype(np.float32) resy.tofile(fout) else: dataobj[m, :] = res toto.update(m, every=5) toto.close() if outFile: fout.close() fin.close()