Пример #1
0
 def __init__(self, width, height, rows, columns, selection_color,
              grid_color, grid_width):
     super(HexCanvas, self).__init__()
     self.grid = hexgrid.Grid(hexgrid.OrientationFlat, hexgrid.Point(0, 0),
                              hexgrid.Point(width, height),
                              morton.Morton(2, 32))
     self.hexes = []
     for x in range(0, rows):
         for y in range(0, columns):
             self.hexes.append(hex_at(x, y))
     lines_dict = {}  # dictionary of Point() to Point()[]
     for h in range(0, len(self.hexes)):
         corners = self.grid.hex_corners(self.hexes[h])
         for i in range(0, 6):
             if corners[i] not in lines_dict.keys():
                 lines_dict[corners[i]] = []
             if not corners[(i + 1) % 6] in lines_dict[corners[i]]:
                 if corners[(i + 1) % 6] not in lines_dict.keys() \
                         or corners[i] not in lines_dict[corners[(i + 1) % 6]]:
                     lines_dict[corners[i]].append(corners[(i + 1) % 6])
     with self.canvas:
         Color(selection_color[0], selection_color[1], selection_color[2],
               selection_color[3])
         self.selection_mesh = Mesh(vertices=hex_vertices(
             self.grid, self.hexes[0]),
                                    indices=[0, 1, 2, 3, 4, 5],
                                    mode='triangle_fan')
         Color(grid_color[0], grid_color[1], grid_color[2], grid_color[3])
         for key in lines_dict.keys():
             lines = []
             for point in lines_dict[key]:
                 lines.append([key.x, key.y, point.x, point.y])
             Line(points=lines, width=grid_width, cap='square')
Пример #2
0
def compute_grid_cell_id(df):
    m = morton.Morton(dimensions=2, bits=64)

    def get_hash(point, grid_size=GRID_SIZE):
        return m.pack(int(point.X // grid_size), int(point.Y // grid_size))

    df['hash'] = df[['X', 'Y']].apply(get_hash,
                                      grid_size=GRID_SIZE,
                                      meta=('hash', int),
                                      axis=1)
    return df
Пример #3
0
def aStar(request):
    global startGu, endGu
    center = hexgrid.Point((float(startX) + float(endX)) / 2,
                           (float(startY) + float(endY)) / 2)
    rate = 110.574 / (111.320 * math.cos(37.55582994870823 * math.pi / 180))
    grid = hexgrid.Grid(hexgrid.OrientationFlat, center,
                        Point(rate * 0.00015, 0.00015), morton.Morton(2, 32))
    sPoint = grid.hex_at(Point(float(startX), float(startY)))
    ePoint = grid.hex_at(Point(float(endX), float(endY)))
    map_size = max(abs(sPoint.q), abs(sPoint.r))
    road1 = Roadtohexgrid.objects.filter(is_danger=1, hexgrid_gu=startGu).all()
    road2 = Roadtohexgrid.objects.filter(is_danger=1, hexgrid_gu=endGu).all()
    total_road = road1.union(road2, all=False)
    wall1 = Roadtohexgrid.objects.filter(is_danger=0, hexgrid_gu=startGu).all()
    wall2 = Roadtohexgrid.objects.filter(is_danger=0, hexgrid_gu=endGu).all()
    total_wall = wall1.union(wall2, all=False)
    wh = GridWithWeights(layout_flat, Point(rate * 0.00015, 0.00015), center,
                         map_size + 5)
    for r in total_road:
        gis = Geometry(r.hexgrid_loc.hex()[8:])
        h = grid.hex_at(shape(gis.geojson))
        wh.weights[(h.q, h.r)] = 1

    for w in total_wall:
        gis = Geometry(w.hexgrid_loc.hex()[8:])
        h = grid.hex_at(shape(gis.geojson))
        wh.weights[(h.q, h.r)] = 200

    start, goal = (sPoint.q, sPoint.r), (ePoint.q, ePoint.r)
    came_from, cost_so_far = a_star_search(wh, start, goal)
    pointList = reconstruct_path(came_from, start=start, goal=goal)
    plist = []
    for p in pointList:
        point = wh.hex_to_pixel(hexgrid.Hex(p[0], p[1]))
        plist.append([point.x, point.y])
    crime_location = {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": plist
        }
    }
    pistes = {"type": "FeatureCollection", "features": [crime_location]}

    return HttpResponse(json.dumps({'pistes': pistes}),
                        content_type="application/json")
Пример #4
0
import pandas
import morton
import time
import copy
import os

############
# recoding #
############

# Uniform #

df = pandas.read_csv('ds_uniform.csv', header=None)
z_values = []
m = morton.Morton(dimensions=2, bits=32)

for i in range(df.count()[0]):
    z_values.append(m.pack(df[0][i], df[1][i]))

df_z_values = pandas.DataFrame(z_values, columns= ["z_value"])
df_z_values.to_csv("z_values_uniform.csv", index_label="index")

del(df)
del(df_z_values)


# Gaussian #
df = pandas.read_csv('ds_gaussian.csv', header=None)
z_values = []
m = morton.Morton(dimensions=2, bits=32)
Пример #5
0
def XYZMorton(x, y, z):
    """ Get morton order from XYZ coordinates """
    m = morton.Morton(dimensions=3, bits=64)
    return m.pack(x, y, z)
Пример #6
0
def MortonXYZ(zindex):
    """ Get XYZ coordinates from morton order """
    m = morton.Morton(dimensions=3, bits=64)
    return m.unpack(zindex)
Пример #7
0
def main(COLL_NAME,
         EXP_NAME,
         COORD_FRAME,
         LOCATIONS,
         BF=[5, 5, 5],
         CHAN_NAMES=None,
         num_threads=6,
         CONFIG_FILE=None):

    L = genfromtxt(LOCATIONS, delimiter=',', skip_header=0,
                   dtype='int32').tolist()
    m = morton.Morton(dimensions=3, bits=64)
    Lzo = sorted([m.pack(L[i][0], L[i][1], L[i][2]) for i in range(len(L))])

    loc = np.asarray([m.unpack(l) for l in Lzo])

    config = configparser.ConfigParser()
    config.read(CONFIG_FILE)
    TOKEN = config['Default']['token']
    boss_url = ''.join((config['Default']['protocol'], '://',
                        config['Default']['host'], '/v1/'))

    #intern
    rem = BossRemote(CONFIG_FILE)

    cfr = rem.get_project(CoordinateFrameResource(COORD_FRAME))

    ext = {
        'x': [cfr.x_start, cfr.x_stop],
        'y': [cfr.y_start, cfr.y_stop],
        'z': [cfr.z_start, cfr.z_stop]
    }

    ## remove coordinates that are outside buffer area.
    x_bnd = [
        np.all([x[0] - BF[0] >= ext['x'][0], x[0] + BF[0] + 1 <= ext['x'][1]])
        for x in loc
    ]
    y_bnd = [
        np.all([y[1] - BF[1] >= ext['y'][0], y[1] + BF[1] + 1 <= ext['y'][1]])
        for y in loc
    ]
    z_bnd = [
        np.all([z[2] - BF[2] >= ext['z'][0], z[2] + BF[2] + 1 <= ext['z'][1]])
        for z in loc
    ]

    xyzbnd = np.asarray(
        [np.all([x_bnd[i], y_bnd[i], z_bnd[i]]) for i in range(len(x_bnd))])

    ## Select only locations that are buffered away from the edge.
    loc = loc[xyzbnd]

    ## Compute the buffered ranges
    x_rng = [[x[0] - BF[0], x[0] + BF[0] + 1] for x in loc]
    y_rng = [[y[1] - BF[1], y[1] + BF[1] + 1] for y in loc]
    z_rng = [[z[2] - BF[2], z[2] + BF[2] + 1] for z in loc]

    ChanList = []
    for ch in CHAN_NAMES:
        di = [{
            'rem':
            rem,
            'ch_rsc':
            ChannelResource(ch, COLL_NAME, EXP_NAME, 'image',
                            datatype='uint8'),
            'ch':
            ch,
            'res':
            0,
            'loc':
            loc[i],
            'xrng':
            x_rng[i],
            'yrng':
            y_rng[i],
            'zrng':
            z_rng[i],
            'bf':
            BF
        } for i in range(len(loc))]

        with ThreadPool(num_threads) as tp:
            out = tp.map(toolbox.getCube, di)
            print(ch)  ##DEBUG
            sys.stdout.flush()  #DEBUG

        ChanList.append(np.asarray(out))

    outArray = np.asarray(ChanList)
    ## outArray will be a numpy array in [channel, synapse, z, y, x] order
    ## this is C-ordering
    return (outArray, loc)