def run(directory, bidirectionalfilepath, homedir): fimodirectorylist = Functions.fimo_directories(directory) counts = dict() for fimo in fimodirectorylist: TF = fimo.split('/')[5] if TF not in counts: counts[TF] = [] fimoname = fimo.split('/')[9] fimofile = fimo + "/fimo.cut.rmdup.ord.merge.bed" chipfile = Functions.parent_dir(Functions.parent_dir(fimo)) + '/ConsolidatedPeaks.merge.bed' vennlist = Functions.venn_d3(bidirectionalfilepath, chipfile, fimofile) counts[TF].append([fimoname, vennlist]) os.chdir(homedir) os.chdir('..') os.chdir("./files") outfile = open("BidirChIpMotifOverlaps.txt",'w') outfile.write("TF\nMotif#\nBidir\tChip\tMotif\tBC\tCB\tBM\tMB\tCM\tMC\tBCM\tCBM\tMBC\n") for key in counts: outfile.write(key) outfile.write("\n") for item in counts[key]: outfile.write(item[0]) outfile.write("\n") for value in item[1]: outfile.write(value) outfile.write("\t") outfile.write("\n")
def validateSolution(self, solution): ''' Solution validation tests ''' if solution.sequence == None or ('?' in solution.levels.values()): sys.stderr.write("SolutionValidator: Level unknown - "+str(solution.levels)+"\n") solution.valid = False return 0 #check if solution is valid valid = True designed_region = solution.sequence #No internal Promoters (score, _, _) = Functions.look_for_promoters(designed_region) if score >= 15.3990166: #0.95 percentile for Promoter PWM scores valid = False sys.stderr.write("SolutionValidator: High Promoter score: "+str(score)+"\n") #No internal Terminator score = Functions.look_for_terminators(designed_region) if score >= 90: #90% confidence from transtermHP valid = False sys.stderr.write("SolutionValidator: High Terminator score\n") #No restriction enzymes #if 'ggtctc' in designed_region or 'gagacc' in designed_region: # sys.stderr.write("SolutionValidator: Restriction enzyme found\n") # valid = False solution.valid = valid return valid
def movement_average_for_stamp(session, stamp): current_trips = Functions.current_trips(session, 1) deltas = [Functions.trip_movement(session, x, stamp, datetime.timedelta(minutes=6)) for x in current_trips] deltas = [x for x in deltas if x != -1] return sum(deltas) / float(len(deltas))
def pull(session, redis_session, interval=60, once=False): while True: # This is timezone specific because the train schedule itself operates on ET, not UTC! now = datetime.datetime.now(pytz.timezone('US/Eastern')) if 1 <= now.hour <= 5: Logger.log.info('Skipping sync, time is between 1 and 6AM') else: Logger.log.info('Syncing routes to database') routes = [x.name for x in session.query(db.Route).all()] try: APIFunctionsV3.sync_trips_and_records(routes, session) # APIFunctionsV3.sync_predictions(routes, session) red_average = Functions.movement_average_for_stamp(session, datetime.datetime.utcnow(), 1) StatCache.circular_store(redis_session, "movement_average", red_average) orange_average = Functions.movement_average_for_stamp(session, datetime.datetime.utcnow(), 2) StatCache.circular_store(redis_session, "orange_movement_average", orange_average) except Exception as e: Logger.log.error('ERROR: Data pull failed, retrying in {} seconds'.format(interval)) traceback.print_exc() if once: break time.sleep(interval)
def run(): #Set home directory homedir = os.path.dirname(os.path.realpath(__file__)) #Get full path to reference genome file (must be in files folder) #referencefilepath = Functions.parent_dir(homedir) + '/files/hg19_whole_genome.fa' #Get full path to bidirectional hits file (must be in files folder) bidirectionalfilepath = Functions.parent_dir(homedir) + '/files/bidirectional_hits.merge.bed' #Get full path to motif database for tomtom (must be in files folder) tomtomdir = Functions.parent_dir(homedir) + '/files/HOCOMOCOv9_AD_MEME.txt' if boolean == True: print "Cleaning directory..." #Deletes all files and folders in given directory/TF/peak_files cl.run(directory) print "running main\npreparing files for MEME..." #Bedtools intersect on all *.bed* files , then bedtools merge to ensure non-overlapping intervals rc.run(directory) #Converts ConsolidatedPeak.merge.bed to ConsolidatedPeak.merge.fasta b2f.run(directory, referencefilepath) print "done\nrunning MEME..." #Runs MEME, FIMO, and TOMTOM on all ConsolidatedPeak.merge.fasta meme.run(directory, 10000000, 10000000, tomtomdir) print "done\nfixing FIMO files..." #Removes duplicates, orders, and eliminates first column of FIMO output files ff.run(directory) print "done\ngetting motif distances to i..." #Calculates motif distance to bidir center for each motif of each TF dist.run(directory, bidirectionalfilepath, homedir) print "done\ngenerating overlap numbers..." #Determines site overlap between bidir, ChIP, and FIMO sites so.run(directory, bidirectionalfilepath, homedir) print "done"
def get_status(self, session): most_recent_trip_record = session.query(TripRecord).filter(TripRecord.trip_id == self.id).order_by( desc(TripRecord.stamp)).first() if most_recent_trip_record is None: return STATUS_UNKNOWN, 0 most_recent_trip_record_age = (datetime.datetime.utcnow() - most_recent_trip_record.stamp).total_seconds() if most_recent_trip_record_age > 180: return STATUS_TERMINATED, 0 exact_station = most_recent_trip_record.get_exact_station(session) if exact_station: return STATUS_AT_STATION, exact_station # If we get this far, we're not at a station # Return what we're between segment = (Functions.find_segment(most_recent_trip_record, session)) if segment[0] != segment[1]: return STATUS_IN_TRANSIT, (Functions.find_segment(most_recent_trip_record, session)) else: return STATUS_AT_STATION, segment[0]
def finder(n): som = 1 for getal in range(2,n+1,4): if Functions.isPrime((getal+4)/2): if Functions.isPrime(getal+1): if div(getal) != False: som += getal return som
def gotoSoundMenu(self, menu, x,y): try: SoundMenu = Sound(self.engine) except Exception as error: Functions.formatException(self.engine, error) self.widgets = [] self.addWidgets()
def gotoRulesMenu(self, menu, x,y): try: RulesMenu = Rules(self.engine) except Exception as error: Functions.formatException(self.engine, error) self.widgets = [] self.addWidgets()
def startGame(self, menu, x,y): try: game = Game.Game(self.engine) except Exception as error: Functions.formatException(self.engine, error) pygame.mouse.set_visible(True) self.engine.inGame = False
def start_game(): if Functions.real_age(int(AgeEnt.get())) == -1: showinfo(title='Ошибка!', message='Ещё маленький страной управлять!') root.quit() elif Functions.real_age(int(AgeEnt.get())) == 1: showinfo(title='Ошибка!', message='Стар уже страной управлять!') root.quit() else: Vars.MyPlayer.age = int(AgeEnt.get()) Vars.MyPlayer.name = NameEnt.get()
def run(directory): directorylist = Functions.fimo_directories(directory) for item in directorylist: os.chdir(item) FileList = Functions.parse_file("fimo.txt") Functions.cut_file("fimo.txt", [i for i in range(1, len(FileList[0]))], "fimo.cut.bed") Functions.remove_duplicates_int("fimo.cut.bed", "fimo.cut.rmdup.bed", True) Functions.order_file("fimo.cut.rmdup.bed", "fimo.cut.rmdup.ord.bed", True) Functions.replace_header("fimo.cut.rmdup.ord.bed", "#chrom\tstart\tstop\tstrand") os.system("bedtools merge -i fimo.cut.rmdup.ord.bed > fimo.cut.rmdup.ord.merge.bed")
def worker_do_benchmarks(rna_list, concensus, tasks_queue, out_queue): """Should be called with do_benchmarks_MP. Fill a dictionnary benchmark with the Functions.do_stats output for the 6 metric. the keys of benchmark are the node names, values a dict{"metric_name", Functions.do_stats} """ benchmark = {} #We will keep track of the benchmark in this dict while True: rna = tasks_queue.get() tasks_queue.task_done() if rna is None: break print 'processing rna on process: ', os.getpid() benchmark[rna] = {} #:Now we want to generate a population, to do all the benchmarks pop = Fct.rand_rna_population(rna_list[rna], bp_mask=Fct.bp_positions(concensus), size=1000) #The first test is the mfe mfe = [VRNA.mfe(sequence)[1] for sequence in pop] benchmark[rna]['mfe'] = mfe #Masked mfe mfe_masked = [VRNA.mfe(sequence, concensus)[1] for sequence in pop] benchmark[rna]['mfe_masked'] = mfe_masked #MFE bp_distance mfe_bp_distance = [VRNA.mfe_bp_distance(sequence, concensus) for sequence in pop] benchmark[rna]['mfe_bp_distance'] = mfe_bp_distance #folding masked bp_distance masked_bp_distance = [VRNA.mfe_bp_distance(sequence, concensus, concensus) for sequence in pop] benchmark[rna]['masked_bp_distance'] = masked_bp_distance #MFE Energy ensemble mfe_energy = [VRNA.fold_probability(sequence)[1] for sequence in pop] benchmark[rna]['mfe_energy'] = mfe_energy #MFE Energy ensemble masked_energy = [VRNA.fold_probability(sequence)[1] for sequence in pop] benchmark[rna]['masked_energy'] = masked_energy out_queue.put(benchmark) print 'This process computed %s benchmarks.' % len(benchmark) return None
def atLoc(mkNameFile,diction,inFol,outFol): mkArray = funcs.singleTifToArray(mkNameFile) outArray= np.zeros(mkArray.shape) for key in diction: dictVal = diction[key] keyArray = funcs.singleTifToArray(inFol + str(key) + "_rval.tif") condlist = [ mkArray == dictVal ] choicelist = [ keyArray ] outArray = np.select(condlist, choicelist, outArray) funcs.array_to_raster(mkNameFile,outArray, outFol+"rval_MK_name_sig2.tif")
def rotate_mask(case): import Masks as masks from math import atan,cos,sin,tan from numpy import deg2rad,zeros import Functions as piv from copy import copy angle = get_mask_angle(case) device,phi,alpha,U,loc = piv.get_case_details(case) rotated_mask = zeros((6,2)) for m,i in zip(masks.Masks[case],range(5)): cmx = m[0] - masks.Masks[case][1][0] cmy = m[1] - masks.Masks[case][1][1] x = cmx*cos(angle) + cmy*sin(angle) y = -cmx*sin(angle) + cmy*cos(angle) rotated_mask[i] = [x,y] rotated_mask[2] = [ 40.*sin(deg2rad(90-float(alpha)-float(phi))), -40.*cos(deg2rad(90-float(alpha)-float(phi))) ] rotated_mask[3] = [ rotated_mask[2][0]-cos(deg2rad(90-float(alpha)-float(phi))), rotated_mask[2][1]-sin(deg2rad(90-float(alpha)-float(phi))), ] rotated_mask[4] = [ rotated_mask[1][0]-cos(deg2rad(90-float(alpha)-float(phi))), rotated_mask[1][1]-sin(deg2rad(90-float(alpha)-float(phi))), ] rotated_mask[5][0] = rotated_mask[0][0] rotated_mask[5][1] = rotated_mask[4][1] - rotated_mask[5][0]*tan(deg2rad(float(alpha)-7)) return rotated_mask
def __init__(self, d=None, position=None, radius=None, intensity=None): """Make a star instance. d: (dictionairy) Must contain position, radius and intensity and can be provided instead of giving these other arguments individually. position: (float, array-like) Coordinates of the star. radius: (float) Radius of the star. intensity: (float) Intensity of the star. """ if d is not None: try: position = np.array([ float(d["position"]["x"]), float(d["position"]["y"]), ]) except (KeyError, ValueError, TypeError): position = np.array(func.pol2cart( float(d["position"]["r"]), float(d["position"]["theta"]) / 180. * np.pi, # Assume deg. )) radius = float(d["radius"]) intensity = float(d["intensity"]) self.position = np.array(position) self.radius = radius self.intensity = intensity
def run(bidirfile, fimodir): distances = dict() directorylist = [fimodir + '/' + item for item in os.listdir(fimodir) if 'fimo_out' in item] for item in directorylist: print item TF = item.split('/')[5].split('_')[0] x = Functions.get_distances_pad_v3(bidirfile, item + "/fimo.cut.txt", True, 1500) if len(x) != 0: start = min(x) stop = max(x) sigma = np.std(x) mu = np.mean(x) N = len(x) y = np.random.uniform(start, stop, N) z = mu/(sigma/math.sqrt(N)) p = 1 - scipy.special.ndtr(z) k = scipy.stats.ks_2samp(x,y) m = scipy.stats.mode(x)[0][0] if -0.25 < m < 0.25: m = 0 else: m = 1 distances[TF] = [k[1],p,m,x] return distances
def event(self): # Handle keyboard events for event in pygame.event.get(): self.engine.globalEvent(event) # Menu keys: if self.inMenu: if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: self.running = False elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP: for player in self.players: player.event(event) # In-game keys else: if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: self.running = False elif event.type == pygame.KEYDOWN and event.key == pygame.K_F10: path = os.path.join("maps", "saved") try: os.mkdir(path) except: pass pygame.image.save(self.map.mask.make_surface(), os.path.join(path, "mask.png")) pygame.image.save(self.map.visual, os.path.join(path, "visual.png")) pygame.image.save(self.map.background.make_surface(), os.path.join(path, "background.png")) self.engine.messageBox.addMessage("Current map saved to " + path + ".") elif event.type == pygame.KEYDOWN and event.key == pygame.K_F11: path = Functions.saveNameIncrement("screenshots", "fullmap", "png") pygame.image.save(self.map.screenImage, path) self.engine.messageBox.addMessage("Screenshot saved to " + path + ".") elif (event.type == pygame.KEYDOWN or event.type == pygame.KEYUP) and not(self.gameOver): for player in self.players: if player.ship.active: player.event(event)
def load_from_db(self,idCharacter,idScenario,c): c.execute('select filename, frameheight, framewidth, name, top, left from Characters where idCharacter = ' + str(idCharacter) + ' and idscenario = ' + str(idScenario)) data = c.fetchone() self.immagini = Functions.carica_imm_sprite('character',data[0],data[1],data[2],1) self.image = self.immagini[0] self.rect = pygame.Rect((data[5],data[4]),self.image.get_size()) self.name = data[3]
def get_next_service_for_station(station_id, direction): predictions = Functions.current_predictions(session, station_id) directed_predictions = [] if (predictions is not None): for prediction in predictions: trip = session.query(db.Trip).filter(db.Trip.id == prediction.trip_id).first() dir = int(trip.destination_station_id > trip.origin_station_id) if (int(direction) is dir): directed_predictions.append(prediction) if len(directed_predictions) == 0: return json.dumps({'prediction1': None, 'prediction2' : None}) directed_predictions.sort(key=lambda x: x.seconds_away_from_stop) if len(directed_predictions) > 1: next_two_pre = {'prediction1': directed_predictions[0].seconds_away_from_stop, 'prediction2' : directed_predictions[1].seconds_away_from_stop} else: next_two_pre = {'prediction1': directed_predictions[0].seconds_away_from_stop, 'prediction2' : None} return json.dumps(next_two_pre) else: return json.dumps({'prediction1': None, 'prediction2' : None})
def apply_watermark(filename): img = io.imread(filename) # Image in gray scale img = color.rgb2grey(img) if img.dtype.name != 'uint8': img = img * 255 img = img.astype(numpy.uint8) image = img.copy() blocks = [] width, height = image.shape hor_block = width / 4 ver_block = height / 4 block_counter = 0 for x in range(0, hor_block): for y in range(0, ver_block): x_coor = x * 4 y_coor = y * 4 block = image[x_coor: x_coor + 4, y_coor: y_coor + 4] blocks.append(block) block_counter += 1 n = block_counter k = Functions.get_biggest_prime(n) for index in range(0, n): block_B = blocks[index] block_A = (blocks[Functions.mapping(index + 1, k, n) - 1]).copy() for x in range(0, 4): for y in range(0, 4): block_B[x, y] = Functions.removeLSB(block_B[x, y]) avg_B = Functions.average(block_B) for i in range(0, 2): for j in range(0, 2): i_coor = i * 2 j_coor = j * 2 blockBS = block_B[i_coor: i_coor+2, j_coor: j_coor+2] average = Functions.average(blockBS) v = 0 if average >= avg_B: v = 1 p = 1 if Functions.ones_in_sixMSB(average) % 2 == 0: p = 0 subblock_a = block_A[i_coor: i_coor+2, j_coor: j_coor+2].copy() avg_as = Functions.average(subblock_a) r = Functions.split_binary_sixMSB(avg_as) if v == 1: v = 2 if p == 1: p = 2 if r[2] == 1: r[2] = 2 if r[4] == 1: r[4] = 2 blockBS[0][0] = (blockBS[0][0] + v + r[0]) blockBS[0][1] = (blockBS[0][1] + p + r[1]) blockBS[1][0] = (blockBS[1][0] + r[2] + r[3]) blockBS[1][1] = (blockBS[1][1] + r[4] + r[5]) return image
def setTasks(self): tasks = Functions.getTasks(self.sg, self.project.id, self.user) self.comb_task.clear() self.comb_task.blockSignals(True) for task in tasks: self.comb_task.addItem(self.formatTaskDisplayName(task), task) self.comb_task.setCurrentIndex(-1) self.comb_task.blockSignals(False)
def run(directory): directorylist = Functions.chip_peak_directories(directory) for item in directorylist: os.chdir(item) FileList = [file1 for file1 in os.listdir(item) if '.bed' in file1] if len(FileList) != 0: if 'outfiles' not in os.listdir(item): os.mkdir("./outfiles") if len(FileList) > 1: os.system("bedtools intersect -a " + FileList[0] + " -b " + " ".join(FileList[1:len(FileList)]) + " > ./outfiles/ConsolidatedPeaks.bed") else: os.system("cat " + FileList[0] + " > ./outfiles/ConsolidatedPeaks.bed") os.chdir("./outfiles") Functions.order_file("ConsolidatedPeaks.bed", "ConsolidatedPeaks.bed", False) os.system("bedtools merge -i ConsolidatedPeaks.bed > ConsolidatedPeaks.merge.bed") else: print "No bed files found in: " + item
def init(self): self.gfxlist = [] for gfx in Functions.getFolders("gfx"): self.gfxlist.append((gfx, gfx)) self.displayModes = [] for mode in pygame.display.list_modes(): self.displayModes.append((mode,str(mode[0]) + "x" + str(mode[1])))
def print_output(self): for i, frame_name in enumerate(self.frames_number): img = fn.get_frame(frame_name) ca.CrowdArt(img, self.frames_p[i], 0, self.p_min, self.p_max, frame_name, 'Alem_P/pressure') ca.CrowdArt(img, self.frames_v[i], 0, self.v_min, self.v_max, frame_name, 'Alem_V/velocity') ca.CrowdArt(img, self.frames_d[i], 0, self.d_min, self.d_max, frame_name, 'Alem_D/density') print '\r Frame ' + str(i + 1) + ' of ' + str(len(self.frames_number)) + ' saved',
def __init__(self, data=None, filename=None, dataname=None, coordsystem="cartesian", outfolder=None, unit=None, inclinations=None, radius_in=0, radius_out=np.inf, diskmass=.01, diskradius=1000., H0=1., R0=1., H_power=1., kappa=10. ): self.data_rotated = None # If the inclination is a single number, put it in a list: try: iter(inclinations) self.inclinations = inclinations except TypeError: self.inclinations = [inclinations] if dataname is None or dataname == "": self.dataname = filename.split("/")[~0] else: self.dataname = dataname print ( "Loading dataset '%s' from file '%s'..." % (self.dataname, filename) ) self.outfolder = outfolder self.unit = unit self.stars = [] self.radius_in = radius_in self.radius_out = radius_out self.diskmass = diskmass self.diskradius = diskradius self.H0 = H0 self.R0 = R0 self.H_power = H_power self.kappa = kappa # [cm^2 / g] # Between 5 and 100 according to Bouvier et al. 1999. if data is not None: self.data = data elif filename is not None: self.load(filename) if coordsystem == "cartesian": pass elif coordsystem == "polar": x, y = func.pol2cart(self.data[:, 0], self.data[:, 1]) self.data[:, 0], self.data[:, 1] = x, y else: raise KeyError("Coordinate system must be 'cartesian' or 'polar'.")
def sprite(self, image): # Sprite creation self.isSprite = True pygame.sprite.Sprite.__init__(self) self.baseImage = pygame.image.load(Functions.gfxPath(image)).convert_alpha() self.image = self.baseImage self.rect = self.image.get_rect() self.rect.center = (self.x, self.y)
def run(directory): directorylist = Functions.chip_peak_directories(directory) for directory1 in directorylist: os.chdir(directory1) RemoveList = [item for item in os.listdir(directory1) if 'ENC' not in item and 'SL' not in item] for item in RemoveList: if '.' in item: os.system("rm " + item) else: shutil.rmtree(directory1 + "/" + item)
def run(directory, maxsites, tomtomdir): directorylist = Functions.chip_peak_directories(directory) for item in directorylist: if os.path.exists(item + "/outfiles"): os.chdir(item + "/outfiles") os.system("meme-chip ConsolidatedPeaks.merge.fasta -oc ./MEME meme-maxsites " + str(maxsites)) os.chdir(item + "/outfiles/MEME") os.system("tomtom combined.meme " + tomtomdir) else: print "File not found in: " + item
def check(self, map): if self.activationTime > 0: self.activationTime -= 1 else: if self.fuel < 1: self.thrust = False if random.uniform(0,1) < 0.1: self.game.objects.append(Smoke(self.game, self.owner, self.x, self.y)) else: target = self.getClosestShip(300) if target != None: if self.target == None: self.target = target Sound.playSound(self.game.engine, 6, False) elif target == self.target: predictedTargetX = target.x - 5*self.dx predictedTargetY = target.y - 5*self.dy predictedSelfX = self.x + 5*self.dx predictedSelfY = self.y + 5*self.dy + 5 if predictedTargetX > predictedSelfX and predictedTargetY > predictedSelfY: targetAngle = math.atan((predictedSelfY-predictedTargetY)/(self.x+2*self.dx-predictedTargetX)) elif predictedTargetX < predictedSelfX and predictedTargetY > predictedSelfY: targetAngle = math.atan((predictedSelfY-predictedTargetY)/(self.x+2*self.dx-predictedTargetX)) + math.pi elif predictedTargetX < predictedSelfX and predictedTargetY < predictedSelfY: targetAngle = Functions.returnAngle(math.atan((predictedSelfY-predictedTargetY)/(self.x+2*self.dx-predictedTargetX))) + math.pi elif predictedTargetX > predictedSelfX and predictedTargetY < predictedSelfY: targetAngle = Functions.returnAngle(math.atan((predictedSelfY-predictedTargetY)/(self.x+2*self.dx-predictedTargetX)) + math.pi) + math.pi else: targetAngle = math.pi/2 if predictedTargetY > predictedSelfY: if Functions.returnAngle(self.angle) < Functions.returnAngle(targetAngle) or Functions.returnAngle(self.angle) > Functions.returnAngle(targetAngle + math.pi): self.angle += 0.1275 else: self.angle -= 0.1275 elif predictedTargetY < predictedSelfY: if Functions.returnAngle(self.angle) < Functions.returnAngle(targetAngle + math.pi) or Functions.returnAngle(self.angle) > Functions.returnAngle(targetAngle): self.angle -= 0.1275 else: self.angle += 0.1275 if math.fabs(Functions.returnAngle(self.angle) - targetAngle) < math.pi/8: self.fuel -= 1 self.thrust = True if random.uniform(0,1) < 0.3: self.game.objects.append(ThrustFlame(self.game, self.owner, self.x-2*self.dx-5*math.cos(self.angle), self.y-2*self.dy-5*math.sin(self.angle), self.dx-1*math.cos(self.angle), self.dy-1*math.sin(self.angle))) else: self.thrust = False self.activationTime = 10 self.target = None
def listGuild(): guilds = bot.guilds for guild in guilds: guildCutSpace = Functions.removeSpace(str(guild.name)) bot.dbList.append(guildCutSpace) return bot.dbList
# Main Loop import Functions as ht #ht for heavy traffic import scipy.stats as st import csv import matplotlib.pyplot as plt from joblib import Parallel, delayed import multiprocessing as mp N = 3 #We want an 3 X 3 switch VLIST = [ht.initializeMatrix(N)[0]] #Initialize a list of lists whose elements are the values of v and the queue length matrix SLIST = [s / 10 for s in range(1, 10)] + [s / 100 for s in range(91, 96) ] + [s / 1000 for s in range(960, 1000)] #SLIST = [s/100 for s in range(91,100)] # a list iof traffic intensity values from 0.1, 0.2 to 0.9,0.91,0.92,...,0.96, 0.961,0.962,...,0.999 PLIST = ["MaxWt", "MaxSize_random", "MaxSize_PriMaxWt", "MaxSize_PriMaxWtLog"] # a list of selection policies ITER = 100000000 #time length of simulation def get_S_qavg_lists(Vs, policy, S): qavg = 0 Queues = ht.initializeMatrix(N)[1] lambdaRv_list = ht.arrivalRate(Vs, S) #A matrix of lambdas -- arrival rates for t in range(1, ITER + 1): Queues = ht.updateQ(Queues, lambdaRv_list)
#Intro Screen import Functions as f win = f.init_scr(25, 150) win = f.intro_scr(win) win = f.wait(win)
# -*- coding: utf-8 -*- """ Created on Fri Dec 21 08:42:47 2018 @author: coirn """ import Functions as F import copy as C data = F.read_file("day10data.txt") data=data[0] data=data.strip("]") data=data.strip("[") data=data.split(", ") datamod= C.deepcopy(data) for x in range(len (data)): data[x]=int(data[x]) for x in range( len (data)-2): datamod[x+2] = data[x+2]- data[x] for x in range (len (data)): datamod[x]= [x, datamod[x]] for x in range (len (data)): data[x]= [x, data[x]] print (datamod) print (data)
sim_name = 'L0100N1504_ref' L,a,h = R.Read_MainProp(sim, tag) L *= (a/h) ################################ READ #################################### pos_St,Mass_St,num_St,num_St_SH = R.Read_Particles(sim, tag) NumOfSubhalos = R.Read_Haloes(sim, tag) ################################ MAIN ################################## Index_Range = F.Get_PartIndexRange(num_St,num_St_SH,NumOfSubhalos) Sel_Group = [] Sel_SubGroup = [] Sel_MStell = [] Sel_Shell = [] for gr in range(len(Index_Range)): for sgr in range(len(Index_Range[gr])): #IDs = (Mass_St[Index_Range[gr][sgr][0]:Index_Range[gr][sgr][1]]) Mstell = np.sum(Mass_St[Index_Range[gr][sgr][0]:Index_Range[gr][sgr][1]]) if (Mstell > Mcut): Sel_Group.append(gr+1) Sel_SubGroup.append(sgr) Sel_MStell.append(np.log10(Mstell)+10) Sel_Shell.append(F.Shell(pos_St[Index_Range[gr][sgr][0]:Index_Range[gr][sgr][1]], Mass_St[Index_Range[gr][sgr][0]:Index_Range[gr][sgr][1]], Rad, L,NBin))
def evaluate_file(file, ellis=False): """ Analyse a given file and calculate its f-measure :param file: The path to the *.wav file :param ellis: If set to true, the algorithm specified by Ellis 2007 will be used for the beat calculation :return: The correct beats (read from *.beats file), the found beats, the correct downbeats, the downbeats, the onset strength envelope, accuracy for true positives of beats and downbeats, f-measure for beats and downbeats """ # Get last part of file path for getting the original beat data # And replace ".wav" with ".beats" filename = file.split(os.path.sep)[2][:-4] + ".beats" c_beats, c_downbeats = get_beats_from_file(filename) beats, downbeats, ose, sig = Main.analyse(file) # Convert beats and downbeats from seconds to frames to compare # int conversion necessary because for this evaluation method values are indices beats = list(map(int, [beat * OSE_SAMPLE_RATE / FFT_HOP for beat in beats])) downbeats = list( map(int, [downbeat * OSE_SAMPLE_RATE / FFT_HOP for downbeat in downbeats])) # Use the algorithm specified by Ellis if ellis: tau_est, tau_index, is_duple_tempo = Functions.estimate_tempo(ose) beats, downbeats, ose = ellis_07_search(ose, tau_index) # Calculate accuracy # Convert error margin to ose frame units and divide by 2 (half of specified allowed in each direction) # So 70 ms allow for 35ms before and 35ms after margin = np.ceil((MARGIN * 0.001) * OSE_SAMPLE_RATE / FFT_HOP / 2) # True positives, false positives, false negatives, for beats and downbeats respectively TP = [] FP = [] FN = [] TP_D = [] FP_D = [] FN_D = [] # Get TP for i in range(len(beats)): # Get allowed values for current beat space = np.arange(beats[i] - margin, beats[i] + margin, 1, dtype=int) for allowed in space: if allowed in c_beats: TP.append(beats[i]) if beats[i] in downbeats and allowed in c_downbeats: TP_D.append(beats[i]) # Get FN: Beat should exist, but is missing for i in range(len(c_beats)): space = np.arange(c_beats[i] - margin, c_beats[i] + margin, 1, dtype=int) found = False for allowed in space: if allowed in beats: found = True break if not found: FN.append(c_beats[i]) # Get FP: Beat should not exist, but something was found for i in range(len(beats)): space = np.arange(beats[i] - margin, beats[i] + margin, 1, dtype=int) found = False for allowed in space: if allowed in c_beats: found = True break if not found: # Increase false positives FP.append(beats[i]) # Get FN Downbeats: Beat should be downbeat, but is not for c_downbeat in c_downbeats: start = c_downbeat - margin if c_downbeat - margin >= 0 else 0 end = c_downbeat + margin if c_downbeat + margin < ose.size else ose.size space = np.arange(start, end, 1, dtype=int) found = False for candidate in space: if candidate in downbeats: found = True break if not found: FN_D.append(c_downbeat) # Get FP Downbeats: Beat should not be downbeat, but was classified as such for db_idx in downbeats: space = np.arange(db_idx - margin, db_idx + margin, 1, dtype=int) misclassified = True for allowed in space: if allowed in c_downbeats: misclassified = False if misclassified: FP_D.append(db_idx) # Calculate F-measure for beats if len(TP) == 0: f_measure = 0 else: precision = len(TP) / (len(TP) + len(FP)) recall = len(TP) / (len(TP) + len(FN)) f_measure = 2 * ((precision * recall) / (precision + recall)) # Calculate F-measure for downbeats if len(TP_D) == 0: f_measure_d = 0 else: precision_d = len(TP_D) / (len(TP_D) + len(FP_D)) recall_d = len(TP_D) / (len(TP_D) + len(FN_D)) f_measure_d = 2 * ((precision_d * recall_d) / (precision_d + recall_d)) # Calculate avg score for TP (beats and downbeats) acc_TP = len(TP) / len(c_beats) acc_TP_down = len(TP_D) / len(c_downbeats) # Print evaluation print("TP accuracy for " + filename[:-6] + ".wav: " + str(round(acc_TP, 2))) print("TP downbeat accuracy: " + str(round(acc_TP_down, 2))) print("F-measure: " + str(round(f_measure, 2))) print("F-measure for downbeats: " + str(round(f_measure_d, 2))) return c_beats, beats, c_downbeats, downbeats, ose, acc_TP, acc_TP_down, f_measure, f_measure_d
#sim = '/cosma5/data/Eagle/ScienceRuns/Planck1/L0100N1504/PE/REFERENCE/data/' sim_name = 'L0025N0376_ref' #sim_name = 'L0100N1504_ref' L, a, h = R.Read_MainProp(sim, tag) L *= (a / h) ################################ READ #################################### pos_St, Mass_St, num_St, num_St_SH = R.Read_Particles(sim, tag) NumOfSubhalos = R.Read_Haloes(sim, tag) SubHalo_gr, SubHalo_sgr, SubHalo_pos = R.Read_Subhaloes(sim, tag) ParticleID, Particle_Binding_Energy = R.Read_Particles_ID(sim, tag) ################################ MAIN ################################## Index_Range = F.Get_PartIndexRange(num_St, num_St_SH, NumOfSubhalos) CenterOfPotential = F.Get_SubHaloCenter(SubHalo_gr, SubHalo_sgr, NumOfSubhalos, SubHalo_pos) Sel_Group = [] Sel_SubGroup = [] Sel_MStell = [] Sel_Shell = [] for gr in range(len(Index_Range)): for sgr in range(len(Index_Range[gr])): #IDs = (Mass_St[Index_Range[gr][sgr][0]:Index_Range[gr][sgr][1]]) Mstell = np.sum( Mass_St[Index_Range[gr][sgr][0]:Index_Range[gr][sgr][1]]) if (Mstell > Mcut): Sel_Group.append(gr + 1)
# -*- coding: utf-8 -*- """ Created on Sun Dec 23 12:08:12 2018 @author: coirn """ import Functions as F tracks = F.read_file("day13list.txt") #tracks = F.read_file("debug13.txt") for x in range(len(tracks)): tracks[x] = [z for z in tracks[x]] up = '^' down = 'v' left = '<' right = '>' turns = ['/', '\\'] xy = [0, 1] directions = [up, down, left, right] crash = False def takeSecond(elem): return elem[1] def initpos(): positions = [] for x in range(len(tracks)):
# -*- coding: utf-8 -*- """ Created on Wed Dec 12 16:42:24 2018 @author: coirn """ ######################Functions and setup####################### import Functions as F licence = F.read_file("day8list.txt") for x in range(len(licence)): licence = licence[x].split(" ") sumtotal = 0 nodes = [] class Node: def __init__(self, addr, metadata=[], children=None): self.addr = addr self.metadata = metadata self.children = children nodes.append(self) def __str__(self): return "Node: " + str(self.number) def add_child_addr(self, child, x): self.children[x] = child def add_metadata_values(self, datum, x): self.metadata[x] = datum
def find_method_info(info): thisdict = { "ainfo": 'Academic-Institutions/', "noainfo": 'Non-Academic-Institutions/', "appinfo": 'O.R.-Application-Areas/', "minfo": 'O.R.-Methodologies/', } toWrite = [[ 'Title', 'Logo', 'Description', 'Desc Word Count', 'Image Gallery', 'Oral History Interview in INFORMS Format', 'Oral History Interview - Other - Embedded', 'Oral History Interview - Other - Reference', 'Memoirs and Autobiographies', 'Library Archives', 'Links and References', 'Indivs. Count', 'Additional Resources' ]] time = str(datetime.datetime.now())[:-7] print(time) writer = pd.ExcelWriter(thisdict[info][:-1] + ' ' + time.replace(':', '‘') + '.xlsx', engine='xlsxwriter') m_links = f.find_m_links(thisdict[info]) print(m_links) for i in m_links: print(i) source_code = requests.get(i) text = source_code.text parse = BeautifulSoup(text, "html.parser") body = parse.find("div", {"class": "content-container"}) title = f.find_title(parse) is_logo = f.find_logo(parse) desc_word_count = f.desc_word_count(parse) img_gal = f.if_img_gall(parse) image = f.image_gall(parse) indiv_count = f.indiv_count(body) interview = f.oral_hist(parse) toWrite.append([ title, is_logo, desc_word_count[0], desc_word_count[1], img_gal, image[1], interview[0], interview[1], interview[2], f.memoirs3(parse), f.archives(parse), f.linksandrefs(parse), indiv_count, f.add_resources(parse) ]) df = pd.DataFrame(toWrite) df.to_excel(writer, header=False, index=False, sheet_name='info') workbook = writer.book method = writer.sheets['info'] text_format = workbook.add_format({'text_wrap': True}) text_format.set_align('top') # celld2 = workbook.cell('D2') # celld2.set_align('right') title_format = workbook.add_format({'text_wrap': True}) title_format.set_bold() # Turns bold on. title_format.set_align('top') method.set_column('A:A', 30, text_format) method.freeze_panes(1, 1) # Freeze first row and first 2 columns. writer.save() print("Finished! Excel file generated under", os.getcwd(), "\n")
# -*- coding: utf-8 -*- # @Author: Xingqi Ye # @Time: 2019-04-07-18 import Functions import pandas as pd import config import numpy as np import matplotlib.pyplot as plt from scipy import stats from statsmodels.stats.diagnostic import acorr_ljungbox pd.set_option('expand_frame_repr', False) daily_data = Functions.import_data() code_list = daily_data.columns code_list = code_list.drop('Date') monthly_data = Functions.transfer_to_period_data(daily_data, 'M') weekly_data = Functions.transfer_to_period_data(daily_data, '5B') # calculate the daily, weekly, monthly return daily_return_data = daily_data.copy() weekly_return_data = weekly_data.copy() monthly_return_data = monthly_data.copy() for x in code_list: daily_return_data[x] = daily_return_data[x].pct_change(1) weekly_return_data[x] = weekly_return_data[x].pct_change(1) monthly_return_data[x] = monthly_return_data[x].pct_change(1)
parser.add_argument('--classifier_fc_dims', default='1024') parser.add_argument('--classifier_batchnorm', default=0, type=int) parser.add_argument('--classifier_dropout', default=0, type=float) # Optimization options parser.add_argument('--batch_size', default=64, type=int) parser.add_argument('--learning_rate', default=1e-4, type=float) parser.add_argument('--reward_decay', default=0.99, type=float) parser.add_argument('--temperature', default=1.0, type=float) # Output options parser.add_argument('--randomize_checkpoint_path', type=int, default=0) parser.add_argument('--record_loss_every', type=int, default=1) parser.add_argument('--checkpoint_every', default=100, type=int) #%%Train loop args = parser.parse_args() vocab = func.load_vocab(args.vocab_json) train_loader_kwargs = { 'question_h5': args.train_questions_h5, 'feature_h5': args.train_features_h5, 'vocab': vocab, 'batch_size': args.batch_size, 'shuffle': args.shuffle_train_data, 'max_samples': args.num_train_samples, 'num_workers': args.loader_num_workers } train_loader = ClevrDataLoader(**train_loader_kwargs)
# Dimensionless Fluxes gamma+/- = gamma+/- * tc / dc gammain = 1.e-2 gammaout = 3.e-3 # Dimensionless Concentrations c0 = c0 / dc c0in = 1. c0out = 0. c_cin = 0.75 c_cout = 0.25 # Resulting Parameters: Turnover = gamma_in / dc, Supersaturation = (c_inf - c+0) / dc, c_inf = gammaout / (kout * dc) turn = gammain eps = gammaout / kout print('Turnover: ', turn) print('Supersaturation:', eps) cspline = np.zeros((4)) cspline = Functions.Spline(gammain, gammaout, kin, kout, c0in, c0out, c_cin, c_cout) ct = np.arange(0,1,(1/100.)) def f(x): condlist = [x < c_cout, (x >= c_cout) & (x <= c_cin),x > c_cin] funclist = [lambda x: gammaout - kout * (x - c0out), lambda x: cspline[0] + cspline[1] * x + cspline[2] * x**2 + cspline[3] * x**3, lambda x: -gammain - kin * (x - c0in)] return np.piecewise(x, condlist, funclist) plt.plot(ct,(f(ct)/gammain)) print(cspline) # In[33]: plotEveryNth = 2000 plt.rcParams["figure.figsize"] = [10,10]
# Delete least correlation data index = list(importances.index) low_importance = [] for i in index: if importances.loc[i]['importance'] < 0.01: low_importance.append(i) for f in low_importance: del x_train[f] del x_test[f] rf.fit(x_train, y_train) # Evaluate performance y_train_predict = rf.predict(x_train) t_mae = Functions.mae(y_train, y_train_predict) t_rmse = Functions.rmse(y_train, y_train_predict) y_predict = rf.predict(x_test) mae = Functions.mae(y_test, y_predict) rmse = Functions.rmse(y_test, y_predict) print('Train:') print('MAE of all: ', t_mae) print('RMSE of all: ', t_rmse) print('Test:') print('Mae of all: ', mae) print('RMSE of all: ', rmse) # Plot graph of test output and predict output plt.figure(figsize=(20, 8)) ax1 = plt.subplot(111)
import Functions # r is read, a is append, and w is overwrite # can do a+ and w+ to read and write new_list = [] with open("test_file", "r") as f: for line in f: new_list.append(float(line.rstrip("\n"))) print(new_list) print("Max value of list is " + str(Functions.max_val(new_list))) print("Average of list is " + str(Functions.compute_list_avg(new_list))) city_list = [] with open("unordered_cities.txt", "r") as f: for line in f: city_list.append(line.rstrip("\n")) sorted_citylist = sorted(city_list) with open("ordered_list", "w") as f: for city in sorted_citylist: f.write(city + "\n")
shadow=True) if title != 0: print("Testing") plt.title(title) else: plt.title("Type 3-2") plt.savefig(impath, bbox_extra_artists=(lgd, ), bbox_inches='tight') plt.close() """ Rest of the Program """ #Setting plot style fun.setPlotStyle() plt.rcParams['figure.figsize'] = (12, 10) #Storing file in dataframe df = fun.simpletextread(file, ',') PIN = df[df['Detector '].str.contains("PIN")] df.drop(PIN.index, axis=0, inplace=True) #Not including PIN values df['Detector '] = df['Detector '].astype(str).str[:-6] #Removing .txt #conditions = [df['Wafer'].str.contains('11'), df['Wafer'].str.contains('12'), df['Wafer'].str.contains('13'), df['Wafer'].str.contains('14')] conditions = [df['Wafer'].str.contains('95'), df['Wafer'].str.contains('30')] #choices = ['WNo11', 'WNo12', 'WNo13', 'WNo14'] choices = ['3.1', '3.2'] df['Type'] = np.select(conditions, choices, default='0')
# Td = OrigTd dtg = [D0] output = [] for curwidth in similaritywidth: for cursigx in sigxvals: for cursigy in sigyvals: for trial in range(10): print(trial) for i in range(5000): if len(states) >= 226: break states.add((19 - current[0], current[1])) # states += [tuple(current)] distl, distr = searchneighbours(current) D = F.divergence(distl, distr, cursigx, cursigy, curwidth) # print(np.append(distl,distr,axis = 0)) D = D[dtype] statedtg = list(finddtg(current, a) for a in actions) # print(statedtg) maxdiv = max(statedtg, key=operator.itemgetter(1))[1] temp2 = [] for s in statedtg: # print(s) if maxdiv == s[1]: temp2 += [s] update = random.choice(temp2) nextaction = statedtg.index(update) nextaction = np.reshape(np.array(nextaction), (1, 1)) # print(nextaction) # print(update)
image = cv2.imread(imagePath) image = cv2.resize(image, (IMAGE_DIMS[1], IMAGE_DIMS[0])) image = img_to_array(image) data.append(image) num_img = num_img + 1 # Extract the class labels from the image path and update the # labels list l = imagePath.split(os.path.sep)[-2] labels.append(l) # In this version of the training script, we use only the alteration that produces an accuracy under 100%, # so we can speed up the training process, without loosing the performance of the net # 1. Compression for step in Functions.frange(0, 1, 0.5): # Load the image and add a JPG compression if step < -0.0001 or step > 0.0001: image = cv2.imread(imagePath) encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 100 - (step * 100)] result, image = cv2.imencode('.jpg', image, encode_param) image = cv2.imdecode(image, 1) try: # Resize the image, as the original picture image = cv2.resize(image, (50, 50)) image = img_to_array(image) # Add the altered image and its label data.append(image) labels.append(l)
expressed = args.expressed samplots = args.samplots plotfile = args.plotfile tissuesummary = args.tissuesummary tissuestats = args.tissuestats tissuediffthressum = args.tissuediffthressum tissuediffthresstats = args.tissuediffthresstats tissuebarplot = args.tissuebarplot tissuediffthresplot = args.tissuediffthresplot # ---------------------- Functions ---------------------- # pd.set_option('max_columns', 100) if tissuesummary: Functions.tissue_summary(data, out_tsdir, out_tsfile, minexp, minsamps) elif tissuestats: a = Functions.tissue_statistics(in_tsfile, savefile, out_statsdir, out_statsfile, genetype, drop_tsfile) elif tissuediffthressum: Functions.tissue_difthres_summaries(data, seqnumsamps, out_thresdir, seqexp, ncpus, num_cores) elif tissuediffthresstats: Functions.tissue_difthres_statistics(in_thresdir, out_statsdir, out_statsfile, genetype, drop_tsfile) elif tissuebarplot: if in_statsfile != None:
for imagePath in imagePaths: image = cv2.imread(imagePath) image = cv2.resize(image, (IMAGE_DIMS[1], IMAGE_DIMS[0])) image = img_to_array(image) data.append(image) num_img = num_img + 1 # Extract the class labels from the image path and update the # labels list l = imagePath.split(os.path.sep)[-2] labels.append(l) # Add the altered images if step_img % 2 == 0: # 1. Rotation for step in Functions.frange(0, 1, 0.5): if step < -0.0001 or step > 0.0001: image = cv2.imread(imagePath) # Rotate the image image = Functions.rotate_image(image, 180 * step) image = Functions.crop_around_center( image, *Functions.largest_rotated_rect(50, 50, math.radians(180 * step))) try: # Resize the image, as the original picture image = cv2.resize(image, (50, 50)) image = img_to_array(image) # Add rhe altered image and its label data.append(image)
def EstimateSPEMean(self,total_hist_data,bkg_hist_data,ped_cutoff): mean_total = fu.WeightedMean(total_hist_data['bins'],total_hist_data['bin_heights']) mean_pedestal = fu.WeightedMean(bkg_hist_data['bins'],bkg_hist_data['bin_heights']) occ = self._EstimateOccupancy(total_hist_data,bkg_hist_data,ped_cutoff) mean_photon_distribution = occ return ((mean_total - mean_pedestal)/mean_photon_distribution)
# FUNDADEBTSSSS = FUNDADEBT[FUNDADEBT.gvkey == 1084] list_vars = ['SUBNOTCONV_C', 'SUBCONV_C', 'CONV_C', 'DD_C', 'DN_C', 'DLTO', 'CMP', 'CL_C'] FUNDADEBT['CHECK_DEBT'] = FUNDADEBT[list_vars].sum(axis=1) FUNDADEBT['CCC'] = FUNDADEBT['dltt'] - FUNDADEBT['CHECK_DEBT'] FUNDADEBT['NP_Exact'] = np.where((FUNDADEBT['CCC'] >= -0.001001) & (FUNDADEBT['CCC'] <= 0.001001), 1, 0) FUNDADEBT['NP_UNDER'] = np.where((FUNDADEBT['CCC'] > 0.001001), 1, 0) FUNDADEBT['NP_OVER'] = np.where((FUNDADEBT['CCC'] < -0.001001), 1, 0) FUNDADEBT['COUNT'] = np.where((FUNDADEBT['dltt'] > 0) & (FUNDADEBT['CHECK_DEBT'] > 0), 1, 0) FUNDADEBT['CHECK_DEBT'] = FUNDADEBT[list_vars].sum(axis=1) # FUNDADEBT['CHECK_DEBT2'] = FUNDADEBT[list_vars].sum(axis=1) # FUNDADEBT['CCC2'] = FUNDADEBT['dltt'] + FUNDADEBT['dd1'] - FUNDADEBT['CHECK_DEBT2'] # FUNDADEBT['CCC3'] = FUNDADEBT['dltt'] - FUNDADEBT['dd1'] - FUNDADEBT['CHECK_DEBT2'] FUNDADEBT = Functions.pct_calculator(list_vars, 'CHECK_DEBT', 'PCT', FUNDADEBT) FUNDADEBTS = FUNDADEBT[(FUNDADEBT.gvkey == 33152)] list_varsp = ['SUBNOTCONV_CPCT', 'SUBCONV_CPCT', 'CONV_CPCT', 'DD_CPCT', 'DN_CPCT', 'DLTOPCT', 'CMPPCT', 'CL_CPCT'] for i in list_varsp: FUNDADEBT[i].fillna(0, inplace=True) # FUNDADEBTSSSSS = FUNDADEBT[FUNDADEBT.gvkey == 1084] FUNDADEBT['TOTALDEBT_C_U'] = FUNDADEBT['SUBNOTCONV_C'] + FUNDADEBT['SUBCONV_C'] +\ FUNDADEBT['CONV_C'] + FUNDADEBT['DD_C'] + FUNDADEBT['DN_C'] + FUNDADEBT['BD_C'] +\ FUNDADEBT['CL_C'] + FUNDADEBT['SHORT_C'] FUNDADEBT = Functions.hhi_calculator(['SUBNOTCONV_C', 'SUBCONV_C', 'CONV_C', 'DD_C', 'DN_C', 'BD_C', 'CL_C','SHORT_C'], 'TOTALDEBT_C_U', 'HH1U', FUNDADEBT) FUNDADEBT = Functions.hhi_calculator(['SUB_C', 'SBN_C', 'BD_C', 'CL_C', 'SHORT_C'], 'TOTALDEBT_C_U', 'HH2U', FUNDADEBT)
session_list.append('session{0}'.format(x)) validSessions.append(x) except: x + 1 print(x) #%% Substitute all 0s with nans only for F0 and remove outliers cols = ["F0final_sma", "voicingFinalUnclipped_sma", "pcm_loudness_sma"] F0Check = 10 F0topQuantile = .95 F0bottomQuantile = .15 topLoud = .95 bottomLoud = .05 allPatData = Functions.removeOutliers(allPatDataRaw, cols, F0Check, F0topQuantile, F0bottomQuantile, topLoud, bottomLoud) allDocData = Functions.removeOutliers(allDocDataRaw, cols, F0Check, F0topQuantile, F0bottomQuantile, topLoud, bottomLoud) #%% Add mel scale to DFs for x, y in zip(allPatData, allDocData): allPatData[x]['melScale'] = python_speech_features.base.hz2mel( allPatData[x]["F0final_sma"]) allDocData[y]['melScale'] = python_speech_features.base.hz2mel( allDocData[y]["F0final_sma"]) print(x) #%% Remove Nans, you need this for the slope anyway allPatDataNoNans = {} allDocDataNoNans = {}
elif float(i) <= 1000: bioactivity_class.append('active') else: bioactivity_class.append('intermediate') #subset DataFrame selection = ['molecule_chembl_id','canonical_smiles','standard_value'] df2=df[selection] #convert bioactivity_class to series so that it can be concatenated bioactivity_class = pd.Series(bioactivity_class, name='bioactivity_class') df3 = pd.concat([df2, bioactivity_class], axis=1) df3.to_csv('bioactivity_data_preprocessed.csv', index=False) #get Lipinski descriptors DataFrame and append to existing DataFram df_lipinski = Functions.lipinski(df3.canonical_smiles) df_combined = pd.concat([df3, df_lipinski], axis=1) #cap the standard_value at 100,000,000 to simplify pIC50 conversion df_norm = Functions.norm_value(df_combined) #convert IC50 value to pIC50 value df_final = Functions.pIC50(df_norm) #subset DataFrame to exclude intermediate bioactivity class df_2class = df_final[df_final.bioactivity_class != 'intermediate'] #PLOTS #Frequency of active vs. inactive bioactivity classes plt.figure(figsize=(5.5, 5.5))
myOPCUA.disconnectOPCUA() GPIO.cleanup() print("Shutdown successful") if __name__ == "__main__": #Script for frunning the main application hostip = "10.148.6.70" #Board/Port Setup (Currently not being used) GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) #GPIO17 Used as the input of the vCtrl GPIO.setup(12, GPIO.OUT) #GPIO18 Pulse Width Modulation / Motor Encoder #Initalize a constants vCtrl = 0 #Still need to be globalized but vCtrl and load is retained from the dashboard load = 0 freq, RatePerMin = Functions.motorEncoder(vCtrl, load) #Takes the input of vCtrl and load #Create an OPCUA server Temp, Vibr, Curr, Rpm = myOPCUA.createOPCUA() #Create an MQTT client and attach our routines to it client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.on_disconnect = on_disconnect #Connects and starts the connection to the mqtt server client.connect(hostip, 1883, 60) client.loop_start() try:
delta = 0. #coupling ph = np.array([ (10.**-10) * 1j, (10.**-9) * -1j, (10.**-10) * -1j, (10.**-9) * 1j, ]) #phase to break degeneracy #vortices coordinates (remember that in our convention the first number is the ordinate) vortex1 = [4.000000000001 / a, 2.330000000002 / a] vortex2 = [4.0000000000002 / a, 2.330000002 / a] ############################################################################################ #kinetic and pairing hamiltonian building (matrices with O(L^4) elements, only O(L^2) filled) kinet = fx.sprshamOBC(Ltilde, t, -4. * t + a**2 * mu, ph, R / a) pair = fx.nonconsOBC(Ltilde, a * delta / 2.) ham = a**-2 * sprs.hstack( (sprs.vstack((kinet, pair)), sprs.vstack( (-(pair.conjugate()), -(kinet.T)))) ) #pairing is created in distruction sector (lower left). Parts are then stacked to create full hamiltonian tic = time.time() vals, vecs = alg.eigh( ham.toarray()) #diagonalization using either full matrix diagonalization. toc = time.time() print("time=" + str(toc - tic)) #prints how long the diagonalization process takes ############################################################################################ #data saving in a compressed format, np.load() needed to read the data
import Functions as fn if __name__ == "__main__": np.random.seed(123) a = 0.08 b = 0.08 r0 = 0.06 sigma = 0.2 #for i in range(10): # path = fn.Vasicek_simulation(a, b, r0, sigma) # plt.plot(path) #plt.show() alpha = 8 noise = np.ones(1001) * 0.1 path = fn.Vasicek_simulation(a, b, r0, sigma) bonds = fn.bond_price(path, alpha) bonds_real = fn.bond_price_real(path, alpha, noise) plt.plot(bonds, label="theoretical bond price") plt.plot(bonds_real, label='real bond price') plt.legend() plt.show() # Using the rolling window approximation for a duration window = 120 return_bond = (bonds_real[1:] - bonds_real[:-1]) / bonds_real[1:] trancate_rate = path[1:] - path[:-1] D = [] for t in range(len(trancate_rate) - window):
print("Loop #:", i + 1) #This loop is only here to ensure that corruption doesnt happen on the last two packets otherwise the sockets could fail or stall if (i >= (loop - 2)): packetErrorProbability = 0 packetDropProbability = 0 #Recieve the packet packet, address, receiverSequence = rdtReceive(serverSocket, bufferSize, receiverSequence, packetErrorProbability, packetDropProbability) #If the packet was good it will be written to the file file.write(packet) #Iterate the loop i = i + 1 #Calculating Received Image file size receivedFileSize = Functions.fileSize(file) #Close the file file.close() #close the socket serverSocket.close() #find the time at the end of the transfer end = time.time() #Calculate the total time it took for the entire transfer elapsedTime = end - start print( "Server: File Received\nReceived File size: {0}\nTime taken in Seconds: {1}" .format(receivedFileSize, elapsedTime))
def rad_toa(LSname, curFol, metaDict): #creates a dict that will hold each bands/rasters name and corresponding arrays # done beforw with eval(varName = create.array), this strangly didn't work for # all band in Python 3.5 rrdict = {} #Handle Landsat 8 differently than 4,5 or 7 if LSname[2] == '8': for x in range(1, 10): xStr = str(x) #read bands as arrays rrdict['arrayDN' + xStr] = funcs.singleTifToArray(curFol + LSname + "_B" + xStr + ".TIF") #convert to radiance and convert to 32-bit floating point for memory saving rrdict['lambda' + xStr] = metaDict['radiance_mult_B' + xStr] * rrdict[ 'arrayDN' + xStr] + metaDict['radiance_add_B' + xStr] rrdict['lambda' + xStr] = rrdict['lambda' + xStr].astype( np.float32) #convert to reflectance and convert to 32-bit floating point for memory saving rrdict['reflectance'+xStr] = ( ( metaDict['reflectance_mult_B'+xStr] * rrdict['arrayDN'+xStr] + \ metaDict['reflectance_add_B'+xStr] ) / \ math.sin(math.radians(metaDict['sun_elevation'])) ) rrdict['reflectance' + xStr] = rrdict['reflectance' + xStr].astype( np.float32) del rrdict['arrayDN' + xStr] elif LSname[2] == '7' or LSname[2] == '5' or LSname[2] == '4': #calculate radiation and toa relfectance if LSname[2] == '7': lastBand = 9 else: lastBand = 8 for x in range(1, lastBand): xStr = str(x) #read bands as arrays, bands 6 need to be handled separately if x != 6: rrdict['arrayDN' + xStr] = funcs.singleTifToArray(curFol + LSname + "_B" + xStr + ".TIF") #convert to radiance and convert to 32-bit floating point for memory saving rrdict['lambda'+xStr] = ( (metaDict['radiance_max_B'+xStr] - metaDict['radiance_min_B'+xStr]) / \ (metaDict['quant_max_B'+xStr] - metaDict['quant_min_B'+xStr])) * \ (rrdict['arrayDN'+xStr] - metaDict['quant_min_B'+xStr]) + \ metaDict['radiance_min_B'+xStr] rrdict['lambda' + xStr] = rrdict['lambda' + xStr].astype( np.float32) #convert to reflectance and convert to 32-bit floating point for memory saving esun = [1970, 1842, 1547, 1044, 225.7, 0, 82.06, 1369][x - 1] #band depending constant e_s_dist = ES_dist(metaDict["julDay"]) rrdict['reflectance'+xStr] = ( np.pi * rrdict['lambda'+xStr] * e_s_dist**2 ) / \ (esun * \ math.sin(math.radians(metaDict['sun_elevation']))) rrdict['reflectance' + xStr] = rrdict['reflectance' + xStr].astype(np.float32) del rrdict['arrayDN' + xStr] return rrdict
def rdtReceive(serverSocket, bufferSize, receiveSeqNum, packetErrorProbability=0, packetDropProbability=0): #this will be the loop identifier, determines if the transfer is complete and if the loop will end successfulReceive = 0 while (not (successfulReceive)): #Receive the packet from the client data, address = serverSocket.recvfrom(bufferSize) #If the probability of dropping a packet causes this If statement to render "true" then the packet will be discarded and will exit the loop if (Functions.errorCondition(packetDropProbability)): print("Data Packet Dropped\n") #Restarts the loop by recieving The correct data from the server successfulReceive = 0 #This else statement will execute in all circumstances where the packet is not dropped else: #Extracts the sequence number, the checksum , and the image packet seqNum, makeChecksum, imagePacket = Functions.extractData(data) #This statement will be true if the manually selected packet Error probability renders the statement true, then the actual image packet will be manually corrupted #using the dataError(packet) function if (Functions.errorCondition(packetErrorProbability)): #The actual corruption of data imagePacket = Functions.dataError(imagePacket) print("\nData Corrupted") #determine the checksum from the packet that was sent receiverChecksum = Functions.makeChecksum(imagePacket) #if the packet has a matching checksum and sequence number, assign the corresponding ACK, create the checksum, and then send the repsonse to the client if ((receiverChecksum == makeChecksum) and (seqNum == receiveSeqNum)): #identify the ackowledgement Ack = receiveSeqNum #Convert the Ack from int to string and then encoding to bytes Ack = b'ACK' + str(Ack).encode("UTF-8") #Server sends the sequence number, the checksum, and the ackowledgement back to the client senderACK = Functions.makePacket(seqNum, Functions.makeChecksum(Ack), Ack) print( "Sequence #: {0}, Receiver Sequence: {1}, Checksum from Client: {2}, Checksum for Received File: {3}\n" .format(seqNum, receiveSeqNum, makeChecksum, receiverChecksum)) #update the expected sequence receiveSeqNum = 1 - seqNum #end the loop successfulReceive = 1 #If the packet is in fact corrupted(wrong checksum or wrong sequence number), send back the ack for the previous packet and request the data again elif ((receiverChecksum != makeChecksum) or (seqNum != receiveSeqNum)): #last acked sequence numvber Ack = 1 - receiveSeqNum #Convert the Ack from int to string and then encoding to bytes Ack = b'ACK' + str(Ack).encode("UTF-8") #Server sends the sequence number, the checksum, and the ackowledgement back to the client senderACK = Functions.makePacket(1 - receiveSeqNum, Functions.makeChecksum(Ack), Ack) print("Server Requested to Resend the Packet") print( "Sequence #: {0}, Receiver Sequence: {1}, Checksum from Client: {2}, Checksum for Received File: {3}\n" .format(seqNum, receiveSeqNum, makeChecksum, receiverChecksum)) #Loop continues until satisfies condition successfulReceive = 0 #sending the Acknowledgement packet to the client serverSocket.sendto(senderACK, address) return imagePacket, address, receiveSeqNum