コード例 #1
0
    def test_get_3d_grid(self):
        '''
        Tests the module to count the events in a 3D grid
        '''
        comp_table = np.array([[1960., 4.0]])
        self.catalogue = Catalogue()
        self.catalogue.data['longitude'] = np.hstack([
            np.arange(35., 41.0, 1.0),
            np.arange(35., 41.0, 1.0)])
        self.catalogue.data['latitude'] = np.hstack([
            np.arange(40., 46.0, 1.0),
            np.arange(40., 46.0, 1.0)])
        self.catalogue.data['depth'] = np.hstack([10.0 * np.ones(6),
                                                  30.0 * np.ones(6)])
        self.catalogue.data['magnitude'] = 4.5 * np.ones(12)
        self.catalogue.data['year'] = 1990. * np.ones(12)


        # Case 1 - one depth layer
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40.0, 45., 0.5, 0., 40., 40.])
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        [gx, gy] = np.meshgrid(np.arange(35.25, 40., 0.5),
                               np.arange(40.25, 45., 0.5))
        ngp = np.shape(gx)[0]  * np.shape(gy)[1]
        gx = np.reshape(gx, [ngp, 1])
        gy = np.reshape(gy, [ngp, 1])
        gz = 20. * np.ones(ngp)
        expected_count = np.zeros(ngp, dtype=float)
        expected_count[[9, 28, 46, 64, 82, 90]] = 2.0
        expected_result = np.column_stack([gx, np.flipud(gy), gz,
                                           expected_count])
        self.model.create_3D_grid(self.catalogue, comp_table)
        np.testing.assert_array_almost_equal(expected_result, self.model.data)

        # Case 2 - multiple depth layers
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40., 45., 0.5, 0., 40., 20.])
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        expected_result = np.vstack([expected_result, expected_result])
        expected_count = np.zeros(200)
        expected_count[[9, 28, 46, 64, 82, 90,
            109, 128, 146, 164, 182, 190]] = 1.0
        expected_result[:, -1] = expected_count
        expected_result[:, 2] = np.hstack([10. * np.ones(100),
                                           30. * np.ones(100)])
        self.model.create_3D_grid(self.catalogue, comp_table)
        np.testing.assert_array_almost_equal(expected_result, self.model.data)
コード例 #2
0
    def test_get_2d_grid(self):
        '''
        Tests the module to count the events across a grid
        '''
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40., 45.0, 0.5, 0., 40., 20.])
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        # Case 1 - all events in grid (including borderline cases)
        comp_table = np.array([[1960., 4.0]])
        lons = np.arange(35.0, 41.0, 1.0)
        lats = np.arange(40.0, 46.0, 1.0)
        mags = 5.0 * np.ones(6)
        years = 2000. * np.ones(6)
        expected_result = np.zeros(100, dtype=int)
        expected_result[[9, 28, 46, 64, 82, 90]] = 1
        np.testing.assert_array_almost_equal(
            expected_result,
            self.model.create_2D_grid_simple(lons, lats, years, mags,
                                             comp_table))
        self.assertEqual(np.sum(expected_result), 6)

        # Case 2 - some events outside grid
        lons = np.arange(35.0, 42.0, 1.0)
        lats = np.arange(40.0, 47.0, 1.0)
        mags = 5.0 * np.ones(7)
        years = 2000. * np.ones(7)
        np.testing.assert_array_almost_equal(
            expected_result,
            self.model.create_2D_grid_simple(lons, lats, years, mags,
                                             comp_table))
        self.assertEqual(np.sum(expected_result), 6)
コード例 #3
0
    def test_instantiation(self):
        '''
        Tests the instantiation of the class
        '''
        # Test 1: Good Grid Limits
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40., 45.0, 0.5, 0., 40., 20.])
        expected_dict = {
            'beta': None,
            'bval': None,
            'catalogue': None,
            'data': None,
            'grid': None,
            'grid_limits': {
                'xmax': 40.0,
                'xmin': 35.0,
                'xspc': 0.5,
                'ymax': 45.0,
                'ymin': 40.0,
                'yspc': 0.5,
                'zmax': 40.0,
                'zmin': 0.0,
                'zspc': 20.0
            },
            'kernel': None,
            'use_3d': False
        }

        self.model = SmoothedSeismicity(self.grid_limits)
        self.assertDictEqual(self.model.__dict__, expected_dict)
        # Test 2 - with b-value set
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        expected_dict['bval'] = 1.0
        expected_dict['beta'] = np.log(10.)
        self.assertDictEqual(self.model.__dict__, expected_dict)
