예제 #1
0
파일: catalogue.py 프로젝트: yetimote/hmtk
    def get_magnitude_time_distribution(self, magnitude_bins, time_bins,
                                        normalisation=False, bootstrap=None):
        '''
        Returns a 2-D histogram indicating the number of earthquakes in a
        set of time-magnitude bins. Time is in decimal years!

        :param numpy.ndarray magnitude_bins:
             Bin edges for the magnitudes

        :param numpy.ndarray time_bins:
            Bin edges for the times

        :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:
            2D histogram of events in magnitude-year bins
        '''
        return bootstrap_histogram_2D(
            self.get_decimal_time(),
            self.data['magnitude'],
            time_bins,
            magnitude_bins,
            xsigma=np.zeros(self.get_number_events()),
            ysigma=self.data['sigmaMagnitude'],
            normalisation=normalisation,
            number_bootstraps=bootstrap)
예제 #2
0
    def get_magnitude_time_distribution(self,
                                        magnitude_bins,
                                        time_bins,
                                        normalisation=False,
                                        bootstrap=None):
        '''
        Returns a 2-D histogram indicating the number of earthquakes in a
        set of time-magnitude bins. Time is in decimal years!

        :param numpy.ndarray magnitude_bins:
             Bin edges for the magnitudes

        :param numpy.ndarray time_bins:
            Bin edges for the times

        :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:
            2D histogram of events in magnitude-year bins
        '''
        return bootstrap_histogram_2D(self.get_decimal_time(),
                                      self.data['magnitude'],
                                      time_bins,
                                      magnitude_bins,
                                      xsigma=np.zeros(
                                          self.get_number_events()),
                                      ysigma=self.data['sigmaMagnitude'],
                                      normalisation=normalisation,
                                      number_bootstraps=bootstrap)
예제 #3
0
    def test_2D_bootstrap_with_uncertainty(self):
        """
        Tests the bootstrap 1D histrogram function with uncertainties
        """
        # Without normalisation
        self.y_sigma = 0.1 * np.ones(len(self.y), dtype=float)
        x_range = np.arange(0., 60., 10.)
        y_range = np.arange(5., 10., 1.0)
        expected_array = np.array([[1.5, 2.0, 2.0, 1.5],
                                   [3.0, 4.0, 4.0, 3.0],
                                   [3.0, 4.0, 4.0, 3.0],
                                   [3.0, 4.0, 4.0, 3.0],
                                   [3.0, 4.0, 4.0, 3.0]])

        hist_values = utils.bootstrap_histogram_2D(
            self.x,
            self.y,
            x_range,
            y_range,
            normalisation=False,
            xsigma=self.x_sigma,
            ysigma=self.y_sigma,
            number_bootstraps=1000)

        array_diff = expected_array - np.round(hist_values, 1)
        print expected_array, hist_values, array_diff
        self.assertTrue(np.all(np.fabs(array_diff) < 0.2))
        # With normalisation
        expected_array = np.array([[0.04, 0.05, 0.05, 0.04],
                                  [0.05, 0.06, 0.06, 0.05],
                                  [0.05, 0.06, 0.06, 0.05],
                                  [0.05, 0.06, 0.06, 0.05],
                                  [0.04, 0.05, 0.05, 0.04]])

        hist_values = utils.bootstrap_histogram_2D(
            self.x,
            self.y,
            x_range,
            y_range,
            normalisation=True,
            xsigma=self.x_sigma,
            ysigma=self.y_sigma,
            number_bootstraps=1000)
        array_diff = expected_array - hist_values
        self.assertTrue(np.all(np.fabs(array_diff) < 0.02))
예제 #4
0
    def test_2D_bootstrap_with_uncertainty(self):
        """
        Tests the bootstrap 1D histrogram function with uncertainties
        """
        # Without normalisation
        self.y_sigma = 0.1 * np.ones(len(self.y), dtype=float)
        x_range = np.arange(0., 60., 10.)
        y_range = np.arange(5., 10., 1.0)
        expected_array = np.array([[1.5, 2.0, 2.0, 1.5],
                                   [3.0, 4.0, 4.0, 3.0],
                                   [3.0, 4.0, 4.0, 3.0],
                                   [3.0, 4.0, 4.0, 3.0],
                                   [3.0, 4.0, 4.0, 3.0]])

        hist_values = utils.bootstrap_histogram_2D(
            self.x,
            self.y,
            x_range,
            y_range,
            normalisation=False,
            xsigma=self.x_sigma,
            ysigma=self.y_sigma,
            number_bootstraps=1000)

        array_diff = expected_array - np.round(hist_values, 1)
        print expected_array, hist_values, array_diff
        self.assertTrue(np.all(np.fabs(array_diff) < 0.2))
        # With normalisation
        expected_array = np.array([[0.04, 0.05, 0.05, 0.04],
                                  [0.05, 0.06, 0.06, 0.05],
                                  [0.05, 0.06, 0.06, 0.05],
                                  [0.05, 0.06, 0.06, 0.05],
                                  [0.04, 0.05, 0.05, 0.04]])

        hist_values = utils.bootstrap_histogram_2D(
            self.x,
            self.y,
            x_range,
            y_range,
            normalisation=True,
            xsigma=self.x_sigma,
            ysigma=self.y_sigma,
            number_bootstraps=1000)
        array_diff = expected_array - hist_values
        self.assertTrue(np.all(np.fabs(array_diff) < 0.02))
