Example #1
0
 def _update_bounding_polygon(self):
     polygons = [im.polygon for im in self._images]
     if len(polygons) == 0:
         self._polygon = SphericalPolygon([])
         self._radec = []
     else:
         self._polygon = SphericalPolygon.multi_union(polygons)
         self._radec = list(self._polygon.to_radec())
Example #2
0
    def set_members(self, mlist, polygon):
        if mlist is None:
            member_list = []
        elif isinstance(mlist, list):
            member_list = mlist
            if [1 for m in mlist if not isinstance(m, SkyLineMember)]:
                raise ValueError("The 'mlist' argument must be either "
                                 "a single 'SkyLineMember' object or a "
                                 "Python list of 'SkyLineMember' objects.")
        elif isinstance(mlist, SkyLineMember):
            member_list = [mlist]
        else:
            raise ValueError("The 'mlist' argument must be either "
                             "a single 'SkyLineMember' object or a "
                             "Python list of 'SkyLineMember' objects.")

        self._members = []

        # Not using set to preserve order
        n = len(member_list)
        if n == 0:
            if polygon is None:
                self.polygon = SphericalPolygon([])
            else:
                self.polygon = deepcopy(polygon)
            self._id = ''
            self._is_mf_mosaic = False

        elif n == 1:
            assert isinstance(member_list[0], SkyLineMember)
            if polygon is None:
                self.polygon = deepcopy(member_list[0].polygon)
            else:
                self.polygon = deepcopy(polygon)
            self._id = member_list[0].id
            self._members.append(member_list[0])
            self._is_mf_mosaic = False

        else:
            assert isinstance(member_list[0], SkyLineMember)
            if polygon is None:
                mpol = deepcopy(member_list[0].polygon)
            else:
                mpol = deepcopy(polygon)
            self._members.append(member_list[0])

            for m in member_list[1:]:
                # Report corrupted members list instead of skipping
                assert isinstance(m, SkyLineMember)

                if m not in self._members:
                    self._members.append(m)
                    if polygon is None:
                        mpol = mpol.union(m.polygon)

            self.polygon = mpol
            self._update_mosaic_flag_id()
Example #3
0
def get_difference(poly1, poly2, pixels=None):
    """attempt to get the difference poly1-poly2 as poly1^~poly2
        use a pixelation to attempt to find an outside point"""
    import matplotlib.pyplot as plt
    from mpl_toolkits.basemap import Basemap
    m = Basemap(projection='moll', lon_0=0)
    if pixels is None:
        pixels = get_healpix_pixelation(4)
    bounding_xyz = list(poly2.points)
    #contained = np.zeros(pixels.shape[0],dtype==bool)
    #for itr in range(0,len(bounding_xyz)):
    #    ra,dec = sgv.vector_to_radec(
    #    contained = contained | contains_points(bounding_xyz[itr],pixels)
    contained = contains_points(pixels, poly2)
    poly2_complement = None
    #poly2_complement = poly2.invert_polygon()
    #contained_c = contains_points(pixels,poly2_complement)
    #assert not np.any(contained & contained_c)
    first_false = 100 + np.argmin(contained[100:])
    #print("orig 1",contains_points(pixels[first_false:first_false+1],poly1),poly1.area())
    #print("orig 2",contains_points(pixels[first_false:first_false+1],poly2),poly2.area())
    print(poly2)
    colors = ['red', 'green', 'blue']
    for itr in range(0, len(bounding_xyz)):
        first_false = 100 + itr + np.argmin(contained[100 + itr:])
        theta_in = pixels[first_false, 0]
        phi_in = pixels[first_false, 1]
        inside_xyz = np.asarray(
            sgv.radec_to_vector(phi_in, theta_in - np.pi / 2., degrees=False))
        loc_poly = SphericalPolygon(bounding_xyz[itr].copy(),
                                    inside_xyz.copy())
        loc_poly.draw(m, color=colors[itr])
        cont = contains_points(pixels[first_false:first_false + 1], loc_poly)
        print("loc contains: ", cont)
        if poly2_complement is None:
            poly2_complement = deepcopy(loc_poly)
        else:
            poly2_complement = deepcopy(
                poly2_complement.intersection(loc_poly))
        cont_comp = contains_points(pixels[first_false:first_false + 1],
                                    poly2_complement)
        print("comp contains: ", cont_comp)
        print("test: ",
              np.all(contains_points(pixels[contained], poly2_complement)))
        print("test: ",
              np.any(contains_points(pixels[~contained], poly2_complement)))
        print("insp: ", list(poly2_complement.inside))
        #print("comp ",itr,contains_points(pixels[first_false:first_false+1],poly2_complement),poly2_complement.area(),poly2_complement.is_clockwise())
        #print("inside c ",list(poly2_complement.inside))
        #print("vert c ",list(poly2_complement.points))
        #for itr2 in range(0,len(list(poly2_complement.inside))):
        #    print("loc cont inside c ",loc_poly.contains_point(list(poly2_complement.inside)[itr2]))
    #print(poly1.area(),poly2.area(),poly2_complement.area())
    plt.show()
    return poly1.intersection(poly2_complement)
