def do_collapse_logic_tree(data, event_num, weights, eqrm_flags, use_C=True): """ Collapse data, such as when several events are used to repressent one event. Data is the array to be collapsed (eg ground_motion or loss) """ if len(data.shape) >= 4: # Assume the extra dimension is the ground motion model if eqrm_flags.atten_collapse_Sa_of_atten_models is True: new_data = _collapse_att_model_dimension(data, weights) else: new_data = data else: # if there is only one attenuation model. no_attn_collapse = ( (len(weights) == 1) or eqrm_flags.atten_collapse_Sa_of_atten_models is False) if no_attn_collapse: new_data = data else: weights = asarray(weights) num_of_att_models = int(len(event_num)/(max(event_num) + 1)) new_data = _collapse_att_model_results(data, weights, num_of_att_models) return new_data, None, None
def do_collapse_logic_tree(data, event_num, weights, eqrm_flags, use_C=True): """ Collapse data, such as when several events are used to repressent one event. Data is the array to be collapsed (eg ground_motion or loss) """ if len(data.shape) >= 4: # Assume the extra dimension is the ground motion model if eqrm_flags.atten_collapse_Sa_of_atten_models is True: new_data = _collapse_att_model_dimension(data, weights) else: new_data = data else: # if there is only one attenuation model. no_attn_collapse = ( (len(weights) == 1) or eqrm_flags.atten_collapse_Sa_of_atten_models is False) if no_attn_collapse: new_data = data else: weights = asarray(weights) num_of_att_models = int(len(event_num) / (max(event_num) + 1)) new_data = _collapse_att_model_results(data, weights, num_of_att_models) return new_data, None, None
def test_collapse_att_model_dimension3(self): gmm = 2 site = 1 rec_model = 1 events = 2 periods = 1 size = gmm * rec_model * site * events * periods data = array([[1., 0], [0, 1.]]) data = reshape(data, (gmm, rec_model, site, events, periods)) weights = [2., 0] sum = _collapse_att_model_dimension(data, weights) actual = array([[2., 0]]) actual = reshape(actual, (1, site, events, periods)) self.assert_ (allclose(sum, actual)) weights = [2.] sum = _collapse_att_model_dimension(data, weights) actual = array([[2., 0]]) actual = reshape(actual, (1, site, events, periods)) self.assert_ (allclose(sum, actual))
def test_collapse_att_model_dimension3(self): gmm = 2 site = 1 rec_model = 1 events = 2 periods = 1 size = gmm * rec_model * site * events * periods data = array([[1., 0], [0, 1.]]) data = reshape(data, (gmm, rec_model, site, events, periods)) weights = [2., 0] sum = _collapse_att_model_dimension(data, weights) actual = array([[2., 0]]) actual = reshape(actual, (1, site, events, periods)) self.assert_(allclose(sum, actual)) weights = [2.] sum = _collapse_att_model_dimension(data, weights) actual = array([[2., 0]]) actual = reshape(actual, (1, site, events, periods)) self.assert_(allclose(sum, actual))
def test_collapse_att_model_dimension2(self): gmm = 3 site = 1 rec_model = 1 events = 2 periods = 4 size = gmm * site * events * periods data = arange(0, size, 1) data = reshape(data, (gmm, rec_model, site, events, periods)) weights = [0.2, 0.3] sum = _collapse_att_model_dimension(data, weights) actual = zeros((gmm, site, events, periods)) for i in [0,1]: actual[i,:] = data[i,...] * weights[i] sum_act = scipy.sum(actual, 0) self.assert_ (allclose(sum, sum_act)) self.assert_ (sum[0, 0, 1, 3] == 7*0.2 + 15*0.3) # FIXME FP precision
def test_collapse_att_model_dimension(self): gmm = 3 rec_model = 1 site = 1 events = 2 periods = 4 size = gmm * rec_model * site * events * periods data = arange(0, size, 1) data = reshape(data, (gmm, rec_model, site, events, periods)) weights = [0.2, 0.3, 0.5] sum = _collapse_att_model_dimension(data, weights) actual = zeros((gmm, site, events, periods)) for i in [0, 1, 2]: actual[i, :] = data[i, :, :, :] * weights[i] sum_act = scipy.sum(actual, 0) self.assert_(allclose(sum, sum_act)) self.assert_(sum[0, 0, 1, 3] == 7 * 0.2 + 15 * 0.3 + 23 * 0.5)