コード例 #1
0
	def initialise(self, dim):
		if not self.init:
			self.dim = dim
			prop = kdtree.Property()
			prop.dimension = dim
			self.index = kdtree.Index(interleaved=False, properties=prop)
			self.init = True
コード例 #2
0
 def __init__(self,
              density_parameter,
              precision_parameter,
              space_bounds,
              global_bounds,
              points=None,
              old_distance=None):
     self.epsilon = density_parameter
     self.delta = precision_parameter
     self.space_bounds = space_bounds
     p = index.Property()
     dimension = len(space_bounds) / 2
     self.dimension = dimension
     p.dimension = dimension
     self.tree = index.Index(properties=p)
     self.id_counter = 0
     self.tree.interleaved = False
     self.bad_boxes = list([search_box(space_bounds.flatten())])
     self.global_bounds = global_bounds
     self.max_length_limit = _maxLengthOfBox(
         self._createRadiusBox([0 * i for i in xrange(0, dimension)],
                               self.epsilon)) / 2.5e3
     self.current_max_length = _maxLengthOfBox(space_bounds)
     self.old_box = list([])
     self.skip_list = list()
     self.skip_radius_multiplier = pow(2.5, dimension)
     if points is not None:
         self.bad_boxes = [
             search_box(self._createRadiusBox(point, old_distance))
             for point in points
         ]
         for point in points:
             self.addPoint(point, False, True)
コード例 #3
0
ファイル: rtreekd.py プロジェクト: zhangOSK/wrs-nxt-IL-RL
 def __init__(self, dimension):
     p = index.Property()
     p.dimension = dimension
     p.storage = index.RT_Memory
     self.__idxkd = index.Index(str(p.dimension) + "d_index", properties=p)
     self.__npoints = 0
     self.__dimension = dimension
コード例 #4
0
def setupIndex():
    idxprop = index.Property()
    idxprop.dimension = DIMENSIONS
    idxprop.dat_extension = 'data'
    idxprop.idx_extension = 'index'
    idx = index.Index('3d_index', properties=idxprop)
    return idx
コード例 #5
0
    def __init__(self, path):
        total_files = int(path)
        total_path = 'data/' + path + '/'

        p = index.Property()
        p.dimension = 128  # D
        p.buffering_capacity = int(math.log(total_files, 10)**2) + 3  # M
        p.dat_extension = 'data'
        p.idx_extension = 'index'
        idx = index.Index('face_recognition_index_' + path, properties=p)

        self.total_files = total_files
        self.path = path
        self.total_path = total_path

        for filename in os.listdir(total_path):
            picture_1 = face_recognition.load_image_file(total_path + filename)
            face_encoding_1 = face_recognition.face_encodings(picture_1)
            if face_encoding_1:
                values = face_encoding_1[0].tolist()
                values = (generate_point(values))
                diccionario.setdefault(len(diccionario), filename)
                idx.insert(len(diccionario) - 1, values)

        file = open("diccionario_" + path + ".json", "w")
        json.dump(diccionario, file)
        file.close()
コード例 #6
0
 def __init__(self, dimension_lengths, O=None):
     """
     Initialize Search Space
     :param dimension_lengths: range of each dimension
     :param O: list of obstacles
     """
     # sanity check
     if len(dimension_lengths) < 2:
         raise Exception("Must have at least 2 dimensions")
     self.dimensions = len(dimension_lengths)  # number of dimensions
     # sanity checks
     if any(len(i) != 2 for i in dimension_lengths):
         raise Exception("Dimensions can only have a start and end")
     if any(i[0] >= i[1] for i in dimension_lengths):
         raise Exception("Dimension start must be less than dimension end")
     self.dimension_lengths = dimension_lengths  # length of each dimension
     p = index.Property()
     p.dimension = self.dimensions
     if O is None:
         self.obs = index.Index(interleaved=True, properties=p)
     else:
         # r-tree representation of obstacles
         # sanity check
         if any(len(o) / 2 != len(dimension_lengths) for o in O):
             raise Exception("Obstacle has incorrect dimension definition")
         if any(o[i] >= o[int(i + len(o) / 2)] for o in O
                for i in range(int(len(o) / 2))):
             raise Exception(
                 "Obstacle start must be less than obstacle end")
         self.obs = index.Index(obstacle_generator(O),
                                interleaved=True,
                                properties=p)
