Ejemplo n.º 1
0
def generate_interpol_to_index(xx):
    return lambda x, xx=np.array(xx, order='F'
                                 ): wadamo_interpolators.linint2index(x, xx)
Ejemplo n.º 2
0
def generate_interpol_to_index(xx):
    return lambda x, xx=np.array(xx,order='F'): wadamo_interpolators.linint2index(x,xx)
Ejemplo n.º 3
0
    def _init_prs_tmp(self, data, poly=True, abscor=True):
        '''
        1. find
            a) sourounding pressure level (prs)
            b) sourounding temperatures (profiles)(prf)

        2. generates the interpolating transmisson functions
        3. index the derivative of th transmission function
        4. generates the interpolating first guess functions
        '''

        # 0.)calc amf
        data['amf'] = 1. / np.cos(np.deg2rad(data['suz'])) + 1. / np.cos(
            np.deg2rad(data['vie']))

        #prs_idx= np.interp(np.clip(data['prs'],self.min_prs,self.max_prs),self.prs,np.arange(self.nle))
        prs_idx = wadamo_interpolators.linint2index(data['prs'], self.prs)

        # 1a)  pressure weights (need 2):
        l_prs_idx = int(np.ceil(prs_idx))
        u_prs_idx = int(l_prs_idx - 1)  #( one level above)
        l_prs_wgt = prs_idx - u_prs_idx
        u_prs_wgt = 1. - l_prs_wgt

        # 1b)  find sourounding temps profile
        lprf, ltmp = None, 0
        uprf, utmp = None, 1000
        for prf in self.prf:
            dum =  self.lut['ckd'][self.ab[0]][prf]['tmp'][l_prs_idx]*l_prs_wgt \
                  +self.lut['ckd'][self.ab[0]][prf]['tmp'][u_prs_idx]*u_prs_wgt
            if dum < data['tmp'] and dum > ltmp:
                ltmp = dum
                lprf = prf
            if dum > data['tmp'] and dum < utmp:
                utmp = dum
                uprf = prf

        if uprf is not None and lprf is not None:
            l_tmp_wgt = (utmp - data['tmp']) / (utmp - ltmp)
            u_tmp_wgt = 1. - l_tmp_wgt
        elif uprf is not None and lprf is None:
            u_tmp_wgt = 1.
            l_tmp_wgt = 0.
            lprf = self.prf[0]
        elif uprf is None and lprf is not None:
            u_tmp_wgt = 0.
            l_tmp_wgt = 1.
            uprf = self.prf[0]
        else:
            print 'strange temperature:', data['tmp']
            #ToDo raise something and exit !=0

        #2.  interpolating transoperator
        def generate_wv2tr(ch):
            #print 'cc',self.lut['cor'][ch]
            if poly is True:
                single_tro = self.single_tro_poly
            else:
                single_tro = self.single_tro_kdis
            if abscor is True:
                ###########TODO: REMOVE, just TESTING
                #self.lut['cor'][ch]=[1.,2.]
                #self.lut['cor'][ch]=[0.,1.]
                ###########TODO: REMOVE, just TESTING
                a, b = self.lut['cor'][ch]
                #print a,b
            else:
                a, b = 0., 1.
            ab = np.array((a, b), order='F')

            def wv2tr(x):
                out = x * 0.
                for iprf, wprf in [[uprf, u_tmp_wgt], [lprf, l_tmp_wgt]]:
                    for iprs, wprs in [[u_prs_idx, u_prs_wgt],
                                       [l_prs_idx, l_prs_wgt]]:
                        out += single_tro[ch][iprf][iprs](
                            x, data['amf']) * wprf * wprs
                return wadamo_poly.explog(out, ab)

            return wv2tr

        self.tro = {ch: generate_wv2tr(ch) for ch in self.ab + self.wb}

        #3. indexing transmission derivative  d_trans__d_tcwv
        if l_tmp_wgt > u_tmp_wgt:
            mprf = lprf
        else:
            mprf = uprf
        if l_prs_wgt > u_prs_wgt:
            m_prs_idx = l_prs_idx
        else:
            m_prs_idx = u_prs_idx

        def generate_d_tr__d_wv(ch):
            def d_tr__d_wv(x):
                #dum  = self.single_tro_poly[ch][mprf][m_prs_idx](np.array((x*0.99,x*1.01)),data['amf'])
                dum0 = self.single_tro_poly[ch][mprf][m_prs_idx](np.array(
                    x * 0.99), data['amf'])
                dum1 = self.single_tro_poly[ch][mprf][m_prs_idx](np.array(
                    x * 1.01), data['amf'])
                return (dum1 - dum0) / (0.02 * x)

            return d_tr__d_wv

        self.d_tro = {ch: generate_d_tr__d_wv(ch) for ch in self.ab}  #+self.wb

        #4.  interpolating first guess-orator
        def generate_tr2wv(ch):
            def tr2wv(x, amf=data['amf']):
                xx = np.array(np.log(x), order='F')
                out = 0.
                for iprf, wprf in [[uprf, u_tmp_wgt], [lprf, l_tmp_wgt]]:
                    for iprs, wprs in [[u_prs_idx, u_prs_wgt],
                                       [l_prs_idx, l_prs_wgt]]:
                        par = np.array(self.lut['ckd'][ch][iprf]
                                       ['trn2wvc_coeff'][iprs, :],
                                       order='F')
                        dum = wrap_trn2wvc_pol(xx, par)
                        #print 'dum',dum
                        out += dum * wprf * wprs
                return out / amf

            return tr2wv

        self.fgu = {ch: generate_tr2wv(ch) for ch in self.ab}
