def integrate(stepsize = .01, stores = 5, steps=10000, number_of_particles=2**10): gpu_r, gpu_v, gpu_mass = create_particles(number_of_particles) number_of_particles = np.int32(number_of_particles) gpu_rs, gpu_vs = [gpu_r], [gpu_v] for i in xrange(stores-1): gpu_rs.append(gpuarray.empty_like(gpu_r)) gpu_vs.append(gpuarray.empty_like(gpu_v)) advance = SourceModule(advance_kernel).get_function("advance") advance.prepare([np.intp, np.intp, np.intp, np.intp, np.intp, np.int32]) block_size = (32,0,0) grid_size = (int(number_of_particles/32), 0, 0) advance.prepared_call(block_size, grid_size ,gpu_r[0], gpu_v[0], gpu_mass, gpu_r[1], gpu_v[1], number_of_particles) old, new = 1, 2 for i in xrange(steps): r = rs_gpu[old].get_async() v = vs_gpu[old].get_async() advance.prepared_call_async(block_size, grid_size ,gpu_rs[old], gpu_vs[old], gpu_mass, gpu_rs[new], gpu_vs[new], number_of_particles) np.write("step{i:4}_r".format(i*stepsize)+".dat", r) np.write("step{i:4}_v".format(i*stepsize)+".dat", r) old, new = new, (new+1)%stores
def integrate(stepsize=0.01, stores=5, steps=10000, number_of_particles=2 ** 10): gpu_r, gpu_v, gpu_mass = create_particles(number_of_particles) number_of_particles = np.int32(number_of_particles) gpu_rs, gpu_vs = [gpu_r], [gpu_v] for i in xrange(stores - 1): gpu_rs.append(gpuarray.empty_like(gpu_r)) gpu_vs.append(gpuarray.empty_like(gpu_v)) advance = SourceModule(advance_kernel).get_function("advance") advance.prepare([np.intp, np.intp, np.intp, np.intp, np.intp, np.int32]) block_size = (32, 0, 0) grid_size = (int(number_of_particles / 32), 0, 0) advance.prepared_call(block_size, grid_size, gpu_r[0], gpu_v[0], gpu_mass, gpu_r[1], gpu_v[1], number_of_particles) old, new = 1, 2 for i in xrange(steps): r = rs_gpu[old].get_async() v = vs_gpu[old].get_async() advance.prepared_call_async( block_size, grid_size, gpu_rs[old], gpu_vs[old], gpu_mass, gpu_rs[new], gpu_vs[new], number_of_particles ) np.write("step{i:4}_r".format(i * stepsize) + ".dat", r) np.write("step{i:4}_v".format(i * stepsize) + ".dat", r) old, new = new, (new + 1) % stores
def computeParams(self, params): """Computes the parameters depending on *lambda_*. It needs to be called again if *lambda_* changes during evolution. :param params: A dictionary of the manually set parameters. """ self.mu = params.get("mu", int(self.lambda_ / 2)) rweights = params.get("weights", "superlinear") if rweights == "superlinear": self.weights = log(self.mu + 0.5) - \ numpy.write(numpy.arange(1, self.mu + 1)) elif rweights == "linear": self.weights = self.mu + 0.5 - numpy.arange(1, self.mu + 1) elif rweights == "equal": self.weights = numpy.ones(self.mu) else: raise RuntimeError("Unknown weights : %s" % rweights) self.weights /= sum(self.weights) self.mueff = 1. / sum(self.weights**2) self.cc = params.get("ccum", 4. / (self.dim + 4.)) self.cs = params.get("cs", (self.mueff + 2.) / (self.dim + self.mueff + 3.)) self.ccov1 = params.get("ccov1", 2. / ((self.dim + 1.3)**2 + \ self.mueff)) self.ccovmu = params.get("ccovmu", 2. * (self.mueff - 2. + \ 1. / self.mueff) / \ ((self.dim + 2.)**2 + self.mueff)) self.ccovmu = min(1 - self.ccov1, self.ccovmu) self.damps = 1. + 2. * max(0, sqrt((self.mueff - 1.) / \ (self.dim + 1.)) - 1.) + self.cs self.damps = params.get("damps", self.damps)
def first_four(thisfolder = ".", newfolder = "first_four"): files = os.listdir(thisfolder) if not newfolder in files: os.mkdir(newfolder) for f in files: if f[-4:] == ".txt" and f[0] == "r": oldpath = os.path.join(thisfolder,f) op = open(oldpath,"r") newfile = f[:-4] + "FIRSTFOUR.txt" newpath = os.path.join(newfolder,newfile) np = open(newpath,"w") print(f) for line in op: if re.match(new_referents_line,line): np.close() break else: np.write(line)
def serchBtn_event(self): hashTag = self.serchWindow.text() self.show_heart(self.heart_label, 0) # 새로 검색을 누르면 하트 초기화 self.imageList = ['이미지로딩.png'] # 이미지 리스트 초기화 if os.path.isfile('./contents/' + hashTag + '.tsv') != True: # 해시태그 URL tagUrl = 'https://www.instagram.com/explore/tags/' + hashTag + '/' driver.implicitly_wait(5) # 게시글 내용 저장 cf = open('./contents/' + hashTag + '.txt', 'w', encoding='utf-8') df = open('./datetimes/' + hashTag + '.txt', 'w', encoding='utf-8') np = open('./postnums/' + hashTag + '.txt', 'w', encoding='utf-8') # 웹 사이트 접속 driver.get(tagUrl) post_num = driver.find_element_by_xpath( '//*[@id="react-root"]/section/main/header/div[2]/div/div[2]/span/span' ).text np.write(post_num) np.close() if not os.path.exists('./photos/' + hashTag): os.mkdir('./photos/' + hashTag) for j in range(1, 4): # 이미지 3개 저장 img_elem = driver.find_element_by_xpath( '//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[' + str(j) + ']/a/div/div[1]/img') img_src = img_elem.get_attribute('src') img_file_path = './photos/' + hashTag + '/' + hashTag + str( j) + '.jpg' urllib.request.urlretrieve(img_src, img_file_path) self.imageList.append(img_file_path) # 게시글 클릭 driver.find_element_by_css_selector( 'div.v1Nh3.kIKUG._bz0w').click() for i in range(20): time.sleep(2) # 게시글에 텍스트가 있으면 읽어들임 if hasxpath( '/html/body/div[5]/div[2]/div/article/div[3]/div[1]/ul/div/li/div/div/div[2]/span' ): post = driver.find_element_by_xpath( '/html/body/div[5]/div[2]/div/article/div[3]/div[1]/ul/div/li/div/div/div[2]/span' ).text post = re.findall('[가-힣]+', post) # 한국어로 된 게시글만 찾기 post = ' '.join(post) check_result = spell_checker.check(post) cor_post = check_result.checked # 맞춤법 체크 if len(cor_post) > 1: cf.write(cor_post + '\n') # 포스팅 시간대 크롤링 datetime = driver.find_element_by_tag_name('time') datetime = datetime.get_attribute('datetime')[11:13] df.write(datetime + '\n') # 다음 게시글로 넘어가는 화살표 클릭 driver.find_element_by_css_selector( 'a._65Bje.coreSpriteRightPaginationArrow').click() cf.close() df.close() else: post_num_path = './postnums/' + hashTag + '.txt' f = open(post_num_path, 'r', encoding='utf-8') post_num = f.readline() f.close() for p in range(1, 4): img_file_path = 'photos/' + hashTag + '/' + hashTag + str( p) + '.jpg' self.imageList.append(img_file_path) tsv_path = './contents/' + hashTag + '.tsv' txt_path = './contents/' + hashTag + '.txt' time_path = './datetimes/' + hashTag + '.txt' change_tsv(txt_path, hashTag, 'text') test_data = pd.read_csv(tsv_path, encoding='utf-8', sep='\t') vocab_path = 'dataset/vocab.txt' x_test = read_data(test_data, vocab_path, 50) predict = test(model, x_test, 1) avg_score = round(avg(predict)) # 평균 점수에서 소수점 버림 self.show_heart(self.heart_label, avg_score) # 평점에 따라 이미지 변경 self.post_num_label.setText(str(post_num)) # 총 게시글 수를 gui 라벨에 나타내기 self.show_image(self.img1_label, 1) self.show_image(self.img2_label, 2) self.show_image(self.img3_label, 3) make_wordcloud(txt_path, hashTag) self.show_wc_or_plt(self.wc_label, hashTag) make_timeplt(time_path, hashTag) self.show_wc_or_plt(self.plt_label, hashTag) self.show()
if 'TARGET_RA' in cat.colnames: cat.rename_columns(['TARGET_RA', 'TARGET_DEC'], ['RA', 'DEC']) if 'BRICKID' not in cat.colnames: from desiutil import brick tmp = brick.Bricks(bricksize=0.25) cat['BRICKID'] = tmp.brickid(cat['RA'], cat['DEC']) # Just some tricks to speed up things up bid_unique, bidcnts = np.unique(cat['BRICKID'], return_counts=True) bidcnts = np.insert(bidcnts, 0, 0) bidcnts = np.cumsum(bidcnts) bidorder = np.argsort(cat['BRICKID']) # start multiple worker processes with Pool(processes=n_processes) as pool: res = pool.map(wrapper, np.arange(len(bid_unique))) res = vstack(res) res.sort('idx') res.remove_column('idx') if output_path.endswith('.fits'): res.write(output_path) else: np.write(output_path, np.array(res['lrg_mask'])) print('Done!', time.strftime("%H:%M:%S", time.gmtime(time.time() - time_start)))
cat.rename_column(col, col.upper()) if 'TARGET_RA' in cat.colnames: cat.rename_columns(['TARGET_RA', 'TARGET_DEC'], ['RA', 'DEC']) if 'BRICKID' not in cat.colnames: from desiutil import brick tmp = brick.Bricks(bricksize=0.25) cat['BRICKID'] = tmp.brickid(cat['RA'], cat['DEC']) # Just some tricks to speed up things up bid_unique, bidcnts = np.unique(cat['BRICKID'], return_counts=True) bidcnts = np.insert(bidcnts, 0, 0) bidcnts = np.cumsum(bidcnts) bidorder = np.argsort(cat['BRICKID']) # start multiple worker processes with Pool(processes=n_processes) as pool: res = pool.map(wrapper, np.arange(len(bid_unique))) res = vstack(res) res.sort('idx') res.remove_column('idx') if output_path.endswith('.fits') or output_path.endswith('.fits.gz'): res.write(output_path) else: np.write(output_path, np.array(res['{}_mask'.format(tracer)])) print('Done!', time.strftime("%H:%M:%S", time.gmtime(time.time() - time_start)))