def return_MatchUpTest(): """ Return a MatchUp dataset object for testing :return: :MatchUpTest: *eopy.matchup.matchupIO.MatchUp* Test match-up dataset """ #################################################################################################################### # 1. Define test sensor function #################################################################################################################### def test_reference_function(X, a, sensor_c, sensor_xt_i, sensor_at_i, sensor_t): return X[:, 0], None def test_sensor_function(X, a, sensor_c, sensor_xt_i, sensor_at_i, sensor_t): """ Arbitary sensor function :type a: numpy.ndarray :param a: calibration parameters :type X: list :param X: List of arrays of sensor observed parameters :return: :measurand: *numpy.ndarray* Computed sensor measurand """ # Extract observed parameters X1 = X[:, 0] X2 = X[:, 1] X3 = X[:, 2] M = len(X1) # Evaluate measurand parameter_derivatives = vstack((ones(M), X1 * X2 / X3, X1**2)).T parameter = [a[0], a[1], a[2]] measurand = dot(parameter_derivatives, parameter) # Evaluate derivatives # In the following order: # > d(measurand)/dX1 # > d(measurand)/dX2 # > d(measurand)/dX3 # > d(measurand)/da0 # > d(measurand)/da1 # > d(measurand)/da2 derivatives = column_stack( (parameter[1] * X1 / X2 + 2 * parameter[2] * X1, parameter[1] * X1 / X3, -parameter[1] * X2 * X1 / X3**2, parameter_derivatives)) return measurand, derivatives def test_adjustment_model(measurand): """ Arbitary sensor adjustment function to sample sensor 1 :type measurand: numpy.ndarray :param measurand: measurand data :return: :adjusted_measurand: *numpy.ndarray* Adjusted sensor measurand :adjusted_measurand_derivatives: *numpy.ndarray* Adjusted sensor measurand derivatives """ adjusted_measurand = 2 * measurand adjusted_measurand_derivatives = ones(len(adjusted_measurand)) return adjusted_measurand, adjusted_measurand_derivatives #################################################################################################################### # 2. Initialise test data #################################################################################################################### values = array([ 470.5, 720.56, 450.9, 295.6, 315.23, 70.5, 70.6, 70.3, 70.7, 70.5, 71.5, 71.6, 71.3, 71.7, 80.5, 80.6, 80.3, 80.7, 150.5, 151.1, 149.8, 150.2, 151.4, 140.5, 141.1, 139.8, 140.2, 160.5, 161.1, 169.8, 160.2, 30.2, 20.4, 28.2, 50.7, 45.6, 29.2, 37.4, 28.2, 50.7, 28.2, 32.4, 22.2, 53.7, ]) unc = [ Uncertainty("r", array([1.6, 1.5, 1.5, 1.3, 1.5])), Uncertainty("r", array([3.1, 3.2, 3.2, 3.1, 3.0])), Uncertainty("r", array([3.3, 3.4, 3.1, 3.2])), Uncertainty("r", array([2.1, 2.2, 2.2, 2.1])), Uncertainty("r", array([5.0, 4.7, 5.1, 5.2, 5.3])), Uncertainty("r", array([4.2, 4.3, 4.4, 4.3])), Uncertainty("r", array([4.0, 3.7, 4.4, 4.7])), Uncertainty("r", array([2.2, 1.7, 2.0, 4.3, 2.6])), Uncertainty("r", array([2.3, 1.2, 2.3, 4.4])), Uncertainty("r", array([3.2, 2.7, 3.0, 5.3])) ] ks = array([1.2, 1.7, 1.3, 1.4, 1.3, 3.2, 3.7, 3.3, 3.4]) unck = [ Uncertainty("r", array([0.25, 0.25, 0.25, 0.25, 0.25])), Uncertainty("r", array([0.2644, 0.2644, 0.2644, 0.2644])) ] idx = { "Nm": [5, 4], "cNm": [0, 5, 9], "Im": [[0, 1], [1, 2]], "sensors": [-1, 1, 2], "sensor_m": [1, 3, 3], "n_sensor": [0, 1, 1, 2, 1, 1, 2, 1, 1, 2], "n_mu": [1, 1, 2, 2, 1, 2, 2, 1, 2, 2], "n_cov": [1, 1, 1, 1, 2, 2, 2, 3, 3, 3], "N_var": [5, 5, 4, 4, 5, 4, 4, 5, 4, 4], "idx": [0, 5, 10, 14, 18, 23, 27, 31, 36, 40, 44], "parameter_sensor": [1, 1, 1, 2, 2, 2], "sensor_model_constant_sensor": [], "sensor_model_contant": None } a = array([1., 1.3, 0.002, 0.5, 1.1, 0.0005]) #################################################################################################################### # 2. Initialise MatchUp object #################################################################################################################### MatchUpTest = MatchUp() MatchUpTest.values = values MatchUpTest.unc = unc MatchUpTest.ks = ks MatchUpTest.unck = unck MatchUpTest.idx = idx MatchUpTest.a = a MatchUpTest.sensor_model = [ test_reference_function, test_sensor_function, test_sensor_function ] MatchUpTest.adjustment_model = [ test_adjustment_model, test_adjustment_model, test_adjustment_model ] return MatchUpTest
def run(self, MatchUpData, sf=1.0, n_sample_max=100000, show=False): """ Return instance of ``eopy.matchup.matchupIO.MatchUp`` for which the only data correlations arise from systematic effects :type MatchUpData: *eopy.matchup.matchupIO.MatchUp* :param MatchUpData: Input match-up data for sampling :type sf: int :param sf: Sampling factor :return: :MatchUpSample: *eopy.matchup.matchupIO.MatchUp* Sampled harmonisation data """ # initialise parameters mcxyz = MatchUpData.idx[ 'idx'] # cumulative total of variables data block mc = MatchUpData.idx['cNm'] # cumulative total of match-ups by series if mc[-1] * sf > n_sample_max: sf = float(n_sample_max) / float(mc[-1]) print "Minimum Sampling Factor:", sf ################################################################################################################ # 1. Determine Match Ups to Include in Sample ################################################################################################################ # Choose a sample of match ups such that data is left with independent errors. # # N.B. - This is not possible for a fully systematic effect, but data with error correlation structures defined # by w matrices can be sampled to achieve this sampling_idxs = { } # initialise dictionary of sampling indices per match up series n_mus = set(MatchUpData.idx['n_mu']) # Find sampling indices by match-up series for n_mu in n_mus: # total number of match up in series (should be the same for each variable so take the first one) mu_total = [ MatchUpData.idx['N_var'][i] for i, n_mu_i in enumerate(MatchUpData.idx['n_mu']) if n_mu_i == n_mu ][0] mu_samples = int( mu_total * sf ) # required number sample match ups (determined by scaling factor) # Find w_matrices indices of any w matrices used to describe error correlation structure of match up data mu_block_idxs = [ i for i, n_mu_i in enumerate(MatchUpData.idx['n_mu']) if n_mu_i == n_mu ] w_indices_mu = [ MatchUpData.unc[mu_block_idx].w_i for mu_block_idx in mu_block_idxs if (MatchUpData.unc[mu_block_idx].typeID == 3) or ( MatchUpData.unc[mu_block_idx].typeID == 4) ] # a. If w matrices present select sample such that errors independent of each other for all w matrices ----- if w_indices_mu != []: idxs = get_sample_idxs(asarray(w_indices_mu, dtype=int32), mu_samples, [w for w in MatchUpData.w_matrices]) # If more match ups sampled than maximum randomly reduce to required amount if len(idxs) > mu_samples: idxs = sorted(sample(idxs, mu_samples)) # ---------------------------------------------------------------------------------------------------------- # b. If no w matrices present free to sample randomly ------------------------------------------------------ else: idxs = sorted(sample(arange(mu_total), mu_samples)) # ---------------------------------------------------------------------------------------------------------- sampling_idxs[ n_mu] = idxs # add match up sample indices to dictionary ################################################################################################################ # 2. Sample Data ################################################################################################################ # a. Initialise sampled harmonisation data product ------------------------------------------------------------- MatchUpSample = MatchUp() MatchUpSample.a = MatchUpData.a[:] MatchUpSample.sensor_model = MatchUpData.sensor_model MatchUpSample.sensor_model_constant = MatchUpData.sensor_model_constant MatchUpSample.adjustment_model = MatchUpData.adjustment_model # -------------------------------------------------------------------------------------------------------------- # b. Update idx attribute of MatchUpSample to describe structure of sampled data -------------------------------- # Start with copy of full dataset idx dictionary attribute # N.B. - deepcopy because of python memory issues with lists nested in dicts MatchUpSample.idx = deepcopy(MatchUpData.idx) # Formulate required replacement idx entries (several can remain the same as the full dataset) idxs = [0] total = 0 for i, n_mu in enumerate(MatchUpData.idx['n_mu']): block_samples = len(sampling_idxs[n_mu]) MatchUpSample.idx['N_var'][i] = block_samples total += block_samples idxs.append(int(total)) MatchUpSample.idx['idx'] = idxs cNm = [0] total = 0 for i, n_mu in enumerate(n_mus): n_mu_sample = len(sampling_idxs[n_mu]) MatchUpSample.idx['Nm'][i] = n_mu_sample total += n_mu_sample cNm.append(total) MatchUpSample.idx['cNm'] = cNm if show: print "Initial Size: ", MatchUpData.idx['Nm'] print "Sample Size: ", MatchUpSample.idx['Nm'] # -------------------------------------------------------------------------------------------------------------- # c. Sample variables and respective uncertainty --------------------------------------------------------------- # Initialise data arrays MatchUpSample.values = zeros(MatchUpSample.idx['idx'][-1]) MatchUpSample.unc = [0] * len(MatchUpSample.idx['n_cov']) # Sample data by data block for i, block_unc in enumerate(MatchUpData.unc): istart = mcxyz[i] # start of full dataset values data block iend = mcxyz[i + 1] # end of full dataset values data block istart_s = MatchUpSample.idx['idx'][ i] # start of sampled values data block iend_s = MatchUpSample.idx['idx'][ i + 1] # end of sampled values data block s_idx = sampling_idxs[MatchUpData.idx['n_mu'][ i]] # indices of match up to sample within values data block # i. Sample values MatchUpSample.values[istart_s:iend_s] = MatchUpData.values[ istart:iend][s_idx] # ii. Sample values uncertainty data if (block_unc.typeID == 3) or (block_unc.typeID == 4): # If block error correlation form was defined by a w matrix # - now simplified to random error correlation by sampling choice # Initialise uncertainty data array MatchUpSample.unc[i] = Uncertainty(1, zeros(len(s_idx))) # Retrieve required w and u matrix and hence determine new random uncertainties w = MatchUpData.w_matrices[block_unc.w_i] u = MatchUpData.u_matrices[block_unc.u_i] for j, s_i in enumerate(s_idx): col_start = w.indices[w.indptr[s_i]] col_end = w.indices[w.indptr[s_i + 1] - 1] + 1 MatchUpSample.unc[i].uR[j] = npsum( u[col_start:col_end]** 2)**0.5 / (col_end - col_start)**0.5 else: # If block error correlation form random or random and systematic simplify to random and sample MatchUpSample.unc[i] = Uncertainty( 1, deepcopy(block_unc.uR[s_idx])) # -------------------------------------------------------------------------------------------------------------- # d. sample k -------------------------------------------------------------------------------------------------- # Initialise k data arrays MatchUpSample.ks = zeros(MatchUpSample.idx['cNm'][-1]) MatchUpSample.unck = [0] * len(MatchUpSample.idx['Nm']) # Sample k and respective uncertainty data by match-up series for i, mu_unck in enumerate(MatchUpData.unck): istart = mc[i] # start of full dataset k data block iend = mc[i + 1] # end of full dataset k data block istart_s = MatchUpSample.idx['cNm'][ i] # start of sampled dataset k data block iend_s = MatchUpSample.idx['cNm'][ i + 1] # end of sampled dataset k data block s_idx = sampling_idxs[ i + 1] # indices of match up to sample within k data block # i. Sample data MatchUpSample.ks[istart_s:iend_s] = MatchUpData.ks[istart:iend][ s_idx] # ii. Sample uncertainties MatchUpSample.unck[i] = Uncertainty(1, deepcopy(mu_unck.uR[s_idx])) # -------------------------------------------------------------------------------------------------------------- # d. sample per match-up data ---------------------------------------------------------------------------------- # Initialise data arrays MatchUpSample.ks = zeros(MatchUpSample.idx['cNm'][-1]) MatchUpSample.unck = [0] * len(MatchUpSample.idx['Nm']) MatchUpSample.time1 = zeros(MatchUpSample.idx['cNm'][-1], dtype=datetime) MatchUpSample.time2 = zeros(MatchUpSample.idx['cNm'][-1], dtype=datetime) if MatchUpData.across_track_index1 is not None: MatchUpSample.across_track_index1 = zeros( MatchUpSample.idx['cNm'][-1]) if MatchUpData.across_track_index2 is not None: MatchUpSample.across_track_index2 = zeros( MatchUpSample.idx['cNm'][-1]) if MatchUpData.along_track_index1 is not None: MatchUpSample.along_track_index1 = zeros( MatchUpSample.idx['cNm'][-1]) if MatchUpData.along_track_index2 is not None: MatchUpSample.along_track_index2 = zeros( MatchUpSample.idx['cNm'][-1]) # Sample by match-up series for i, mu_unck in enumerate(MatchUpData.unck): istart = mc[i] # start of full dataset k data block iend = mc[i + 1] # end of full dataset k data block istart_s = MatchUpSample.idx['cNm'][ i] # start of sampled dataset k data block iend_s = MatchUpSample.idx['cNm'][ i + 1] # end of sampled dataset k data block s_idx = sampling_idxs[ i + 1] # indices of match up to sample within k data block # i. Sample k data MatchUpSample.ks[istart_s:iend_s] = MatchUpData.ks[istart:iend][ s_idx] # ii. Sample k uncertainties MatchUpSample.unck[i] = Uncertainty(1, deepcopy(mu_unck.uR[s_idx])) # iii. Sample indices if MatchUpData.across_track_index1 is not None: MatchUpSample.across_track_index1[ istart_s:iend_s] = MatchUpData.across_track_index1[ istart:iend][s_idx] if MatchUpData.across_track_index2 is not None: MatchUpSample.across_track_index2[ istart_s:iend_s] = MatchUpData.across_track_index2[ istart:iend][s_idx] if MatchUpData.along_track_index1 is not None: MatchUpSample.along_track_index1[ istart_s:iend_s] = MatchUpData.along_track_index1[ istart:iend][s_idx] if MatchUpData.along_track_index2 is not None: MatchUpSample.along_track_index2[ istart_s:iend_s] = MatchUpData.along_track_index2[ istart:iend][s_idx] # iv. Sample time MatchUpSample.time1[istart_s:iend_s] = MatchUpData.time1[ istart:iend][s_idx] MatchUpSample.time2[istart_s:iend_s] = MatchUpData.time2[ istart:iend][s_idx] # -------------------------------------------------------------------------------------------------------------- # d. sample additional variables ------------------------------------------------------------------------------- # todo - write sampling of additional variables # -------------------------------------------------------------------------------------------------------------- return MatchUpSample
def return_MatchUpTest_r__(): """ Return a MatchUp dataset object for testing :return: :MatchUpTest: *eopy.matchup.matchupIO.MatchUp* Test match-up dataset """ #################################################################################################################### # 1. Initialise test data #################################################################################################################### values = array([ 470.5, 720.56, 450.9, 295.6, 315.23, 70.5, 70.6, 70.3, 70.7, 70.5, 71.5, 71.6, 71.3, 71.7, 80.5, 80.6, 80.3, 80.7, 150.5, 151.1, 149.8, 150.2, 151.4, 140.5, 141.1, 139.8, 140.2, 160.5, 161.1, 169.8, 160.2, 30.2, 20.4, 28.2, 50.7, 45.6, 29.2, 37.4, 28.2, 50.7, 28.2, 32.4, 22.2, 53.7, ]) unc = [ Uncertainty(1, array([1.6, 1.5, 1.5, 1.3, 1.5])), Uncertainty(1, array([3.1, 3.2, 3.2, 3.1, 3.0])), Uncertainty(1, array([3.3, 3.4, 3.1, 3.2])), Uncertainty(1, array([2.1, 2.2, 2.2, 2.1])), Uncertainty(1, array([5.0, 4.7, 5.1, 5.2, 5.3])), Uncertainty(1, array([4.2, 4.3, 4.4, 4.3])), Uncertainty(1, array([4.0, 3.7, 4.4, 4.7])), Uncertainty(1, array([2.2, 1.7, 2.0, 4.3, 2.6])), Uncertainty(1, array([2.3, 1.2, 2.3, 4.4])), Uncertainty(1, array([3.2, 2.7, 3.0, 5.3])) ] ks = array([1.2, 1.7, 1.3, 1.4, 1.3, 3.2, 3.7, 3.3, 3.4]) unck = [ Uncertainty(1, array([0.25, 0.25, 0.25, 0.25, 0.25])), Uncertainty(1, array([0.2644, 0.2644, 0.2644, 0.2644])) ] idx = { "Nm": [5, 4], "cNm": [0, 5, 9], "Im": [[0, 1], [1, 2]], "sensors": [-1, 1, 2], "sensor_ms": [1, 3, 3], "n_sensor": [0, 1, 1, 2, 1, 1, 2, 1, 1, 2], "n_mu": [1, 1, 2, 2, 1, 2, 2, 1, 2, 2], "n_cov": [1, 1, 1, 1, 2, 2, 2, 3, 3, 3], "N_var": [5, 5, 4, 4, 5, 4, 4, 5, 4, 4], "idx": [0, 5, 10, 14, 18, 23, 27, 31, 36, 40, 44], "Ia": [1, 1, 1, 2, 2, 2] } a = array([1., 1.3, 0.002, 0.5, 1.1, 0.0005]) #################################################################################################################### # 3. Initialise MatchUp object #################################################################################################################### MatchUpTest = MatchUp() MatchUpTest.values = values MatchUpTest.unc = unc MatchUpTest.ks = ks MatchUpTest.unck = unck MatchUpTest.idx = idx MatchUpTest.a = a return MatchUpTest
def test_run_multi_rsw_sf1(self): """ Test for Sample2Ind.run() for test ``eopy.matchup.matchupIO.MatchUp`` object with data for multiple matchup series - scale factor 1 """ ################################################################################################################ # 1. Initialise Test Data Object ################################################################################################################ MatchUpTest = return_MatchUpTest_rsw() ################################################################################################################ # 2. Define expected values ################################################################################################################ values_expected = array([ 470.5, 450.9, 315.23, 70.5, 70.3, 70.5, 71.5, 71.3, 80.5, 80.3, 150.5, 149.8, 151.4, 140.5, 139.8, 160.5, 169.8, 20.2, 19.7, 20.7, 13.1, 11.8, 12.6, 13.7 ]) unc_expected = [ Uncertainty(1, array([1.6, 1.5, 1.5])), Uncertainty(1, array([3.1, 3.2, 3.0])), Uncertainty(1, array([3.3, 3.1])), Uncertainty(1, array([2.1, 2.2])), Uncertainty(1, array([5.0, 5.1, 5.3])), Uncertainty(1, array([4.2, 4.4])), Uncertainty(1, array([4.0, 4.4])), Uncertainty(1, array([0.951314593, 0.951314593, 0.855102109])), Uncertainty(1, array([0.951314593, 0.728010979])), Uncertainty(1, array([0.951314593, 0.728010979])) ] ks_expected = array([1.2, 1.3, 1.3, 3.2, 3.3]) unck_expected = [ Uncertainty(1, array([0.25, 0.25, 0.25])), Uncertainty(1, array([0.2644, 0.2644])) ] idx_expected = { "Nm": [3, 2], "cNm": [0, 3, 5], "Im": [[0, 1], [1, 2]], "sensors": [-1, 1, 2], "sensor_ms": [1, 3, 3], "n_sensor": [0, 1, 1, 2, 1, 1, 2, 1, 1, 2], "n_mu": [1, 1, 2, 2, 1, 2, 2, 1, 2, 2], "n_cov": [1, 1, 1, 1, 2, 2, 2, 3, 3, 3], "N_var": [3, 3, 2, 2, 3, 2, 2, 3, 2, 2], "idx": [0, 3, 6, 8, 10, 13, 15, 17, 20, 22, 24], "Ia": [1, 1, 1, 2, 2, 2] } w_matrices_expected = [] u_matrices_expected = [] ################################################################################################################ # 3. Run MatchUpData.read_data() ################################################################################################################ Sample2IndOp = Sample2Ind() MatchUpSample = Sample2IndOp.run(MatchUpTest) values_test = MatchUpSample.values unc_test = MatchUpSample.unc w_matrices_test = MatchUpSample.w_matrices u_matrices_test = MatchUpSample.u_matrices ks_test = MatchUpSample.ks unck_test = MatchUpSample.unck idx_test = MatchUpSample.idx ################################################################################################################ # 4. Compare retrieve values to expect values ################################################################################################################ # Test HData object attribute by attribute # a. values self.assertEqual(values_test.tolist(), values_expected.tolist()) # b. unc for block_unc_test, block_unc_expected in zip(unc_test, unc_expected): self.assertEqual(block_unc_expected.typeID, block_unc_test.typeID) for uR_expected, uR_test in zip(block_unc_expected.uR, block_unc_test.uR): self.assertAlmostEqual(uR_expected, uR_test, places=5) # c. w_matrices self.assertEqual(w_matrices_test, w_matrices_expected) # d. u_matrices self.assertEqual(u_matrices_test, u_matrices_expected) # e. ks self.assertEqual(ks_test.tolist(), ks_expected.tolist()) # f. unck for block_unck_test, block_unck_expected in zip( unck_test, unck_expected): self.assertEqual(block_unck_expected.typeID, block_unck_test.typeID) for uR_expected, uR_test in zip(block_unck_expected.uR, block_unck_test.uR): self.assertAlmostEqual(uR_expected, uR_test, places=5) # h. idx self.assertEqual(set(idx_expected.keys()), set(idx_test.keys())) for key in idx_expected.keys(): idx_i_test = idx_test[key] idx_i_expected = idx_expected[key] if isinstance(idx_i_expected, ndarray): self.assertEqual(idx_i_test.tolist(), idx_i_expected.tolist()) else: self.assertEqual(idx_i_test, idx_i_expected)
def return_MatchUpTest_rsw(): """ Return a MatchUp dataset object for testing :return: :MatchUpTest: *eopy.matchup.matchupIO.MatchUp* Test match-up dataset """ #################################################################################################################### # 1. Initialise test data #################################################################################################################### w2_matchup1 = array([[0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0], [0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5]]) w1_matchup2 = array([[0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5]]) w2_matchup2 = array([[0.5, 0.5, 0.0, 0.0, 0.0], [0.0, 0.0, 0.5, 0.5, 0.0], [0.0, 0.0, 0.5, 0.5, 0.0], [0.0, 0.0, 0.0, 0.5, 0.5]]) u2_matchup1 = array([1.0, 0.9, 0.78, 1.0, 0.9, 0.68, 1.0]) u1_matchup2 = array([1.0, 0.9, 0.9, 0.5, 0.9, 0.58, 1.1]) u2_matchup2 = array([1.0, 0.9, 0.9, 0.5, 0.8]) values = array([ 470.5, 720.56, 450.9, 295.6, 315.23, 70.5, 70.6, 70.3, 70.7, 70.5, 71.5, 71.6, 71.3, 71.7, 80.5, 80.6, 80.3, 80.7, 150.5, 151.1, 149.8, 150.2, 151.4, 140.5, 141.1, 139.8, 140.2, 160.5, 161.1, 169.8, 160.2, 20.2, 21.0, 19.7, 19.7, 20.7, 13.1, 13.2, 11.8, 15.2, 12.6, 13.7, 13.7, 11.3 ]) unc = [ Uncertainty(1, array([1.6, 1.5, 1.5, 1.3, 1.5])), Uncertainty(1, array([3.1, 3.2, 3.2, 3.1, 3.0])), Uncertainty(1, array([3.3, 3.4, 3.1, 3.2])), Uncertainty(1, array([2.1, 2.2, 2.2, 2.1])), Uncertainty(1, array([5.0, 4.7, 5.1, 5.2, 5.3])), Uncertainty(1, array([4.2, 4.3, 4.4, 4.3])), Uncertainty(1, array([4.0, 3.7, 4.4, 4.7])), Uncertainty(3, (0, 0)), Uncertainty(3, (1, 1)), Uncertainty(3, (2, 2)) ] ks = array([1.2, 1.7, 1.3, 1.4, 1.3, 3.2, 3.7, 3.3, 3.4]) unck = [ Uncertainty(1, array([0.25, 0.25, 0.25, 0.25, 0.25])), Uncertainty(1, array([0.2644, 0.2644, 0.2644, 0.2644])) ] idx = { "Nm": [5, 4], "cNm": [0, 5, 9], "Im": [[0, 1], [1, 2]], "sensors": [-1, 1, 2], "sensor_ms": [1, 3, 3], "n_sensor": [0, 1, 1, 2, 1, 1, 2, 1, 1, 2], "n_mu": [1, 1, 2, 2, 1, 2, 2, 1, 2, 2], "n_cov": [1, 1, 1, 1, 2, 2, 2, 3, 3, 3], "N_var": [5, 5, 4, 4, 5, 4, 4, 5, 4, 4], "idx": [0, 5, 10, 14, 18, 23, 27, 31, 36, 40, 44], "Ia": [1, 1, 1, 2, 2, 2] } a = array([1., 1.3, 0.002, 0.5, 1.1, 0.0005]) w_matrices = [ csr_matrix(w2_matchup1), csr_matrix(w1_matchup2), csr_matrix(w2_matchup2) ] u_matrices = [u2_matchup1, u1_matchup2, u2_matchup2] #################################################################################################################### # 3. Initialise MatchUp object #################################################################################################################### MatchUpTest = MatchUp() MatchUpTest.values = values MatchUpTest.unc = unc MatchUpTest.ks = ks MatchUpTest.unck = unck MatchUpTest.idx = idx MatchUpTest.a = a MatchUpTest.w_matrices = w_matrices MatchUpTest.u_matrices = u_matrices return MatchUpTest
def run(self, MatchUpData, sf=1, samples=None, show=False): """ Return a randomly sampled instance of ``eopy.matchup.matchupIO.MatchUp`` :type MatchUpData: *eopy.matchup.matchupIO.MatchUp* :param MatchUpData: Input match-up data for sampling :type sf: int :param sf: Sampling factor :type samples: int :param samples: Number of samples to include per match-up series :return: :MatchUpSample: *eopy.matchup.matchupIO.MatchUp* Sampled harmonisation data """ # initialise parameters mcxyz = MatchUpData.idx[ 'idx'] # cumulative total of variables data block mc = MatchUpData.idx['cNm'] # cumulative total of match-ups by series ################################################################################################################ # 1. Determine Match Ups to Include in Sample ################################################################################################################ # Choose a sample of match ups such that data is left with independent errors. # # N.B. - This is not possible for a fully systematic effect, but data with error correlation structures defined # by w matrices can be sampled to achieve this sampling_idxs = { } # initialise dictionary of sampling indices per match up series n_mus = set(MatchUpData.idx['n_mu']) # Find sampling indices by match-up series for n_mu in n_mus: # total number of match up in series (should be the same for each variable so take the first one) mu_total = [ MatchUpData.idx['N_var'][i] for i, n_mu_i in enumerate(MatchUpData.idx['n_mu']) if n_mu_i == n_mu ][0] mu_samples = mu_total / sf # required number sample match ups (determined by scaling factor) idxs = sorted(sample(arange(mu_total), mu_samples)) sampling_idxs[ n_mu] = idxs # add match up sample indices to dictionary ################################################################################################################ # 2. Sample Data ################################################################################################################ # a. Initialise sampled harmonisation data product ------------------------------------------------------------- MatchUpSample = MatchUp() MatchUpSample.a = MatchUpData.a[:] MatchUpSample.sensor_model = MatchUpData.sensor_model MatchUpSample.sensor_model_constant = MatchUpData.sensor_model_constant MatchUpSample.adjustment_model = MatchUpData.adjustment_model # -------------------------------------------------------------------------------------------------------------- # b. Update idx attribute of MatchUpSample to describe structure of sampled data ------------------------------- # Start with copy of full dataset idx dictionary attribute # N.B. - deepcopy because of python memory issues with lists nested in dicts MatchUpSample.idx = deepcopy(MatchUpData.idx) # Formulate required replacement idx entries (several can remain the same as the full dataset) idxs = [0] total = 0 for i, n_mu in enumerate(MatchUpData.idx['n_mu']): block_samples = len(sampling_idxs[n_mu]) MatchUpSample.idx['N_var'][i] = block_samples total += block_samples idxs.append(int(total)) MatchUpSample.idx['idx'] = idxs cNm = [0] total = 0 for i, n_mu in enumerate(n_mus): n_mu_sample = len(sampling_idxs[n_mu]) MatchUpSample.idx['Nm'][i] = n_mu_sample total += n_mu_sample cNm.append(total) MatchUpSample.idx['cNm'] = cNm if show: print "Sample Size: ", MatchUpSample.idx['Nm'] # -------------------------------------------------------------------------------------------------------------- # c. Sample variables and respective uncertainty --------------------------------------------------------------- # Initialise data arrays MatchUpSample.values = zeros(MatchUpSample.idx['idx'][-1]) MatchUpSample.unc = [0] * len(MatchUpSample.idx['n_cov']) # Sample data by data block for i, block_unc in enumerate(MatchUpData.unc): istart = mcxyz[i] # start of full dataset values data block iend = mcxyz[i + 1] # end of full dataset values data block istart_s = MatchUpSample.idx['idx'][ i] # start of sampled values data block iend_s = MatchUpSample.idx['idx'][ i + 1] # end of sampled values data block s_idx = sampling_idxs[MatchUpData.idx['n_mu'][ i]] # indices of match up to sample within values data block # i. Sample values MatchUpSample.values[istart_s:iend_s] = MatchUpData.values[ istart:iend][s_idx] # ii. Sample values uncertainty data if block_unc.form == 'ave': # If block error correlation form was defined by a w matrix # - now simplified to random error correlation by sampling choice # Initialise uncertainty data array MatchUpSample.unc[i] = Uncertainty("r", zeros(len(s_idx))) # Retrieve required W matrix and uncertainty vector and hence determine new random uncertainties w = MatchUpData.w_matrices[block_unc.w_i] u = MatchUpData.uncertainty_vectors[block_unc.u_i] for j, s_i in enumerate(s_idx): col_start = w.indices[w.indptr[j]] col_end = w.indices[w.indptr[j + 1] - 1] + 1 MatchUpSample.unc[i].uR[j] = npsum( u[col_start:col_end]**2)**0.5 else: # If block error correlation form random or random and systematic simplify to random and sample MatchUpSample.unc[i] = Uncertainty( "r", deepcopy(block_unc.uR[s_idx])) # -------------------------------------------------------------------------------------------------------------- # d. sample k -------------------------------------------------------------------------------------------------- # Initialise k data arrays MatchUpSample.ks = zeros(MatchUpSample.idx['cNm'][-1]) MatchUpSample.unck = [0] * len(MatchUpSample.idx['Nm']) # Sample k and respective uncertainty data by match-up series for i, mu_unck in enumerate(MatchUpData.unck): istart = mc[i] # start of full dataset k data block iend = mc[i + 1] # end of full dataset k data block istart_s = MatchUpSample.idx['cNm'][ i] # start of sampled dataset k data block iend_s = MatchUpSample.idx['cNm'][ i + 1] # end of sampled dataset k data block s_idx = sampling_idxs[ i + 1] # indices of match up to sample within k data block # i. Sample data MatchUpSample.ks[istart_s:iend_s] = MatchUpData.ks[istart:iend][ s_idx] # ii. Sample uncertainties MatchUpSample.unck[i] = Uncertainty("r", deepcopy(mu_unck.uR[s_idx])) # -------------------------------------------------------------------------------------------------------------- # d. sample times ---------------------------------------------------------------------------------------------- # todo - write sampling of times # -------------------------------------------------------------------------------------------------------------- # e. sample additional variables ------------------------------------------------------------------------------- # todo - write sampling of additional variables # -------------------------------------------------------------------------------------------------------------- return MatchUpSample
def test_run_single___w(self): """ Test for Transform2NormInd.run() for test ``eopy.matchup.matchupIO.MatchUp`` object with data for multiple matchup series - random uncertainty type only """ # Test Description # ================ # # 1. This test intialises an example *eopy.matchup.matchupIO.MatchUp* object # # 2. Compare transformed dataset to expected value ################################################################################################################ # 1. Initialise Test Data Object ################################################################################################################ MatchUpTest = return_MatchUpTest___w() ################################################################################################################ # 2. Define expected values ################################################################################################################ w1 = array([[ 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25 ]]) w2 = array([[ 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25 ]]) u1 = array( [1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0]) u2 = array( [2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0]) # Original dataset values (should be unchanged) MatchUpOriginal_expected = return_MatchUpTest___w() # Transformed dataset values_expected = array([ 5.0, 2.5, 5.0, 2.5, 1.0, 0.5, 3.0, 1.5, 3.0, 3.0, 6.0, 3.0, 6.0, 0.5, 1.0, 1.5, 3.0, 1.5, 3.0, 3.5, 1.0, 0.5, 4.0, 2.0, 4.0, 2.0 ]) unc_expected = [Uncertainty(3, (0, 0)), Uncertainty(3, (1, 1))] ks_expected = array([4.8, 6.8, 5.2, 5.6, 5.2]) unck_expected = [Uncertainty(1, array([0.25, 0.25, 0.25, 0.25, 0.25]))] idx_expected = { "Nm": [5], "cNm": [0, 5, 10], "Im": [[1, 2]], "sensors": [1, 2], "sensor_ms": [1], "n_sensor": [1, 2], "n_mu": [1, 1], "n_cov": [1, 1], "N_var": [13, 13], "idx": [0, 13, 26], "Ia": [1, 1, 1, 2, 2, 2] } a_expected = array([1., 1.3, 0.002, 0.5, 1.1, 0.0005]) ################################################################################################################ # 3. Run Transform2NormInd.run() ################################################################################################################ Transform2NormIndOp = Transform2NormInd() MatchUpTransform = Transform2NormIndOp.run(MatchUpTest) values_test = MatchUpTransform.values unc_test = MatchUpTransform.unc w_matrices_test = MatchUpTransform.w_matrices u_matrices_test = MatchUpTransform.u_matrices ks_test = MatchUpTransform.ks unck_test = MatchUpTransform.unck idx_test = MatchUpTransform.idx ################################################################################################################ # 4. Compare retrieve values to expect values ################################################################################################################ # Test transformed data object attribute by attribute # a. values for i, (value_expected, value_test) in enumerate(zip(values_expected, values_test)): self.assertAlmostEqual(value_expected, value_test, places=5, msg=str(i) + ": Expected " + str(value_expected) + " != Test " + str(value_test)) # b. unc for block_unc_test, block_unc_expected in zip(unc_test, unc_expected): self.assertEqual(block_unc_expected.typeID, block_unc_test.typeID) self.assertEqual(block_unc_expected.w_i, block_unc_test.w_i) self.assertEqual(block_unc_expected.u_i, block_unc_test.u_i) # e. ks for k_expected, k_test in zip(ks_expected, ks_test): self.assertAlmostEqual(k_test.tolist(), k_expected.tolist(), places=5) # f. unck for block_unck_test, block_unck_expected in zip( unck_test, unck_expected): self.assertEqual(block_unck_expected.typeID, block_unck_test.typeID) self.assertEqual(block_unck_expected.uR.tolist(), block_unck_test.uR.tolist()) # h. idx self.assertEqual(set(idx_expected.keys()), set(idx_test.keys())) for key in idx_expected.keys(): idx_i_test = idx_test[key] idx_i_expected = idx_expected[key] if isinstance(idx_i_expected, ndarray): self.assertEqual(idx_i_test.tolist(), idx_i_expected.tolist()) else: self.assertEqual(idx_i_test, idx_i_expected) # Test original data object preserved attribute by attribute # a. values for i, (value_original_expected, value_original_test) in enumerate( zip(MatchUpOriginal_expected.values, MatchUpTest.values)): self.assertAlmostEqual(value_original_expected, value_original_test, places=5) # b. unc for block_unc_original_expected, block_unc_original_test in zip( MatchUpOriginal_expected.unc, MatchUpTest.unc): self.assertEqual(block_unc_original_expected.typeID, block_unc_original_test.typeID) self.assertEqual(block_unc_original_expected.w_i, block_unc_original_test.w_i) self.assertEqual(block_unc_original_expected.u_i, block_unc_original_test.u_i) # e. ks for k_original_expected, k_original_test in zip( MatchUpOriginal_expected.ks, MatchUpTest.ks): self.assertAlmostEqual(k_original_test.tolist(), k_original_expected.tolist(), places=5) # f. unck for block_unck_original_expected, block_unck_original_test in zip( MatchUpOriginal_expected.unck, MatchUpTest.unck): self.assertEqual(block_unck_original_expected.typeID, block_unck_original_test.typeID) self.assertEqual(block_unck_original_expected.uR.tolist(), block_unck_original_test.uR.tolist()) # h. idx self.assertEqual(set(MatchUpOriginal_expected.idx), set(MatchUpTest.idx)) for key in MatchUpOriginal_expected.idx.keys(): idx_i_original_test = MatchUpTest.idx[key] idx_i_original_expected = MatchUpOriginal_expected.idx[key] if isinstance(idx_i_original_expected, ndarray): self.assertEqual(idx_i_original_test.tolist(), idx_i_original_expected.tolist()) else: self.assertEqual(idx_i_original_test, idx_i_original_expected)
def test_run_multi_r__(self): """ Test for Transform2NormInd.run() for test ``eopy.matchup.matchupIO.MatchUp`` object with data for multiple matchup series - random uncertainty type only """ # Test Description # ================ # # 1. This test intialises an example *eopy.matchup.matchupIO.MatchUp* object # # 2. Compare transformed dataset to expected value ################################################################################################################ # 1. Initialise Test Data Object ################################################################################################################ MatchUpTest = return_MatchUpTest_r__() ################################################################################################################ # 2. Define expected values ################################################################################################################ # Original dataset values (should be unchanged) MatchUpOriginal_expected = return_MatchUpTest_r__() # Transformed dataset values_expected = array([ 294.0625, 480.3733333, 300.6, 227.3846154, 210.1533333, 22.74193548, 22.0625, 21.96875, 22.80645161, 23.5, 21.66666667, 21.05882353, 23, 22.40625, 38.33333333, 36.63636364, 36.5, 38.42857143, 30.1, 32.14893617, 29.37254902, 28.88461538, 28.56603774, 33.45238095, 32.81395349, 31.77272727, 32.60465116, 40.125, 43.54054054, 38.59090909, 34.08510638, 13.72727273, 12, 14.1, 11.79069767, 17.53846154, 12.69565217, 31.16666667, 12.26086957, 11.52272727, 8.8125, 12, 7.4, 10.13207547 ]) unc_expected = [ Uncertainty(1, array([1.6, 1.5, 1.5, 1.3, 1.5])), Uncertainty(1, array([3.1, 3.2, 3.2, 3.1, 3.0])), Uncertainty(1, array([3.3, 3.4, 3.1, 3.2])), Uncertainty(1, array([2.1, 2.2, 2.2, 2.1])), Uncertainty(1, array([5.0, 4.7, 5.1, 5.2, 5.3])), Uncertainty(1, array([4.2, 4.3, 4.4, 4.3])), Uncertainty(1, array([4.0, 3.7, 4.4, 4.7])), Uncertainty(1, array([2.2, 1.7, 2.0, 4.3, 2.6])), Uncertainty(1, array([2.3, 1.2, 2.3, 4.4])), Uncertainty(1, array([3.2, 2.7, 3.0, 5.3])) ] ks_expected = array([ 4.8, 6.8, 5.2, 5.6, 5.2, 12.10287443, 13.99394856, 12.48108926, 12.85930408 ]) unck_expected = [ Uncertainty(1, array([0.25, 0.25, 0.25, 0.25, 0.25])), Uncertainty(1, array([0.2644, 0.2644, 0.2644, 0.2644])) ] idx_expected = { "Nm": [5, 4], "cNm": [0, 5, 9], "Im": [[0, 1], [1, 2]], "sensors": [-1, 1, 2], "sensor_ms": [1, 3, 3], "n_sensor": [0, 1, 1, 2, 1, 1, 2, 1, 1, 2], "n_mu": [1, 1, 2, 2, 1, 2, 2, 1, 2, 2], "n_cov": [1, 1, 1, 1, 2, 2, 2, 3, 3, 3], "N_var": [5, 5, 4, 4, 5, 4, 4, 5, 4, 4], "idx": [0, 5, 10, 14, 18, 23, 27, 31, 36, 40, 44], "Ia": [1, 1, 1, 2, 2, 2] } a_expected = array([1., 1.3, 0.002, 0.5, 1.1, 0.0005]) w_matrices_expected = [] u_matrices_expected = [] ################################################################################################################ # 3. Run Transform2NormInd.run() ################################################################################################################ Transform2NormIndOp = Transform2NormInd() MatchUpTransform = Transform2NormIndOp.run(MatchUpTest) values_test = MatchUpTransform.values unc_test = MatchUpTransform.unc w_matrices_test = MatchUpTransform.w_matrices u_matrices_test = MatchUpTransform.u_matrices ks_test = MatchUpTransform.ks unck_test = MatchUpTransform.unck idx_test = MatchUpTransform.idx ################################################################################################################ # 4. Compare retrieve values to expect values ################################################################################################################ # Test transformed data object attribute by attribute # a. values for i, (value_expected, value_test) in enumerate(zip(values_expected, values_test)): self.assertAlmostEqual(value_expected, value_test, places=5, msg=str(i)) # b. unc for block_unc_test, block_unc_expected in zip(unc_test, unc_expected): self.assertEqual(block_unc_expected.typeID, block_unc_test.typeID) self.assertEqual(block_unc_expected.uR.tolist(), block_unc_test.uR.tolist()) # c. w_matrices self.assertEqual(w_matrices_test, w_matrices_expected) # d. u_matrices self.assertEqual(u_matrices_test, u_matrices_expected) # e. ks for k_expected, k_test in zip(ks_expected, ks_test): self.assertAlmostEqual(k_test.tolist(), k_expected.tolist(), places=5) # f. unck for block_unck_test, block_unck_expected in zip( unck_test, unck_expected): self.assertEqual(block_unck_expected.typeID, block_unck_test.typeID) self.assertEqual(block_unck_expected.uR.tolist(), block_unck_test.uR.tolist()) # h. idx self.assertEqual(set(idx_expected.keys()), set(idx_test.keys())) for key in idx_expected.keys(): idx_i_test = idx_test[key] idx_i_expected = idx_expected[key] if isinstance(idx_i_expected, ndarray): self.assertEqual(idx_i_test.tolist(), idx_i_expected.tolist()) else: self.assertEqual(idx_i_test, idx_i_expected) # Test original data object preserved attribute by attribute # a. values for i, (value_original_expected, value_original_test) in enumerate( zip(MatchUpOriginal_expected.values, MatchUpTest.values)): self.assertAlmostEqual(value_original_expected, value_original_test, places=5) # b. unc for block_unc_original_expected, block_unc_original_test in zip( MatchUpOriginal_expected.unc, MatchUpTest.unc): self.assertEqual(block_unc_original_expected.typeID, block_unc_original_test.typeID) self.assertEqual(block_unc_original_expected.uR.tolist(), block_unc_original_test.uR.tolist()) # c. w_matrices self.assertEqual(MatchUpOriginal_expected.w_matrices, MatchUpTest.w_matrices) # d. u_matrices self.assertEqual(MatchUpOriginal_expected.u_matrices, MatchUpTest.u_matrices) # e. ks for k_original_expected, k_original_test in zip( MatchUpOriginal_expected.ks, MatchUpTest.ks): self.assertAlmostEqual(k_original_test.tolist(), k_original_expected.tolist(), places=5) # f. unck for block_unck_original_expected, block_unck_original_test in zip( MatchUpOriginal_expected.unck, MatchUpTest.unck): self.assertEqual(block_unck_original_expected.typeID, block_unck_original_test.typeID) self.assertEqual(block_unck_original_expected.uR.tolist(), block_unck_original_test.uR.tolist()) # h. idx self.assertEqual(set(MatchUpOriginal_expected.idx), set(MatchUpTest.idx)) for key in MatchUpOriginal_expected.idx.keys(): idx_i_original_test = MatchUpTest.idx[key] idx_i_original_expected = MatchUpOriginal_expected.idx[key] if isinstance(idx_i_original_expected, ndarray): self.assertEqual(idx_i_original_test.tolist(), idx_i_original_expected.tolist()) else: self.assertEqual(idx_i_original_test, idx_i_original_expected)
def return_MatchUpTest___w(): """ Return a MatchUp dataset object for testing :return: :MatchUpTest: *eopy.matchup.matchupIO.MatchUp* Test match-up dataset """ #################################################################################################################### # 1. Initialise test data #################################################################################################################### w1 = array([[ 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25 ]]) w2 = array([[ 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25, 0.00, 0.00, 0.00, 0.00 ], [ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.25, 0.25, 0.25 ]]) u1 = array( [1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0]) u2 = array( [2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0]) values = array([5.0, 3.0, 3.0, 2.5, 6.0, 3.0, 2.0, 4.0, 3.0, 4.0]) unc = [Uncertainty(3, (0, 0)), Uncertainty(3, (1, 1))] ks = array([1.2, 1.7, 1.3, 1.4, 1.3]) unck = [Uncertainty(1, array([0.25, 0.25, 0.25, 0.25, 0.25]))] idx = { "Nm": [5], "cNm": [0, 5, 10], "Im": [[1, 2]], "sensors": [1, 2], "sensor_ms": [1], "n_sensor": [1, 2], "n_mu": [1, 1], "n_cov": [1, 1], "N_var": [5, 5], "idx": [0, 5, 10], "Ia": [1, 1, 1, 2, 2, 2] } a = array([1., 1.3, 0.002, 0.5, 1.1, 0.0005]) w_matrices = [csr_matrix(w1), csr_matrix(w2)] u_matrices = [u1, u2] #################################################################################################################### # 3. Initialise MatchUp object #################################################################################################################### MatchUpTest = MatchUp() MatchUpTest.values = values MatchUpTest.unc = unc MatchUpTest.ks = ks MatchUpTest.unck = unck MatchUpTest.idx = idx MatchUpTest.a = a MatchUpTest.w_matrices = w_matrices MatchUpTest.u_matrices = u_matrices return MatchUpTest