当前位置: 首页>>代码示例>>Python>>正文


Python site.SiteCollection类代码示例

本文整理汇总了Python中openquake.hazardlib.site.SiteCollection的典型用法代码示例。如果您正苦于以下问题:Python SiteCollection类的具体用法?Python SiteCollection怎么用?Python SiteCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SiteCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_sites

    def test_from_sites(self):
        s1 = Site(location=Point(10, 20, 30),
                  vs30=1.2, vs30measured=True,
                  z1pt0=3.4, z2pt5=5.6, backarc=True)
        s2 = Site(location=Point(-1.2, -3.4, -5.6),
                  vs30=55.4, vs30measured=False,
                  z1pt0=66.7, z2pt5=88.9, backarc=False)
        cll = SiteCollection([s1, s2])
        self.assertTrue((cll.vs30 == [1.2, 55.4]).all())
        self.assertTrue((cll.vs30measured == [True, False]).all())
        self.assertTrue((cll.z1pt0 == [3.4, 66.7]).all())
        self.assertTrue((cll.z2pt5 == [5.6, 88.9]).all())
        self.assertTrue((cll.mesh.lons == [10, -1.2]).all())
        self.assertTrue((cll.mesh.lats == [20, -3.4]).all())
        self.assertTrue((cll.backarc == [True, False]).all())
        self.assertIs(cll.mesh.depths, None)
        for arr in (cll.vs30, cll.z1pt0, cll.z2pt5):
            self.assertIsInstance(arr, numpy.ndarray)
            self.assertEqual(arr.flags.writeable, False)
            self.assertEqual(arr.dtype, float)
        for arr in (cll.vs30measured, cll.backarc):
            self.assertIsInstance(arr, numpy.ndarray)
            self.assertEqual(arr.flags.writeable, False)
            self.assertEqual(arr.dtype, bool)
        self.assertEqual(len(cll), 2)

        # test __toh5__ and __fromh5__
        array, attrs = cll.__toh5__()
        newcll = cll.__new__(cll.__class__)
        newcll.__fromh5__(array, attrs)
        self.assertEqual(newcll, cll)
开发者ID:HadiGhofrani,项目名称:oq-hazardlib,代码行数:31,代码来源:site_test.py

示例2: test_within_region

 def test_within_region(self):
     region = wkt.loads('POLYGON((0 0, 9 0, 9 9, 0 9, 0 0))')
     col = SiteCollection(self.SITES)
     reducedcol = col.within(region)
     # point (10, 20) is out, point (11, 12) is out, point (0, 2)
     # is on the boundary i.e. out, (1, 1) is in
     self.assertEqual(len(reducedcol), 1)
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:7,代码来源:site_test.py

示例3: test_expand_1d

 def test_expand_1d(self):
     col = SiteCollection(self.SITES)
     col = col.filter(numpy.array([1, 0, 1, 1]))
     data_condensed = numpy.array([5, 6, 7])
     data_expanded = col.expand(data_condensed, placeholder=100)
     data_expanded_expected = numpy.array([5, 100, 6, 7])
     numpy.testing.assert_array_equal(data_expanded, data_expanded_expected)
开发者ID:amirj700,项目名称:oq-hazardlib,代码行数:7,代码来源:site_test.py

示例4: test_depths_go_to_zero

    def test_depths_go_to_zero(self):
        # Depth information is meant to be discarded when a site collection is
        # created.
        s1 = Site(location=Point(10, 20, 30),
                  vs30=1.2, vs30measured=True,
                  z1pt0=3.4, z2pt5=5.6)
        s2 = Site(location=Point(-1.2, -3.4, -5.6),
                  vs30=55.4, vs30measured=False,
                  z1pt0=66.7, z2pt5=88.9)
        cll = SiteCollection([s1, s2])

        cll_sites = list(cll)
        exp_s1 = Site(location=Point(10, 20, 0.0),
                      vs30=1.2, vs30measured=True,
                      z1pt0=3.4, z2pt5=5.6)
        exp_s2 = Site(location=Point(-1.2, -3.4, 0.0),
                      vs30=55.4, vs30measured=False,
                      z1pt0=66.7, z2pt5=88.9)

        for i, s in enumerate([exp_s1, exp_s2]):
            self.assertEqual(s, cll_sites[i])

        # test equality of site collections
        sc = SiteCollection([exp_s1, exp_s2])
        self.assertEqual(cll, sc)

        # test nonequality of site collections
        # (see https://github.com/gem/oq-hazardlib/pull/403)
        sc._vs30 = numpy.array([numpy.nan, numpy.nan])
        self.assertNotEqual(cll, sc)