コード例 #7
0
ファイル: voxels.py プロジェクト: francesshei/bsb
    def create(morphology, N, compartments=None):
        from rtree import index
        from rtree.index import Rtree

        p = index.Property(dimension=3)
        tree = index.Index(properties=p)
        if compartments is None:
            compartments = morphology.compartments
        N = min(len(compartments), N)
        for compartment in compartments:
            tree.insert(int(compartment.id),
                        tuple([*compartment.midpoint, *compartment.midpoint]))
        hit_detector = HitDetector.for_rtree(tree)
        bounds, voxels, length, error = voxelize(
            N, morphology.get_bounding_box(compartments=compartments),
            hit_detector)
        voxel_map = morphology.create_compartment_map(tree,
                                                      m_grid(bounds, length),
                                                      voxels, length)
        if error == 0:
            return VoxelCloud(bounds, voxels, length, voxel_map)
        else:
            raise NotImplementedError(
                "Voxelization error: could not find the right amount of voxels. Try N {}"
                .format(
                    # Suggest the closest we got to N for a next attempt
                    ("+" if error > 0 else "") + str(error)))
コード例 #8
0
    def __init__(self, segmentFactory, useIndex=False):
        # We will need the segmentFactory to generate segments on demand
        self.segmentFactory = segmentFactory
        # Prepare network
        self._subnets = []
        self._useIndex = useIndex

        if (self._useIndex):
            # These structures need to be updated for each
            # segment we add to network.

            # Keep index of segments so we don't need to marshal them
            # in/out of rtree.
            self._segments = {}
            self._idsBySegment = {}

            # Lookup table for subnets by segment coordinates.
            # (need to update subnet lookups as they merge)
            self._subnetLookupBySegment = {}
            # rtree spatial index for intersection test speedup
            # setup properties first
            p = index.Property()
            p.index_capacity = 10
            p.leaf_capacity = 10
            p.near_minimum_overlap_factor = 3
            self._spatialIndex = index.Index(properties=p)
コード例 #9
0
 def __init__(self, armName, moveGroup, preemptionCheck):
     # wait for linear path planner
     rospy.wait_for_service('/apc/plan_linear_path')
     rospy.wait_for_service('/apc/invert_trajectory')
     rospy.wait_for_service('/apc/compute_ik_solution')
     rospy.wait_for_service('/apc/plan_cartesian_linear_path')
     self._linearPathPlanner = rospy.ServiceProxy('/apc/plan_linear_path', PlanLinearPath)
     self._trajectoryInverter = rospy.ServiceProxy('/apc/invert_trajectory', InvertTrajectory)
     self._inverseKinematicsSolver = rospy.ServiceProxy('/apc/compute_ik_solution', ComputeIKSolution)
     self._cartesianLinearPathPlanner = rospy.ServiceProxy('/apc/plan_cartesian_linear_path',
                                                           PlanCartesianLinearPath)
     self._armName = armName
     self._moveGroup = moveGroup
     self._roadmap = roadmap.Roadmap()
     self._preemptionCheck = preemptionCheck
     # We are using an RTree to save a mapping between poses and configurations in the roadmap
     prop = index.Property()
     prop.dimension = 6
     self._poseIKCache = index.Index(properties=prop)
     jointNames = ['s0', 's1', 'e0', 'e1', 'w0', 'w1', 'w2']
     if armName == 'left_arm':
         self._armKinematics = baxter_pykdl.baxter_kinematics('left')
         self._limb = baxter_interface.Limb('left')
         self._jointNames = map(lambda x: 'left_' + x, jointNames)
     else:
         self._armKinematics = baxter_pykdl.baxter_kinematics('right')
         self._limb = baxter_interface.Limb('right')
         self._jointNames = map(lambda x: 'right_' + x, jointNames)
