Esempio n. 1
0
def is_quadrupture_class(d):
    """
    Check if JSON file fulfills QuadRupture class criteria:

        - Are top and bottom edges horizontal?
        - Are the four points in each quad coplanar?

    Args:
        d (dict): Rupture JSON dictionary.

    Returns:
        bool: Can the rupture be represented in the QuadRupture class?
    """
    f = d['features'][0]
    geom = f['geometry']
    if geom['type'] == 'Point':
        return False
    polygons = geom['coordinates'][0]
    try:
        len(polygons)
    except Exception:
        return False
    n_polygons = len(polygons)
    for i in range(n_polygons):
        p = polygons[i]
        n_points = len(p)
        n_pairs = int((n_points - 1) / 2)
        n_quads = n_pairs - 1

        for k in range(n_quads):
            # Four points of each quad should be co-planar within a tolerance
            quad = [
                Point(p[k][0], p[k][1], p[k][2]),
                Point(p[k + 1][0], p[k + 1][1], p[k + 1][2]),
                Point(p[-(k + 3)][0], p[-(k + 3)][1], p[-(k + 3)][2]),
                Point(p[-(k + 2)][0], p[-(k + 2)][1], p[-(k + 2)][2])
            ]
            test = utils.is_quad(quad)
            if test[0] is False:
                return False

            # Within each quad, top and bottom edges must be horizontal
            tops = np.array([quad[0].depth, quad[1].depth])
            if not np.isclose(tops[0], tops, rtol=0,
                              atol=constants.DEPTH_TOL).all():
                return False
            bots = np.array([quad[2].depth, quad[3].depth])
            if not np.isclose(bots[0], bots, rtol=0,
                              atol=constants.DEPTH_TOL).all():
                return False

    return True
Esempio n. 2
0
def is_quadrupture_class(d):
    """
    Check if JSON file fulfills QuadRupture class criteria:

        - Are top and bottom edges horizontal?
        - Are the four points in each quad coplanar?

    Args:
        d (dict): Rupture JSON dictionary.

    Returns:
        bool: Can the rupture be represented in the QuadRupture class?
    """
    isQuad = True

    f = d['features'][0]
    geom = f['geometry']
    polygons = geom['coordinates'][0]
    n_polygons = len(polygons)
    for i in range(n_polygons):
        p = polygons[i]
        n_points = len(p)
        n_pairs = int((n_points - 1) / 2)
        n_quads = n_pairs - 1

        for k in range(n_quads):
            # Four points of each quad should be co-planar within a tolerance
            quad = [Point(p[k][0], p[k][1], p[k][2]),
                    Point(p[k + 1][0], p[k + 1][1], p[k + 1][2]),
                    Point(p[-(k + 3)][0], p[-(k + 3)][1], p[-(k + 3)][2]),
                    Point(p[-(k + 2)][0], p[-(k + 2)][1], p[-(k + 2)][2])]
            test = utils.is_quad(quad)
            if test[0] is False:
                isQuad = False

            # Within each quad, top and bottom edges must be horizontal
            tops = np.array([quad[0].depth, quad[1].depth])
            if not np.isclose(tops[0], tops, rtol=0,
                              atol=constants.DEPTH_TOL).all():
                isQuad = False
            bots = np.array([quad[2].depth, quad[3].depth])
            if not np.isclose(bots[0], bots, rtol=0,
                              atol=constants.DEPTH_TOL).all():
                isQuad = False

    return isQuad
Esempio n. 3
0
    def _setQuadrilaterals(self):
        """
        Create internal list of N quadrilaterals. Reverses quad if dip
        direction is incorrect.
        """

        # Make sure arrays are numpy arrays.
        self._lon = np.array(self._lon)
        self._lat = np.array(self._lat)
        self._depth = np.array(self._depth)

        # Find the nans, which tells is where the separate polygons/groups are
        group_ends = np.where(np.isnan(self._lon))[0]
        n_groups = len(group_ends)

        # Check that arrays are the same length
        if len(self._lon) != len(self._lat) != len(self._depth):
            raise IndexError(
                'Length of input lon, lat, depth arrays must be equal')

        # Construct quads
        group_start = 0

        self._quadrilaterals = []
        self._group_index = []
        groupind = 0
        for i in range(n_groups):
            lonseg = self._lon[group_start:group_ends[i]]
            latseg = self._lat[group_start:group_ends[i]]
            depthseg = self._depth[group_start:group_ends[i]]

            # Each group can have many contiguous quadrilaterals defined in it
            # separations (nans) between segments mean that segments are not
            # contiguous.

            npoints = len(lonseg)
            nquads = int((npoints - 4) / 2) + 1
            quad_start = 0
            quad_end = -1
            for j in range(nquads):
                P0 = Point(lonseg[quad_start], latseg[quad_start],
                           depthseg[quad_start])
                P1 = Point(lonseg[quad_start + 1], latseg[quad_start + 1],
                           depthseg[quad_start + 1])
                P2 = Point(lonseg[quad_end - 1], latseg[quad_end - 1],
                           depthseg[quad_end - 1])
                P3 = Point(lonseg[quad_end], latseg[quad_end],
                           depthseg[quad_end])
                quad = [P0, P1, P2, P3]

                # Enforce plane by moving P2 -- already close because of check
                # in read_rupture_file/is_quadrupture_class/is_quad

                dummy, fixed_quad = utils.is_quad(quad)

                # Reverse quad if necessary
                fixed_quad = self._fixStrikeDirection(fixed_quad)

                self._quadrilaterals.append(fixed_quad)

                quad_start = quad_start + 1
                quad_end = quad_end - 1

            group_start = group_ends[i] + 1
            self._group_index.extend([groupind] * nquads)
            groupind = groupind + 1