Esempio n. 1
0
def main():
	with open("/home/lgblkb/PycharmProjects/Egistic/Scripts/polygon.xml") as fd:
		xml=fd.read()
	headers={'content-type':'application/xml'}
	json_data=Box(requests.post(data=xml,url="https://geo.egistic.kz/geoserver/wps",headers=headers).json())
	# simple_logger.debug('json_data.keys():\n%s',json_data.keys())
	lines_count=i_feature=0
	for i_feature,feature in enumerate(json_data.features):
		# simple_logger.debug('feature: %s',feature)
		# simple_logger.debug('feature.geometry: %s',feature.geometry)
		linestring=shg.shape(feature.geometry)
		line=TheLine(linestring)  #.plot()
		if len(line)<4: continue
		elif line[0]!=line[-1]:
			lines_count+=1
			# line.plot()
			continue
		# print('Aha')
		# simple_logger.debug('len(line): %s',len(line))
		ThePoly(line.xy).plot(lw=0.7)
	simple_logger.info('Total number of features: %s',i_feature)
	simple_logger.debug('lines_count: %s',lines_count)
	conversion_percentage=(i_feature-lines_count)/i_feature*100
	simple_logger.debug('conversion_percentage: %.3f%%',conversion_percentage)
	
	plt.show()
	
	
	
	pass
Esempio n. 2
0
def main():
    test_folder = gsup.Folder(
        r'/home/lgblkb/PycharmProjects/egistic_navigation/egistic_navigation/test_folderchik_3'
    )
    a = test_folder.create_iterated()
    simple_logger.debug('a: %s', a)

    pass
Esempio n. 3
0
	def generate_grid_points(self,grid_resolution):
		corners=self.bounds_xy[[0,2]]
		x_grid_info=np.arange(*corners[:,0],step=grid_resolution)
		y_grid_info=np.arange(*corners[:,1],step=grid_resolution)
		grid_x,grid_y=np.meshgrid(x_grid_info,y_grid_info)
		xy_coors=np.stack([grid_x.ravel(),grid_y.ravel()]).T
		# print(xy_coors)
		xy_df=pd.DataFrame(xy_coors,columns=['x','y'])
		xy_df['inside']=xy_df.apply(lambda coor:self.polygon.contains(shg.Point([coor.x,coor.y])),axis=1)
		xy_df=xy_df[xy_df['inside']].drop(columns=['inside'])
		simple_logger.debug('xy_df.shape: %s',xy_df.shape)
		return xy_df
Esempio n. 4
0
	def generate_clusters(self,grid_resolution,n_clusters,show='',random_state=1):
		# interior_points=self.get_interior_points(distance=grid_resolution)
		interior_points=self.generate_grid_points(grid_resolution=grid_resolution)
		logger.debug('len(interior_points): %s',len(interior_points))
		n_clusters=min(n_clusters,len(interior_points))
		simple_logger.debug('n_clusters: %s',n_clusters)
		kmeans=KMeans(n_clusters=n_clusters,random_state=random_state)
		kmeans.fit(interior_points)
		if show:
			plot_clusters,plot_self=1,0
			if len(show)==1: plot_clusters=int(show)
			elif len(show)==2: plot_clusters,plot_self=[int(x) for x in show]
			if plot_self: self.plot()
			if plot_clusters:
				plt.scatter(kmeans.cluster_centers_[:,0],kmeans.cluster_centers_[:,1],c='k')
		return kmeans.cluster_centers_
Esempio n. 5
0
def test_create_iterated_path():
    path = r'/home/lgblkb/PycharmProjects/egistic_navigation/egistic_navigation/configs_local_koko.yaml'
    new_path = create_iterated_path(path)
    simple_logger.debug('new_path:\n%s', new_path)

    path = r'/home/lgblkb/PycharmProjects/egistic_navigation/egistic_navigation/configs_local_koko_2.yaml'
    new_path = create_iterated_path(path)
    simple_logger.debug('new_path:\n%s', new_path)

    path = r'/home/lgblkb/PycharmProjects/egistic_navigation/egistic_navigation/configs.yaml'
    new_path = create_iterated_path(path)
    simple_logger.debug('new_path:\n%s', new_path)
