示例#1
0
 def intersections(self):
     #
     # Get common transcripts in sets of the same population from dist-file
     #
     algo = ""
     if int(self.v.get()) == 1:
         algo = "Qgrs"
     if int(self.v.get()) == 2:
         algo = "QgrsWeb"
     if int(self.v.get()) == 3:
         algo = "Pqs"
     inters.intersect(self.pop.get(), algo)
     return
示例#2
0
文件: main.py 项目: hacknus/samanta
    def initial_condition(self, set_seed=True):
        '''
		takes number of cities and a boolean as arguments
		if boolean is true, then the seed will be fixed such that on every run the 'random' values are the same
		this makes it easy to compare in the debug phase
		'''
        if set_seed:
            np.random.seed(0)  #to get each time the same random numbers

        for i in range(self.n):
            pos = np.random.rand(2)
            self.city_list.append(city(pos, i))
            self.ant_list.append(ant(self.city_list[i], self.n, i))
            self.ant_list.append(ant(self.city_list[i], self.n, i))

        self.paths = Paths(self.n, self.city_list)
        for i in range(self.n):
            for j in range(self.n):
                for k in range(len(self.objects)):
                    if intersect(self.city_list[i].position,
                                 self.city_list[j].position,
                                 self.objects[k][0], self.objects[k][1]):
                        self.paths.distances[i][j] = 10000
                        self.paths.distances[j][i] = 10000
                        self.paths.distances[j][i] = 10000
示例#3
0
def compute_light(light, scene, intersection, viewer):
    to_light = light.position - intersection.position
    occlusion = None
    other_objects = [o for o in scene.objects if o != intersection.obj]
    for obj in other_objects:
        occlusion = intersect(obj, Ray(intersection.position, to_light))
        if occlusion != None:
            dist_to_occl = la.norm(occlusion.position - intersection.position)
            if dist_to_occl < la.norm(to_light) and to_light.dot(
                    occlusion.position - intersection.position) > 0:
                return np.array([0., 0., 0.])
    return phong_illuminate(light, intersection.position, intersection.normal,
                            intersection.obj, viewer)
示例#4
0
def trace_ray(ray, scene, on_reflection_object=None, n_reflections=0):
    n_reflections += 1
    if n_reflections == 6:
        return np.array([0., 0., 0.])
    intersections = []
    #Find the object to print on the image
    other_objects = [o for o in scene.objects if o != on_reflection_object]
    for obj in other_objects:
        intersection = intersect(obj, ray)
        if intersection != None:
            intersections.append(intersection)

    if len(intersections) > 0:
        min_dist = inf
        for inter in intersections:
            dist_from_inter = la.norm(ray.starting_point - inter.position)
            if dist_from_inter < min_dist:
                closest_instersection = inter
                min_dist = dist_from_inter

        result_color = ambiant_illuminate(
            closest_instersection.obj) if len(scene.lights) > 0 else np.array(
                [0., 0., 0.])
        for light in scene.lights:
            result_color += compute_light(light, scene, closest_instersection,
                                          ray.starting_point)

        R = ray.direction
        N = closest_instersection.normal
        reflection_ray = Ray(closest_instersection.position,
                             R - 2 * R.dot(N) * N)
        reflection_factor = closest_instersection.obj.material.reflection
        result_color = result_color * (
            1 - reflection_factor) + reflection_factor * trace_ray(
                reflection_ray,
                scene,
                on_reflection_object=closest_instersection.obj,
                n_reflections=n_reflections)
        return result_color
    else:
        return np.array([0., 0., 0.])
示例#5
0
def main():
    sys.setrecursionlimit(1500)
    print(sys.getrecursionlimit())
    pd.set_option('display.max_columns', 999)
    cols = [
        "poly_name", "poi_density", "avg_pw_dist", "diameter", "gyration",
        "chull_area_km2", "chull_perim_km", "mean_intersec_area",
        "st_dev_intersec_area", "mean_jaccard_sim", "st_dev_jaccard_sim"
    ]
    vpoly_properties_df = pd.DataFrame(columns=cols)
    #data folder: /home/olivera/Documents/data
    for i in range(1, 314):
        print("working on poly ", str(i))
        name = "poly_" + str(i)
        poi_density = poi_density_read(i)
        #calculated when central point is mean coord
        avg_pw_dist = adgc(i)
        avg_dist = avg_pw_dist[0]
        diameter = avg_pw_dist[1]
        gyration = avg_pw_dist[2]

        chull_area_km2 = avg_pw_dist[3]
        chull_perim_km = avg_pw_dist[4]
        intersec_res = intersect(i)
        intersec_st_dev = intersec_res[0]
        intersec_mean = intersec_res[1]
        jaccard_st_dev = intersec_res[2]
        jaccard_mean = intersec_res[3]
        #calculated when central point is vpoly centroid
        avg_pw_dist_2 = adg2(i)
        avg_dist2 = avg_pw_dist_2[0]
        diameter2 = avg_pw_dist_2[1]
        gyration2 = avg_pw_dist_2[2]

        comm_coverage_overall = comm_coverage(i)
        coverage_area_km2 = comm_coverage_overall[0]
        coverage_avg_area_km2 = comm_coverage_overall[1]

        new_row = {
            'poly_name': name,
            'poi_density': poi_density,
            'avg_pw_dist': avg_dist,
            'diameter': diameter,
            'gyration': gyration,
            'chull_area_km2': chull_area_km2,
            'chull_perim_km': chull_perim_km,
            'mean_intersec_area': intersec_mean,
            'st_dev_intersec_area': intersec_st_dev,
            'mean_jaccard_sim': jaccard_mean,
            'st_dev_jaccard_sim': jaccard_st_dev,
            'avg_pw_dist2': avg_dist2,
            'diameter2': diameter2,
            'gyration2': gyration2,
            'coverage_area_km2': coverage_area_km2,
            'coverage_avg_area_km2': coverage_avg_area_km2
        }
        vpoly_properties_df = vpoly_properties_df.append(new_row,
                                                         ignore_index=True)

    #print(vpoly_properties_df)
    nonull = vpoly_properties_df.fillna(0)
    nonull.to_pickle(
        "/home/olivera/Documents/data/vpoly_properties_update.pkl")