コード例 #4
0
    def test_get_2d_grid(self):
        '''
        Tests the module to count the events across a grid
        '''
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40., 45.0, 0.5, 0., 40., 20.])
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        # Case 1 - all events in grid (including borderline cases)
        comp_table = np.array([[1960., 4.0]])
        lons = np.arange(35.0, 41.0, 1.0)
        lats = np.arange(40.0, 46.0, 1.0)
        mags = 5.0 * np.ones(6)
        years = 2000. * np.ones(6)
        expected_result = np.zeros(100, dtype=int)
        expected_result[[9, 28, 46, 64, 82, 90]] = 1
        np.testing.assert_array_almost_equal(expected_result,
            self.model.create_2D_grid_simple(lons, lats, years, mags,
                                             comp_table))
        self.assertEqual(np.sum(expected_result), 6)

        # Case 2 - some events outside grid
        lons = np.arange(35.0, 42.0, 1.0)
        lats = np.arange(40.0, 47.0, 1.0)
        mags = 5.0 * np.ones(7)
        years = 2000. * np.ones(7)
        np.testing.assert_array_almost_equal(expected_result,
            self.model.create_2D_grid_simple(lons, lats, years, mags,
                                             comp_table))
        self.assertEqual(np.sum(expected_result), 6)
コード例 #5
0
    def test_instantiation(self):
        '''
        Tests the instantiation of the class
        '''
        # Test 1: Good Grid Limits
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40., 45.0, 0.5, 0., 40., 20.])
        expected_dict = {'beta': None,
                         'bval': None,
                         'catalogue': None,
                         'data': None,
                         'grid': None,
                         'grid_limits': {'xmax': 40.0,
                                         'xmin': 35.0,
                                         'xspc': 0.5,
                                         'ymax': 45.0,
                                         'ymin': 40.0,
                                         'yspc': 0.5,
                                         'zmax': 40.0,
                                         'zmin': 0.0,
                                         'zspc': 20.0},
                         'kernel': None,
                         'use_3d': False}

        self.model = SmoothedSeismicity(self.grid_limits)
        self.assertDictEqual(self.model.__dict__, expected_dict)
        # Test 2 - with b-value set
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        expected_dict['bval'] = 1.0
        expected_dict['beta'] = np.log(10.)
        self.assertDictEqual(self.model.__dict__, expected_dict)
コード例 #6
0
    def test_get_3d_grid(self):
        '''
        Tests the module to count the events in a 3D grid
        '''
        comp_table = np.array([[1960., 4.0]])
        self.catalogue = Catalogue()
        self.catalogue.data['longitude'] = np.hstack(
            [np.arange(35., 41.0, 1.0),
             np.arange(35., 41.0, 1.0)])
        self.catalogue.data['latitude'] = np.hstack(
            [np.arange(40., 46.0, 1.0),
             np.arange(40., 46.0, 1.0)])
        self.catalogue.data['depth'] = np.hstack(
            [10.0 * np.ones(6), 30.0 * np.ones(6)])
        self.catalogue.data['magnitude'] = 4.5 * np.ones(12)
        self.catalogue.data['year'] = 1990. * np.ones(12)

        # Case 1 - one depth layer
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40.0, 45., 0.5, 0., 40., 40.])
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        [gx, gy] = np.meshgrid(np.arange(35.25, 40., 0.5),
                               np.arange(40.25, 45., 0.5))
        ngp = np.shape(gx)[0] * np.shape(gy)[1]
        gx = np.reshape(gx, [ngp, 1])
        gy = np.reshape(gy, [ngp, 1])
        gz = 20. * np.ones(ngp)
        expected_count = np.zeros(ngp, dtype=float)
        expected_count[[9, 28, 46, 64, 82, 90]] = 2.0
        expected_result = np.column_stack(
            [gx, np.flipud(gy), gz, expected_count])
        self.model.create_3D_grid(self.catalogue, comp_table)
        np.testing.assert_array_almost_equal(expected_result, self.model.data)

        # Case 2 - multiple depth layers
        self.grid_limits = Grid.make_from_list(
            [35.0, 40., 0.5, 40., 45., 0.5, 0., 40., 20.])
        self.model = SmoothedSeismicity(self.grid_limits, bvalue=1.0)
        expected_result = np.vstack([expected_result, expected_result])
        expected_count = np.zeros(200)
        expected_count[[9, 28, 46, 64, 82, 90, 109, 128, 146, 164, 182,
                        190]] = 1.0
        expected_result[:, -1] = expected_count
        expected_result[:, 2] = np.hstack(
            [10. * np.ones(100), 30. * np.ones(100)])
        self.model.create_3D_grid(self.catalogue, comp_table)
        np.testing.assert_array_almost_equal(expected_result, self.model.data)
