Exemplo n.º 1
0
    def bins_edges(self, dist_bin_width, coord_bin_width):
        """
        Define bin edges for disaggregation histograms, from the bin data
        collected from the ruptures.

        :param dists:
            array of distances from the ruptures
        :param lons:
            array of longitudes from the ruptures
        :param lats:
            array of latitudes from the ruptures
        :param dist_bin_width:
            distance_bin_width from job.ini
        :param coord_bin_width:
            coordinate_bin_width from job.ini
        """
        dist_edges = dist_bin_width * numpy.arange(
            int(self.min_dist / dist_bin_width),
            int(numpy.ceil(self.max_dist / dist_bin_width) + 1))

        west = numpy.floor(self.west / coord_bin_width) * coord_bin_width
        east = numpy.ceil(self.east / coord_bin_width) * coord_bin_width
        lon_extent = get_longitudinal_extent(west, east)

        lon_edges, _, _ = npoints_between(
            west, 0, 0, east, 0, 0,
            numpy.round(lon_extent / coord_bin_width) + 1)

        lat_edges = coord_bin_width * numpy.arange(
            int(numpy.floor(self.south / coord_bin_width)),
            int(numpy.ceil(self.north / coord_bin_width) + 1))

        return dist_edges, lon_edges, lat_edges
Exemplo n.º 2
0
 def test_topo(self):
     lons, lats, depths = geodetic.npoints_between(lon1=40.77,
                                                   lat1=38.9,
                                                   depth1=2,
                                                   lon2=31.14,
                                                   lat2=46.23,
                                                   depth2=-4,
                                                   npoints=7)
     expected_lons = [
         40.77, 39.316149154562076, 37.8070559966114, 36.23892429550906,
         34.60779411051164, 32.90956020775102, 31.14
     ]
     expected_lats = [
         38.9, 40.174608368560094, 41.43033989236144, 42.66557829138413,
         43.87856696738466, 45.067397797471415, 46.23
     ]
     expected_depths = [2, 1, 0, -1, -2, -3, -4]
     assert_aeq(lons, expected_lons)
     assert_aeq(lats, expected_lats)
     assert_aeq(depths, expected_depths)
     # the last and the first points should be exactly the same as two
     # original corner points, so no "assertAlmostEqual" for them
     self.assertEqual(lons[0], 40.77)
     self.assertEqual(lats[0], 38.9)
     self.assertEqual(depths[0], 2)
     self.assertEqual(lons[-1], 31.14)
     self.assertEqual(lats[-1], 46.23)
     self.assertEqual(depths[-1], -4)
Exemplo n.º 3
0
    def bins_edges(self, dist_bin_width, coord_bin_width):
        """
        Define bin edges for disaggregation histograms, from the bin data
        collected from the ruptures.

        :param dists:
            array of distances from the ruptures
        :param lons:
            array of longitudes from the ruptures
        :param lats:
            array of latitudes from the ruptures
        :param dist_bin_width:
            distance_bin_width from job.ini
        :param coord_bin_width:
            coordinate_bin_width from job.ini
        """
        dist_edges = dist_bin_width * numpy.arange(
            int(self.min_dist / dist_bin_width),
            int(numpy.ceil(self.max_dist / dist_bin_width) + 1))

        west = numpy.floor(self.west / coord_bin_width) * coord_bin_width
        east = numpy.ceil(self.east / coord_bin_width) * coord_bin_width
        lon_extent = get_longitudinal_extent(west, east)

        lon_edges, _, _ = npoints_between(
            west, 0, 0, east, 0, 0,
            numpy.round(lon_extent / coord_bin_width) + 1)

        lat_edges = coord_bin_width * numpy.arange(
            int(numpy.floor(self.south / coord_bin_width)),
            int(numpy.ceil(self.north / coord_bin_width) + 1))

        return dist_edges, lon_edges, lat_edges
Exemplo n.º 4
0
def _define_bins(bins_data, mag_bin_width, dist_bin_width, coord_bin_width, truncation_level, n_epsilons):
    """
    Define bin edges for disaggregation histograms.

    Given bins data as provided by :func:`_collect_bins_data`, this function
    finds edges of histograms, taking into account maximum and minimum values
    of magnitude, distance and coordinates as well as requested sizes/numbers
    of bins.
    """
    mags, dists, lons, lats, tect_reg_types, trt_bins, _ = bins_data

    mag_bins = mag_bin_width * numpy.arange(
        int(numpy.floor(mags.min() / mag_bin_width)), int(numpy.ceil(mags.max() / mag_bin_width) + 1)
    )

    dist_bins = dist_bin_width * numpy.arange(
        int(numpy.floor(dists.min() / dist_bin_width)), int(numpy.ceil(dists.max() / dist_bin_width) + 1)
    )

    west, east, north, south = get_spherical_bounding_box(lons, lats)
    west = numpy.floor(west / coord_bin_width) * coord_bin_width
    east = numpy.ceil(east / coord_bin_width) * coord_bin_width
    lon_extent = get_longitudinal_extent(west, east)
    lon_bins, _, _ = npoints_between(west, 0, 0, east, 0, 0, numpy.round(lon_extent / coord_bin_width + 1))

    lat_bins = coord_bin_width * numpy.arange(
        int(numpy.floor(south / coord_bin_width)), int(numpy.ceil(north / coord_bin_width) + 1)
    )

    eps_bins = numpy.linspace(-truncation_level, truncation_level, n_epsilons + 1)

    return mag_bins, dist_bins, lon_bins, lat_bins, eps_bins, trt_bins
