Ejemplo n.º 1
0
def init_matrices(ens, mask, obs, rng):
    state_size = 2
    report_step = 5
    meas_data = MeasData(mask)
    meas_block = meas_data.addBlock("OBS", report_step, len(obs))

    A = Matrix(state_size, mask.countEqual(True))
    active_iens = 0
    for iens, params in enumerate(ens):
        if mask[iens]:
            state = forward_model(params)
            meas_block[0, iens] = measure(state)

            A[0, active_iens] = params[0]
            A[1, active_iens] = params[1]

            active_iens += 1

    S = meas_data.createS()

    obs_data = ObsData()
    obs_block = obs_data.addBlock("OBS", 1)
    for iobs, obs_value in enumerate(obs):
        obs_block[iobs] = obs_value

    R = obs_data.createR()
    dObs = obs_data.createDObs()
    E = obs_data.createE(rng, meas_data.getActiveEnsSize())
    D = obs_data.createD(E, S)

    obs_data.scale(S, E=E, D=D, R=R, D_obs=dObs)
    return (A, S, E, D, R, dObs)
Ejemplo n.º 2
0
    def test_create(self):
        obs_data = ObsData()
        obs_size = 10
        block = obs_data.addBlock("OBS" , obs_size)
        self.assertTrue( isinstance( block , ObsBlock ))

        block[0] = (100,10)
        block[1] = (120,12)
        D = obs_data.createDObs()
        self.assertTrue( isinstance(D , Matrix ))
        self.assertEqual( D.dims() , (2,2))
        
        self.assertEqual( D[0,0] , 100 )
        self.assertEqual( D[1,0] , 120 )
        self.assertEqual( D[0,1] , 10 )
        self.assertEqual( D[1,1] , 12 )

        obs_data.scaleMatrix( D )
        self.assertEqual( D[0,0] , 10 )
        self.assertEqual( D[1,0] , 10 )
        self.assertEqual( D[0,1] , 1 )
        self.assertEqual( D[1,1] , 1 )
        
        R = obs_data.createR()
        self.assertEqual( (2,2) , R.dims() )

        with self.assertRaises(IndexError):
            obs_data[10]

        v,s = obs_data[0]
        self.assertEqual( v , 100 )
        self.assertEqual( s , 10 )


        v,s = obs_data[1]
        self.assertEqual( v , 120 )
        self.assertEqual( s , 12 )