Example #4
0
def get_poly(theta_vertices, phi_vertices, theta_in, phi_in):
    """get the SphericalPolygon object for the geometry"""
    bounding_theta = theta_vertices - np.pi / 2.  #to radec
    bounding_phi = phi_vertices
    bounding_xyz = np.asarray(
        sgv.radec_to_vector(bounding_phi, bounding_theta, degrees=False)).T
    inside_xyz = np.asarray(
        sgv.radec_to_vector(phi_in, theta_in - np.pi / 2., degrees=False))

    sp_poly = SphericalPolygon(bounding_xyz, inside=inside_xyz)
    return sp_poly
Example #5
0
    def run(self, dataSlice, slicePoint=None):
        # RA and Dec from dataSlice doesn't necessarily match healpix
        RA = dataSlice['fieldRA'][0]
        Dec = dataSlice['fieldDec'][0]
        # Get RA and Dec from slicer
        RA = slicePoint['ra']
        Dec = slicePoint['dec']
        nside = slicePoint['nside']
        # get the boundaries from HealPix
        bounding = hp.boundaries(nside, slicePoint['sid'], step=1).T
        inside_val = np.asarray(
            sgv.radec_to_vector(slicePoint['ra'],
                                slicePoint['dec'],
                                degrees=False))
        test_pointing = SphericalPolygon(bounding, inside_val)

        overlap_area = [
            test_pointing.intersection(survey_polygon).area()
            for survey_polygon in survey_list[self.region_name]
        ]
        total = sum(overlap_area)
        healpix_area = test_pointing.area()
        return min(total, 4 * np.pi - total)
Example #6
0
    def __init__(self,
                 image,
                 wcs_fwd,
                 wcs_inv,
                 pix_area=1.0,
                 convf=1.0,
                 mask=None,
                 id=None,
                 skystat=None,
                 stepsize=None,
                 meta=None):
        """ Initializes the SkyImage object.

        Parameters
        ----------
        image : numpy.ndarray
            A 2D array of image data.

        wcs_fwd : function
            "forward" pixel-to-world transformation function.

        wcs_inv : function
            "inverse" world-to-pixel transformation function.

        pix_area : float, optional
            Average pixel's sky area.

        convf : float, optional
            Conversion factor that when multiplied to `image` data converts
            the data to "uniform" (across multiple images) surface
            brightness units.

            .. note::

              The functionality to support this conversion is not yet
              implemented and at this moment `convf` is ignored.

        mask : numpy.ndarray
            A 2D array that indicates
            what pixels in the input `image` should be used for sky
            computations (``1``) and which pixels should **not** be used
            for sky computations (``0``).

        id : anything
            The value of this parameter is simple stored within the `SkyImage`
            object. While it can be of any type, it is prefereble that `id` be
            of a type with nice string representation.

        skystat : callable, None, optional
            A callable object that takes a either a 2D image (2D
            `numpy.ndarray`) or a list of pixel values (a Nx1 array) and
            returns a tuple of two values: some statistics (e.g., mean,
            median, etc.) and number of pixels/values from the input image
            used in computing that statistics.

            When `skystat` is not set, `SkyImage` will use
            :py:class:`~jwst_pipeline.skymatch.skystatistics.SkyStats` object
            to perform sky statistics on image data.

        stepsize : int, None, optional
            Spacing between vertices of the image's bounding polygon. Default
            value of `None` creates bounding polygons with four vertices
            corresponding to the corners of the image.

        meta : dict, None, optional
            A dictionary of various items to be stored within the `SkyImage`
            object.

        """
        self.image = image
        self.convf = convf
        self.meta = meta
        self._id = id
        self._pix_area = pix_area

        # WCS
        self.wcs_fwd = wcs_fwd
        self.wcs_inv = wcs_inv

        # initial sky value:
        self._sky = 0.0

        # check that mask has the same shape as image:
        if mask is None:
            self.mask = None

        else:
            if image is None:
                raise ValueError("'mask' must be None when 'image' is None")

            self.mask = np.asanyarray(mask, dtype=np.bool)

            if self.mask.shape != image.shape:
                raise ValueError("'mask' must have the same shape as 'image'.")

        # create spherical polygon bounding the image
        if image is None or wcs_fwd is None or wcs_inv is None:
            self._radec = [(np.array([]), np.array([]))]
            self._polygon = SphericalPolygon([])
            self._poly_area = 0.0

        else:
            self.calc_bounding_polygon(stepsize)

        # set sky statistics function (NOTE: it must return statistics and
        # the number of pixels used after clipping)
        if skystat is None:
            self.set_builtin_skystat()
        else:
            self.skystat = skystat
Example #7
0
    def calc_sky(self, overlap=None, delta=True):
        """
        Compute sky background value.

        Parameters
        ----------
        overlap : SkyImage, SkyGroup, SphericalPolygon, list of tuples, \
None, optional
            Another `SkyImage`, `SkyGroup`,
            :py:class:`spherical_geometry.polygons.SphericalPolygon`, or
            a list of tuples of (RA, DEC) of vertices of a spherical
            polygon. This parameter is used to indicate that sky statistics
            should computed only in the region of intersection of *this*
            image with the polygon indicated by `overlap`. When `overlap` is
            `None`, sky statistics will be computed over the entire image.

        delta : bool, optional
            Should this function return absolute sky value or the difference
            between the computed value and the value of the sky stored in the
            `sky` property.

        Returns
        -------
        skyval : float, None
            Computed sky value (absolute or relative to the `sky` attribute).
            If there are no valid data to perform this computations (e.g.,
            because this image does not overlap with the image indicated by
            `overlap`), `skyval` will be set to `None`.

        npix : int
            Number of pixels used to compute sky statistics.

        polyarea : float
            Area (in srad) of the polygon that bounds data used to compute
            sky statistics.

        """
        if overlap is None:

            if self.mask is None:
                data = self.image
            else:
                data = self.image[self.mask]

            polyarea = self.poly_area

        else:
            fill_mask = np.zeros(self.image.shape, dtype=bool)

            if isinstance(overlap, SkyImage):
                intersection = self.intersection(overlap)
                polyarea = np.fabs(intersection.area())
                radec = list(intersection.to_radec())

            elif isinstance(overlap, SkyGroup):
                radec = []
                polyarea = 0.0
                for im in overlap:
                    intersection = self.intersection(im)
                    polyarea1 = np.fabs(intersection.area())
                    if polyarea1 == 0.0:
                        continue
                    polyarea += polyarea1
                    radec += list(intersection.to_radec())

            elif isinstance(overlap, SphericalPolygon):
                radec = []
                polyarea = 0.0
                for p in overlap._polygons:
                    intersection = self.intersection(SphericalPolygon([p]))
                    polyarea1 = np.fabs(intersection.area())
                    if polyarea1 == 0.0:
                        continue
                    polyarea += polyarea1
                    radec += list(intersection.to_radec())

            else:  # assume a list of (ra, dec) tuples:
                radec = []
                polyarea = 0.0
                for r, d in overlap:
                    poly = SphericalPolygon.from_radec(r, d)
                    polyarea1 = np.fabs(poly.area())
                    if polyarea1 == 0.0 or len(r) < 4:
                        continue
                    polyarea += polyarea1
                    radec.append(self.intersection(poly).to_radec())

            if polyarea == 0.0:
                return (None, 0, 0.0)

            for ra, dec in radec:
                if len(ra) < 4:
                    continue

                # set pixels in 'fill_mask' that are inside a polygon to True:
                x, y = self.wcs_inv(ra, dec)
                poly_vert = list(zip(*[x, y]))

                polygon = region.Polygon(True, poly_vert)
                fill_mask = polygon.scan(fill_mask)

            if self.mask is not None:
                fill_mask &= self.mask

            data = self.image[fill_mask]

            if data.size < 1:
                return (None, 0, 0.0)

        # Calculate sky
        try:

            skyval, npix = self._skystat(data)

        except ValueError:

            return (None, 0, 0.0)

        if delta:
            skyval -= self._sky

        return skyval, npix, polyarea