예제 #5
0
 def test_2D_bootstrap_no_uncertainty(self):
     """
     Tests the bootstrap 1D histrogram function with no uncertainties
     """
     # Without normalisation
     x_range = np.arange(0., 60., 10.)
     y_range = np.arange(5., 10., 1.0)
     expected_array = np.array([[1., 2., 2., 2.],
                                [2., 4., 4., 4.],
                                [2., 4., 4., 4.],
                                [2., 4., 4., 4.],
                                [2., 4., 4., 4.]])
     np.testing.assert_array_almost_equal(expected_array,
         utils.bootstrap_histogram_2D(self.x, self.y, x_range, y_range))
     # With normalisation
     expected_array = expected_array / np.sum(expected_array)
     np.testing.assert_array_almost_equal(expected_array,
         utils.bootstrap_histogram_2D(self.x, self.y, x_range, y_range,
                                      normalisation=True))
예제 #6
0
 def test_2D_bootstrap_no_uncertainty(self):
     """
     Tests the bootstrap 1D histrogram function with no uncertainties
     """
     # Without normalisation
     x_range = np.arange(0., 60., 10.)
     y_range = np.arange(5., 10., 1.0)
     expected_array = np.array([[1., 2., 2., 2.],
                                [2., 4., 4., 4.],
                                [2., 4., 4., 4.],
                                [2., 4., 4., 4.],
                                [2., 4., 4., 4.]])
     np.testing.assert_array_almost_equal(expected_array,
         utils.bootstrap_histogram_2D(self.x, self.y, x_range, y_range))
     # With normalisation
     expected_array = expected_array / np.sum(expected_array)
     np.testing.assert_array_almost_equal(expected_array,
         utils.bootstrap_histogram_2D(self.x, self.y, x_range, y_range,
                                      normalisation=True))
예제 #7
0
    def get_magnitude_depth_distribution(self,
                                         magnitude_bins,
                                         depth_bins,
                                         normalisation=False,
                                         bootstrap=None):
        '''
        Returns a 2-D magnitude-depth histogram for the catalogue

        :param numpy.ndarray magnitude_bins:
             Bin edges for the magnitudes

        :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:
            2D histogram of events in magnitude-depth bins
        '''
        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)

        if len(self.data['sigmaMagnitude']) == 0:
            self.data['sigmaMagnitude'] = np.zeros(self.get_number_events(),
                                                   dtype=float)

        return bootstrap_histogram_2D(self.data['magnitude'],
                                      self.data['depth'],
                                      magnitude_bins,
                                      depth_bins,
                                      boundaries=[(0., None), (None, None)],
                                      xsigma=self.data['sigmaMagnitude'],
                                      ysigma=self.data['depthError'],
                                      normalisation=normalisation,
                                      number_bootstraps=bootstrap)
예제 #8
0
파일: catalogue.py 프로젝트: yetimote/hmtk
    def get_magnitude_depth_distribution(self, magnitude_bins, depth_bins,
                                         normalisation=False, bootstrap=None):
        '''
        Returns a 2-D magnitude-depth histogram for the catalogue

        :param numpy.ndarray magnitude_bins:
             Bin edges for the magnitudes

        :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:
            2D histogram of events in magnitude-depth bins
        '''
        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)

        if len(self.data['sigmaMagnitude']) == 0:
            self.data['sigmaMagnitude'] = np.zeros(self.get_number_events(),
                                                   dtype=float)

        return bootstrap_histogram_2D(self.data['magnitude'],
                                      self.data['depth'],
                                      magnitude_bins,
                                      depth_bins,
                                      boundaries=[(0., None), (None, None)],
                                      xsigma=self.data['sigmaMagnitude'],
                                      ysigma=self.data['depthError'],
                                      normalisation=normalisation,
                                      number_bootstraps=bootstrap)