开发者ID:amirj700,项目名称:oq-hazardlib,代码行数:30,代码来源:site_test.py

示例5: test_expand_no_filtering

 def test_expand_no_filtering(self):
     col = SiteCollection(self.SITES)
     data_condensed = numpy.array([3, 2, 1, 0])
     data_expanded = col.expand(data_condensed, total_sites=4,
                                placeholder=100)
     data_expanded_expected = data_condensed
     numpy.testing.assert_array_equal(data_expanded, data_expanded_expected)
开发者ID:MaksimEritov,项目名称:oq-hazardlib,代码行数:7,代码来源:site_test.py

示例6: test_filter

    def test_filter(self):
        col = SiteCollection(self.SITES)
        filtered = col.filter(numpy.array([True, False, True, False]))
        arreq = numpy.testing.assert_array_equal
        arreq(filtered.vs30, [1.2, 2])
        arreq(filtered.vs30measured, [True, True])
        arreq(filtered.z1pt0, [3, 9])
        arreq(filtered.z2pt5, [5, 17])
        arreq(filtered.mesh.lons, [10, 0])
        arreq(filtered.mesh.lats, [20, 2])
        arreq(filtered.mesh.depths, [30, 0])
        arreq(filtered.sids, [0, 2])

        filtered = col.filter(numpy.array([False, True, True, True]))
        arreq(filtered.vs30, [55.4, 2, 4])
        arreq(filtered.vs30measured, [False, True, False])
        arreq(filtered.z1pt0, [6, 9, 22])
        arreq(filtered.z2pt5, [8, 17, 11])
        arreq(filtered.mesh.lons, [11, 0, 1])
        arreq(filtered.mesh.lats, [12, 2, 1])
        arreq(filtered.mesh.depths, [13, 0, 3])

        # test serialization to hdf5
        fd, fpath = tempfile.mkstemp(suffix='.hdf5')
        os.close(fd)
        with hdf5.File(fpath, 'w') as f:
            f['sitecol'] = filtered
            saved = f['sitecol']
            self.assertEqual(saved, filtered)
        os.remove(fpath)
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:30,代码来源:site_test.py

示例7: test_split

    def test_split(self):
        col = SiteCollection(self.SITES)
        close_sites, far_sites = col.split(Point(10, 19), distance=200)
        self.assertEqual(len(close_sites), 1)
        self.assertEqual(len(far_sites), 3)

        close_sites, far_sites = col.split(Point(10, 19), distance=0)
        self.assertIsNone(close_sites)
        self.assertEqual(len(far_sites), 4)

        close_sites, far_sites = col.split(Point(10, 19), distance=None)
        self.assertEqual(len(close_sites), 4)
        self.assertIsNone(far_sites)
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:13,代码来源:site_test.py

示例8: test_expand_2d

 def test_expand_2d(self):
     col = SiteCollection(self.SITES).filter(numpy.array([False, True, False, True]))
     data_condensed = numpy.array([
         [1, 2, 3],
         [5, 6, 7],
     ])
     data_expanded = col.expand(data_condensed, placeholder=-1)
     data_expanded_expected = numpy.array([
         [-1, -1, -1],
         [1, 2, 3],
         [-1, -1, -1],
         [5, 6, 7],
     ])
     numpy.testing.assert_array_equal(data_expanded, data_expanded_expected)
开发者ID:lorcangallagher,项目名称:oq-hazardlib,代码行数:14,代码来源:site_test.py

