Example #1
0
    def __init__(self,corefile=os.path.join(about_me()['cawadir'],'luts','cloud_core_meris.nc4'),used_ab=None):
        self.about_me=about_me()
        with Dataset(corefile,'r') as ncds:
            #get the full lut
            self.lut=np.array(ncds.variables['lut'][:],order='F')
            self.jlut=np.array(ncds.variables['jlut'][:],order='F')
            self.axes=tuple([np.array(ncds.variables[a][:]) for a in ncds.variables['lut'].dimensions[:-1]])
            self.jaxes=tuple([np.array(ncds.variables[a][:]) for a in ncds.variables['jlut'].dimensions[:-1]])
            self.ny_nx=np.array(ncds.variables['jaco'][:])
            self.wb=ncds.getncattr('win_bnd').split(',')
            self.ab=ncds.getncattr('abs_bnd').split(',')
            self.cha={bb:
                          {kk:ncds.groups['cha'].groups[bb].getncattr(kk)
                            for kk in ('bwvl','cwvl')} 
                      for bb in self.wb+self.ab}

            if used_ab is None:
                self.ab_idx=None
            else:
                self.ab=[used_ab,]
                self.ab_idx=pos_in_list(ncds.getncattr('abs_bnd').split(','),used_ab)[0]
                

        #generic forward 
        self._forward=lut2func.lut2func(self.lut,self.axes)
        #generic jacobian 
        self._jacobian=lut2jacobian_lut.jlut2func({'lut':self.jlut
                                                   ,'axes':self.jaxes
                                                   ,'ny':self.ny_nx[0]
                                                   ,'nx':self.ny_nx[1]})

        #global predefinition of input for speed reasons
        self.xaa=np.zeros(2)
        self.par=np.zeros(5)
        self.mes=np.zeros(len(self.wb)+len(self.ab))
        
        #local predefine inp for speed
        inp=np.zeros(7)
       
        def forward(woo,par):
            '''
            Input:
                woo: state (ctp,cot)
                par: parameter (alb, sza, vza, azd, dwvl)                    
                aot is aot at winband [0]
                wvc is sqrt of wvc
                
            Output:
                normalized radiances at winbands and  absbands
            '''    
            inp[:2],inp[2:]=woo,par
            if self.ab_idx is None:
                return self._forward(inp)
            else:
                return self._forward(inp)[((0,1+self.ab_idx),)]
                
        self.forward =forward
        def jforward(woo,geo):
            '''
            as forward, but returns jacobian
            output must be limited to the first three elements (the state and not the geometry)
            '''
            inp[:2],inp[2:]=woo,geo            
            if self.ab_idx is None:
                return self._jacobian(inp)[:,:2]
            else:
                return self._jacobian(inp)[(0,1+self.ab_idx),:2]
        
        self.jforward=jforward
 
        #min_state
        a=np.array([self.axes[i].min() for i in range(2)])
        #max_state
        b=np.array([self.axes[i].max() for i in range(2)])       
        self.inverter=oe.my_inverter(self.forward,a,b,jaco=self.jforward)
        
        #finaly preset SE
        sew=[0.0001 for i in self.wb]
        sea=[0.0001  for i in self.ab]
        self.SE=np.diag(sew+sea)