コード例 #10
0
ファイル: sgrid.py プロジェクト: moghimis/sci-wms
    def make_rtree(self):

        with self.dataset() as nc:
            sg = load_grid(nc)

            def rtree_generator_function():
                c = 0
                centers = np.dstack((sg.center_lon, sg.center_lat))
                for i, axis in enumerate(centers):
                    for j, (x, y) in enumerate(axis):
                        c += 1
                        yield (c, (x, y, x, y), (i, j))

            logger.info(
                "Building Faces (centers) Rtree Topology Cache for {0}".format(
                    self.name))
            _, temp_file = tempfile.mkstemp(suffix='.face')
            start = time.time()
            p = index.Property()
            p.filename = str(temp_file)
            p.overwrite = True
            p.storage = index.RT_Disk
            p.dimension = 2
            idx = index.Index(p.filename,
                              rtree_generator_function(),
                              properties=p,
                              overwrite=True,
                              interleaved=True)
            idx.close()

            logger.info(
                "Built Faces (centers) Rtree Topology Cache in {0} seconds.".
                format(time.time() - start))
            shutil.move('{}.dat'.format(temp_file), self.face_tree_data_file)
            shutil.move('{}.idx'.format(temp_file), self.face_tree_index_file)
コード例 #11
0
    def __init__(self, nodes, closed: bool, config: dict, container=None):
        """
        :param nodes: initial set of nodes (list of 2/3D coordinates)
        :param closed: whether nodes form a close line
        :param config: morphogenesis parameters
        :param container: optional list of nodes that constrain the growth (via influence on repulsion forces)
        """
        self.nodes = nodes
        self.config = config

        # Init rtree index
        self.index_props = index.Property()
        self.index_props.dimension = config['DIMENSIONS']
        self.index = None
        self.container = container

        self.VISIBILITY_RADIUS = config['VISIBILITY_RADIUS']
        self.REPULSION_FAC = config['REPULSION_FAC']
        self.ATTRACTION_FAC = config['ATTRACTION_FAC']
        self.SPLIT_DIST_THRESHOLD = config['SPLIT_DIST_THRESHOLD']
        self.SIMPLIFICATION_DIST_THRESHOLD = config[
            'SIMPLIFICATION_DIST_THRESHOLD']
        self.SPLIT_CROWD_THRESHOLD = config['SPLIT_CROWD_THRESHOLD']
        self.RAND_OPTIMIZATION_FAC = config['RAND_OPTIMIZATION_FAC']
        self.ATTRACTION = config['ATTRACTION']
        self.SIMPLIFICATION = config['SIMPLIFICATION']
        self.SUBDIVISION_METHOD = config['SUBDIVISION_METHOD']

        self.CLOSED = closed
コード例 #12
0
    def build_geodb(cls, path_streetjson, filename, overwrite=True):
        """ Build up a R-Tree based geodb of street segments.

            Args:
                path_streetjson - (str) Path to street db json file
                filename - (str) filename used to store R-tree index
                overwrite - (bool) whether to overwrite existing file
                        Note: rtree does not support read-only mode.
        """
        idx_p = index.Property()
        idx_p.overwrite = overwrite
        idx = index.Index(filename, properties=idx_p)
        with open(path_streetjson, "r") as fd_r:
            for line in fd_r.readlines():
                street_data = json.loads(line)
                points = street_data["points"]
                # Note: X(long)-Y(lat) coordinates
                db_idx = 0
                for seg_id, (start_pt, end_pt) in enumerate(zip(points, islice(points, 1, None))):
                    bbox = ( # left, bottom, right, top
                        min(start_pt[0], end_pt[0]), min(start_pt[1], end_pt[1]),
                        max(start_pt[0], end_pt[0]), max(start_pt[1], end_pt[1])
                    )
                    headings = cls.get_angels(start_pt, end_pt, False)
                    db_data = {"st_name": street_data["name"],
                               "segment_id": seg_id,
                               "segment_points": (start_pt, end_pt),
                               "headings": headings}
                    idx.insert(db_idx, bbox, obj=db_data)
                    db_idx += 1
        return idx