Example #8
0
def test_geos1():
    """do second test posted to bug report"""
    n_fill = 10

    theta1_high_fill = np.full(n_fill, 5.)
    theta1_low_fill = np.full(n_fill, -65.)
    phi1_high_fill = np.linspace(50. - 360., 50. - 1., n_fill)
    phi1_low_fill = phi1_high_fill[::-1]
    theta1s = np.hstack(
        [theta1_high_fill, theta1_low_fill, theta1_high_fill[0]])
    phi1s = np.hstack([phi1_high_fill, phi1_low_fill, phi1_high_fill[0]])

    phi_in1 = 0.
    theta_in1 = 70.

    bounding_xyz1 = np.array(sgv.radec_to_vector(phi1s, theta1s,
                                                 degrees=True)).T
    inside_xyz1 = np.array(
        sgv.radec_to_vector(phi_in1, theta_in1, degrees=True))
    sp_poly1 = SphericalPolygon(bounding_xyz1, inside=inside_xyz1)

    theta2_high_fill = np.full(n_fill, -30.)
    theta2_low_fill = np.full(n_fill, -85.)
    phi2_high_fill = np.linspace(65 - 360., 55. - 10., n_fill)
    phi2_low_fill = np.linspace(5 - 360., 5. - 10., n_fill)[::-1]
    theta2s = np.hstack(
        [theta2_high_fill, theta2_low_fill, theta2_high_fill[0]])
    phi2s = np.hstack([phi2_high_fill, phi2_low_fill, phi2_high_fill[0]])

    phi_in2 = 0.
    theta_in2 = 70.

    bounding_xyz2 = np.array(sgv.radec_to_vector(phi2s, theta2s,
                                                 degrees=True)).T
    inside_xyz2 = np.array(
        sgv.radec_to_vector(phi_in2, theta_in2, degrees=True))
    sp_poly2 = SphericalPolygon(bounding_xyz2, inside=inside_xyz2)

    int_poly = sp_poly2.intersection(sp_poly1)

    theta_out = -50. * np.pi / 180.
    phi_out = 0.
    outside_xyz = np.array(
        sgv.radec_to_vector(phi_out, theta_out, degrees=False))

    theta_in3 = 70. * np.pi / 180.
    phi_in3 = 0.
    inside_xyz3 = np.array(
        sgv.radec_to_vector(phi_in3, theta_in3, degrees=False))

    print("area int, area 1,area 2: ", int_poly.area(), sp_poly1.area(),
          sp_poly2.area())
    print("Should be True , True : ",
          int_poly.area() <= sp_poly1.area(),
          int_poly.area() <= sp_poly2.area())
    assert int_poly.area() <= sp_poly1.area()
    assert int_poly.area() <= sp_poly2.area()

    assert not int_poly.contains_point(outside_xyz)
    assert not sp_poly1.contains_point(outside_xyz)
    assert not sp_poly2.contains_point(outside_xyz)
    print("Should be True ,True ,True : ",
          int_poly.contains_point(inside_xyz1),
          sp_poly1.contains_point(inside_xyz1),
          sp_poly2.contains_point(inside_xyz1))
    assert int_poly.contains_point(inside_xyz1)
    assert sp_poly1.contains_point(inside_xyz1)
    assert sp_poly2.contains_point(inside_xyz1)
    print("Should be True ,True ,True : ",
          int_poly.contains_point(inside_xyz2),
          sp_poly1.contains_point(inside_xyz2),
          sp_poly2.contains_point(inside_xyz2))
    assert int_poly.contains_point(inside_xyz2)
    assert sp_poly1.contains_point(inside_xyz2)
    assert sp_poly2.contains_point(inside_xyz2)
    print("Should be True ,True ,True : ",
          int_poly.contains_point(inside_xyz3),
          sp_poly1.contains_point(inside_xyz3),
          sp_poly2.contains_point(inside_xyz3))
    assert int_poly.contains_point(inside_xyz3)
    assert sp_poly1.contains_point(inside_xyz3)
    assert sp_poly2.contains_point(inside_xyz3)

    inside_res = list(int_poly.inside)
    for itr in range(0, len(inside_res)):
        print("Should be True ,True ,True : ",
              int_poly.contains_point(inside_res[itr]),
              sp_poly1.contains_point(inside_res[itr]),
              sp_poly2.contains_point(inside_res[itr]))
        assert int_poly.contains_point(inside_res[itr])
        assert sp_poly1.contains_point(inside_res[itr])
        assert sp_poly2.contains_point(inside_res[itr])