Example #2
0
    def __init__(self, ocean_lut=os.path.join('.', 'luts', 'ocean', 'ocean_core_meris.nc4')):
        # sys.stderr.write('entering CawaTcwvOceanCore... \n')
        libdir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'libs')
        sys.path.append(libdir)

        with Dataset(ocean_lut, 'r') as ncds:
            # get the full lut
            self.lut = np.array(ncds.variables['lut'][:], order='F')
            self.jlut = np.array(ncds.variables['jlut'][:], order='F')
            self.axes = tuple([np.array(ncds.variables[a][:]) for a in ncds.variables['lut'].dimensions[:-1]])
            self.jaxes = tuple([np.array(ncds.variables[a][:]) for a in ncds.variables['jlut'].dimensions[:-1]])
            self.ny_nx = np.array(ncds.variables['jaco'][:])
            self.wb = ncds.getncattr('win_bnd').split(',')
            self.ab = ncds.getncattr('abs_bnd').split(',')

        # generic forward
        self._forward = lut2func.lut2func(self.lut, self.axes)
        # generic jacobian
        self._jacobian = lut2jacobian_lut.jlut2func({'lut': self.jlut,
                                                     'axes': self.jaxes,
                                                     'ny': self.ny_nx[0],
                                                     'nx': self.ny_nx[1]})

        # global predefinition of input for speed reasons
        self.xaa = np.zeros(3)
        self.par = np.zeros(3)
        self.mes = np.zeros(len(self.wb) + len(self.ab))

        # local predefine inp for speed
        inp = np.zeros(6)

        def forward(woo, geo):
            """
            Input:
                woo: state (wvc aot wsp)
                geo: azi vie suz                    
                aot is aot at winband [0]
                wvc is sqrt of wvc
                
            Output:
                normalized radiances at winbands
                -np.log(effective_transmission)/sqrt(amf) at absbands
                
                effective_transmission= L_toa/L_0
                with L_0 is normalized radiance without water vapor
                                
            """
            inp[:3], inp[3:] = woo, geo
            return self._forward(inp)

        self.forward = forward

        def jforward(woo, geo):
            """
            as forward, but returns jacobian
            output must be limited to the first three elements (the state and not the geometry)
            """
            inp[:3], inp[3:] = woo, geo
            return self._jacobian(inp)[:, :3]

        self.jforward = jforward

        # min_state
        a = np.array([self.axes[i].min() for i in range(3)])
        # max_state
        b = np.array([self.axes[i].max() for i in range(3)])
        self.inverter = oe.my_inverter(self.forward, a, b, jaco=self.jforward)

        # finaly preset SE
        sew = [0.0001 for i in self.wb]
        sea = [0.001 for i in self.ab]
        self.SE = np.diag(sew + sea)
Example #3
0
    def __init__(self,
                 corefile=os.path.join(about_me()['cawadir'], 'luts',
                                       'cloud_core_meris.nc4'),
                 used_ab=None):
        self.about_me = about_me()
        with Dataset(corefile, 'r') as ncds:
            #get the full lut
            self.lut = np.array(ncds.variables['lut'][:], order='F')
            self.jlut = np.array(ncds.variables['jlut'][:], order='F')
            self.axes = tuple([
                np.array(ncds.variables[a][:])
                for a in ncds.variables['lut'].dimensions[:-1]
            ])
            self.jaxes = tuple([
                np.array(ncds.variables[a][:])
                for a in ncds.variables['jlut'].dimensions[:-1]
            ])
            self.ny_nx = np.array(ncds.variables['jaco'][:])
            self.wb = ncds.getncattr('win_bnd').split(',')
            self.ab = ncds.getncattr('abs_bnd').split(',')
            self.cha = {
                bb: {
                    kk: ncds.groups['cha'].groups[bb].getncattr(kk)
                    for kk in ('bwvl', 'cwvl')
                }
                for bb in self.wb + self.ab
            }

            if used_ab is None:
                self.ab_idx = None
            else:
                self.ab = [
                    used_ab,
                ]
                self.ab_idx = pos_in_list(
                    ncds.getncattr('abs_bnd').split(','), used_ab)[0]

        #generic forward
        self._forward = lut2func.lut2func(self.lut, self.axes)
        #generic jacobian
        self._jacobian = lut2jacobian_lut.jlut2func({
            'lut': self.jlut,
            'axes': self.jaxes,
            'ny': self.ny_nx[0],
            'nx': self.ny_nx[1]
        })

        #global predefinition of input for speed reasons
        self.xaa = np.zeros(2)
        self.par = np.zeros(5)
        self.mes = np.zeros(len(self.wb) + len(self.ab))

        #local predefine inp for speed
        inp = np.zeros(7)

        def forward(woo, par):
            '''
            Input:
                woo: state (ctp,cot)
                par: parameter (alb, sza, vza, azd, dwvl)                    
                aot is aot at winband [0]
                wvc is sqrt of wvc
                
            Output:
                normalized radiances at winbands and  absbands
            '''
            inp[:2], inp[2:] = woo, par
            if self.ab_idx is None:
                return self._forward(inp)
            else:
                return self._forward(inp)[((0, 1 + self.ab_idx), )]

        self.forward = forward

        def jforward(woo, geo):
            '''
            as forward, but returns jacobian
            output must be limited to the first three elements (the state and not the geometry)
            '''
            inp[:2], inp[2:] = woo, geo
            if self.ab_idx is None:
                return self._jacobian(inp)[:, :2]
            else:
                return self._jacobian(inp)[(0, 1 + self.ab_idx), :2]

        self.jforward = jforward

        #min_state
        a = np.array([self.axes[i].min() for i in range(2)])
        #max_state
        b = np.array([self.axes[i].max() for i in range(2)])
        self.inverter = oe.my_inverter(self.forward, a, b, jaco=self.jforward)

        #finaly preset SE
        sew = [0.0001 for i in self.wb]
        sea = [0.0001 for i in self.ab]
        self.SE = np.diag(sew + sea)
