Ejemplo n.º 1
0
def get_kk(fhead):
    mete = readxml('%smetadata.xml'%fhead)
    vZa = np.array([i+ np.zeros((23,23)) for i in mete['mVz']])
    vAa = np.array([i+ np.zeros((23,23)) for i in mete['mVa']])

    ks = []
    for i in [2,3,4,8,11,12]:
        if i ==8:
            i -= 1
            kk = kernels.Kernels(vZa[i] ,mete['SAG_Z'],mete['SAG_A']-vAa[i],\
                                 RossHS=False,MODISSPARSE=True,\
                                 RecipFlag=True,normalise=1,\
                                 doIntegrals=False,LiType='Dense',RossType='Thick')
            ks.append(kk)
            kk = kernels.Kernels(vZa[i+1] ,mete['SAG_Z'],mete['SAG_A']-vAa[i+1],\
                                 RossHS=False,MODISSPARSE=True,\
                                 RecipFlag=True,normalise=1,\
                                 doIntegrals=False,LiType='Dense',RossType='Thick')
            ks.append(kk)

        else:
            i -= 1
            kk = kernels.Kernels(vZa[i] ,mete['SAG_Z'],mete['SAG_A']-vAa[i],\
                                 RossHS=False,MODISSPARSE=True,\
                                 RecipFlag=True,normalise=1,\
                                 doIntegrals=False,LiType='Dense',RossType='Thick')
            ks.append(kk)
    return ks
Ejemplo n.º 2
0
def get_kk(fhead):
    mete = readxml('%smetadata.xml' % fhead)
    vZa = np.nanmean(mete['VIAG_Z'].reshape(13,
                                            len(mete['VIAG_Z']) / 13, 23, 23),
                     axis=1)
    vAa = np.nanmean(mete['VIAG_A'].reshape(13,
                                            len(mete['VIAG_Z']) / 13, 23, 23),
                     axis=1)

    ks = []
    for i in [2, 3, 4, 8, 11, 12]:
        if i == 8:
            i -= 1
            kk = kernels.Kernels(vZa[i] ,mete['SAG_Z'],mete['SAG_A']-vAa[i],\
                                 RossHS=False,MODISSPARSE=True,\
                                 RecipFlag=True,normalise=1,\
                                 doIntegrals=False,LiType='Dense',RossType='Thick')
            ks.append(kk)
            kk = kernels.Kernels(vZa[i+1] ,mete['SAG_Z'],mete['SAG_A']-vAa[i+1],\
                                 RossHS=False,MODISSPARSE=True,\
                                 RecipFlag=True,normalise=1,\
                                 doIntegrals=False,LiType='Dense',RossType='Thick')
            ks.append(kk)

        else:
            i -= 1
            kk = kernels.Kernels(vZa[i] ,mete['SAG_Z'],mete['SAG_A']-vAa[i],\
                                 RossHS=False,MODISSPARSE=True,\
                                 RecipFlag=True,normalise=1,\
                                 doIntegrals=False,LiType='Dense',RossType='Thick')
            ks.append(kk)
    return ks
Ejemplo n.º 3
0
    def create_observation_operator(self, metadata, x_forecast, band):
        """The linear kernel models..."""

        K = kernels.Kernels(metadata.vza[metadata.mask],
                            metadata.sza[metadata.mask],
                            metadata.raa[metadata.mask],
                            LiType="Sparse",
                            doIntegrals=False,
                            normalise=1,
                            RecipFlag=True,
                            RossHS=False,
                            MODISSPARSE=True,
                            RossType="Thick")
        good_obs = metadata.mask.sum()  # size of H_matrix
        all_obs = metadata.mask.ravel().shape[0]  # All obs
        zz = np.zeros(all_obs)
        ross = zz * 0.
        li = zz * 0.
        ross[metadata.mask.flatten()] = K.Ross
        li[metadata.mask.flatten()] = K.Li
        data = np.c_[np.r_[np.ones(all_obs), zz, zz], np.r_[zz, ross, zz],
                     np.r_[zz, zz, li]].T
        offsets = [0, all_obs, 2 * all_obs]
        H_matrix = sp.dia_matrix((data, offsets),
                                 shape=(all_obs, self.n_params * all_obs),
                                 dtype=np.float32)
        # The following arrangement is all isotropics, all volumetrics and then
        # all geometrics. For the non-linear model, it might be better to have
        # all data per grid cell, and not all clobbered together.
        return H_matrix.tocsr()