Example #9
0
def test_geos2():
    """do initial test posted to spherical_geometry problem report"""
    n_fill = 10

    theta1_high_fill = np.full(n_fill, 5.)
    theta1_low_fill = np.full(n_fill, -65.)
    phi1_high_fill = np.linspace(50. - 360., 50. - 1., n_fill)
    phi1_low_fill = phi1_high_fill[::-1]
    theta1s = np.hstack(
        [theta1_high_fill, theta1_low_fill, theta1_high_fill[0]])
    phi1s = np.hstack([phi1_high_fill, phi1_low_fill, phi1_high_fill[0]])

    phi_in1 = 0.
    theta_in1 = 0.

    bounding_xyz1 = np.array(sgv.radec_to_vector(phi1s, theta1s,
                                                 degrees=True)).T
    inside_xyz1 = np.array(
        sgv.radec_to_vector(phi_in1, theta_in1, degrees=True))
    sp_poly1 = SphericalPolygon(bounding_xyz1, inside=inside_xyz1)

    theta2_high_fill = np.full(n_fill, -30.)
    theta2_low_fill = np.full(n_fill, -85.)
    phi2_high_fill = np.linspace(65 - 360., 55. - 10., n_fill)
    phi2_low_fill = np.linspace(5 - 360., 5. - 10., n_fill)[::-1]
    theta2s = np.hstack(
        [theta2_high_fill, theta2_low_fill, theta2_high_fill[0]])
    phi2s = np.hstack([phi2_high_fill, phi2_low_fill, phi2_high_fill[0]])

    phi_in2 = 0.
    theta_in2 = -70.

    bounding_xyz2 = np.array(sgv.radec_to_vector(phi2s, theta2s,
                                                 degrees=True)).T
    inside_xyz2 = np.array(
        sgv.radec_to_vector(phi_in2, theta_in2, degrees=True))
    sp_poly2 = SphericalPolygon(bounding_xyz2, inside=inside_xyz2)

    int_poly = sp_poly2.intersection(sp_poly1)

    theta_out = 30. * np.pi / 180.
    phi_out = 0.
    outside_xyz = np.array(
        sgv.radec_to_vector(phi_out, theta_out, degrees=False))

    theta_in3 = -40. * np.pi / 180.
    phi_in3 = 0.
    inside_xyz3 = np.array(
        sgv.radec_to_vector(phi_in3, theta_in3, degrees=False))

    assert not int_poly.contains_point(outside_xyz)

    assert not int_poly.contains_point(outside_xyz)
    assert not sp_poly1.contains_point(outside_xyz)
    assert not sp_poly2.contains_point(outside_xyz)
    assert not int_poly.contains_point(inside_xyz1)
    assert sp_poly1.contains_point(inside_xyz1)
    assert not sp_poly2.contains_point(inside_xyz1)
    assert not int_poly.contains_point(inside_xyz2)
    assert not sp_poly1.contains_point(inside_xyz2)
    assert sp_poly2.contains_point(inside_xyz2)
    assert int_poly.contains_point(inside_xyz3)
    assert sp_poly1.contains_point(inside_xyz3)
    assert sp_poly2.contains_point(inside_xyz3)
