Ejemplo n.º 1
0
    def test_save_only_nonzero_gmvs(self):
        ses = mock.Mock()

        gmvs = numpy.matrix([[0.0, 0, 1]])
        gmf_dict = {PGA: dict(rupture_ids=[1, 2, 3], gmvs=gmvs)}

        points = make_mock_points(1)
        with helpers.patch('openquake.engine.writer.CacheInserter') as m:
            core._save_gmfs(ses, gmf_dict, points)
            self.assertEqual(1, m.add.call_count)
Ejemplo n.º 2
0
    def test_donot_save_trivial_gmf(self):
        ses = mock.Mock()

        # setup two ground motion fields on a region made by three
        # locations. On the first two locations the values are
        # nonzero, in the third one is zero. Then, we will expect the
        # cache inserter to add only two entries.
        gmvs = numpy.matrix([[1.0, 1.0], [1.0, 1.0], [0.0, 0.0]])
        gmf_dict = {PGA: dict(rupture_ids=[1, 2], gmvs=gmvs)}
        points = make_mock_points(3)
        with helpers.patch("openquake.engine.writer.CacheInserter") as m:
            core._save_gmfs(ses, gmf_dict, points)
            self.assertEqual(2, m.add.call_count)
Ejemplo n.º 3
0
    def test_save_only_nonzero_gmvs(self):
        gmf_set = mock.Mock()

        gmvs = numpy.matrix([[0.0, 0, 1]])
        gmf_dict = {imt.PGA: dict(rupture_ids=[1, 2, 3], gmvs=gmvs)}

        fake_bulk_inserter = mock.Mock()
        with helpers.patch('openquake.engine.writer.BulkInserter') as m:
            m.return_value = fake_bulk_inserter
            core._save_gmfs(
                gmf_set, gmf_dict, [mock.Mock()], 1)
            call_args = fake_bulk_inserter.add_entry.call_args_list[0][1]
            self.assertEqual([1], call_args['gmvs'])
            self.assertEqual([3], call_args['rupture_ids'])
Ejemplo n.º 4
0
    def test_donot_save_trivial_gmf(self):
        ses = mock.Mock()

        # setup two ground motion fields on a region made by three
        # locations. On the first two locations the values are
        # nonzero, in the third one is zero. Then, we will expect the
        # cache inserter to add only two entries.
        gmvs = numpy.matrix([[1., 1.],
                             [1., 1.],
                             [0., 0.]])
        gmf_dict = {PGA: dict(rupture_ids=[1, 2], gmvs=gmvs)}
        points = make_mock_points(3)
        with helpers.patch('openquake.engine.writer.CacheInserter') as m:
            core._save_gmfs(
                ses, gmf_dict, points)
            self.assertEqual(2, m.add.call_count)
Ejemplo n.º 5
0
    def test_donot_save_trivial_gmf(self):
        gmf_set = mock.Mock()

        # setup two ground motion fields on a region made by three
        # locations. On the first two locations the values are
        # nonzero, in the third one is zero. Then, we will expect the
        # bulk inserter to add only two entries.
        gmvs = numpy.matrix([[1., 1.],
                             [1., 1.],
                             [0., 0.]])
        gmf_dict = {imt.PGA: dict(rupture_ids=[1, 2], gmvs=gmvs)}

        fake_bulk_inserter = mock.Mock()
        with helpers.patch('openquake.engine.writer.BulkInserter') as m:
            m.return_value = fake_bulk_inserter
            core._save_gmfs(
                gmf_set, gmf_dict, [mock.Mock(), mock.Mock(), mock.Mock()], 1)
            self.assertEqual(2, fake_bulk_inserter.add_entry.call_count)