Ejemplo n.º 1
0
def test_polygon_self_intersection():
    # should detect self segment intersection of the polygon not near a
    # Pole
    p1 = shape.Point(-115.488281, 45.867063)
    p2 = shape.Point(-91.230469, 36.075742)
    p3 = shape.Point(-95.800781, 54.807017)
    p4 = shape.Point(-108.457031, 39.951859)
    p5 = shape.Point(0.0, 0.0)
    points_with_self_intersecting_segments = [p1, p2, p3, p4, p5]
    with pytest.raises(AssertionError) as ex:
        poly = shape.Polygon(points_with_self_intersecting_segments)
        validate_polygon(poly)
    assert('self intersecting' in str(ex.value))

    # should detect self segment intersection of the polygon near the
    # South Pole, with the Pole outside the polygon
    p1 = shape.Point(0.6128286003, -89.8967940441)
    p2 = shape.Point(210.6391743183, -89.9073892376)
    p3 = shape.Point(90.6405151921, -89.8972874698)
    p4 = shape.Point(270.6114701911, -89.90689353)
    p5 = shape.Point(0.0, 0.0)
    points_with_self_intersecting_segments = [p1, p2, p3, p4, p5]
    with pytest.raises(AssertionError) as ex:
        poly = shape.Polygon(points_with_self_intersecting_segments)
        validate_polygon(poly)
    assert('self intersecting' in str(ex.value))

    # should detect self segment intersection of the polygon near the
    # South Pole, with the Pole inside the polygon
    p1 = shape.Point(0.6128286003, -89.8967940441)
    p2 = shape.Point(130.6391743183, -89.9073892376)
    p3 = shape.Point(90.6405151921, -89.8972874698)
    p4 = shape.Point(270.6114701911, -89.90689353)
    p5 = shape.Point(0.0, 0.0)
    points_with_self_intersecting_segments = [p1, p2, p3, p4, p5]
    with pytest.raises(AssertionError) as ex:
        poly = shape.Polygon(points_with_self_intersecting_segments)
        validate_polygon(poly)
    assert('self intersecting' in str(ex.value))

    # should detect self segment intersection of the polygon which
    # intersects with meridian = 0
    p1 = shape.Point(-7.910156, 13.293411)
    p2 = shape.Point(4.042969, 7.068185)
    p3 = shape.Point(4.746094, 18.030975)
    p4 = shape.Point(-6.855469, 6.369894)
    p5 = shape.Point(0.0, 0.0)
    points_with_self_intersecting_segments = [p1, p2, p3, p4, p5]
    with pytest.raises(AssertionError) as ex:
        poly = shape.Polygon(points_with_self_intersecting_segments)
        validate_polygon(poly)
    assert('self intersecting' in str(ex.value))
Ejemplo n.º 2
0
def build_a_plane_position(plane):
    from astropy.io import fits
    from astropy.wcs import wcs
    from caom2 import SegmentType, Point, Vertex, Position, shape
    logging.error('do i get here?')
    try:
        z = fits.open('/usr/src/app/draogmims2caom2/draogmims2caom2/tests'
                      '/data/gmims_HBN_Fan.fits')
        w = wcs.WCS(z[0].header)
        points = []
        vertices = []
        segment_type = SegmentType['MOVE']

        for x, y in ([0, 0], [1, 0], [1, 1], [0, 1]):
            v = w.all_pix2world(x * z[0].header['naxis1'],
                                y * z[0].header['naxis2'], 1, 1)
            points.append(Point(float(v[0]), float(v[1])))
            vertices.append(Vertex(float(v[0]), float(v[1]), segment_type))
            segment_type = SegmentType['LINE']
        vertices.append(
            Vertex(points[0].cval1, points[0].cval2, SegmentType['CLOSE']))

        polygon = shape.Polygon(points=points,
                                samples=shape.MultiPolygon(vertices))
        position = Position(time_dependent=False, bounds=polygon)
        plane.position = position
    except Exception as e:
        logging.error('wtf {}'.format(e))
Ejemplo n.º 3
0
    def get_poly_position(self):
        position = plane.Position()

        if self.caom_version >= 23:
            v0 = shape.Vertex(0.0, 0.0, shape.SegmentType.MOVE)
            v1 = shape.Vertex(1.0, 2.0, shape.SegmentType.LINE)
            v2 = shape.Vertex(2.0, 3.0, shape.SegmentType.LINE)
            v3 = shape.Vertex(3.0, 4.0, shape.SegmentType.LINE)
            v4 = shape.Vertex(0.0, 0.0, shape.SegmentType.CLOSE)
            vl = [v0, v1, v2, v3, v4]

            samples = shape.MultiPolygon(vertices=vl)

            p1 = shape.Point(0.0, 0.0)
            p2 = shape.Point(1.0, 2.0)
            p3 = shape.Point(2.0, 3.0)
            p4 = shape.Point(3.0, 4.0)
            p = [p1, p2, p3, p4]
            polygon = shape.Polygon(points=p, samples=samples)

            position.bounds = polygon

        position.dimension = wcs.Dimension2D(10, 20)
        position.resolution = 0.5
        position.sample_size = 1.1
        position.time_dependent = False

        return position
