コード例 #1
0
    def _test(self, mlons, mlats, mdepths, slons, slats, sdepths,
              expected_mpoint_indices):
        mlons, mlats, mdepths = [numpy.array(arr, float)
                                 for arr in (mlons, mlats, mdepths)]
        slons, slats, sdepths = [numpy.array(arr, float)
                                 for arr in (slons, slats, sdepths)]
        actual_indices = geodetic.min_distance(mlons, mlats, mdepths,
                                               slons, slats, sdepths,
                                               indices=True)
        numpy.testing.assert_equal(actual_indices, expected_mpoint_indices)
        dists = geodetic.min_distance(mlons, mlats, mdepths,
                                      slons, slats, sdepths)
        expected_closest_mlons = mlons.flat[expected_mpoint_indices]
        expected_closest_mlats = mlats.flat[expected_mpoint_indices]
        expected_closest_mdepths = mdepths.flat[expected_mpoint_indices]
        expected_distances = geodetic.distance(
            expected_closest_mlons, expected_closest_mlats,
            expected_closest_mdepths,
            slons, slats, sdepths
        )
        self.assertTrue((dists == expected_distances).all())

        # testing min_geodetic_distance with the same lons and lats
        min_geod_distance = geodetic.min_geodetic_distance(mlons, mlats,
                                                           slons, slats)
        min_geo_distance2 = geodetic.min_distance(mlons, mlats, mdepths * 0,
                                                  slons, slats, sdepths * 0)
        numpy.testing.assert_almost_equal(min_geod_distance, min_geo_distance2)
コード例 #2
0
def prefilter_background_model(hdf5,
                               sites,
                               integration_distance,
                               msr=WC1994(),
                               aspect=1.5):
    """
    Identify those points within the integration distance
    :param sites:
        Sites for consideration (can be None!)
    :param float integration_distance:
        Maximum distance from rupture to site for consideration
    :param msr:
        Magnitude scaling relation
    :param float aspect:
        Aspect ratio
    :returns:
        Boolean vector indicating if sites are within (True) or outside (False)
        the integration distance
    """
    bg_locations = hdf5["Grid/Locations"][:].astype("float64")
    n_locations = bg_locations.shape[0]
    if not sites:
        # Apply no filtering - all sources valid
        return numpy.ones(n_locations, dtype=bool)
    distances = min_distance(sites.lons, sites.lats,
                             numpy.zeros_like(sites.lons), bg_locations[:, 0],
                             bg_locations[:, 1], numpy.zeros(n_locations))
    # Add buffer equal to half of length of median area from Mmax
    mmax_areas = msr.get_median_area(hdf5["Grid/MMax"][:], 0.0)
    mmax_lengths = numpy.sqrt(mmax_areas / aspect)
    return distances <= (0.5 * mmax_lengths + integration_distance)
コード例 #3
0
def prefilter_background_model(hdf5, branch_key, sites, integration_distance,
                               msr=WC1994(), aspect=1.5):
    """
    Identify those points within the integration distance
    :param sites:
        Sites for consideration (can be None!)
    :param float integration_distance:
        Maximum distance from rupture to site for consideration
    :param msr:
        Magnitude scaling relation
    :param float aspect:
        Aspect ratio
    :returns:
        Boolean vector indicating if sites are within (True) or outside (False)
        the integration distance
    """
    bg_locations = hdf5["Grid/Locations"][:].astype("float64")
    n_locations = bg_locations.shape[0]
    if not sites:
        # Apply no filtering - all sources valid
        return numpy.ones(n_locations, dtype=bool)
    distances = min_distance(sites.lons, sites.lats,
                             numpy.zeros_like(sites.lons),
                             bg_locations[:, 0],
                             bg_locations[:, 1],
                             numpy.zeros(n_locations))
    # Add buffer equal to half of length of median area from Mmax
    mmax_areas = msr.get_median_area(
        hdf5["/".join(["Grid", branch_key, "MMax"])][:], 0.0)
    mmax_lengths = numpy.sqrt(mmax_areas / aspect)
    return distances <= (0.5 * mmax_lengths + integration_distance)
コード例 #4
0
ファイル: mesh.py プロジェクト: krisvanneste/oq-hazardlib
 def _geodetic_min_distance(self, mesh, indices):
     """
     Wrapper around :func:`openquake.hazardlib.geo.geodetic.min_distance`
     for two meshes: either (or both, or neither) can have empty depths.
     """
     if self.depths is None:
         depths1 = numpy.zeros_like(self.lons)
     else:
         depths1 = self.depths
     if mesh.depths is None:
         depths2 = numpy.zeros_like(mesh.lons)
     else:
         depths2 = mesh.depths
     return geodetic.min_distance(self.lons, self.lats, depths1, mesh.lons, mesh.lats, depths2, indices)
コード例 #5
0
ファイル: mesh.py プロジェクト: cbworden/oq-hazardlib
 def _geodetic_min_distance(self, mesh, indices):
     """
     Wrapper around :func:`openquake.hazardlib.geo.geodetic.min_distance`
     for two meshes: either (or both, or neither) can have empty depths.
     """
     if self.depths is None:
         depths1 = numpy.zeros_like(self.lons)
     else:
         depths1 = self.depths
     if mesh.depths is None:
         depths2 = numpy.zeros_like(mesh.lons)
     else:
         depths2 = mesh.depths
     return geodetic.min_distance(self.lons, self.lats, depths1, mesh.lons,
                                  mesh.lats, depths2, indices)