def transform_voxel(J_vox, use_rotation=True, use_inversion=True): # Apply a random element of the cube isometry group (Oh) to the J # specifying a unit cube (voxel.) This consists of selecting a # random rotation (from 24) followed by inversion (reflection # through the origin.) If both are active, this implements # reflections as well. # Assumes vertex indices translate to (m,n,l) with m fastest, i.e. # 0 -> [0,0,0], 1 -> [1,0,0], 2 -> [0,1,0], 3 -> [1,1,0], etc. # All 48 possible transformations appear uniformly, though # depending on J_vox there may be fewer distinct outcomes of # course. # This is to pad with zeros and ensure length 3 format_str = "{0:0" + str(3) + "b}" U = sp.zeros((3, 8), dtype=sp.int64) for i in range(8): u_str = format_str.format(i) U[:, i] = [int(u) for u in u_str] U = sp.flipud(U) # Translate to [-1,1] vertices V = 2 * U - 1 if use_rotation: # Random rotation matrix R = get_random_rot() else: # No rotation R = sp.eye(len(V)) V_prime = R.dot(V) U_prime = (V_prime + 1) / 2 # This is to apply the full octahedral transformation group # (i.e. including reflections!) Inversion just "reflects through # the origin", but then translate back so corner (-1,-1,-1) is at # the origin. if use_inversion is True: if sp.rand() < 0.5: U_prime *= -1 U_prime += sp.ones((3, 1)).dot(sp.ones((1, 8))) # Get the mapped variable indices, i.e. variable i maps to # corresponding I_prime = sp.array([[1, 2, 4]]).dot(U_prime) I_prime = sp.int64(I_prime[0, :]) # Need to invert the map I_P_inv = sp.argsort(I_prime) J_vox_prime = J_vox[sp.ix_(I_P_inv, I_P_inv)] return J_vox_prime
def plot_people(ifig, dom, people, contacts, U, colors, time=-1, axis=None, plot_people=True, plot_contacts=True, plot_velocities=True, plot_paths=False, paths=None, plot_sensors=False, sensors=[], savefig=False, filename='fig.png', cmap='winter'): """ This function draws spheres for the individuals, \ lines for the active contacts and arrows for the \ (desired or real) velocities. Parameters ---------- ifig: int figure number dom: Domain contains everything for managing the domain people: numpy array people coordinates and radius : x,y,r contacts: numpy array all the contacts : i,j,dij,eij_x,eij_y U: numpy array people velocities colors: numpy array scalar field used to define people colors time: float time in seconds axis: numpy array matplotlib axis : [xmin, xmax, ymin, ymax] plot_people: boolean draws spheres for people if true plot_paths: boolean draws people paths if true paths: numpy array coordinates of the people paths plot_sensors: boolean draws sensor lines if true sensors: numpy array sensor line coordinates (see also the sensor function below) savefig: boolean writes the figure as a png file if true filename: string png filename used to write the figure cmap: string matplotlib colormap name """ fig = plt.figure(ifig) plt.clf() ax1 = fig.add_subplot(111) # Domain ax1.imshow(dom.image, interpolation='nearest', extent=[dom.xmin, dom.xmax, dom.ymin, dom.ymax], origin='lower') if (plot_people): # People #offsets = list(zip(people[:,:2])) ## for older versions of matplotlib... offsets = people[:, :2] ec = EllipseCollection(widths=2 * people[:, 2], heights=2 * people[:, 2], angles=0, units='xy', cmap=plt.get_cmap(cmap), offsets=offsets, transOffset=ax1.transData) ec.set_array(colors) ax1.add_collection(ec) if (plot_contacts): # Contacts Nc = contacts.shape[0] if (Nc > 0): for ic in sp.arange(Nc): i = sp.int64(contacts[ic, 0]) j = sp.int64(contacts[ic, 1]) if (j != -1): line = Line2D([people[i, 0], people[j, 0]], [people[i, 1], people[j, 1]], lw=1., alpha=0.6, color='k') else: line = Line2D([ people[i, 0], people[i, 0] - (people[i, 2] + contacts[ic, 2]) * contacts[ic, 3] ], [ people[i, 1], people[i, 1] - (people[i, 2] + contacts[ic, 2]) * contacts[ic, 4] ], lw=1., alpha=0.6, color='k') ax1.add_line(line) if (plot_velocities): # Velocities Np = people.shape[0] for ip in sp.arange(Np): arrow = Arrow(people[ip, 0], people[ip, 1], U[ip, 0], U[ip, 1], width=0.3) ax1.add_patch(arrow) if ((plot_paths) and (paths is not None)): mpaths = sp.ma.masked_values(paths, 1e99) pathlines = [] for id in sp.arange(paths.shape[0]): pathlines.append(sp.swapaxes(mpaths[id, :, :], 0, 1)) pathlinecoll = LineCollection(pathlines, linewidths=0.5, linestyle="solid", cmap=plt.get_cmap(cmap)) pathlinecoll.set_array(colors) ax1.add_collection(pathlinecoll) if (plot_sensors): # Sensors for ss in sensors: line = Line2D([ss[0], ss[2]], [ss[1], ss[3]], lw=1., alpha=0.6, color='g') ax1.add_line(line) if (axis): ax1.set_xlim(axis[0], axis[1]) ax1.set_ylim(axis[2], axis[3]) ax1.set_xticks([]) ax1.set_yticks([]) ax1.axis('off') if (time >= 0): ax1.set_title('time = {:.2F}'.format(time) + ' s') fig.canvas.draw() if (savefig): fig.savefig(filename, dpi=600, bbox_inches='tight', pad_inches=0)
def quant(wavelet, delta): #iw = zeros((len(wavelet.data),len(wavelet.data[0])),int64) iw = np.int64(wavelet.data / delta) wavelet.data = iw return wavelet
pallets.set_index(scipy.arange(len(pallets)), inplace=True) dln = [] for i in pallets['PALLET']: # recorre pallets(de la nave) dftemp = df2[(df2.PALLET == i)] dftemp.set_index(scipy.arange(len(dftemp)), inplace=True) if len(dftemp ) > 1: # unicamente los q tienen mas de 1 codigo de barra demandTemp = demandDF[demandDF['CODIGO BARRAS'].isin( dftemp.cb.values)] #.sample(40) demandTemp['adjPasillo'] = demandTemp.PASILLO.map( lambda pasillo: int(pasillo - 100 * int(pasillo / 100)) ) # numero de pasillo sin tener en cta la nave demandTemp['adjRack'] = scipy.int64(demandTemp.RACK / 10) #no es 390 deja 39 finesPasillo = pd.read_excel( 'C:/Users/mbbedoya/MaBe/SMART BP/Archivos/ubicacionPasillo.xlsx', 'fines de pasillo') #lee pestaña fines de pasillo pasillos = pasillos[pasillos.nave == nave] finesPasillo = finesPasillo[finesPasillo.nave == nave] #pdb.set_trace() entrada = pd.read_excel( 'C:/Users/mbbedoya/MaBe/SMART BP/Archivos/ubicacionPasillo.xlsx', 'ENTRADA') entrada.columns = ['entradaX', 'entradaY', 'ubicacion'] toEntrada = finesPasillo.merge(entrada, how='inner', left_on='ubicacion', right_on='ubicacion')
global_mask = (global_mask + sp.sparse.kron(sp.sparse.eye(n_windows), auto_mask)).sign() # Get the block sparse format bsr = sp.sparse.bsr_matrix(global_mask, blocksize=blocksize) bsr.eliminate_zeros() # need to call this to eliminate blocks of all zeros # The dense blocks blocks = sp.float32(bsr.data) # Dense mask for each active block mask_data = np.array([[[1]]] * len(bsr.indices)) active_mask = sp.sparse.bsr_matrix( (mask_data, bsr.indices, bsr.indptr)).toarray() # np.savetxt("active_mask.txt", active_mask, delimiter='', fmt="%i") active_mask = sp.int64(active_mask.flatten()) print("Done creating input data") # #### MODEL CREATION #### builder = popart.Builder() # Reshape the blocks to the desired format blocks = sp.reshape(blocks, [blocks.shape[0], -1]) blocks = np.array(list(blocks), dtype=sp.float32) logits = builder.addInitializedInputTensor(blocks) probs = builder.customOp( opName="BsSoftmax", opVersion=1, domain="ai.graphcore", inputs=[logits], attributes={
h5proc_file = tables.openFile(proc_filename, mode = "r", title = "Proc_file") list_group = h5proc_file.root.fields._f_listNodes("Group") p_coordinate=h5proc_file.root.topology.cartesian_coord.read() p_coordinate[2]=p_coordinate[2]-list_read_proc[0] x_start=p_coordinate[0]*(shape[0]-1) #-1 to account for the 1 node overlapping x_end=x_start+shape[0] y_start=p_coordinate[1]*(shape[1]-1) y_end=y_start+shape[1] z_start=p_coordinate[2]*(shape[2]-1) z_end=z_start+shape[2] k=0 #Counts the 6 components for group in list_group: list_array=group._f_listNodes("Array") #List of all recorded arrays in "group" for array in list_array: num=scipy.int64(repr(array).split()[0][17:]) if num==cycle: num_final=num Fields_local[k,x_start:x_end,y_start:y_end,z_start:z_end]=array.read() k=k+1 h5proc_file.close() #Write the .vtr file rtg = vtk.vtkRectilinearGrid() rtg.SetDimensions(Nxc+1,Nyc+1,Nzlocal) rtg.SetExtent(0,Nxc,0,Nyc,rankproc*Nzc/numproc,(rankproc+1)*Nzc/numproc) rtg.SetXCoordinates(vtkXcoordinates) rtg.SetYCoordinates(vtkYcoordinates) rtg.SetZCoordinates(vtkZcoordinates) Bx=Fields_local[0,:,:,:].swapaxes(0,2).flatten().astype("float32")