Exemplo 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)
Exemplo n.º 2
0
    def test_create(self):
        ens_size = 10
        ens_mask = BoolVector(default_value=True, initial_size=ens_size)
        data = MeasData(ens_mask)
        self.assertEqual(len(data), 0)
        self.assertTrue(isinstance(data, MeasData))

        block1 = data.addBlock("OBS1", 10, 5)
        block2 = data.addBlock("OBS2", 27, 10)

        with self.assertRaises(TypeError):
            data[1.782]

        with self.assertRaises(KeyError):
            data["NO-this-does-not-exist"]

        with self.assertRaises(IndexError):
            data[2]

        last0 = data[-1]
        last1 = data[1]
        self.assertEqual(last0, last1)

        self.assertTrue("OBS1-10" in data)
        self.assertTrue("OBS2-27" in data)
        self.assertEqual(len(data), 2)

        self.assertTrue(isinstance(block1, MeasBlock))
        self.assertTrue(isinstance(block2, MeasBlock))

        self.assertEqual(block1.getObsSize(), 5)
        self.assertEqual(block2.getObsSize(), 10)

        l = []
        for b in data:
            l.append(b)

        self.assertEqual(len(l), 2)
        self.assertEqual(l[0], block1)
        self.assertEqual(l[1], block2)

        with self.assertRaises(ValueError):
            S = data.createS()

        for iens in range(ens_size):
            block1[0, iens] = 5
            block2[0, iens] = 10
            block2[1, iens] = 15

        self.assertEqual(3, data.activeObsSize())
        S = data.createS()

        self.assertEqual(S.dims(), (3, ens_size))

        for iens in range(ens_size):
            self.assertEqual(S[0, iens], 5)
            self.assertEqual(S[1, iens], 10)
            self.assertEqual(S[2, iens], 15)

        pfx = 'MeasData(len = '
        self.assertEqual(pfx, repr(data)[:len(pfx)])