Esempio n. 6
0
	def synthesize(cls,cities_count,poly_extent=1000,hole_count=0,seed=None,hole_cities_count=None):
		if seed is None: seed=np.random.randint(0,int(1e6))
		simple_logger.info('seed: %s',seed)
		np.random.seed(seed)
		try_count=0
		while True:
			try_count+=1
			simple_logger.debug('Try main_poly: %s',try_count)
			seed=np.random.randint(100000000)
			try:
				unholy_field=cls.from_tsp(cities_count=cities_count,seed=seed,city_locator=lambda ps:ps*poly_extent)
				if hole_count<1: return unholy_field
				# holes_current_count=0
				holes=list()

				for i in range(1000):
					#.plot()
					seed=np.random.randint(100000000)
					hole=cls.from_tsp(cities_count=hole_cities_count or np.random.randint(4,10),seed=seed,
					                  city_locator=lambda ps:ps*np.random.randint(poly_extent*0.2,poly_extent*0.5)+
					                                         np.random.randint(poly_extent*0.1,poly_extent*0.2,2))
					# holy_poly=shg.Polygon(unholy_field.xy,[hole.xy,*map(lambda h:h.xy,holes)])
					# hole.plot()

					# simple_logger.debug('unholy_field.p.contains(hole.p): %s',unholy_field.p.contains(hole.p))
					# simple_logger.debug('unholy_field.p.intersects(hole.p): %s',unholy_field.p.intersects(hole.p))
					if not unholy_field.p.contains(hole.p): continue

					# 	simple_logger.debug('Contains!!!')
					# if unholy_field.p.intersects(hole.p):
					# 	simple_logger.debug('Intersects!!!')
					# if (not unholy_field.p.contains(hole.p)) or unholy_field.p.intersects(hole.p):
					# 	continue
					# hole.plot()
					# unholy_field.plot()
					# plt.show()
					hole_friendly=True
					for other_hole in holes:
						# simple_logger.debug('other_hole.p.intersects(hole.p):\n%s',other_hole.p.intersects(hole.p))
						# simple_logger.debug('other_hole.p.within(hole.p):\n%s',other_hole.p.within(hole.p))
						if other_hole.p.intersects(hole.p) or other_hole.p.within(hole.p):
							hole_friendly=False
							break
					if not hole_friendly: continue

					holes.append(hole)
					holy_poly=shg.Polygon(unholy_field.xy,list(map(lambda x:x.xy,holes)))  #.buffer(0)

					# if not holy_poly.is_valid:
					# 	holes.pop()
					# 	continue

					holy_field=cls(holy_poly,area=holy_poly.area)

					simple_logger.debug('Proper hole created at i = %s',i)
					# holy_field.plot()
					# unholy_field.plot()
					# plt.show()

					if len(holy_field.holes)==hole_count:
						# if holes_current_count==hole_count:
						gc.collect()
						return holy_field
				gc.collect()
			# if holy_field.is_multilinestring:
			# 	# holes_current_count+=1
			# 	# simple_logger.debug('holy_field:\n%s',holy_field)
			# 	# the_hole.plot()
			# 	# unholy_field.plot()
			# 	# plt.show()
			# 	# holes.append(the_hole)
			# 	# simple_logger.debug('Hole %s added.',hole_count)
			# 	# holy_field=cls(shg.Polygon(unholy_field.xy,holes=list(map(lambda x:x.xy,holes))))#.plot(c='r')
			# 	if len(holy_field.holes)==hole_count:
			# 		# if holes_current_count==hole_count:
			# 		return holy_field
			except Exception as exc:
				simple_logger.debug('exc:\n%s',exc)
				raise
				pass
def main():
    env = gym.make('Egistic_Nav_Env:nav_env-v0')
    simple_logger.debug('env.action_space:\n%s', env.action_space)
    # simple_logger.debug('env.action_space:\n%s',env.env)
    simple_logger.debug('env.metadata:\n%s', env.metadata)
    simple_logger.debug('env.observation_space:\n%s', env.observation_space)
    simple_logger.debug('env.reward_range:\n%s', env.reward_range)
    simple_logger.debug('env.spec:\n%s', env.spec)
    simple_logger.debug('env.action_space:\n%s', env.action_space)

    # gym.make('gym_foo:foo-v0')
    pass