コード例 #13
0
    def __init__(self):
        self.s = rospy.Service('gp_query_server', Query, self.query_server)
        self.best_node_srv = rospy.Service('best_node_server', BestNode,
                                           self.best_node_srv_callback)
        self.reevaluate_client = rospy.ServiceProxy('reevaluate', Reevaluate)

        self.visualize_mean = rospy.get_param('~visualize/mean', False)
        self.visualize_sigma = rospy.get_param('~visualize/sigma', False)
        self.visualize_pts = rospy.get_param('~visualize/pts', False)
        self.resolution = rospy.get_param('~visualize/resolution', 1)

        self.gain_sub = rospy.Subscriber('gain_node', Node, self.gain_callback)
        self.pose_sub = rospy.Subscriber('pose', Pose, self.pose_callback)
        self.marker_pub = rospy.Publisher('pig_markers',
                                          MarkerArray,
                                          queue_size=10)
        self.mean_pub = rospy.Publisher('mean_markers',
                                        MarkerArray,
                                        queue_size=10)
        self.sigma_pub = rospy.Publisher('sigma_markers',
                                         MarkerArray,
                                         queue_size=10)

        if self.visualize_pts:
            rospy.Timer(rospy.Duration(1), self.rviz_callback)
        if self.visualize_mean or self.visualize_sigma:
            rospy.Timer(rospy.Duration(5), self.evaluate)

        # Get environment boundaries
        try:
            self.min = rospy.get_param('boundary/min')
            self.max = rospy.get_param('boundary/max')
        except KeyError:
            rospy.logwarn("Boundary parameters not specified")
            rospy.logwarn("Defaulting to (-100, -100, 0), (100, 100, 3)...")
            self.min = [-100, -100, 0]
            self.max = [100, 100, 3]

        try:
            self.range = rospy.get_param('aep/gain/r_max') * 2
        except KeyError:
            rospy.logwarn("Range max parameter not specified")
            rospy.logwarn("Defaulting to 8 m...")

        self.bbx = (self.min[0], self.min[1], self.min[2], self.max[0],
                    self.max[1], self.max[2])

        self.x = None
        self.y = None
        self.z = None

        self.hyperparam = gp.HyperParam(l=1, sigma_f=1, sigma_n=0.1)

        # Create r-tree
        p = index.Property()
        p.dimension = 3
        self.idx = index.Index(properties=p)
        self.id = 0

        rospy.Timer(rospy.Duration(5), self.reevaluate_timer_callback)
コード例 #14
0
ファイル: test_r_tree.py プロジェクト: phate09/SafeDRL
 def test_leaves(self):
     os.chdir(os.path.expanduser("~/Development") + "/SafeDRL")
     p = index.Property(dimension=4)
     r = index.Index('save/rtree', properties=p, interleaved=False)
     # nearest = list(r.nearest((0.5, 1.0, 0, 0.25, 0.5, 0.75, 0.5, 0.75), objects='raw'))
     leaves = r.leaves()
     print(leaves)