Exemplo n.º 5
0
def _define_bins(bins_data, mag_bin_width, dist_bin_width, coord_bin_width,
                 truncation_level, n_epsilons):
    """
    Define bin edges for disaggregation histograms.

    Given bins data as provided by :func:`_collect_bins_data`, this function
    finds edges of histograms, taking into account maximum and minimum values
    of magnitude, distance and coordinates as well as requested sizes/numbers
    of bins.
    """
    mags, dists, lons, lats, tect_reg_types, trt_bins, _ = bins_data

    mag_bins = mag_bin_width * numpy.arange(
        int(numpy.floor(mags.min() / mag_bin_width)),
        int(numpy.ceil(mags.max() / mag_bin_width) + 1))

    dist_bins = dist_bin_width * numpy.arange(
        int(numpy.floor(dists.min() / dist_bin_width)),
        int(numpy.ceil(dists.max() / dist_bin_width) + 1))

    west, east, north, south = get_spherical_bounding_box(lons, lats)
    west = numpy.floor(west / coord_bin_width) * coord_bin_width
    east = numpy.ceil(east / coord_bin_width) * coord_bin_width
    lon_extent = get_longitudinal_extent(west, east)
    lon_bins, _, _ = npoints_between(
        west, 0, 0, east, 0, 0, numpy.round(lon_extent / coord_bin_width + 1))

    lat_bins = coord_bin_width * numpy.arange(
        int(numpy.floor(south / coord_bin_width)),
        int(numpy.ceil(north / coord_bin_width) + 1))

    eps_bins = numpy.linspace(-truncation_level, truncation_level,
                              n_epsilons + 1)

    return mag_bins, dist_bins, lon_bins, lat_bins, eps_bins, trt_bins
Exemplo n.º 6
0
 def test(self):
     lons, lats, depths = geodetic.npoints_between(lon1=40.77,
                                                   lat1=38.9,
                                                   depth1=17.5,
                                                   lon2=31.14,
                                                   lat2=46.23,
                                                   depth2=5.2,
                                                   npoints=7)
     expected_lons = [
         40.77, 39.316149154562076, 37.8070559966114, 36.23892429550906,
         34.60779411051164, 32.90956020775102, 31.14
     ]
     expected_lats = [
         38.9, 40.174608368560094, 41.43033989236144, 42.66557829138413,
         43.87856696738466, 45.067397797471415, 46.23
     ]
     expected_depths = [17.5, 15.45, 13.4, 11.35, 9.3, 7.25, 5.2]
     self.assertTrue(numpy.allclose(lons, expected_lons))
     self.assertTrue(numpy.allclose(lats, expected_lats))
     self.assertTrue(numpy.allclose(depths, expected_depths))
     # the last and the first points should be exactly the same as two
     # original corner points, so no "assertAlmostEqual" for them
     self.assertEqual(lons[0], 40.77)
     self.assertEqual(lats[0], 38.9)
     self.assertEqual(depths[0], 17.5)
     self.assertEqual(lons[-1], 31.14)
     self.assertEqual(lats[-1], 46.23)
     self.assertEqual(depths[-1], 5.2)
Exemplo n.º 7
0
 def test_same_points(self):
     lon, lat, depth = 1.2, 3.4, 5.6
     lons, lats, depths = geodetic.npoints_between(
         lon, lat, depth, lon, lat, depth, npoints=7
     )
     expected_lons = [lon] * 7
     expected_lats = [lat] * 7
     expected_depths = [depth] * 7
     self.assertTrue(numpy.allclose(lons, expected_lons))
     self.assertTrue(numpy.allclose(lats, expected_lats))
     self.assertTrue(numpy.allclose(depths, expected_depths))
Exemplo n.º 8
0
 def test_same_points(self):
     lon, lat, depth = 1.2, 3.4, 5.6
     lons, lats, depths = geodetic.npoints_between(
         lon, lat, depth, lon, lat, depth, npoints=7
     )
     expected_lons = [lon] * 7
     expected_lats = [lat] * 7
     expected_depths = [depth] * 7
     assert_aeq(lons, expected_lons)
     assert_aeq(lats, expected_lats)
     assert_aeq(depths, expected_depths)
