def test_1D_bootstrap_no_uncertainty(self): """ Tests the bootstrap 1D histrogram function with no uncertainties """ # Without normalisation x_range = np.arange(0., 60., 10.) expected_array = np.array([7., 14., 14., 14., 14.]) np.testing.assert_array_almost_equal(expected_array, utils.bootstrap_histogram_1D(self.x, x_range)) # Now with normalisaton expected_array = expected_array / np.sum(expected_array) np.testing.assert_array_almost_equal(expected_array, utils.bootstrap_histogram_1D(self.x, x_range, normalisation=True))
def get_depth_distribution(self, depth_bins, normalisation=False, bootstrap=None): ''' Gets the depth distribution of the earthquake catalogue to return a single histogram. Depths may be normalised. If uncertainties are found in the catalogue the distrbution may be bootstrap sampled :param numpy.ndarray depth_bins: Bin edges for the depths :param bool normalisation: Choose to normalise the results such that the total contributions sum to 1.0 (True) or not (False) :param int bootstrap: Number of bootstrap samples :returns: Histogram of depth values ''' if len(self.data['depth']) == 0: # If depth information is missing raise ValueError('Depths missing in catalogue') if len(self.data['depthError']) == 0: self.data['depthError'] = np.zeros(self.get_number_events(), dtype=float) return bootstrap_histogram_1D(self.data['depth'], depth_bins, self.data['depthError'], normalisation=normalisation, number_bootstraps=bootstrap, boundaries=(0., None))
def magnitude_distribution( catalogue, magnitude_bins_nr, normalisation, bootstrap): bins = numpy.linspace(catalogue.data['magnitude'].min(), catalogue.data['magnitude'].max(), magnitude_bins_nr + 1) return bins, bootstrap_histogram_1D( catalogue.data['magnitude'], bins, catalogue.data.get('sigmaMagnitude', numpy.zeros( catalogue.get_number_events(), dtype=float)), normalisation=normalisation, number_bootstraps=bootstrap, boundaries=(0., None))
def test_1D_bootstrap_with_uncertainty(self): """ Tests the bootstrap 1D histrogram function with uncertainties """ self.x_sigma = 1.0 * np.ones(len(self.x), dtype=float) expected_array = np.array([0.17, 0.22, 0.22, 0.22, 0.17]) x_range = np.arange(0., 60., 10.) hist_values = utils.bootstrap_histogram_1D(self.x, x_range, uncertainties=self.x_sigma, number_bootstraps=1000, normalisation=True) np.testing.assert_array_almost_equal(np.round(hist_values, 2), expected_array)
def test_1D_bootstrap_with_uncertainty(self): """ Tests the bootstrap 1D histrogram function with uncertainties """ self.x_sigma = 1.0 * np.ones(len(self.x), dtype=float) expected_array = np.array([0.17, 0.22, 0.22, 0.22, 0.17]) x_range = np.arange(0., 60., 10.) hist_values = utils.bootstrap_histogram_1D( self.x, x_range, uncertainties=self.x_sigma, number_bootstraps=1000, normalisation=True) np.testing.assert_array_almost_equal(np.round(hist_values, 2), expected_array)
def get_depth_distribution(self, depth_bins, normalisation=False, bootstrap=None): ''' Gets the depth distribution of the earthquake catalogue to return a single histogram. Depths may be normalised. If uncertainties are found in the catalogue the distrbution may be bootstrap sampled :param numpy.ndarray depth_bins: getBin edges for the depths :param bool normalisation: Choose to normalise the results such that the total contributions sum to 1.0 (True) or not (False) :param int bootstrap: Number of bootstrap samples :returns: Histogram of depth values ''' if len(self.data['depth']) == 0: # If depth information is missing raise ValueError('Depths missing in catalogue') if len(self.data['depthError']) == 0: self.data['depthError'] = np.zeros(self.get_number_events(), dtype=float) return bootstrap_histogram_1D(self.data['depth'], depth_bins, self.data['depthError'], normalisation=normalisation, number_bootstraps=bootstrap, boundaries=(0., None))