def test_union1d(self): a = np.array([5, 4, 7, 1, 2]) b = np.array([2, 4, 3, 3, 2, 1, 5]) ec = np.array([1, 2, 3, 4, 5, 7]) c = union1d(a, b) assert_array_equal(c, ec) assert_array_equal([], union1d([], []))
def test_union1d(self): a = np.array([5, 4, 7, 1, 2]) b = np.array([2, 4, 3, 3, 2, 1, 5]) ec = np.array([1, 2, 3, 4, 5, 7]) c = union1d(a, b) assert_array_equal(c, ec) # Tests gh-10340, arguments to union1d should be # flattened if they are not already 1D x = np.array([[0, 1, 2], [3, 4, 5]]) y = np.array([0, 1, 2, 3, 4]) ez = np.array([0, 1, 2, 3, 4, 5]) z = union1d(x, y) assert_array_equal(z, ez) assert_array_equal([], union1d([], []))
def test_manyways(self): a = np.array([5, 7, 1, 2, 8]) b = np.array([9, 8, 2, 4, 3, 1, 5]) c1 = setxor1d(a, b) aux1 = intersect1d(a, b) aux2 = union1d(a, b) c2 = setdiff1d(aux2, aux1) assert_array_equal(c1, c2)
def ratio6(self,burst_time=200,bgInd=None,sigInd=None,RCH=0,GCH=1,pre=60,buffer=10): try: if self.channels<2 or self.ch==None or self.scantype!='linescan': return except: return m=mean(self.ch[RCH][:][4:],1) s=sqrt(var(m)) if sigInd==None or bgInd==None: sigInd=where(m>mean(m)+s)[0]+3 bgInd=where(m<mean(m)-s/4)[0]+3 bgInd=bgInd[union1d(where(bgInd<(min(sigInd)-20))[0],where(bgInd>(max(sigInd)+20))[0])] Rmax=max(m) sigInd=where(m>(Rmax/2+mean(mean(self.ch[RCH][:][bgInd])))/2)[0]+3 self.sigInd,self.bgInd=sigInd,bgInd dt=self.dt self.RSig=mean(self.ch[RCH][:][sigInd.round()],0) self.GSig=mean(self.ch[GCH][:][sigInd.round()],0) self.RBg=mean(self.ch[RCH][:][bgInd.round()],0) self.GBg=mean(self.ch[GCH][:][bgInd.round()],0) beg=round((burst_time-pre)/dt) end=round((burst_time-buffer)/dt) print beg,end print self.GSig.shape print self.GBg.shape self.G0=mean(self.GSig[beg:end]-self.GBg[beg:end]) self.R0=mean(self.RSig[beg:end]-self.RBg[beg:end]) self.GRB=(self.GSig-self.GBg-self.G0)/(self.RSig-self.RBg) self.GR=self.GSig/self.RSig self.GR0=mean(self.GSig[beg:end]/self.RSig[beg:end]) self.G=(self.GSig-self.GBg-self.G0)/self.G0 self.GRV0=var(self.GR[beg:end]) self.GV0=var(self.G[beg:end]) self.tvec=arange(len(self.GR))*dt-burst_time
def ghost_layer(submesh, mesh, p, tupper, tlower, parameters = None): ncoord = mesh.number_of_nodes ntriangles = mesh.number_of_triangles if parameters is None: layer_width = 2 else: layer_width = parameters['ghost_layer_width'] full_ids = num.arange(tlower, tupper) n0 = mesh.neighbours[full_ids, :] n0 = num.unique(n0.flat) n0 = num.extract(n0>=0,n0) n0 = num.extract(num.logical_or(n0<tlower, tupper<= n0), n0) layer_cells = {} layer_cells[0] = n0 # Find the subsequent layers of ghost triangles for i in range(layer_width-1): # use previous layer as a start n0 = mesh.neighbours[n0, :] n0 = num.unique(n0.flat) n0 = num.extract(n0>=0,n0) n0 = num.extract(num.logical_or(n0<tlower, tupper<= n0), n0) for j in xrange(i+1): n0 = numset.setdiff1d(n0,layer_cells[j]) layer_cells[i+1] = n0 # Build the triangle list and make note of the vertices new_trianglemap = layer_cells[0] for i in range(layer_width-1): new_trianglemap = numset.union1d(new_trianglemap,layer_cells[i+1]) new_subtriangles = num.concatenate((num.reshape(new_trianglemap, (-1,1)), mesh.triangles[new_trianglemap]), 1) fullnodes = submesh["full_nodes"][p] full_nodes_ids = num.array(fullnodes[:,0],num.int) new_nodes = num.unique(mesh.triangles[new_trianglemap].flat) new_nodes = numset.setdiff1d(new_nodes,full_nodes_ids) new_subnodes = num.concatenate((num.reshape(new_nodes, (-1,1)), mesh.nodes[new_nodes]), 1) # Clean up before exiting del (new_nodes) del (layer_cells) del (n0) del (new_trianglemap) # Return the triangles and vertices sitting on the boundary layer return new_subnodes, new_subtriangles, layer_width
def ghost_layer(submesh, mesh, p, tupper, tlower, parameters=None): ncoord = mesh.number_of_nodes ntriangles = mesh.number_of_triangles if parameters is None: layer_width = 2 else: layer_width = parameters['ghost_layer_width'] full_ids = num.arange(tlower, tupper) n0 = mesh.neighbours[full_ids, :] n0 = num.unique(n0.flat) n0 = num.extract(n0 >= 0, n0) n0 = num.extract(num.logical_or(n0 < tlower, tupper <= n0), n0) layer_cells = {} layer_cells[0] = n0 # Find the subsequent layers of ghost triangles for i in range(layer_width - 1): # use previous layer as a start n0 = mesh.neighbours[n0, :] n0 = num.unique(n0.flat) n0 = num.extract(n0 >= 0, n0) n0 = num.extract(num.logical_or(n0 < tlower, tupper <= n0), n0) for j in range(i + 1): n0 = numset.setdiff1d(n0, layer_cells[j]) layer_cells[i + 1] = n0 # Build the triangle list and make note of the vertices new_trianglemap = layer_cells[0] for i in range(layer_width - 1): new_trianglemap = numset.union1d(new_trianglemap, layer_cells[i + 1]) new_subtriangles = num.concatenate( (num.reshape(new_trianglemap, (-1, 1)), mesh.triangles[new_trianglemap]), 1) fullnodes = submesh["full_nodes"][p] full_nodes_ids = num.array(fullnodes[:, 0], num.int) new_nodes = num.unique(mesh.triangles[new_trianglemap].flat) new_nodes = numset.setdiff1d(new_nodes, full_nodes_ids) new_subnodes = num.concatenate( (num.reshape(new_nodes, (-1, 1)), mesh.nodes[new_nodes]), 1) # Clean up before exiting del (new_nodes) del (layer_cells) del (n0) del (new_trianglemap) # Return the triangles and vertices sitting on the boundary layer return new_subnodes, new_subtriangles, layer_width