Esempio n. 8
0
def get_the_best_solution(
    crop_field,
    offset_distance,
    save_folder,
    show,
):
    # field_lines=crop_field.get_optimal_field_lines(offset_distance,show=show)
    # field_lines=crop_field.get_optimal_field_lines(offset_distance,show=show)
    # single_piece_cost=len(field_lines)
    single_piece_cost, _ = crop_field.get_min_altitude(use_mp=use_mp)
    min_cost = single_piece_cost
    simple_logger.info('Single_piece_cost: %s', single_piece_cost)
    # filepath=save_folder.get_filepath('initial',single_piece_cost=single_piece_cost,ext='.png')
    # save_current_figure(filepath,clear_after=clear_figure_after_plot)
    # if not clear_figure_after_plot: plt.show()
    # return
    set_of_fields = SetOfFields()
    set_of_fields.add(crop_field, solution_cost=single_piece_cost)

    for i_start, start_node in enumerate(crop_field.all_points):
        for solution_fields in crop_field.get_subfields(
                start_node, offset_distance=offset_distance, show=show):
            if len(solution_fields) == 1:
                # simple_logger.info('min_cost: %s',min_cost)
                # return min_cost,set_of_fields.solutions[min_cost][0]
                plt.clf()
                break
            cumulative_cost = 0
            # cumulative_cost=sum(gsup.ParallelTasker(calculate_field_cost,offset_distance=offset_distance,error_cost=single_piece_cost*2,show=False)\
            #                     .set_run_params(solution_field=solution_fields).run(sleep_time=0.1))

            for solution_field in solution_fields:
                if solution_field.is_empty:
                    cumulative_cost += single_piece_cost
                else:
                    cumulative_cost += calculate_field_cost(solution_field,
                                                            offset_distance,
                                                            single_piece_cost *
                                                            2,
                                                            show=show)
                    solution_field.plot()

            # remaining_shrinked_poly=remaining_field.geometry.buffer(-offset_distance/2,join_style=shg.JOIN_STYLE.mitre)
            # if isinstance(remaining_shrinked_poly,shg.MultiPolygon):
            # 	cumulative_cost=p1_cost
            # 	for sub_shrinked_poly in remaining_shrinked_poly:
            # 		expanded_poly=sub_shrinked_poly.buffer(offset_distance/2,cap_style=shg.CAP_STYLE.flat)
            # 		try:
            # 			sub_field_cost=len(FieldPoly(expanded_poly).get_optimal_field_lines(offset_distance,show=show))
            # 		except:
            # 			sub_field_cost=single_piece_cost*2
            # 		cumulative_cost+=sub_field_cost
            # else:
            # 	try:
            # 		remaining_cost=len(remaining_field.get_optimal_field_lines(offset_distance,show=show))
            # 	except:
            # 		remaining_cost=single_piece_cost*2
            # 	cumulative_cost=p1_cost+remaining_cost
            simple_logger.debug('cumulative_cost: %s', cumulative_cost)

            filepath = save_folder.get_filepath(
                start_node_index=i_start,
                cumulative_cost=cumulative_cost,
                ext='.png',
                iterated=True)
            save_current_figure(filepath, clear_after=clear_figure_after_plot)
            if not clear_figure_after_plot: plt.show()

            if cumulative_cost < single_piece_cost:
                simple_logger.info('Another solution found!')
                if cumulative_cost < min_cost: min_cost = cumulative_cost
                is_main_field_new = set_of_fields.add(
                    *solution_fields, solution_cost=cumulative_cost)
                # simple_logger.debug('is_main_field_new: %s',is_main_field_new)
                if is_main_field_new:
                    # for sf in solution_fields: sf.plot()
                    # filepath=save_folder.get_filepath(start_node_index=i_start,cumulative_cost=cumulative_cost,ext='.png')
                    # save_current_figure(filepath,clear_after=clear_figure_after_plot)
                    # if not clear_figure_after_plot: plt.show()
                    pass
            plt.clf()

    # if len(save_folder.children())==1: save_folder.delete()

    simple_logger.info('min_cost: %s', min_cost)

    return min_cost, set_of_fields.solutions[min_cost][0]