示例9: test_double_filter

 def test_double_filter(self):
     col = SiteCollection(self.SITES)
     filtered = col.filter(numpy.array([True, False, True, True]))
     filtered2 = filtered.filter(numpy.array([False, True, False]))
     arreq = numpy.testing.assert_array_equal
     arreq(filtered2.vs30, [2])
     arreq(filtered2.vs30measured, [True])
     arreq(filtered2.z1pt0, [9])
     arreq(filtered2.z2pt5, [17])
     arreq(filtered2.mesh.lons, [0])
     arreq(filtered2.mesh.lats, [2])
     arreq(filtered2.mesh.depths, [0])
     filtered2 = filtered.filter(numpy.array([True, False, True]))
     arreq(filtered2.vs30, [1.2, 4.])
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:14,代码来源:site_test.py

示例10: filter_hanging_wall

    def filter_hanging_wall(self, filter_type=None):
        """
        Opt to consider only hanging wall or footwall sites 

        """
        if not filter_type:
            # Considers both footwall and hanging wall 
            return self.target_sites
        elif not filter_type in ['HW', 'FW']:
            raise ValueError('Hanging wall filter must be either "HW" or "FW"')
        else:
            pass

        # Gets the Rx distance
        r_x = self.surface.get_rx_distance(self.target_sites.mesh)
        selected_sites = []
        if filter_type == "HW":
            # Only hanging wall
            idx = np.where(r_x >= 0.)[0]
        else:
            # Only footwall
            idx = np.where(r_x < 0.)[0]
        for val in idx:
            selected_sites.append(self.target_sites.sites[val])
        self.target_sites = SiteCollection(selected_sites)
        return self.target_sites
开发者ID:luisera,项目名称:gmpe-smtk,代码行数:26,代码来源:configure.py

示例11: test_from_points

    def test_from_points(self):
        lons = [10, -1.2]
        lats = [20, -3.4]
        cll = SiteCollection.from_points(lons, lats, [1, 2], SiteModelParam())
        assert_eq(cll.vs30, [1.2, 1.2])
        assert_eq(cll.vs30measured, [True, True])
        assert_eq(cll.z1pt0, [3.4, 3.4])
        assert_eq(cll.z2pt5, [5.6, 5.6])
        assert_eq(cll.mesh.lons, [10, -1.2])
        assert_eq(cll.mesh.lats, [20, -3.4])
        assert_eq(cll.mesh.depths, None)
        assert_eq(cll.backarc, [False, False])

        for arr in (cll.vs30, cll.z1pt0, cll.z2pt5):
            self.assertIsInstance(arr, numpy.ndarray)
            self.assertEqual(arr.dtype, float)
        for arr in (cll.vs30measured, cll.backarc):
            self.assertIsInstance(arr, numpy.ndarray)
            self.assertEqual(arr.flags.writeable, False)
            self.assertEqual(arr.dtype, bool)
        self.assertEqual(len(cll), 2)

        # test split_in_tiles
        tiles = cll.split_in_tiles(0)
        self.assertEqual(len(tiles), 1)

        tiles = cll.split_in_tiles(1)
        self.assertEqual(len(tiles), 1)

        tiles = cll.split_in_tiles(2)
        self.assertEqual(len(tiles), 2)
开发者ID:amirj700,项目名称:oq-hazardlib,代码行数:31,代码来源:site_test.py

示例12: _append_target_sites

 def _append_target_sites(self, distances, azimuth, origin_location, vs30,
                          line_azimuth=90., origin_point=(0.5, 0.5),
                          as_log=False,  vs30measured=True, z1pt0=None,
                          z2pt5=None, backarc=False):
     """
     Appends the target sites along a line with respect to the rupture,
     given an already set origin target site
     """
     for offset in distances:
         target_loc = origin_location.point_at(offset, 0., azimuth)
         self.target_sites.append(Site(target_loc,
                                       vs30,
                                       z1pt0,
                                       z2pt5,
                                       vs30measured=vs30measured,
                                       backarc=backarc))
     self.target_sites_config = {
         "TYPE": "Line",
         "RMAX": distances[-1],
         "SPACING": np.nan if len(distances) < 2 else
         distances[1] - distances[0],  # FIXME does it make sense?
         "AZIMUTH": line_azimuth,
         "ORIGIN": origin_point,
         "AS_LOG": as_log,
         "VS30": vs30,
         "VS30MEASURED": vs30measured,
         "Z1.0": z1pt0,
         "Z2.5": z2pt5,
         "BACKARC": backarc}
     self.target_sites = SiteCollection(self.target_sites)
     return self.target_sites
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:31,代码来源:configure.py

