コード例 #1
0
    def test(self):
        mags = numpy.array([4.4, 5, 3.2, 7, 5.9])
        dists = numpy.array([4, 1.2, 3.5, 52.1, 17])
        lats = numpy.array([-25, -10, 0.6, -20, -15])
        lons = numpy.array([179, -179, 176.4, -179.55, 180])
        trts = [0, 1, 2, 2, 1]
        trt_bins = ['foo', 'bar', 'baz']

        # This is ignored by _define_bins, but it is returned by
        # _collect_bins_data so we need to maintain that contract
        probs_no_exceed = None

        bins_data = (mags, dists, lons, lats, trts, trt_bins,
                     probs_no_exceed)

        (mag_bins, dist_bins, lon_bins, lat_bins,  eps_bins, trt_bins_
         ) = disagg._define_bins(
            bins_data, mag_bin_width=1, dist_bin_width=4.2,
            coord_bin_width=1.2, truncation_level=1, n_epsilons=4
        )

        aae = numpy.testing.assert_array_equal
        aaae = numpy.testing.assert_array_almost_equal
        aae(mag_bins, [3, 4, 5, 6, 7])
        aaae(dist_bins, [0., 4.2, 8.4, 12.6, 16.8, 21., 25.2, 29.4, 33.6,
                         37.8, 42., 46.2, 50.4, 54.6])
        aaae(lon_bins, [176.4, 177.6, 178.8, -180., -178.8])
        aaae(lat_bins, [-25.2, -24., -22.8, -21.6, -20.4, -19.2, -18., -16.8,
                        -15.6, -14.4, -13.2, -12., -10.8, -9.6, -8.4, -7.2,
                        -6., -4.8, -3.6, -2.4, -1.2, 0., 1.2])
        aae(eps_bins, [-1., -0.5, 0., 0.5, 1.])
        self.assertIs(trt_bins, trt_bins_)
コード例 #2
0
    def test(self):
        mags = numpy.array([4.4, 5, 3.2, 7, 5.9])
        dists = numpy.array([4, 1.2, 3.5, 52.1, 17])
        lats = numpy.array([-25, -10, 0.6, -20, -15])
        lons = numpy.array([179, -179, 176.4, -179.55, 180])
        trts = [0, 1, 2, 2, 1]
        trt_bins = ['foo', 'bar', 'baz']

        # This is ignored by _define_bins, but it is returned by
        # _collect_bins_data so we need to maintain that contract
        probs_no_exceed = None

        bins_data = (mags, dists, lons, lats, trts, trt_bins,
                     probs_no_exceed)

        (mag_bins, dist_bins, lon_bins, lat_bins,  eps_bins, trt_bins_
         ) = disagg._define_bins(
            bins_data, mag_bin_width=1, dist_bin_width=4.2,
            coord_bin_width=1.2, truncation_level=1, n_epsilons=4
        )

        aae = numpy.testing.assert_array_equal
        aaae = numpy.testing.assert_array_almost_equal
        aae(mag_bins, [3, 4, 5, 6, 7])
        aaae(dist_bins, [0., 4.2, 8.4, 12.6, 16.8, 21., 25.2, 29.4, 33.6,
                         37.8, 42., 46.2, 50.4, 54.6])
        aaae(lon_bins, [176.4, 177.6, 178.8, -180., -178.8])
        aaae(lat_bins, [-25.2, -24., -22.8, -21.6, -20.4, -19.2, -18., -16.8,
                        -15.6, -14.4, -13.2, -12., -10.8, -9.6, -8.4, -7.2,
                        -6., -4.8, -3.6, -2.4, -1.2, 0., 1.2])
        aae(eps_bins, [-1., -0.5, 0., 0.5, 1.])
        self.assertIs(trt_bins, trt_bins_)
コード例 #3
0
ファイル: disagg_test.py プロジェクト: matley/oq-hazardlib
    def test(self):
        mags = numpy.array([4.4, 5, 3.2, 7, 5.9])
        dists = numpy.array([4, 1.2, 3.5, 52.1, 17])
        lats = numpy.array([-25, -10, 0.6, -20, -15])
        lons = numpy.array([179, -179, 176.4, -179.55, 180])
        joint_probs = None
        trts = [0, 1, 2, 2, 1]
        trt_bins = ["foo", "bar", "baz"]

        bins_data = mags, dists, lons, lats, joint_probs, trts, trt_bins

        mag_bins, dist_bins, lon_bins, lat_bins, eps_bins, trt_bins_ = disagg._define_bins(
            bins_data, mag_bin_width=1, dist_bin_width=4.2, coord_bin_width=1.2, truncation_level=1, n_epsilons=4
        )

        aae = numpy.testing.assert_array_equal
        aaae = numpy.testing.assert_array_almost_equal
        aae(mag_bins, [3, 4, 5, 6, 7])
        aaae(dist_bins, [0.0, 4.2, 8.4, 12.6, 16.8, 21.0, 25.2, 29.4, 33.6, 37.8, 42.0, 46.2, 50.4, 54.6])
        aaae(lon_bins, [176.4, 177.6, 178.8, -180.0, -178.8])
        aaae(
            lat_bins,
            [
                -25.2,
                -24.0,
                -22.8,
                -21.6,
                -20.4,
                -19.2,
                -18.0,
                -16.8,
                -15.6,
                -14.4,
                -13.2,
                -12.0,
                -10.8,
                -9.6,
                -8.4,
                -7.2,
                -6.0,
                -4.8,
                -3.6,
                -2.4,
                -1.2,
                0.0,
                1.2,
            ],
        )
        aae(eps_bins, [-1.0, -0.5, 0.0, 0.5, 1.0])
        self.assertIs(trt_bins, trt_bins_)