Exemplo n.º 9
0
 def test_same_points(self):
     lon, lat, depth = 1.2, 3.4, 5.6
     lons, lats, depths = geodetic.npoints_between(
         lon, lat, depth, lon, lat, depth, npoints=7
     )
     expected_lons = [lon] * 7
     expected_lats = [lat] * 7
     expected_depths = [depth] * 7
     assert_aeq(lons, expected_lons)
     assert_aeq(lats, expected_lats)
     assert_aeq(depths, expected_depths)
Exemplo n.º 10
0
def lon_lat_bins(bb, coord_bin_width):
    """
    Define lon, lat bin edges for disaggregation histograms.

    :param bb: bounding box west, south, east, north
    :param coord_bin_width: bin width
    """
    west, south, east, north = bb
    west = numpy.floor(west / coord_bin_width) * coord_bin_width
    east = numpy.ceil(east / coord_bin_width) * coord_bin_width
    lon_extent = get_longitudinal_extent(west, east)
    lon_bins, _, _ = npoints_between(
        west, 0, 0, east, 0, 0, numpy.round(lon_extent / coord_bin_width + 1))
    lat_bins = coord_bin_width * numpy.arange(
        int(numpy.floor(south / coord_bin_width)),
        int(numpy.ceil(north / coord_bin_width) + 1))
    return lon_bins, lat_bins
Exemplo n.º 11
0
def get_resampled_coordinates(lons, lats):
    """
    Resample polygon line segments and return the coordinates of the new
    vertices. This limits distortions when projecting a polygon onto a
    spherical surface.

    Parameters define longitudes and latitudes of a point collection in the
    form of lists or numpy arrays.

    :return:
        A tuple of two numpy arrays: longitudes and latitudes
        of resampled vertices.
    """
    num_coords = len(lons)
    assert num_coords == len(lats)

    lons1 = numpy.array(lons)
    lats1 = numpy.array(lats)
    lons2 = numpy.concatenate((lons1[1:], lons1[0:1]))
    lats2 = numpy.concatenate((lats1[1:], lats1[0:1]))
    distances = geodetic.geodetic_distance(lons1, lats1, lons2, lats2)

    resampled_lons = [lons[0]]
    resampled_lats = [lats[0]]
    for i in xrange(num_coords):
        next_point = (i + 1) % num_coords
        lon1, lat1 = lons[i], lats[i]
        lon2, lat2 = lons[next_point], lats[next_point]

        distance = distances[i]
        num_points = int(distance / UPSAMPLING_STEP_KM) + 1
        if num_points >= 2:
            # We need to increase the resolution of this arc by adding new
            # points.
            new_lons, new_lats, _ = geodetic.npoints_between(
                lon1, lat1, 0, lon2, lat2, 0, num_points
            )
            resampled_lons.extend(new_lons[1:])
            resampled_lats.extend(new_lats[1:])
        else:
            resampled_lons.append(lon2)
            resampled_lats.append(lat2)
    # we cut off the last point because it repeats the first one.
    return numpy.array(resampled_lons[:-1]), numpy.array(resampled_lats[:-1])
Exemplo n.º 12
0
def get_resampled_coordinates(lons, lats):
    """
    Resample polygon line segments and return the coordinates of the new
    vertices. This limits distortions when projecting a polygon onto a
    spherical surface.

    Parameters define longitudes and latitudes of a point collection in the
    form of lists or numpy arrays.

    :return:
        A tuple of two numpy arrays: longitudes and latitudes
        of resampled vertices.
    """
    num_coords = len(lons)
    assert num_coords == len(lats)

    lons1 = numpy.array(lons)
    lats1 = numpy.array(lats)
    lons2 = numpy.concatenate((lons1[1:], lons1[0:1]))
    lats2 = numpy.concatenate((lats1[1:], lats1[0:1]))
    distances = geodetic.geodetic_distance(lons1, lats1, lons2, lats2)

    resampled_lons = [lons[0]]
    resampled_lats = [lats[0]]
    for i in range(num_coords):
        next_point = (i + 1) % num_coords
        lon1, lat1 = lons[i], lats[i]
        lon2, lat2 = lons[next_point], lats[next_point]

        distance = distances[i]
        num_points = int(distance / UPSAMPLING_STEP_KM) + 1
        if num_points >= 2:
            # We need to increase the resolution of this arc by adding new
            # points.
            new_lons, new_lats, _ = geodetic.npoints_between(
                lon1, lat1, 0, lon2, lat2, 0, num_points
            )
            resampled_lons.extend(new_lons[1:])
            resampled_lats.extend(new_lats[1:])
        else:
            resampled_lons.append(lon2)
            resampled_lats.append(lat2)
    # we cut off the last point because it repeats the first one.
    return numpy.array(resampled_lons[:-1]), numpy.array(resampled_lats[:-1])