コード例 #15
0
def init_search(Q, path, frontEnd):
    if frontEnd == False:
        total_path = 'data/' + path + '/'
    else:
        total_path = 'data/imageInput/'
    total_files = int(path)

    with open("diccionario_" + path + ".json") as json_file:
        dict = json.load(json_file)

    picture_1 = face_recognition.load_image_file(total_path + Q)
    face_encoding_1 = face_recognition.face_encodings(picture_1)
    if face_encoding_1:
        values = face_encoding_1[0].tolist()
        values = (generate_point(values))
        p = index.Property()
        p.dimension = 128  # D
        p.buffering_capacity = int(math.log(total_files, 10)**2) + 3  # M
        p.dat_extension = 'data'
        p.idx_extension = 'index'
        p.overwrite = False
        idx = index.Index('face_recognition_index_' + path, properties=p)
        return idx, values, dict
    else:
        return None, None, None
コード例 #16
0
def construct_rtree_index(dataset):
    p = index.Property()
    rtree_idx = index.Index(properties=p)
    count = 0
    for coordinate in dataset:
        rtree_idx.insert(count, (*coordinate, *coordinate))
        count += 1
    return rtree_idx
コード例 #17
0
 def compute_node_index(self):
     prop = index.Property()
     prop.dimension = 2
     self._node_index = index.Index(properties=prop)
     for vidx in range(len(self.graph.vs)):
         position = self.get_screen_coordinates(vidx)
         position += position
         self._node_index.insert(vidx, position)
コード例 #18
0
ファイル: sampler.py プロジェクト: rizasif/hfts_grasp_planner
 def __init__(self, c_space_sampler):
     super(ExtendedFreeSpaceModel, self).__init__(c_space_sampler)
     self._scaling_factors = c_space_sampler.get_scaling_factors()
     prop = index.Property()
     prop.dimension = c_space_sampler.get_space_dimension()
     self._approximate_index = index.Index(properties=prop)
     self._approximate_configs = []
     self._temporal_mini_cache = []
コード例 #19
0
 def test_4d(self):
     """Test we make and query a 4D index"""
     p = index.Property()
     p.dimension = 4
     idx = index.Index(properties = p, interleaved = False)
     idx.insert(1, (0, 0, 60, 60, 22, 22.0, 128, 142))
     hits = idx.intersection((-1, 1, 58, 62, 22, 24, 120, 150))
     self.assertEqual(list(hits), [1])
コード例 #20
0
ファイル: kdtree.py プロジェクト: psavine42/viper-server
def index_2d():
    p = index.Property()
    p.dimension = 2
    p.dat_extension = 'data'
    p.idx_extension = 'index'
    st = './data/index{}'.format(time.time())
    idx3d = index.Index(st, properties=p)
    return idx3d
コード例 #21
0
    def __init__(self, dim=2):
        #TODO: Review this

        p = index.Property()
        p.dimension = dim
        self.V = index.Index(interleaved=True,
                             properties=p)  # vertices in an rtree
        self.G = nx.DiGraph()
コード例 #22
0
def storeNew(filename, model, info=None):
    """
    This creates a pickle file containing the list of earthquake sources
    representing an earthquake source model.

    :parameter filename:
        The name of the file where the to store the model
    :parameter model:
        A list of OpenQuake hazardlib source instances
    """
    # Preparing output filenames
    dname = os.path.dirname(filename)
    slist = re.split('\.', os.path.basename(filename))
    # SIDx
    p = index.Property()
    p.dimension = 3
    sidx = index.Rtree(os.path.join(dname, slist[0]), properties=p)
    #
    cpnt = 0
    l_other = []
    l_points = []
    for src in model:
        if isinstance(src,
                      (AreaSource, SimpleFaultSource, ComplexFaultSource,
                       CharacteristicFaultSource, NonParametricSeismicSource)):
            l_other.append(src)
        else:

            if len(src.hypocenter_distribution.data) == 1:
                srcs = [src]
            else:
                srcs = _split_point_source(src)

            x, y = getcoo(srcs[0].location.longitude,
                          srcs[0].location.latitude)

            for src in srcs:
                l_points.append(src)
                # calculate distances
                z = src.hypocenter_distribution.data[0][1]
                sidx.insert(cpnt, (x, y, z, x, y, z))
                cpnt += 1

    # All the other sources
    fou = open(filename, 'wb')
    pickle.dump(l_other, fou)
    fou.close()
    # Load info
    if info is None:
        info = _get_model_info(model)
    # Points
    fou = open(os.path.join(dname, slist[0]) + '_points.pkl', 'wb')
    pickle.dump(l_points, fou)
    fou.close()
    # Info
    fou = open(os.path.join(dname, slist[0]) + '_info.pkl', 'wb')
    pickle.dump(info, fou)
    fou.close()
