def click_ellipse(self): self.check_click() print('click ellipse') self.do_ellipse += 1 if (self.do_ellipse == 1): self.click_vec = [] if (self.do_ellipse == 2): ellipse_id = self.graphic_id max_id = 0 for i in self.graphics: max_id = max(max_id, i.graphic_id) self.graphic_id = max_id + 1 print(self.click_vec, self.R, self.G, self.B) new_ellipse = ellipse.ellipse(self.canvas_image, ellipse_id, self.canvas_width, self.canvas_height, self.R, self.G, self.B) print(self.click_vec[0][0], self.click_vec[0][1], self.click_vec[1][0], self.click_vec[1][1], self.click_vec[2][0], self.click_vec[2][1]) new_ellipse.draw_ellipse( self.click_vec[0][0], self.click_vec[0][1], abs(self.click_vec[1][0] - self.click_vec[0][0]), abs(self.click_vec[2][1] - self.click_vec[0][1])) self.do_ellipse = 0 self.graphics.append(new_ellipse) self.refresh() self.click_vec = [] self.text2.setText('绘制椭圆完毕,点击的所有点为\n' + self.last_click_info) return self.text2.setText('开始绘制椭圆')
def draw_ellipse(self,res_cmd): ellipse_id = int(res_cmd[0]) x = int(res_cmd[1]) y = int(res_cmd[2]) rx = int(res_cmd[3]) ry = int(res_cmd[4]) new_ellipse = ellipse.ellipse(self.canvas_image,ellipse_id,self.canvas_width,self.canvas_height,self.R,self.G,self.B) new_ellipse.draw_ellipse(x,y,rx,ry) self.graphics.append(new_ellipse)
def main(): ''' About: This is the main function. ''' ## get intro intro() ## get the first ellipses params1 = {'f1': elps.point(1, 0), 'f2': elps.point(2, 0), 'a': 2} e1 = elps.ellipse(**params1) ## get the second ellipses params2 = {'f1': elps.point(0, 0), 'f2': elps.point(4, 0), 'a': 5} e2 = elps.ellipse(**params2) ## call simulate_many overlap = simulate_many(1000000, e1, e2) ## print the simulation result summary(overlap, e1, e2)
def enclosing_ellipse(pointset, center): #t,d,s = tilt_d_s_given_center(pointset,np.array(center)) pmax = max(pointset, key=lambda p: np.dot(*(2*[np.array(center)-p]))) t = math.atan2((pmax[1]-center[1]),(pmax[0]-center[0])) d,s = d_s_given_center_tilt(pointset, np.array(center), t) a2 = 0.25 * s**2 b2 = 0.25 * (s**2-d**2) c = math.cos(t) s = math.sin(t) R = np.array([[c,-s],[s,c]]) sigmas2 = np.dot(R,[[a2,0],[0,b2]]).dot(R.T) return ellipse( mean = center, sigmas2 = sigmas2 )
def getDataset(self, train=True): """ returns the dataset for the given database, for test dataset set train = False """ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") if self.dataset == "ELLIPSE": a = np.array([[0,1.0],[1.0,2.0]]) b = a*0.5 myE = el.ellipse(device, 500, 100, a, b) if train == True: return myE.create_dataset(myE.examples) return myE.create_dataset(myE.valid) if self.dataset == "SWISS": myS = sw.SwissRoll(device, 500, 0.2) if train == True: return myS.create_dataset(myS.examples) return myS.create_dataset(myS.valid) #open file myFile = h5py.File(self.dataString, 'r', self.driver) if train == True: inputString = "train_inputs" labelsString = "train_labels" else: inputString = "test_inputs" labelsString = "test_labels" #get hdf5 datsets features = myFile.get(inputString) labels = myFile.get(labelsString) #convert to tensors features = torch.from_numpy(np.array(features)) labels = torch.from_numpy(np.array(labels)) #close file to ensure dataset is in memory myFile.close() #conver to correct datatypes features = features.float() if self.conv_sg == False: labels = labels.long() dataset = torch.utils.data.TensorDataset(features, labels) return dataset
def enclosing_ellipse(pointset, center): #t,d,s = tilt_d_s_given_center(pointset,np.array(center)) pmax = max(pointset, key=lambda p: np.dot(*(2 * [np.array(center) - p]))) t = math.atan2((pmax[1] - center[1]), (pmax[0] - center[0])) d, s = d_s_given_center_tilt(pointset, np.array(center), t) a2 = 0.25 * s**2 b2 = 0.25 * (s**2 - d**2) c = math.cos(t) s = math.sin(t) R = np.array([[c, -s], [s, c]]) sigmas2 = np.dot(R, [[a2, 0], [0, b2]]).dot(R.T) return ellipse(mean=center, sigmas2=sigmas2)
def generate_ellipse_networks(n, network): a = 0.42 b = 0.12 clusters = {} clusters[0] = [] clusters[1] = [] neurons_per_cluster = math.floor(n / 2) points = ellipse(a, b, neurons_per_cluster, 0.0001) points = points[:-1] n_i = 0 for point in points: network[n_i] = np.array([point[0] + 0.5, point[1] + 0.1]) clusters[0].append(network[n_i]) n_i = n_i + 1 network[n_i] = np.array([point[0] + 0.5, point[1] + 0.35]) clusters[1].append(network[n_i]) n_i = n_i + 1 return clusters
# -*- coding: utf-8 -*- """ Created on Tue Feb 19 21:30:17 2013 @author: Peter """ import ellipse import hyperbel [phi,r] = ellipse.ellipse(150,3,4) [phi,r] = ellipse.ellipse(150,5,4) [phi,r] = hyperbel.hyperbel(150,5,4,1) [phi,r] = hyperbel.hyperbel(150,5,4,6)
tfile = r.TFile.Open(outname+'.root', 'RECREATE') book = autoBook(tfile) names = ['delta_Aqq','delta_Aqg','error_Aqq','error_Aqg','pullqq','pullqg'] fixedLimits = [(-1,1),(-1,1),(0.05,0.45),(0.04,0.14),(-5,5),(-5,5)] meanNLL = sum(e.NLL for e in tree) / tree.GetEntries() limits = fixedLimits wNLL = 40000 within=0 for e in tree: truth = e.gen_fitX,e.gen_fitY,1. mean = e.fitX,e.fitY sigmas2 = [[e.fitXX,e.fitXY], [e.fitXY,e.fitYY]] el = ellipse(mean=mean,sigmas2=sigmas2) if np.dot(truth, el.matrix).dot(truth) < 0: within+=1 nbins = 30 book.fill(meanNLL, 'meanNLL', nbins, -6.2e6,-5.8e6) book.fill(e.NLL-meanNLL, 'dNLL', nbins, -wNLL,wNLL) try: values = 100*np.array([e.fitX-e.gen_fitX, e.fitY-e.gen_fitY, e.sigmaX, e.sigmaY]) values = tuple(values) + (values[0]/values[2], values[1]/values[3]) for n,v,lim in zip(names,values,limits): book.fill(v,n,nbins,*lim) book.fill(tuple(values[2:4]), 'errors2D', (nbins,nbins), (limits[2][0],limits[3][0]), (limits[2][1],limits[3][1])) except: pass print within c = r.TCanvas()
# Simulated: ellipticaWN = gio.readFITSIMG( "tests/input/elliptical_Simulated/img1000_n6_re10_band_rNoise_sim_0.fits" ).astype(numpy.float32) spiralWN = gio.readFITSIMG( "tests/input/spiral_Simulated/ima1.fits").astype(numpy.float32) img = gio.readFITSIMG(path + testingImg).astype(numpy.float32) imgSp = gio.readFITSIMG(pathSp + testingImgSp).astype(numpy.float32) galaxyIO.runSextractor(path, testingImg, 0) dic, data = galaxyIO.readSextractorOutput("0.cat") dic, data = galaxyIO.filterSextractorData(img, dic, data) bcg = gio.readFITSIMG("0_bcg.fits").astype(numpy.float32) e = ellipse.ellipse(dic, data, False, 1000.0) print("Read " + testingImg + " image") print(e.posx, e.posy) # Testing spirality profile: #testDistances(img,e,1000,numpy.array([0.2,0.3,0.4,0.5,0.6,0.7,0.8],dtype=numpy.float32)) galaxyIO.runSextractor(pathSp, testingImgSp, 0) dic, data = galaxyIO.readSextractorOutput("0.cat") dic, data = galaxyIO.filterSextractorData(img, dic, data) bcg = gio.readFITSIMG("0_bcg.fits").astype(numpy.float32) e = ellipse.ellipse(dic, data, False, 1000.0) print("Read " + testingImg + " image") print(e.posx, e.posy) # Testing spirality profile: