def test_transform_params_for_trans_coeffs_long_to_short(self, mock): mock.side_effect = fake_map_func result = pp.transform_params_for_trans_coeffs( self.params, self.initial_no_transform, self.long_slice, self.transform_funcs, self.included, 'long_to_short') aae(result, np.arange(14) / 2)
def test_limit_weights(): w = {'a': 0.3, 'b': 0.1, 'c': 0.05, 'd': 0.05, 'e': 0.5} actual_exp = {'a': 0.3, 'b': 0.2, 'c': 0.1, 'd': 0.1, 'e': 0.3} actual = ffn.core.limit_weights(w, 0.3) assert actual.sum() == 1.0 for k in actual_exp: assert actual[k] == actual_exp[k] w = pd.Series(w) actual = ffn.core.limit_weights(w, 0.3) assert actual.sum() == 1.0 for k in actual_exp: assert actual[k] == actual_exp[k] w = pd.Series({'a': 0.29, 'b': 0.1, 'c': 0.06, 'd': 0.05, 'e': 0.5}) assert w.sum() == 1.0 actual = ffn.core.limit_weights(w, 0.3) assert actual.sum() == 1.0 assert all(x <= 0.3 for x in actual) aae(actual['a'], 0.300, 3) aae(actual['b'], 0.190, 3) aae(actual['c'], 0.114, 3) aae(actual['d'], 0.095, 3) aae(actual['e'], 0.300, 3)
def test_set_bounds_for_Q_robust(self): self.robust_bounds = True expected = np.zeros(100, dtype=object) expected[:] = None expected[10: 30] = 0.001 smo._set_bounds_for_Q(self, slice(10, 30)) aae(self.lower_bound, expected)
def test_transform_params_for_trans_coeffs_short_to_long(self, mock): mock.side_effect = fake_map_func result = pp.transform_params_for_trans_coeffs( self.params, self.initial_transform, self.short_slice, self.transform_funcs, self.included, 'short_to_long') aae(result, np.arange(16))
def check_loss_map_stats(self, job): mean_maps = models.LossMap.objects.filter( output__oq_job=job, statistics='mean', loss_type='structural').order_by('poe') data = numpy.zeros((3, 4, 4)) # 3 clp x (3 quantiles + 1 mean) x 4 assets for j, mm in enumerate(mean_maps): dataset = mm.lossmapdata_set.order_by('asset_ref') data[j][0] = [d.value for d in dataset] quantile_maps = models.LossMap.objects.filter( output__oq_job=job, statistics='quantile', poe=mm.poe, loss_type='structural').order_by('quantile') for i, qm in enumerate(quantile_maps, 1): dataset = qm.lossmapdata_set.order_by('asset_ref') data[j][i] = [d.value for d in dataset] stat = data.transpose(2, 1, 0) # to shape (N, Q + 1, P) expected_data = [] lines = open(self._test_path('expected/loss_map_stats-structural.csv')) next(lines) # skip header for line in lines: values = line.split(',')[1] vals = [map(float, piece.split(':')) for piece in values.split(' ')] expected_data.append(vals) aae(numpy.array(expected_data), stat, decimal=1)
def test_initial_trans_coeffs(self, mock_tf): mock_tf.nr_coeffs_first_func.return_value = 3 mock_tf.nr_coeffs_second_func.return_value = 10 expected = [np.zeros((2, 3)), np.zeros((2, 10))] initials = smo._initial_trans_coeffs(self) for i, e in zip(initials, expected): aae(i, e)
def test_expand_params(self, mock_pt): mock_pt.transform_params_for_X_zero.return_value = np.arange(3) mock_pt.transform_params_for_trans_coeffs.return_value = np.ones(9) mock_pt.transform_params_for_P_zero.return_value = np.ones(3) * 17 expected = np.array([0] * 5 + [1] * 9 + [0, 1, 2] + [17] * 3) aae(smo._transform_params(self, np.zeros(18), 'short_to_long'), expected)
def test_clean_control_specs_missing_observation_drop_observation(self): self.data.loc[2, 'c2'] = np.nan self.controls_with_missings = 'drop_observations' msp._clean_controls_specification(self) res = [['c1', 'c2'], ['c1', 'c2']] assert_equal(self.controls, res) aae(self.obs_to_keep, np.array([True, True, False, True, True]))
def test_map_params_to_x_zero_without_replacement(self): exp = np.zeros((self.nind, self.nemf, self.nfac)) exp[:, 0] = np.array([10, 11, 12]) exp[:, 1] = np.array([13, 14, 15]) pp._map_params_to_X_zero(self.params, self.initial, self.filler, self.slice) aae(self.initial, exp)
def test_to_log_returns_ts(): data = ts actual = data.to_log_returns() assert len(actual) == len(data) assert np.isnan(actual[0]) aae(actual[1], -0.019, 3) aae(actual[9], -0.022, 3)
def test_QR_MGS_decomposition(): 'verify the computed Q and R matrices' np.random.seed(6) M = 6 N = 5 A = np.random.rand(M,N) Q1, R1 = qra.QR_MGS(A) aae(A, np.dot(Q1, R1), decimal=10)
def test_simulate_cascade(grid_and_cascade): g = grid_and_cascade[0] for p in np.arange(0.2, 1.0, 0.1): source, times, tree = simulate_cascade( g, p, source=None, return_tree=True) dist = shortest_distance(tree, source=source).a dist[dist == MAXINT] = -1 aae(dist, times)
def test_set_bounds_P_zero_restricted_not_robust(self): self.robust_bounds = False self.restrict_P_zeros = True expected = np.zeros(100, dtype=object) expected[:] = None expected[self.bound_indices[:4]] = 0.0 smo._set_bounds_for_P_zero(self, slice(10, 20)) aae(self.lower_bound, expected)
def test_QR_MGS_Q_orthogonal(): 'verify the orthogonality of the computed Q' np.random.seed(1) M = 6 N = 5 A = np.random.rand(M,N) Q1, R1 = qra.QR_MGS(A) aae(np.identity(N), np.dot(Q1.T,Q1), decimal=10)
def test_to_returns_ts(): data = ts actual = data.to_returns() assert len(actual) == len(data) assert np.isnan(actual[0]) aae(actual[1], -0.019, 3) aae(actual[9], -0.022, 3)
def test_QR_Givens_Q_from_QR_Givens_orthogonal(): 'verify the orthogonality of the computed Q' np.random.seed(78) M = 6 N = 5 A = np.random.rand(M,N) qra.QR_Givens(A) Q = qra.Q_from_QR_Givens(A=A) aae(np.identity(M), np.dot(Q.T,Q), decimal=10)
def test_House_vector_orthogonal_reflection(): 'verify that the resulting Householder reflection is orthogonal' np.random.seed(14) # real vector a = np.random.rand(7) v, beta = qra.House_vector(x=a) P = np.identity(a.size) - beta*np.outer(v,v) aae(np.dot(P.T,P), np.dot(P,P.T), decimal=10) aae(np.dot(P.T,P), np.identity(a.size), decimal=10)
def test_get_B(): z_k = np.array([2, 3]) H_k = np.eye(2) * 3 x_i_k__k = np.array([3, 3]) P_i_k__k = np.eye(2) obs = get_B_i_k(z_k, H_k, x_i_k__k, P_i_k__k) exp = np.array([[94., 85.], [85., 94.]]) aae(exp, obs)
def test_anch_outcome_from_final_factors_with_linear_anchoring(self): self.anchoring = True self.anchoring_update_type = 'linear' self._anchor_final_factors = Mock( return_value=self.exp_anchored_factors) exp = np.ones(10) * 3.6 calc = smo._anchoring_outcome_from_final_factors( self, self.final_factors, self.al, self.ai) aae(calc, exp)
def test_map_params_to_trans_coeffs_long_to_short(self, mock_tf): mock_tf.some_transform_func.side_effect = fake_transform_func exp1 = np.array([[10, 11, 12], [13, 14, 15]]) exp2 = np.array([[8, 8.5, 9, 9.5], [10.5, 11, 11.5, 12]]) pp._map_params_to_trans_coeffs(self.params, self.initial_no_transform, self.long_slice, self.transform_funcs, self.included, 'long_to_short') aae(self.initial_no_transform[0], exp1) aae(self.initial_no_transform[1], exp2)
def test_process_selectors_numpy_array_loc(np_params_converter): calculated = process_selectors( constraints=[{"type": "equality", "loc": [1, 4]}], params=np.arange(6) + 10, tree_converter=np_params_converter, param_names=list("abcdefg"), ) aae(calculated[0]["index"], np.array([1, 4]))
def test_transform_params_for_p_zero_long_to_short(self): params_for_P_zero = expected = np.array( [100, 20, 10, 173, 41, 235, 256, 32, 16, 365, 78, 458]) result = pp.transform_params_for_P_zero( params_for_P_zero, self.filler_2mat, self.boo_2mat, False, 'long_to_short') expected = self.params[self.slice_2mat] aae(result, expected)
def test_map_params_to_trans_coeffs_without_transformation(self): exp1 = np.array([[10, 11, 12], [13, 14, 15]]) exp2 = np.array([[16, 17, 18, 19], [20, 21, 22, 23]]) pp._map_params_to_trans_coeffs( self.params, self.initial_no_transform, self.short_slice) aae(self.initial_no_transform[0], exp1) aae(self.initial_no_transform[1], exp2)
def test_initial_deltas_without_controls_besides_constant(self): self.controls = [[], [], []] exp1 = np.array([[3], [0], [0], [4], [0], [0]]) exp2 = np.array([[5], [6], [0]]) exp3 = np.array([[7], [0], [0], [0]]) expected = [exp1, exp2, exp3] calculated = smo._initial_deltas(self) for calc, ex in zip(calculated, expected): aae(calc, ex)
def test_get_x_j_k_k(): H_k = np.array([[1, 2], [3, 4]]) K_j__k = np.array([[1, 2], [3, 4]]) * 2 z_k = np.array([2, 3]) x_k__l = np.array([2, 3]) * 2 obs = get_x_j_k__k(x_k__l, K_j__k, z_k, H_k) exp = np.array([-156, -342]) aae(exp, obs)
def test_unit_vector_TCS_returns_unit_vector(): 'the computed vectos must be unitary' inclination, declination = np.meshgrid(np.linspace(-90, 90, 3), np.linspace(0, 180, 3)) inclination = np.ravel(inclination) declination = np.ravel(declination) vx, vy, vz = coord.unit_vector_TCS(inclination, declination) norm = np.sqrt(vx * vx + vy * vy + vz * vz) aae(norm, np.ones_like(norm), decimal=15)
def test_QR_MCS_Cholesky(): 'verify that R is the transpose of the Cholesky factor of ATA' np.random.seed(98) M = 6 N = 5 A = np.random.rand(M,N) ATA = np.dot(A.T,A) Q1, R1 = qra.QR_MGS(A) aae(ATA, np.dot(R1.T,R1), decimal=10)
def test_map_params_to_trans_coeffs_without_transformation(self): exp1 = np.array([[10, 11, 12], [13, 14, 15]]) exp2 = np.array([[16, 17, 18, 19], [20, 21, 22, 23]]) pp._map_params_to_trans_coeffs(self.params, self.initial_no_transform, self.short_slice) aae(self.initial_no_transform[0], exp1) aae(self.initial_no_transform[1], exp2)
def test_map_params_to_trans_coeffs_long_to_short(self, mock_tf): mock_tf.some_transform_func.side_effect = fake_transform_func exp1 = np.array([[10, 11, 12], [13, 14, 15]]) exp2 = np.array([[8, 8.5, 9, 9.5], [10.5, 11, 11.5, 12]]) pp._map_params_to_trans_coeffs( self.params, self.initial_no_transform, self.long_slice, self.transform_funcs, self.included, 'long_to_short') aae(self.initial_no_transform[0], exp1) aae(self.initial_no_transform[1], exp2)
def test_y_data_focus_on_rows(self): data = np.tile(np.arange(6), 16).reshape(16, 6) self.data = DataFrame(data=data, columns=self.different_meas) self.data['period'] = np.arange(4).repeat(4) self.data['a'] = 10 res = np.vstack([np.arange(6).repeat(3).reshape(6, 3)] * 4) res = np.vstack([res, np.ones(3) * 10]) aae(dc.y_data_chs(self), res)
def test_initial_deltas_with_controls_and_constants(self): exp1 = np.array([ [3, 0, 0], [0, 0, 0], [0, 0, 0], [4, 0, 0], [0, 0, 0], [0, 0, 0]]) exp2 = np.array([[5, 0, 0, 0], [6, 0, 0, 0], [0, 0, 0, 0]]) exp3 = np.array([[7, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]) expected = [exp1, exp2, exp3] calculated = smo._initial_deltas(self) for calc, ex in zip(calculated, expected): aae(calc, ex)
def test_QR_Givens_Cholesky(): 'verify that R is the transpose of the Cholesky factor of ATA' np.random.seed(8) M = 6 N = 5 A = np.random.rand(M,N) ATA = np.dot(A.T,A) qra.QR_Givens(A) R = np.triu(A) aae(ATA, np.dot(R.T,R), decimal=10)
def test_map_params_to_H_without_psi_transformation(self): expected = np.array([ [10, 0, 0], [0, 11, 0], [0, 3, 12], [13, 0, 14], [0, 15, 16]]) pp._map_params_to_H(params=self.params, initial=self.initial, params_slice=self.slice, boo=self.boo) aae(self.initial, expected)
def test_Givens_cs2rho_Givens_rho2cs(): 'verify consistency' np.random.seed(11) a = 10*np.random.rand() b = 10*np.random.rand() c, s = qra.Givens_rotation(a=a, b=b) rho = qra.Givens_cs2rho(c=c, s=s) c2, s2 = qra.Givens_rho2cs(rho=rho) aae(c, c2, decimal=10) aae(s, s2, decimal=10)
def test_transform_params_for_p_zero_long_to_short(self): params_for_P_zero = expected = np.array( [100, 20, 10, 173, 41, 235, 256, 32, 16, 365, 78, 458]) result = pp.transform_params_for_P_zero(params_for_P_zero, self.filler_2mat, self.boo_2mat, False, 'long_to_short') expected = self.params[self.slice_2mat] aae(result, expected)
def check_df(expected, result, decimals=None): # check all columns in result for col in expected.columns.values: assert col in result.keys() # check all items in result match expected for k, v in result.items(): if decimals is None or k == 'Protein ID': assert (expected[k] == v).all() else: aae(np.round(expected[k], decimals), np.round(v, decimals))
def test_simulate_cascade(grid_and_cascade): g = grid_and_cascade[0] for p in np.arange(0.2, 1.0, 0.1): source, times, tree = simulate_cascade(g, p, source=None, return_tree=True) dist = shortest_distance(tree, source=source).a dist[dist == MAXINT] = -1 aae(dist, times)
def test_geodetic2geocentric_latitude_geocentric2geodetic_latitude(): 'verify results for known input' geodetic_latitude = np.array([-60, -45, -30, 0, 30, 45, 60]) a, f = el.WGS84() b = a * (1 - f) geocentric_latitude = coord.geodetic2geocentric_latitude( geodetic_latitude, a, b) geodetic_latitude2 = coord.geocentric2geodetic_latitude( geocentric_latitude, a, b) aae(geodetic_latitude, geodetic_latitude2, decimal=12)
def test_y_data_focus_on_rows(self): data = np.tile(np.arange(6), 16).reshape(16, 6) self.data = DataFrame(data=data, columns=self.different_meas) self.data["__period__"] = np.arange(4).repeat(4) self.data["a"] = 10 res = np.vstack([np.arange(6).repeat(4).reshape(6, 4)] * 4) res = np.vstack([res, np.ones(4) * 10]) aae(DataProcessor.y_data(self), res)
def test_get_internal_bounds(): params = pd.DataFrame() params["_internal_free"] = [True, False, False, True] params["_internal_lower"] = [-np.inf, 2, 3, 5] params["_internal_upper"] = [-10, 3, 5, np.inf] expected = (np.array([-np.inf, 5]), np.array([-10, np.inf])) res = tp._get_internal_bounds(params) assert len(res) == len(expected) for arr_res, arr_expected in zip(res, expected): aae(arr_res, arr_expected)
def test_rotation_NED_orthogonality(): 'Rotation matrix must be mutually orthogonal' latitude = np.array([0, -15, 22.5, -30, 45, -60, 75, -90]) longitude = np.array([-17, 0, 30, 9, 90, 23, 180, 1]) R = coord.rotation_NED(latitude, longitude) for Ri in R: M = np.array([[Ri[0], Ri[1], Ri[2]], [Ri[3], Ri[4], Ri[5]], [Ri[6], 0, Ri[7]]]) aae(np.dot(M.T, M), np.identity(3), decimal=15) aae(np.dot(M, M.T), np.identity(3), decimal=15)
def test_deltas_bool_without_controls_besides_constants(self): exp1 = np.array([False, True, True, False, True, True]).reshape(6, 1) exp2 = np.array([False, False, True]).reshape(3, 1) exp3 = np.array([False, True, True, True]).reshape(4, 1) expected = [exp1, exp2, exp3] self.controls = [[], [], []] calculated = smo._deltas_bool(self) for calc, ex in zip(calculated, expected): aae(calc, ex)
def test_process_selectors_dataframe_loc(df_params, df_params_converter): constraints = [{"type": "equality", "loc": ["b", "e"]}] calculated = process_selectors( constraints=constraints, params=df_params, tree_converter=df_params_converter, param_names=list("abcdefg"), ) aae(calculated[0]["index"], np.array([1, 4]))
def test_initial_p_normal_filters(p_mocker): p_mocker.square_root_filters = False expected = [np.zeros((10, 2, 3, 3)), np.zeros((20, 3, 3))] calculated = SkillModel._initial_p(p_mocker) for calc, exp in zip(calculated, expected): aae(calc, exp) # test that the second is pointing to the same data as the first. calc1, calc2 = calculated calc1 += 1 aae(calc2, np.ones_like(calc2))
def test_Int1(): 'compare with reference values from Fjær et al., 2008, Appendix D-5' r1 = 0.2 q1 = 0.4 R1 = 1.2 r2 = 0.4 q2 = 0.4 R2 = 1.0 reference = np.array([0.0595689, 0.162188]) computed = np.array([disk.Int1(q1, r1, R1), disk.Int1(q2, r2, R2)]) aae(reference, computed, decimal=6)
def test_QR_Givens_Q_from_QR_Givens_decomposition(): 'verify the computed Q and R matrices' np.random.seed(7) M = 6 N = 5 A = np.random.rand(M,N) A2 = A.copy() qra.QR_Givens(A2) Q = qra.Q_from_QR_Givens(A=A2) R = np.triu(A2) aae(A, np.dot(Q, R), decimal=10)
def check_loss_map_quantile(self, job): lm_with_quantile = models.LossMap.objects.filter( output__oq_job=job, statistics='quantile', loss_type='structural').order_by('poe') self.assertEqual(lm_with_quantile.count(), 9) actual_0 = [ point.value for point in models.LossMapData.objects.filter( loss_map=lm_with_quantile[0]).order_by( 'asset_ref', 'loss_map__poe')] aae(actual_0, [376.24261986, 219.38682742, 639.86715118, 753.55988728])
def test_y_data_focus_on_columns(self): df = DataFrame(data=np.arange(4).repeat(4), columns=['period']) for var in self.different_meas + ['a']: df[var] = np.arange(16) self.data = df res = np.vstack( [np.array([[0, 1, 3]] * 6), np.array([[4, 5, 7]] * 6), np.array([[8, 9, 11]] * 6), np.array([[12, 13, 15]] * 7)]) aae(dc.y_data_chs(self), res)
def test_map_params_to_trans_coeffs_short_to_long(self, mock_tf): mock_tf.some_transform_func.side_effect = fake_transform_func exp1 = np.array([[10, 11, 12], [13, 14, 15]]) exp2 = np.array([[32, 34, 36, 38, 1], [40, 42, 44, 46, 1]]) pp._map_params_to_trans_coeffs( self.params, self.initial_transform, self.short_slice, self.transform_funcs, self.included) aae(self.initial_transform[0], exp1) aae(self.initial_transform[1], exp2)
def test_geodetic2geocentric_latitude_known_input(): 'verify results for known input' latitude = np.array([-60, -45, -30, 0, 30, 45, 60]) a, f = el.WGS84() b = a * (1 - f) aux = (b * b) / (a * a) sqrt3 = np.sqrt(3) tangent = np.array([-sqrt3, -1, -1 / sqrt3, 0, 1 / sqrt3, 1, sqrt3]) true = np.rad2deg(np.arctan(aux * tangent)) computed = coord.geodetic2geocentric_latitude(latitude, a, b) aae(true, computed, decimal=12)
def test_maps_params_to_p_normal_filters(p_params): initial = np.zeros((5, 2, 3, 3)) expected0 = np.array([[1, 0.1, 0.2], [0.1, 2, 0.3], [0.2, 0.3, 3]]) expected1 = np.array([[4, 0.5, 0.6], [0.5, 5, 0.7], [0.6, 0.7, 6]]) expected = np.zeros_like(initial) expected[:, 0] = expected0 expected[:, 1] = expected1 _map_params_to_p(p_params, initial, False) aae(initial, expected)
def check_loss_map_quantile(self, job): lm_with_quantile = models.LossMap.objects.filter( output__oq_job=job, statistics='quantile', loss_type='structural').order_by('poe') self.assertEqual(lm_with_quantile.count(), 9) actual_0 = [ point.value for point in models.LossMapData.objects.filter( loss_map=lm_with_quantile[0]).order_by( 'asset_ref', 'loss_map__poe')] aae(actual_0, [401.955278940267, 232.802818304691, 644.37214688894, 777.097165009322])
def test_unusualness(): """ Checks unusualness on small sample. For calculations, see calculation-of-unusualness.odt, which uses the bernouili random variable variance p(1-p). """ question = ExamQuestion(EVALS_SAMPLE, 1) actual = _unusualness("Grader A", question) expected = 0.1800983877 aae(expected, actual)
def test_map_params_to_trans_coeffs_short_to_long(self, mock_tf): mock_tf.some_transform_func.side_effect = fake_transform_func exp1 = np.array([[10, 11, 12], [13, 14, 15]]) exp2 = np.array([[32, 34, 36, 38, 1], [40, 42, 44, 46, 1]]) pp._map_params_to_trans_coeffs(self.params, self.initial_transform, self.short_slice, self.transform_funcs, self.included) aae(self.initial_transform[0], exp1) aae(self.initial_transform[1], exp2)
def test_map_params_to_deltas(self): expected0 = np.array( [[10, 11, 12], [13, 14, 15], [0, 16, 17], [18, 19, 20]]) expected1 = np.array( [[0, 21], [22, 23], [24, 25], [26, 27], [28, 29], [30, 31]]) pp._map_params_to_deltas(self.params, self.initial, self.slices, self.bools) aae(self.initial[0], expected0) aae(self.initial[1], expected1)
def test_set_bounds_for_X_zero(self): self.lower_bound = np.empty(100, dtype=object) self.lower_bound[:] = None params_slice = slice(10, 22) expected = self.lower_bound.copy() expected[[16, 20]] = 0 smo._set_bounds_for_X_zero(self, params_slice=params_slice) aae(self.lower_bound, expected)
def test_c_data_with_constants(self): res1 = [[1.0, 'c1_t0_0', 'c2_t0_0'], [1.0, 'c1_t0_1', 'c2_t0_1'], [1.0, 'c1_t0_2', 'c2_t0_2'], [1.0, 'c1_t0_4', 'c2_t0_4']] res2 = [[1.0, 'c1_t1_0', 'c2_t1_0', 'c3_t1_0'], [1.0, 'c1_t1_1', 'c2_t1_1', 'c3_t1_1'], [1.0, 'c1_t1_2', 'c2_t1_2', 'c3_t1_2'], [1.0, 'c1_t1_4', 'c2_t1_4', 'c3_t1_4']] res = [res1, res2] calculated = dc.c_data_chs(self) for i, calc in enumerate(calculated): aae(calc, np.array(res[i], dtype=object))
def check_loss_map_mean(self, job): lm_with_stats = models.LossMap.objects.filter( output__oq_job=job, statistics='mean', loss_type='structural').order_by('poe') self.assertEqual(lm_with_stats.count(), 3) actual = [ point.value for point in models.LossMapData.objects.filter( loss_map__in=lm_with_stats).order_by( 'asset_ref', 'loss_map__poe')] aae(actual, [542.132838477895, 0.0, 0.0, 254.790354584725, 0.0, 0.0, 653.871039876869, 0.0, 0.0, 806.2713593155, 0.0, 0.0])
def check_loss_map_mean(self, job): lm_with_stats = models.LossMap.objects.filter( output__oq_job=job, statistics='mean', loss_type='structural').order_by('poe') self.assertEqual(lm_with_stats.count(), 3) actual = [ point.value for point in models.LossMapData.objects.filter( loss_map__in=lm_with_stats).order_by( 'asset_ref', 'loss_map__poe')] aae(actual, [514.22057893, 0., 0., 227.85575576, 0., 0., 652.50322751, 0., 0., 778.04645901, 0., 0.])