コード例 #7
0
ファイル: widgets.py プロジェクト: gem/qt-experiments
    def on_click(self):
        try:
            ll = float(self.fields['Length_Limit'].widget.text())
            bw = float(self.fields['BandWidth'].widget.text())
            dilate = ll * bw
        except ValueError:
            dilate = 0

        self.grid_dialog.set_grid(
            Grid.make_from_catalogue(self.catalogue, 1, dilate))
        if self.grid_dialog.exec_():
            self.grid = self.grid_dialog.get_grid()
コード例 #8
0
ファイル: widgets.py プロジェクト: gem/qt-experiments
    def get_grid(self):
        table = self.tableWidget

        ret = []

        for row in range(table.rowCount()):
            data = [table.item(row, 0).data(0),
                    table.item(row, 1).data(0),
                    table.item(row, 2).data(0)]

            ret.extend([float(d) for d in data])

        return Grid.make_from_list(ret)
コード例 #9
0
res, spc = 1, 50
#res, spc = 0.2, 250

# model
#[xmin, xmax, spcx, ymin, ymax, spcy, zmin, spcz]
map_config = {
    'min_lon': -95.0,
    'max_lon': -25.0,
    'min_lat': -65.0,
    'max_lat': 25.0,
    'resolution': 'l'
}
#_l = [ 118.5,  124,  res,  20.0,   26.5,  res,    0,   300,   300]
#_l = [ -95.,  -25,  res,  -65,   25,  res,    0,   800,   800]
_l = [-80, -30, res, -37, 13, res, 0, 30, 30]
grid_limits = Grid.make_from_list(_l)

nx = round((_l[1] - _l[0]) / _l[2], 0)
ny = round((_l[4] - _l[3]) / _l[5], 0)
grid_shape = (nx, ny)
print grid_shape
model = SmoothedSeismicity(grid_limits, bvalue=1.0)

# Time-varying completeness
comp_table = np.array([[1980., 3.5], [1970., 4.5], [1960., 5.0]])

if model_name == 'hmtk_sa3':
    comp_table = np.array([[1986, 3.], [1986, 3.5], [1986, 4.], [1960, 4.5],
                           [1958, 5.], [1958, 5.5], [1927, 6.], [1898, 6.5],
                           [1885, 7.], [1885, 7.5], [1885, 8.]])
else:
コード例 #10
0
ファイル: 07_smoothing.py プロジェクト: preinh/pshab
catalogue.sort_catalogue_chronologically()
# print catalogue.get_number_events()

# res, spc = 0.5, 100
res, spc = 1, 50
# res, spc = 0.2, 250


# model
# [xmin, xmax, spcx, ymin, ymax, spcy, zmin, spcz]
map_config = {"min_lon": -95.0, "max_lon": -25.0, "min_lat": -65.0, "max_lat": 25.0, "resolution": "l"}
# _l = [ 118.5,  124,  res,  20.0,   26.5,  res,    0,   300,   300]
# _l = [ -95.,  -25,  res,  -65,   25,  res,    0,   800,   800]
_l = [-80, -30, res, -37, 13, res, 0, 30, 30]
grid_limits = Grid.make_from_list(_l)

nx = round((_l[1] - _l[0]) / _l[2], 0)
ny = round((_l[4] - _l[3]) / _l[5], 0)
grid_shape = (nx, ny)
print grid_shape
model = SmoothedSeismicity(grid_limits, bvalue=1.0)

# Time-varying completeness
comp_table = np.array([[1980.0, 3.5], [1970.0, 4.5], [1960.0, 5.0]])


if model_name == "hmtk_sa3":
    comp_table = np.array(
        [
            [1986, 3.0],