Example #10
0
def analyze_protein(protein):
    prot = protein[0]
    chain = protein[1]
    print("Downloading {}{}.".format(prot, chain))

    cmd = "wget https://files.rcsb.org/download/{}.pdb".format(prot)
    proc = Popen(shlex.split(cmd), stdout=DEVNULL, stderr=STDOUT)
    proc.communicate()

    print("Extracting coordinates.")
    cmd = "./pdb_to_xyz.R {}.pdb --chain-id={} -o {}.txt".format(
        prot, chain, prot)
    proc = Popen(shlex.split(cmd), stdout=DEVNULL, stderr=STDOUT)
    proc.communicate()

    print("Removing pdb file.")
    proc = Popen(["rm", "{}.pdb".format(prot)], stdout=DEVNULL, stderr=STDOUT)
    proc.communicate()

    print("Analyzing protein")

    for proj in projections:
        cmd = "./polynomial_invariant {}.txt --names-db=internal --arrow --nb-projections={} --output-diagram={}{}_gl_{}.txt".format(
            prot, proj, prot, chain, proj)
        proc = Popen(shlex.split(cmd), stdout=DEVNULL, stderr=STDOUT)
        proc.communicate()

        name = "{}{}_gl_{}.txt".format(prot, chain, proj)
        origins, origin_types = [], []
        file = open(name, "r")
        next(file)
        me = 0
        checked = []
        vertex_to_index_list = dict()
        edges_to_add = []
        for l in file:
            line = l.strip('\n').split('\t')
            if line[3] != 'UNKNOWN':
                if '*' not in line[3]:
                    origin_types.append(line[3])
                    origins.append(
                        [float(line[0]),
                         float(line[1]),
                         float(line[2])])
                    if line[3] not in checked:
                        vertex_to_index_list[repr(line[3])] = me
                        me += 1

        origins = numpy.array(origins)
        voro = SphericalVoronoi(origins)
        voro.sort_vertices_of_regions()
        for i in range(len(voro.regions)):
            for j in range(i + 1, len(voro.regions)):
                intersect = list(set(voro.regions[i]) & set(voro.regions[j]))
                if intersect:
                    permissable = set(
                        [1, len(voro.regions[i]),
                         len(voro.regions[j])])
                    index_A = [voro.regions[i].index(x) for x in intersect]
                    diff_A = [
                        abs(j - i) for i, j in zip(index_A[:-1], index_A[1:])
                    ]
                    index_B = [voro.regions[j].index(x) for x in intersect]
                    diff_B = [
                        abs(j - i) for i, j in zip(index_B[:-1], index_B[1:])
                    ]
                    # print ("intersect",intersect,"voro[i]",voro.regions[i],"voro[j]",voro.regions[j])
                    # print ("index_A",index_A,"diff_A",diff_A,"index_B",index_B,"diff_B",diff_B)
                    # print ("perm_A",permissable & set(diff_A),"perm_B", permissable & set(diff_B))
                    if permissable & set(diff_A) and permissable & set(diff_B):
                        for k in range(int(len(intersect) / 2)):
                            edges_to_add.append(
                                (vertex_to_index_list[repr(origin_types[i])],
                                 vertex_to_index_list[repr(origin_types[j])]))


# Comment lines 155 - 165 and uncomment lines 169-170 to go to previous version.

# for k in range(int(len(intersect)/2)):
#     edges_to_add.append((vertex_to_index_list[repr(origin_types[i])],vertex_to_index_list[repr(origin_types[j])]))