Ejemplo n.º 4
0
def get_kk(angles):
    vza ,sza,raa = angles
    kk = kernels.Kernels(vza,sza,raa,\
                         RossHS=False,MODISSPARSE=True,\
                         RecipFlag=True,normalise=1,\
                         doIntegrals=False,LiType='Sparse',RossType='Thick')
    return kk
Ejemplo n.º 5
0
def get_kk(fhead):
    mete = readxml('%smetadata.xml' % fhead)
    vZa = np.array([i + np.zeros((23, 23)) for i in mete['mVz']])
    vAa = np.array([i + np.zeros((23, 23)) for i in mete['mVa']])
    sza = mete['mSz'][0]
    vza = mete['mVz'][3]
    rel_a = (mete['mSa'] - mete['mVa'])[3]
    kk = kernels.Kernels(vza ,sza,rel_a,\
                         RossHS=False,MODISSPARSE=True,\
                         RecipFlag=True,normalise=1,\
                         doIntegrals=False,LiType='Dense',RossType='Thick')
    return kk
Ejemplo n.º 6
0
    def predict_boa_refl_MCD43(self, the_date, the_band):
        # find modis matching dataset
        print "FIX band_equivalences!!!!!!!!!!"
        band_equivalences = [[[1, 1.]], [[2, 1.]], [[3, 1.]], [[4, 1.]],
                             [[5, 1.]], [[6, 1.]], [[7, 1.]]]
        sza, saa, vza, vaa = self.get_l1c_angles(the_date)
        raa = vaa - saa
        K = kernels.Kernels(vza,
                            sza,
                            raa,
                            LiType='Sparse',
                            doIntegrals=False,
                            normalise=1,
                            RecipFlag=True,
                            RossHS=False,
                            MODISSPARSE=True,
                            RossType='Thick')
        kk = np.array([1., K.Ross[0], K.Li[0]])

        k = min(self.modis_filelist["MCD43A1"].keys(),
                key=lambda x: abs(x - the_date))
        pred_boa_refl = np.zeros((2400, 2400))
        for band, w in band_equivalences[the_band]:

            g = gdal.Open(
                'HDF4_EOS:EOS_GRID:"%s":MOD_Grid_BRDF:BRDF_Albedo_Parameters_Band%d'
                % (self.modis_filelist["MCD43A1"][k], band))
            kernel_weights = g.ReadAsArray() / 10000.
            g = gdal.Open(
                'HDF4_EOS:EOS_GRID:"%s":MOD_Grid_BRDF:BRDF_Albedo_Band_Quality_Band%d'
                % (self.modis_filelist["MCD43A2"][k], band))
            qa = g.ReadAsArray()
            print "Only best quality MCD43 samples selected"
            kernel_weights = np.where(qa == 0, kernel_weights, np.nan)

            pred_boa_refl += w * np.sum(kernel_weights * kk[:, None, None],
                                        axis=0)
        return pred_boa_refl
Ejemplo n.º 7
0
        return a


co_bands = readfile([2, 3, 4, 8, 13, 11, 12],
                    'data/50SMG20164100',
                    bounds=None)

vZa = np.nanmean(co_bands['VIAG_Z'].reshape(13, 12, 23, 23), axis=1)
vAa = np.nanmean(co_bands['VIAG_A'].reshape(13, 12, 23, 23), axis=1)

ks = []
for i in [2, 3, 4, 8, 11, 12]:
    if i == 8:
        i -= 1
        kk = kernels.Kernels(vZa[i] , co_bands['SAG_Z'],co_bands['SAG_A']-vAa[i],\
                             RossHS=False,MODISSPARSE=True,\
                             RecipFlag=True,normalise=1,\
                             doIntegrals=False,LiType='Dense',RossType='Thick')
        ks.append(kk)
        kk = kernels.Kernels(vZa[i+1] , co_bands['SAG_Z'],co_bands['SAG_A']-vAa[i+1],\
                                RossHS=False,MODISSPARSE=True,\
                                RecipFlag=True,normalise=1,\
                                doIntegrals=False,LiType='Dense',RossType='Thick')
        ks.append(kk)

    else:
        i -= 1
        kk = kernels.Kernels(vZa[i] , co_bands['SAG_Z'],co_bands['SAG_A']-vAa[i],\
                             RossHS=False,MODISSPARSE=True,\
                             RecipFlag=True,normalise=1,\
                             doIntegrals=False,LiType='Dense',RossType='Thick')
        ks.append(kk)