Ejemplo n.º 4
0
def test_open_polygon():
    p1 = shape.Point(-117.246094, 52.942018)
    p2 = shape.Point(-101.601563, 56.535258)
    p3 = shape.Point(-97.382813, 44.809122)
    p4 = shape.Point(-111.445313, 37.405074)
    # SphericalPolygon requires p1 == p5 for a closed polygon
    p5 = shape.Point(-117.246094, 52.942018)
    too_few_points = [p1, p2]
    min_closed_points = [p1, p2, p3]
    closed_points = [p1, p2, p3, p4, p5]
    counter_clockwise_points = [p4, p3, p2, p1]

    # should detect that the polygons is not clockwise
    with pytest.raises(AssertionError) as ex:
        validate_polygon(shape.Polygon(counter_clockwise_points))
    assert('not in clockwise direction' in str(ex.value))
    # should detect that polygon is requires a minimum of 4 points
    with pytest.raises(AssertionError) as ex:
        validate_polygon(shape.Polygon(too_few_points))
    assert('invalid polygon: 2 points' in str(ex.value))

    # polygon default constructor
    validate_polygon(shape.Polygon())

    # should detect that polygon is closed
    validate_polygon(shape.Polygon(min_closed_points))
    validate_polygon(shape.Polygon(closed_points))

    # should detect that multipolygon is not closed
    v0 = shape.Vertex(-126.210938, 67.991108, shape.SegmentType.MOVE)
    v1 = shape.Vertex(-108.984375, 70.480896, shape.SegmentType.LINE)
    v2 = shape.Vertex(-98.789063, 66.912834, shape.SegmentType.LINE)
    v3 = shape.Vertex(-75.234375, 60.217991, shape.SegmentType.LINE)
    v4 = shape.Vertex(-87.890625, 52.241256, shape.SegmentType.LINE)
    v5 = shape.Vertex(-110.742188, 54.136696, shape.SegmentType.LINE)
    v6 = shape.Vertex(0.0, 0.0, shape.SegmentType.CLOSE)
    v7 = shape.Vertex(24.609375, 62.895218, shape.SegmentType.MOVE)
    v8 = shape.Vertex(43.593750, 67.322924, shape.SegmentType.LINE)
    v9 = shape.Vertex(55.898438, 62.734601, shape.SegmentType.LINE)
    v10 = shape.Vertex(46.757813, 56.145550, shape.SegmentType.LINE)
    v11 = shape.Vertex(26.015625, 55.354135, shape.SegmentType.LINE)
    v12 = shape.Vertex(0.0, 0.0, shape.SegmentType.CLOSE)
    closed_vertices = [
        v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12]

    # should detect that multipolygon is closed
    validate_multipolygon(shape.MultiPolygon(closed_vertices))
Ejemplo n.º 5
0
    def test_plane_level_position(self):
        # special handling, because nan == nan is False
        p1 = [
            Point(cval1=float('nan'), cval2=float('nan')),
            Point(cval1=100.25, cval2=-30.5),
            Point(cval1=100.25, cval2=30.0),
            Point(cval1=float('nan'), cval2=float('nan'))
        ]
        p2 = [
            Point(cval1=float('nan'), cval2=float('nan')),
            Point(cval1=100.25, cval2=-30.5),
            Point(cval1=100.25, cval2=30.0),
            Point(cval1=float('nan'), cval2=float('nan'))
        ]

        v1 = [
            Vertex(p1[0].cval1, p1[0].cval2, SegmentType.MOVE),
            Vertex(p1[1].cval1, p1[1].cval2, SegmentType.LINE),
            Vertex(p1[2].cval1, p1[2].cval2, SegmentType.LINE),
            Vertex(p1[3].cval1, p1[3].cval2, SegmentType.LINE),
            Vertex(p1[0].cval1, p1[0].cval2, SegmentType.CLOSE)
        ]
        v2 = [
            Vertex(p2[0].cval1, p2[0].cval2, SegmentType.MOVE),
            Vertex(p2[1].cval1, p2[1].cval2, SegmentType.LINE),
            Vertex(p2[2].cval1, p2[2].cval2, SegmentType.LINE),
            Vertex(p2[3].cval1, p2[3].cval2, SegmentType.LINE),
            Vertex(p2[0].cval1, p2[0].cval2, SegmentType.CLOSE)
        ]

        poly1 = shape.Polygon(points=p1, samples=shape.MultiPolygon(v1))
        poly2 = shape.Polygon(points=p2, samples=shape.MultiPolygon(v2))

        o1 = Position(time_dependent=False, bounds=poly1)
        o2 = Position(time_dependent=False, bounds=poly2)

        report = diff.get_differences(o1, o2, 'caom test instances')
        assert report is None, 'NaN comparison failure'
Ejemplo n.º 6
0
    def get_position(self):
        position = plane.Position()
        
        v1 = shape.Vertex(1.0, 2.0, shape.SegmentType.LINE)
        v2 = shape.Vertex(2.0, 3.0, shape.SegmentType.LINE)
        v3 = shape.Vertex(3.0, 4.0, shape.SegmentType.LINE)
        v4 = shape.Vertex(0.0, 0.0, shape.SegmentType.CLOSE)
        vl = [v1, v2, v3, v4]

        polygon = shape.Polygon()
        polygon.vertices = vl
        
        position.bounds = polygon
        position.dimension = wcs.Dimension2D(10, 20)
        position.resolution = 0.5
        position.sample_size = 1.1
        position.time_dependent = False
        
        return position