コード例 #1
0
    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))
コード例 #2
0
    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))
コード例 #3
0
ファイル: catalogue.py プロジェクト: yetimote/hmtk
    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))
コード例 #4
0
ファイル: histogram.py プロジェクト: gem/qt-experiments
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))
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
    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))