コード例 #1
0
    def getlingeodelay(self,
                       dataobj,
                       lat=None,
                       lon=None,
                       inc=None,
                       wvl=np.pi * 4.):
        '''Write delay to a matrix / HDF5 object or a file directly. This is used when the latitude and longitude values are available for each radar pixel. Incidence angle can be a constant or a file name.
		LinearNDinterpolator is used and is not that stable...

		Args:
			* dataobj  (str or HDF5 or np.array): Final output. If str, output is written to file.
		Kwargs:
			* lat  (str)            : Path to the latitude file (np.float32).
			* lon  (str)            : Path to the longitude file (np.float32).
			* inc  (str or np.float): Path to incidence angle file in degrees (str) or a constant float.
			* 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.fnc = processor.make3dintp(self.Delfn, self.lonlist, self.latlist,
                                        self.hgt, self.hgtscale)

        minAltp = self.dict['minAltP']

        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.'

        assert lat is not None, 'PyAPS: Need a valid latitude file.'
        assert lon is not None, 'PyAPS: Need a valid longitude file.'

        if isinstance(inc, float) or isinstance(inc, np.float64) or isinstance(
                inc, np.float32):
            cinc = np.cos(inc * np.pi / 180.)
            incFileFlag = False
        else:
            assert inc is not None, 'PyAPS: Need a valid incidence angle file or constant.'
            incFileFlag = True
            incin = open(inc, 'rb')

        latin = open(lat, 'rb')
        lonin = open(lon, 'rb')
        demin = open(self.hfile, 'rb')

        for m in range(self.ny):
            if self.fmt in ('HGT'):
                dem = np.fromfile(file=demin,
                                  dtype=self.demtype,
                                  count=self.nx)
            elif self.fmt in ('RMG'):
                dem = np.fromfile(file=demin,
                                  dtype=self.demtype,
                                  count=2 * self.nx)
                dem = dem[self.nx:]

            laty = np.fromfile(file=latin, dtype=np.float32, count=self.nx)
            lonx = np.fromfile(file=lonin, dtype=np.float32, count=self.nx)

            lonx[lonx < 0] += 360.

            if incFileFlag:
                incz = np.fromfile(file=incin, dtype=np.float32, count=self.nx)
                cinc = np.cos(incz * np.pi / 180.)

            dem[dem < minAltp] = minAltp
            demy = dem.astype(np.float64)
            llh = np.zeros((self.nx, 3))
            llh[:, 0] = lonx
            llh[:, 1] = laty
            llh[:, 2] = demy / self.hgtscale
            res = self.fnc(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

        latin.close()
        lonin.close()
        demin.close()
        if incFileFlag:
            incin.close()
コード例 #2
0
    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()