def display_2d_hists(self): fig, axes = utils.init_grid(rows=self.numobj, cols=4, figsize=(16,4*self.numobj)) if config['mec']['dithered']: bins = [np.linspace(0, sp.sample_time * sp.numframes, 50), np.linspace(-mp.array_size[0], 0, 50), np.linspace(0, mp.array_size[0], mp.array_size[0]), np.linspace(0, mp.array_size[1], mp.array_size[1])] else: bins = [np.linspace(0, sp.sample_time * sp.numframes, 50), np.linspace(-mp.array_size[0], 0, 50), range(mp.array_size[0]), range(mp.array_size[1])] # if config['data']['trans_polar']: # bins[2] = np.linspace(0, np.sqrt(((mp.array_size[0]/2)**2) * 2), mp.array_size[0]) # bins[3] = np.linspace(-np.pi,np.pi, mp.array_size[1]) coord = 'tpxy' for o in range(self.numobj): H, _ = np.histogramdd(self.photons[o], bins=bins) for p, pair in enumerate([['y','x'], ['x','p'], ['x','t'], ['p','t']]): inds = coord.find(pair[0]), coord.find(pair[1]) sumaxis = tuple(np.delete(range(len(coord)), inds)) image = np.sum(H, axis=sumaxis) if pair in [['x','p'], ['x','t']]: image = image.T inds = inds[1], inds[0] axes[o,p].imshow(image, aspect='auto', origin='lower', norm=LogNorm(), extent=[bins[inds[0]][0],bins[inds[0]][-1],bins[inds[1]][0],bins[inds[1]][-1]]) plt.show(block=True)
def get_simple_warehouse(): dimensions = (4, 4) grid = utils.init_grid(dimensions) # Fill out first column, bottom to top grid[0][0] = NavigableTileCell() grid[0][1] = NavigableTileCell() grid[0][2] = NavigableTileCell() grid[0][3] = NavigableTileCell() # Fill out second column, bottom to top grid[1][0] = NavigableTileCell() grid[1][1] = ShelvingCell(Direction.SOUTH) grid[1][2] = ShelvingCell(Direction.NORTH) grid[1][3] = NavigableTileCell() # Fill out third column, bottom to top grid[2][0] = NavigableTileCell() grid[2][1] = ShelvingCell(Direction.SOUTH) grid[2][2] = ShelvingCell(Direction.NORTH) grid[2][3] = NavigableTileCell() # Fill out fourth column, bottom to top grid[3][0] = NavigableTileCell() grid[3][1] = NavigableTileCell() grid[3][2] = NavigableTileCell() grid[3][3] = NavigableTileCell() warehouse = GridWarehouse(dimensions, grid) return warehouse
def generateHeatmap(boundaryFile, coordval, outfile=utils.FILE_TIFF, dtype=utils.np.uint32, nodata=-1): """ coordval = { (20.31, 102.34672): 12, (latVal, lonVal): val } """ cells, lons, lats = processShapeFile(boundaryFile, onlyone=True) def cell2rc(coords): return (coords[1] - lats[0], coords[0] - lons[0]) active, processed_cnt = cells.get('main'), 0 if not active: echo('ERR processing boundary, stopping here') return grid, transform, nodata = utils.init_grid(lons, lats, dtype, nodata, active) for key in coordval: if len(key) != 2 or not key[0] or not key[1]: continue val = coordval[key] cell = utils.deg2cell(key) if cell in active: echo(f'processing {key} = {val}') processed_cnt += 1 utils.fill_hotspot(grid, cell2rc(cell), val) echo(f'total processed {processed_cnt}') utils.write_tiff(outfile, grid, transform, nodata)
def generateShapes(boundaryFile, keyval, outfile=utils.FILE_TIFF, dtype=utils.np.uint32, recordfn=lambda x: x[3], nodata=-1): """ keyval = { 'SomeState': 1.2, 'SomeCouty': 1.3 } """ cells, lons, lats = processShapeFile(boundaryFile, recordfn) def cell2rc(coords): return (coords[1] - lats[0], coords[0] - lons[0]) grid, transform, nodata = utils.init_grid(lons, lats, dtype, nodata) for key in keyval: if not key: continue val, active = keyval[key], cells.get(key.lower().strip()) if not active: echo(f'ERR cannot find {key} in boundary file') continue echo(f'processing {key}') for cell in active: r, c = cell2rc(cell) grid[r, c, 0] = val utils.write_tiff(outfile, grid, transform, nodata)
def get_georgia_tech_library_warehouse(): larger_warehouse = get_larger_warehouse() larger_warehouse_grid = larger_warehouse.grid dimensions = (8, 16) grid = utils.init_grid(dimensions) for col_num in range(8): for row_num in range(16): grid[col_num][row_num] = copy.copy( larger_warehouse_grid[col_num][row_num % 4]) return GridWarehouse(dimensions, grid)
def get_larger_warehouse(): dimensions = (8, 4) grid = utils.init_grid(dimensions) for row_num in range(4): grid[0][row_num] = NavigableTileCell() for col_num in range(1, 7): grid[col_num][0] = NavigableTileCell() grid[col_num][1] = ShelvingCell(Direction.NORTH) grid[col_num][2] = ShelvingCell(Direction.SOUTH) grid[col_num][3] = NavigableTileCell() for row_num in range(4): grid[7][row_num] = NavigableTileCell() warehouse = GridWarehouse(dimensions, grid) return warehouse
def display_2d_hists(self, ind=None): fig, axes = utils.init_grid(rows=self.num_classes, cols=3, figsize=(16,4*self.num_classes)) # fig, axes = utils.init_grid(rows=self.num_classes, cols=4) if ind: fig.suptitle(f'{ind}', fontsize=16) if not self.normalised: bins = [np.linspace(0, sp.sample_time * sp.numframes, 50), np.linspace(-120, 0, 50), range(mp.array_size[0]), range(mp.array_size[1])] else: radius = 1. bins = [np.linspace(-radius,radius,50), np.linspace(-radius,radius,50), np.linspace(-radius,radius,mp.array_size[0]), np.linspace(-radius,radius,mp.array_size[0])] coord = 'tpxy' for o in range(self.num_classes): if ind: H, _ = np.histogramdd(self.data[ind, (self.labels[ind] == o)], bins=bins) else: H, _ = np.histogramdd(self.data[self.labels==o], bins=bins) for p, pair in enumerate([['x','y'], ['x','p'], ['x','t']]): inds = coord.find(pair[0]), coord.find(pair[1]) sumaxis = tuple(np.delete(range(len(coord)), inds)) image = np.sum(H, axis=sumaxis) if pair in [['x','p'], ['x','t']]: image = image.T inds = inds[1], inds[0] axes[o,p].imshow(image, norm=None, aspect='auto', extent=[bins[inds[0]][0],bins[inds[0]][-1],bins[inds[1]][0],bins[inds[1]][-1]]) axes[o,p].set_xlabel(f'{pair[1]}', fontsize=18) axes[o,p].set_ylabel(f'{pair[0]}', fontsize=16) axes[o, p].set_xlim([-1,1]) axes[o, p].set_ylim([-1,1]) plt.tight_layout() plt.show(block=True)