Пример #1
0
    def test_hdistance(self):
        """Expected values are taken from OpenSHA,
        org.opensha.commons.geo.LocationUtilsTest.testHorzDistance."""

        site1 = shapes.Site(0.0, 90.0)
        site2 = shapes.Site(20.4, 32.6)
        site3 = shapes.Site(20.0, 32.4)
        site4 = shapes.Site(0.0, -90.0)
        site5 = shapes.Site(20.2, 32.0)
        site6 = shapes.Site(20.6, 32.2)

        test = lambda result, site1, site2: self.assertAlmostEqual(
            result, shapes.hdistance(site1.latitude, site1.longitude,
                                     site2.latitude, site2.longitude),
            places=6)
        test(6382.5960025, site1, site2)
        test(6404.835013, site3, site1)
        test(13565.796382, site5, site4)
        test(13588.035392, site4, site6)
        test(43.6090311, site2, site3)
        test(48.2790582, site2, site6)
        test(69.3145862, site2, site5)
        test(60.6198752, site3, site6)
        test(48.2952067, site5, site3)
        test(43.7518411, site5, site6)
Пример #2
0
    def test_hdistance(self):
        """Expected values are taken from OpenSHA,
        org.opensha.commons.geo.LocationUtilsTest.testHorzDistance."""

        site1 = shapes.Site(0.0, 90.0)
        site2 = shapes.Site(20.4, 32.6)
        site3 = shapes.Site(20.0, 32.4)
        site4 = shapes.Site(0.0, -90.0)
        site5 = shapes.Site(20.2, 32.0)
        site6 = shapes.Site(20.6, 32.2)

        test = lambda result, site1, site2: self.assertAlmostEqual(
            result,
            shapes.hdistance(site1.latitude, site1.longitude, site2.latitude,
                             site2.longitude),
            places=6)
        test(6382.5960025, site1, site2)
        test(6404.835013, site3, site1)
        test(13565.796382, site5, site4)
        test(13588.035392, site4, site6)
        test(43.6090311, site2, site3)
        test(48.2790582, site2, site6)
        test(69.3145862, site2, site5)
        test(60.6198752, site3, site6)
        test(48.2952067, site5, site3)
        test(43.7518411, site5, site6)
Пример #3
0
def _distgen(site, lat_bin_edges, lon_bin_edges, distance_bin_edges,
             nlat, nlon, nmag, neps, ntrt, ndist):
    """
    Common part of the code for all extractors that compute distances.
    """
    slat = site.latitude
    slon = site.longitude
    enumeration = ((i, j, k, l, m)
                   for i in xrange(nlat - 1)
                   for j in xrange(nlon - 1)
                   for k in xrange(nmag - 1)
                   for l in xrange(neps - 1)
                   for m in xrange(ntrt))
    for i, j, k, l, m in enumeration:
        meanlat = (lat_bin_edges[i] + lat_bin_edges[i + 1]) / 2
        meanlon = (lon_bin_edges[j] + lon_bin_edges[j + 1]) / 2
        dist = hdistance(meanlat, meanlon, slat, slon)
        if dist < distance_bin_edges[0] \
                or dist > distance_bin_edges[-1]:
            continue
        ii = 0
        for ii in xrange(ndist - 1):
            if dist >= distance_bin_edges[ii] \
                    and dist < distance_bin_edges[ii + 1]:
                break
        yield i, j, k, l, m, ii
Пример #4
0
def _distgen(site, lat_bin_edges, lon_bin_edges, distance_bin_edges, nlat,
             nlon, nmag, neps, ntrt, ndist):
    """
    Common part of the code for all extractors that compute distances.
    """
    slat = site.latitude
    slon = site.longitude
    enumeration = ((i, j, k, l, m) for i in xrange(nlat - 1)
                   for j in xrange(nlon - 1) for k in xrange(nmag - 1)
                   for l in xrange(neps - 1) for m in xrange(ntrt))
    for i, j, k, l, m in enumeration:
        meanlat = (lat_bin_edges[i] + lat_bin_edges[i + 1]) / 2
        meanlon = (lon_bin_edges[j] + lon_bin_edges[j + 1]) / 2
        dist = hdistance(meanlat, meanlon, slat, slon)
        if dist < distance_bin_edges[0] \
                or dist > distance_bin_edges[-1]:
            continue
        ii = 0
        for ii in xrange(ndist - 1):
            if dist >= distance_bin_edges[ii] \
                    and dist < distance_bin_edges[ii + 1]:
                break
        yield i, j, k, l, m, ii