Example #4
0
    def __init__(self,
                 ocean_lut=os.path.join('.', 'luts', 'ocean',
                                        'ocean_core_meris.nc4')):
        # sys.stderr.write('entering CawaTcwvOceanCore... \n')
        libdir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                              'libs')
        sys.path.append(libdir)

        with Dataset(ocean_lut, 'r') as ncds:
            # get the full lut
            self.lut = np.array(ncds.variables['lut'][:], order='F')
            self.jlut = np.array(ncds.variables['jlut'][:], order='F')
            self.axes = tuple([
                np.array(ncds.variables[a][:])
                for a in ncds.variables['lut'].dimensions[:-1]
            ])
            self.jaxes = tuple([
                np.array(ncds.variables[a][:])
                for a in ncds.variables['jlut'].dimensions[:-1]
            ])
            self.ny_nx = np.array(ncds.variables['jaco'][:])
            self.wb = ncds.getncattr('win_bnd').split(',')
            self.ab = ncds.getncattr('abs_bnd').split(',')

        # generic forward
        self._forward = lut2func.lut2func(self.lut, self.axes)
        # generic jacobian
        self._jacobian = lut2jacobian_lut.jlut2func({
            'lut': self.jlut,
            'axes': self.jaxes,
            'ny': self.ny_nx[0],
            'nx': self.ny_nx[1]
        })

        # global predefinition of input for speed reasons
        self.xaa = np.zeros(3)
        self.par = np.zeros(3)
        self.mes = np.zeros(len(self.wb) + len(self.ab))

        # local predefine inp for speed
        inp = np.zeros(6)

        def forward(woo, geo):
            """
            Input:
                woo: state (wvc aot wsp)
                geo: azi vie suz                    
                aot is aot at winband [0]
                wvc is sqrt of wvc
                
            Output:
                normalized radiances at winbands
                -np.log(effective_transmission)/sqrt(amf) at absbands
                
                effective_transmission= L_toa/L_0
                with L_0 is normalized radiance without water vapor
                                
            """
            inp[:3], inp[3:] = woo, geo
            return self._forward(inp)

        self.forward = forward

        def jforward(woo, geo):
            """
            as forward, but returns jacobian
            output must be limited to the first three elements (the state and not the geometry)
            """
            inp[:3], inp[3:] = woo, geo
            return self._jacobian(inp)[:, :3]

        self.jforward = jforward

        # min_state
        a = np.array([self.axes[i].min() for i in range(3)])
        # max_state
        b = np.array([self.axes[i].max() for i in range(3)])
        self.inverter = oe.my_inverter(self.forward, a, b, jaco=self.jforward)

        # finaly preset SE
        sew = [0.0001 for i in self.wb]
        sea = [0.001 for i in self.ab]
        self.SE = np.diag(sew + sea)