Exemplo n.º 13
0
def lon_lat_bins(bb, coord_bin_width):
    """
    Define bin edges for disaggregation histograms.

    Given bins data as provided by :func:`collect_bin_data`, this function
    finds edges of histograms, taking into account maximum and minimum values
    of magnitude, distance and coordinates as well as requested sizes/numbers
    of bins.
    """
    west, south, east, north = bb
    west = numpy.floor(west / coord_bin_width) * coord_bin_width
    east = numpy.ceil(east / coord_bin_width) * coord_bin_width
    lon_extent = get_longitudinal_extent(west, east)
    lon_bins, _, _ = npoints_between(
        west, 0, 0, east, 0, 0, numpy.round(lon_extent / coord_bin_width + 1))
    lat_bins = coord_bin_width * numpy.arange(
        int(numpy.floor(south / coord_bin_width)),
        int(numpy.ceil(north / coord_bin_width) + 1))
    return lon_bins, lat_bins
Exemplo n.º 14
0
def lon_lat_bins(bb, coord_bin_width):
    """
    Define bin edges for disaggregation histograms.

    Given bins data as provided by :func:`collect_bin_data`, this function
    finds edges of histograms, taking into account maximum and minimum values
    of magnitude, distance and coordinates as well as requested sizes/numbers
    of bins.
    """
    west, south, east, north = bb
    west = numpy.floor(west / coord_bin_width) * coord_bin_width
    east = numpy.ceil(east / coord_bin_width) * coord_bin_width
    lon_extent = get_longitudinal_extent(west, east)
    lon_bins, _, _ = npoints_between(
        west, 0, 0, east, 0, 0,
        numpy.round(lon_extent / coord_bin_width + 1))
    lat_bins = coord_bin_width * numpy.arange(
        int(numpy.floor(south / coord_bin_width)),
        int(numpy.ceil(north / coord_bin_width) + 1))
    return lon_bins, lat_bins
Exemplo n.º 15
0
 def test(self):
     lons, lats, depths = geodetic.npoints_between(
         lon1=40.77, lat1=38.9, depth1=17.5,
         lon2=31.14, lat2=46.23, depth2=5.2,
         npoints=7
     )
     expected_lons = [40.77, 39.316149154562076, 37.8070559966114,
                      36.23892429550906, 34.60779411051164,
                      32.90956020775102, 31.14]
     expected_lats = [38.9, 40.174608368560094, 41.43033989236144,
                      42.66557829138413, 43.87856696738466,
                      45.067397797471415, 46.23]
     expected_depths = [17.5, 15.45, 13.4, 11.35, 9.3, 7.25, 5.2]
     self.assertTrue(numpy.allclose(lons, expected_lons))
     self.assertTrue(numpy.allclose(lats, expected_lats))
     self.assertTrue(numpy.allclose(depths, expected_depths))
     # the last and the first points should be exactly the same as two
     # original corner points, so no "assertAlmostEqual" for them
     self.assertEqual(lons[0], 40.77)
     self.assertEqual(lats[0], 38.9)
     self.assertEqual(depths[0], 17.5)
     self.assertEqual(lons[-1], 31.14)
     self.assertEqual(lats[-1], 46.23)
     self.assertEqual(depths[-1], 5.2)
Exemplo n.º 16
0
 def test_topo(self):
     lons, lats, depths = geodetic.npoints_between(
         lon1=40.77, lat1=38.9, depth1=2,
         lon2=31.14, lat2=46.23, depth2=-4,
         npoints=7
     )
     expected_lons = [40.77, 39.316149154562076, 37.8070559966114,
                      36.23892429550906, 34.60779411051164,
                      32.90956020775102, 31.14]
     expected_lats = [38.9, 40.174608368560094, 41.43033989236144,
                      42.66557829138413, 43.87856696738466,
                      45.067397797471415, 46.23]
     expected_depths = [2, 1, 0, -1, -2, -3, -4]
     assert_aeq(lons, expected_lons)
     assert_aeq(lats, expected_lats)
     assert_aeq(depths, expected_depths)
     # the last and the first points should be exactly the same as two
     # original corner points, so no "assertAlmostEqual" for them
     self.assertEqual(lons[0], 40.77)
     self.assertEqual(lats[0], 38.9)
     self.assertEqual(depths[0], 2)
     self.assertEqual(lons[-1], 31.14)
     self.assertEqual(lats[-1], 46.23)
     self.assertEqual(depths[-1], -4)