# print ("len",len(voro.vertices))
        print("Creating graph.")

        g = igraph.Graph(len(origin_types), directed=False)

        origin_types = [
            x.split("|")[0].strip('m').strip('s') for x in origin_types
        ]
        g.vs["label"] = [x for x in origin_types]
        g.add_edges(edges_to_add)
        all_connections = []
        for edge in g.es:
            src = g.vs[edge.source]['label']
            tgt = g.vs[edge.target]['label']
            if (src == '3_1' and tgt != '3_1'):
                all_connections.append((src, tgt))
            elif (src != '3_1' and tgt == '3_1'):
                all_connections.append((tgt, src))

        proj_errors = 0
        error_pairs = []
        for pair in all_connections:

            if theoretical_values[pair[0]][pair[1]] != 1:
                proj_errors += 1
                error_pairs.append(pair)
        try:
            errors = round(proj_errors / len(all_connections), 4)
        except ZeroDivisionError:
            errors = 'NaN'

        edges_between = []
        for edge in g.es:
            src = g.vs[edge.source]['label']
            tgt = g.vs[edge.target]['label']
            if (src == '3_1' and tgt == '2_1'):
                edges_between.append((src, tgt))
            elif (src == '2_1' and tgt == '3_1'):
                edges_between.append((tgt, src))

        if len(edges_between) > 0:
            try:
                interface = round(len(edges_between) / len(all_connections), 4)
            except ZeroDivisionError:
                interface = 'NaN'
        else:
            interface = 'NaN'

        area_31, area_21 = [], []
        all_area_31, all_area_21 = [], []

        # voro_areas = voro.calculate_areas()

        print("voro_areas: ", voro_areas)
        for i in range(len(voro.regions)):
            voronoi_cell = numpy.asarray(
                [list(voro.vertices[x]) for x in voro.regions[i]])
            if origin_types[i] == '3_1':
                sph_pol = SphericalPolygon(voronoi_cell)
                area_31.append(sph_pol.area())
            elif origin_types[i] == '2_1':
                sph_pol = SphericalPolygon(voronoi_cell)

                area_21.append(sph_pol.area())
        all_area_31 = numpy.sum(area_31)
        all_area_21 = numpy.sum(area_21)

        all_graphs.append({
            'n': str(proj),
            'Error': errors,
            'Interface': interface,
            'Protein': prot + chain,
            'Spectrum': len(set(origin_types)),
            'Error Pairs': set(error_pairs),
            'Full Spectrum': set(origin_types),
            'Area  3_1': all_area_31,
            'Area 2_1': all_area_21,
            'Area 2_1/3_1': all_area_21 / all_area_31
        })
Example #11
0
    dRA1 = width / np.cos((Dec + hl) * np.pi / 180)
    dRA2 = width / np.cos((Dec - hl) * np.pi / 180)
    coord1 = np.asarray(
        [RA - dRA2, RA - dRA1, RA + dRA1, RA + dRA2, RA - dRA2])  #RA
    coord2 = np.asarray([Dec - hl, Dec + hl, Dec + hl, Dec - hl,
                         Dec - hl])  #Dec
    return coord1, coord2


# create the triangle test region 'survey'
temp_survey = []
coord1 = np.asarray([60, 40, 80, 60])  #RA
coord2 = np.asarray([10, -20, -20, 10])  #Dec
bounding = np.array(sgv.radec_to_vector(coord1, coord2, degrees=True)).T
inside_val = np.asarray(sgv.radec_to_vector(60, -10, degrees=True))
test_poly = SphericalPolygon(bounding, inside_val)
temp_survey.append(test_poly)
coord1 = np.asarray([160, 140, 180, 160])  #RA
coord2 = np.asarray([10, -20, -20, 10])  #Dec
bounding = np.array(sgv.radec_to_vector(coord1, coord2, degrees=True)).T
inside_val = np.asarray(sgv.radec_to_vector(160, -10, degrees=True))
test_poly = SphericalPolygon(bounding, inside_val)
temp_survey.append(test_poly)
survey_list['triangles'] = temp_survey

# create a WFIRST survey area based off of OGLE
temp_survey = []
coord1 = np.asarray([269.3875, 269.3917, 270.7667, 269.3875])  #RA
coord2 = np.asarray([-27.9944, -29.2208, -28.6108, -27.9944])  #Dec
bounding = np.array(sgv.radec_to_vector(coord1, coord2, degrees=True)).T
inside_val = np.asarray(sgv.radec_to_vector(269.3917, -29.1, degrees=True))