コード例 #23
0
ファイル: test_r_tree.py プロジェクト: phate09/SafeDRL
 def test_simple2(self):
     os.chdir(os.path.expanduser("~/Development") + "/SafeDRL")
     p = index.Property(dimension=4)
     r = index.Index('save/rtree', properties=p, interleaved=False)
     print(
         list(
             r.intersection((0.5, 1.0, 0, 0.25, 0.5, 0.75, 0.5, 0.75),
                            objects='raw')))
     print(list(r.intersection((0.5, 1.0, 0, 0.25, 0.5, 0.75, 0.6, 0.75))))
コード例 #24
0
ファイル: common.py プロジェクト: soraxas/sbp-env
 def __init__(self, dimension: int):
     """
     :param dimension: A positive integer that represents :math:`d`,
         the dimensionality of the C-space.
     """
     p = index.Property()
     p.dimension = dimension
     self.V = index.Index(interleaved=True, properties=p)
     self.E = {}  # edges in form E[child] = parent
コード例 #25
0
 def __init__(self):
   p = index.Property()
   p.dimension = 128 #D
   p.buffering_capacity = 10 #M
   p.dat_extension = 'data'
   p.idx_extension = 'index'
   self.idx = index.Index('128d', properties=p)
   self.extract_features()
   self.insert_all()
コード例 #26
0
def make_index():
    p = index.Property()
    p.dimension = 3
    p.dat_extension = 'data'
    p.idx_extension = 'index'
    p.storage = index.RT_Memory
    p.overwrite = True
    idx3 = index.Index(properties=p)
    return idx3
コード例 #27
0
    def __init__(self, saved_path='', bounds=[], override=True):
        p = index.Property()
        p.overwrite = override
        self.r_idx = index.Index(saved_path, properties=p)

        for bound in bounds:
            ID, left, bottom, right, top = bound
            # print( ID, left, bottom, right, top)
            self.r_idx.insert(ID, (left, bottom, right, top))
コード例 #28
0
def test_non_stream_input():
    p = index.Property()
    idx = index.Index(properties=p)
    for i, coords in enumerate(boxes15):
        idx.add(i, coords)

    assert 0 in idx.intersection((0, 0, 60, 60))
    hits = list(idx.intersection((0, 0, 60, 60)))
    assert hits == [0, 4, 16, 27, 35, 40, 47, 50, 76, 80]
コード例 #29
0
    def __init__(self):
        self.index_to_device = self.sql_data_devices(True)[0]
        self.device_to_index = self.sql_data_devices(False)[0]
        self.device_to_site = self.sql_data_devices(False)[1]
        self.site_to_devices = self.sql_data_devices(True)[1]

        self.p = index.Property()
        self.p.dimension = 3
        self.idx = index.Index(properties=self.p)
        self.load_data()
コード例 #30
0
    def test_stream_input(self):
        p = index.Property()
        sindex = index.Index(self.boxes15_stream(), properties=p)
        bounds = (0, 0, 60, 60)
        hits = sindex.intersection(bounds)
        self.assertEqual(sorted(hits), [0, 4, 16, 27, 35, 40, 47, 50, 76, 80])
        objects = list(sindex.intersection((0, 0, 60, 60), objects=True))

        self.assertEqual(len(objects), 10)
        self.assertEqual(objects[0].object, 42)