def __init__(self, cparams, logfiles, pparams, cport, pport): """Initialize the controller. Args: cparams: configuration parameters. logfiles: names of files to log to. pparams: pump parameters. cport: controller serial port. pport: pump serial port. """ pumpdriver_package = 'plugins.%s' % pparams['pumpdriver'] control_function_package = 'plugins.%s' % cparams['controlfun'] # Import pumpdriver pumpdriver = __import__(pumpdriver_package, globals(), locals(), ['Pump'], -1) # Fetch the control computation, make it a method of self. _temp = __import__(control_function_package, globals(), locals(), ['computeControl'], -1) self.computeControl = types.MethodType(_temp.computeControl, self) #self.ser_lock = cport.lock self.stdout_lock = threading.RLock() # Make the pump driver as appropriate. self.pump = pumpdriver.Pump(cparams, logfiles, pparams, cport, pport) # Data from config.ini self.logfiles = logfiles self.pparams = pparams self.cparams = cparams # all controller parameters live here self.blank_filename = self.logfiles['blanklog'] # Serial ports self.serpt = cport self.pport = pport # This lock is for the following tx/rx raw values. # TODO: should the controller know the number of chambers # in advance of measuring? self.OD_datalock = threading.RLock() self.tx_blank = [] self.rx_blank = [] self.rx_val = [] self.tx_val = [] self.z = [] # Make sure to close all the pinch valves at startup. with self.serpt.lock: print 'Closing all valves;' self.serpt.write("clo;") # Construct the timer threads that perform repeated actions. # TODO: make serial check period configurable. self.start_time = None # Set on call to start() control_period = int(cparams['period']) self.cont_timer = mytimer(control_period, self.controlLoop) self.ser_timer = mytimer(2, self.serialCheck)
def __init__(self,cparams,logfiles,pparams,cport,pport): pumpdriver = __import__('plugins.'+pparams['pumpdriver'],globals(), locals(),['Pump'],-1) _temp = __import__('plugins.'+cparams['controlfun'],globals(),locals(), ['computeControl'],-1) self.computeControl = types.MethodType(_temp.computeControl,self) # self.ser_lock = cport.lock self.stdout_lock = threading.RLock() self.pump = pumpdriver.Pump(cparams,logfiles,pparams,cport,pport) self.odcal = 1 #data from config.ini self.logfiles = logfiles self.pparams = pparams self.cparams = cparams #all controller parameters live here #serial ports self.serpt = cport self.pport = pport #This lock is for the following tx/rx raw values. self.OD_datalock = threading.RLock() self.tx_blank = [] self.rx_blank = [] self.rx_val = [] self.tx_val = [] self.z = [] with self.serpt.lock: self.serpt.write("clo;") # self.serpt.flush() #start the control-loop timer. self.start_time = time(); self.cont_timer = mytimer(int(cparams['period']),self.controlLoop) self.cont_timer.start() #start the serial polling timer self.ser_timer = mytimer(2, self.serialCheck) self.ser_timer.start()
""" -------------------------------- @Author: Dyson @Contact: [email protected] @file: mytimer.py @time: 2017/7/20 11:18 -------------------------------- """ import sys import os sys.path.append(sys.prefix + "\\Lib\\MyWheels") reload(sys) sys.setdefaultencoding('utf8') import mytimer mytimer = mytimer.mytimer() class timer0(object): def __init__(self): pass def main(self): mytimer.cmd_timer('python %s' % (os.getcwd() + r'\controller.py'), '17:00', 60 * 60 * 24) if __name__ == '__main__': timer0 = timer0() timer0.main()
def exeSim(self): x = 2 + 6 if not self.load1: self.openSubKinDef() if self.load1 and not self.load2: self.openSubSigList() #if self.file1.get() == "" or self.file2.get() == "": if not (self.load1 and self.load2): # dialog = Tk() # dialog.grid() # label1 = Label(dialog, text="You must PICK and LOAD source files first").grid(row=0) # ok = Button(dialog, text=' OK ', command=dialog.quit).grid(row=1) print "Simulations not started due to input file error" self.textBox.insert( Tkinter.END, "Simulations not started due to input file error\n") self.lineCount += 1 else: #print "numSimulations = "+self.numSimulations.get() numSubstrates = len(self.sigSubstrates) mt = mytimer() mt.start() kinaseSimulationsCounts = dict() #empty array with one member for each simulation s = self.numSimulations.get().replace(',', '') emptyCounts = [0 for x in range(0, int(s))] simulations = dict() for kinase in self.allKinases.keys(): simulations[kinase] = copy.deepcopy(emptyCounts) #now simulations[kin][s] points to kinase by name kin, sth simulation for s in range(0, int(self.numSimulations.get().replace(',', ''))): (substratesChosen, kinaseCounts) = rsr.randoPermutationSimulation( self.substrate2kinases, numSubstrates) for substrate in substratesChosen: kinases = self.substrate2kinases[substrate] for kinase in kinases: #k = allKinases.keys().index(kinase) simulations[kinase][s] += 1 if (s % 100 == 99): print "Simulation " + str( s + 1) + " complete\t" + mt.elapsed() self.textBox.insert( Tkinter.END, "Simulation " + str(s + 1) + " complete\t" + mt.elapsed() + "\n") self.textBox.see(Tkinter.END) self.lineCount += 1 if self.lineCount % 10 == 0: self.parent.update() self.currSim.set(str(s)) meanSimulations = [0 for x in self.allKinases.keys()] stdSimulations = [0 for x in self.allKinases.keys()] self.zscoreKinases = [0 for x in self.allKinases.keys()] self.pvalueKinases = [0 for x in self.allKinases.keys()] self.results = [] for k in range(0, len(self.allKinases.keys())): #meanSimulations[k] = math.mean(simulations[k]) meanSimulations[k] = numpy.mean( simulations[self.allKinases.keys()[k]]) #stdSimulations[k] = math.stdev(simulations[k]) stdSimulations[k] = numpy.std( simulations[self.allKinases.keys()[k]]) # if stdSimulations[k] == 0: # print "nan detected" # if numpy.isnan(stdSimulations[k]): # print "nan detected" kinase = self.allKinases.keys()[k] if stdSimulations[k] == 0: self.zscoreKinases[k] = 0.0 self.pvalueKinases[k] = 0.0 else: if kinase in self.sigKinaseCount: self.zscoreKinases[k] = ( self.sigKinaseCount[kinase] - meanSimulations[k]) / stdSimulations[k] else: self.zscoreKinases[k] = ( 0 - meanSimulations[k]) / stdSimulations[k] self.pvalueKinases[k] = scipy.stats.norm.sf( abs(self.zscoreKinases[k])) * 2 self.results.append( (self.pvalueKinases[k], self.allKinases.keys()[k], self.zscoreKinases[k])) print "sorting results\t" + mt.elapsed() #self.textBox.insert(Tkinter.END, "sorting results\t"+mt.elapsed()) self.results.sort() print "sorting complete\t" + mt.elapsed() self.textBox.insert(Tkinter.END, "sorting complete\t" + mt.elapsed() + "\n") self.textBox.see(Tkinter.END) self.lineCount += 1 outFile = None if self.outFilename != self.OPTIONAL: outFile = open(self.outFilename.get(), 'w') print "(kinase)\t(z-score)\t(p-value 2 tail)" self.textBox.insert(Tkinter.END, "(kinase)\t(z-score)\t(p-value 2 tail)" + "\n") if outFile: outFile.write("(kinase)\t(z-score)\t(p-value 2 tail)" + "\n") self.textBox.see(Tkinter.END) self.lineCount += 1 for result in self.results: (p, kinase, z) = result print kinase + "\t%.03f\t%.03f" % (z, p) self.textBox.insert(Tkinter.END, kinase + "\t%.03f\t%.03f\n" % (z, p)) self.textBox.see(Tkinter.END) self.lineCount += 1 if self.lineCount % 10 == 0: self.parent.update() if outFile: outFile.write(kinase + "\t%.03f\t%.03f\n" % (z, p))
import subprocess from effect import * import pygame import os import time from mytimer import mytimer from utils import fix_model import json from time import sleep myTimer = None cv2_WND_PROP_FULLSCREEN = cv2.WND_PROP_FULLSCREEN cv2_WINDOW_FULLSCREEN = cv2.WINDOW_FULLSCREEN cv2.namedWindow("frame", cv2_WND_PROP_FULLSCREEN) cv2.setWindowProperty("frame", cv2_WND_PROP_FULLSCREEN, cv2_WINDOW_FULLSCREEN) mTimer = mytimer() currrDir = (os.path.dirname(os.path.realpath(__file__))) print(currrDir + "/screensaver/1.jpg") global screensaverImg screensaverImg = cv2.imread(currrDir + "/screensaver/1.jpg") def getRez(): cmd = ['xrandr'] cmd2 = ['grep', '*'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) p2 = subprocess.Popen(cmd2, stdin=p.stdout, stdout=subprocess.PIPE) p.stdout.close() resolution_string, junk = p2.communicate() resolution = resolution_string.split()[0].decode("utf-8")
first = True #allows user to choose clades investigated # start at 0 (FirstTaxon) thru Phylum (Kingdom and Superkingdom unreliable) clades_to_proces = range(0, 7) #Want general to specific clades_to_proces.reverse() cladeBaseCounts = [0 for x in range(len(clades_to_proces))] #cladeIndex = ["firstTAXON"]+[tl.LINNAEUS_TAXONOMY_REVERSE[x] for x in clades_to_proces] #cladeIndex.reverse() mt = mytimer.mytimer() mt.start() print >> sys.stderr, "OPENING FILE " + sys.argv[1] + "\t" + ( mt.elapsedAsTimeStamp()) k = 0 period = 100 * 1000 for line in open(sys.argv[1]): splits = line.split('\t') if first: colnames = splits clades = colnames[1:-1] first = False else: curr_dict = taxonomyTree