示例13: test_from_points

    def test_from_points(self):
        lons = [10, -1.2]
        lats = [20, -3.4]
        depths = [30, -5.6]
        req_params = 'vs30 vs30measured z1pt0 z2pt5 backarc'.split()
        cll = SiteCollection.from_points(
            lons, lats, depths, SiteModelParam(), req_params)
        assert_eq(cll.vs30, [1.2, 1.2])
        assert_eq(cll.vs30measured, [True, True])
        assert_eq(cll.z1pt0, [3.4, 3.4])
        assert_eq(cll.z2pt5, [5.6, 5.6])
        assert_eq(cll.mesh.lons, [10, -1.1999999999999886])
        assert_eq(cll.mesh.lats, [20, -3.4])
        assert_eq(cll.mesh.depths, [30, -5.6])
        assert_eq(cll.backarc, [False, False])

        for arr in (cll.vs30, cll.z1pt0, cll.z2pt5):
            self.assertIsInstance(arr, numpy.ndarray)
            self.assertEqual(arr.dtype, float)
        for arr in (cll.vs30measured, cll.backarc):
            self.assertIsInstance(arr, numpy.ndarray)
            self.assertEqual(arr.dtype, bool)
        self.assertEqual(len(cll), 2)

        # test split_in_tiles
        tiles = cll.split_in_tiles(0)
        self.assertEqual(len(tiles), 1)

        tiles = cll.split_in_tiles(1)
        self.assertEqual(len(tiles), 1)

        tiles = cll.split_in_tiles(2)
        self.assertEqual(len(tiles), 2)
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:33,代码来源:site_test.py

示例14: get_target_sites_line

    def get_target_sites_line(self, maximum_distance, spacing, vs30,
            line_azimuth=90., origin_point=(0.5, 0.5), vs30measured=True,
            z1pt0=None, z2pt5=None):
        """
        Defines the target sites along a line with respect to the rupture
        """
        azimuth, origin_point, z1pt0, z2pt5 = _setup_site_peripherals(
            line_azimuth,
            origin_point,
            vs30,
            z1pt0,
            z2pt5,
            self.strike,
            self.surface)

        targets = [origin_point]
        self.target_sites = []
        distance = 0.
        cum_dist = distance + spacing
        while distance < maximum_distance:
            target_loc= origin_point.point_at(cum_dist, 0., azimuth)
            # Get Rupture distance
            temp_mesh = Mesh(np.array(target_loc.longitude),
                             np.array(target_loc.latitude),
                             np.array(target_loc.depth))
            distance = self.surface.get_min_distance(temp_mesh)
            self.target_sites.append(Site(target_loc, 
                                          vs30, 
                                          vs30measured, 
                                          z1pt0,
                                          z2pt5))
            cum_dist += spacing
        self.target_sites = SiteCollection(self.target_sites)
        return self.target_sites
开发者ID:luisera,项目名称:gmpe-smtk,代码行数:34,代码来源:configure.py

示例15: test_normal

 def test_normal(self):
     lons = [10, -1.2]
     lats = [20, -3.4]
     maximum_distance = {"Subduction IntraSlab": 200}
     sitecol = SiteCollection.from_points(lons, lats, SiteModelParam())
     tile = Tile(sitecol, maximum_distance)
     self.assertEqual(repr(tile), "<Tile -1 <= lon <= 10, -3 <= lat <= 20>")
     src = make_point_source(1, 10)
     self.assertTrue(src in tile)
开发者ID:treviallen,项目名称:oq-hazardlib,代码行数:9,代码来源:site_test.py


注:本文中的openquake.hazardlib.site.SiteCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。