Ejemplo n.º 4
0
    def _init_prs_tmp(self, data, poly=True, abscor=True):
        '''
        1. find
            a) sourounding pressure level (prs)
            b) sourounding temperatures (profiles)(prf)

        2. generates the interpolating transmisson functions
        3. index the derivative of th transmission function
        4. generates the interpolating first guess functions
        '''

        # 0.)calc amf
        data['amf'] = 1. / np.cos(np.deg2rad(data['suz'])) + 1. / np.cos(
            np.deg2rad(data['vie']))

        #prs_idx= np.interp(np.clip(data['prs'],self.min_prs,self.max_prs),self.prs,np.arange(self.nle))
        prs_idx = wadamo_interpolators.linint2index(data['prs'], self.prs)

        # 1a)  pressure weights (need 2):
        l_prs_idx = int(np.ceil(prs_idx))
        u_prs_idx = int(l_prs_idx - 1)  #( one level above)
        l_prs_wgt = prs_idx - u_prs_idx
        u_prs_wgt = 1. - l_prs_wgt

        # 1b)  find sourounding temps profile
        lprf, ltmp = None, 0
        uprf, utmp = None, 1000
        for prf in self.prf:
            dum =  self.lut['ckd'][self.ab[0]][prf]['tmp'][l_prs_idx]*l_prs_wgt \
                  +self.lut['ckd'][self.ab[0]][prf]['tmp'][u_prs_idx]*u_prs_wgt
            if dum < data['tmp'] and dum > ltmp:
                ltmp = dum
                lprf = prf
            if dum > data['tmp'] and dum < utmp:
                utmp = dum
                uprf = prf

        if uprf is not None and lprf is not None:
            l_tmp_wgt = (utmp - data['tmp']) / (utmp - ltmp)
            u_tmp_wgt = 1. - l_tmp_wgt
        elif uprf is not None and lprf is None:
            u_tmp_wgt = 1.
            l_tmp_wgt = 0.
            lprf = self.prf[0]
        elif uprf is None and lprf is not None:
            u_tmp_wgt = 0.
            l_tmp_wgt = 1.
            uprf = self.prf[0]
        else:
            print 'strange temperature:', data['tmp']
            #ToDo raise something and exit !=0

        #2.  interpolating transoperator
        def generate_wv2tr(ch):
            #print 'cc',self.lut['cor'][ch]
            if poly is True:
                single_tro = self.single_tro_poly
            else:
                single_tro = self.single_tro_kdis
            if abscor is True:
                ###########TODO: REMOVE, just TESTING
                #self.lut['cor'][ch]=[1.,2.]
                #self.lut['cor'][ch]=[0.,1.]
                ###########TODO: REMOVE, just TESTING
                a, b = self.lut['cor'][ch]
                #print a,b
            else:
                a, b = 0., 1.
            ab = np.array((a, b), order='F')

            def wv2tr(x):
                out = x * 0.
                for iprf, wprf in [[uprf, u_tmp_wgt], [lprf, l_tmp_wgt]]:
                    for iprs, wprs in [[u_prs_idx, u_prs_wgt],
                                       [l_prs_idx, l_prs_wgt]]:
                        out += single_tro[ch][iprf][iprs](
                            x, data['amf']) * wprf * wprs
                return wadamo_poly.explog(out, ab)

            return wv2tr

        self.tro = {ch: generate_wv2tr(ch) for ch in self.ab + self.wb}

        #3. indexing transmission derivative  d_trans__d_tcwv
        if l_tmp_wgt > u_tmp_wgt:
            mprf = lprf
        else:
            mprf = uprf
        if l_prs_wgt > u_prs_wgt:
            m_prs_idx = l_prs_idx
        else:
            m_prs_idx = u_prs_idx

        def generate_d_tr__d_wv(ch):
            def d_tr__d_wv(x):
                #dum  = self.single_tro_poly[ch][mprf][m_prs_idx](np.array((x*0.99,x*1.01)),data['amf'])
                dum0 = self.single_tro_poly[ch][mprf][m_prs_idx](np.array(
                    x * 0.99), data['amf'])
                dum1 = self.single_tro_poly[ch][mprf][m_prs_idx](np.array(
                    x * 1.01), data['amf'])
                return (dum1 - dum0) / (0.02 * x)

            return d_tr__d_wv

        self.d_tro = {ch: generate_d_tr__d_wv(ch) for ch in self.ab}  #+self.wb

        #4.  interpolating first guess-orator
        def generate_tr2wv(ch):
            def tr2wv(x, amf=data['amf']):
                xx = np.array(np.log(x), order='F')
                out = 0.
                for iprf, wprf in [[uprf, u_tmp_wgt], [lprf, l_tmp_wgt]]:
                    for iprs, wprs in [[u_prs_idx, u_prs_wgt],
                                       [l_prs_idx, l_prs_wgt]]:
                        par = np.array(
                            self.lut['ckd'][ch][iprf]['trn2wvc_coeff']
                            [iprs, :],
                            order='F')
                        dum = wrap_trn2wvc_pol(xx, par)
                        #print 'dum',dum
                        out += dum * wprf * wprs
                return out / amf

            return tr2wv

        self.fgu = {ch: generate_tr2wv(ch) for ch in self.ab}