def diff(oldfile, newfile, print_on_diff=True, move_on_diff=False, run_on_diff=None): print "diff %s %s" % (oldfile, newfile) fromfile = oldfile # Handle not existing old-file case fromdate = time.ctime(0) fromlines = "" if os.path.exists(fromfile): fromdate = time.ctime(os.stat(fromfile).st_mtime) fromlines = open(fromfile, "U").readlines() tofile = newfile todate = time.ctime(os.stat(tofile).st_mtime) tolines = open(tofile, "U").readlines() output = "".join(difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=3)) # Backup old file and move new file over if move_on_diff and ( len(output) > 0 or os.stat(newfile).st_uid != os.stat(oldfile).st_uid or os.stat(newfile).st_gid != os.stat(oldfile).st_gid ): copyfile(oldfile, oldfile + ".old") rename(newfile, oldfile) elif move_on_diff and len(output) == 0: os.remove(newfile) if print_on_diff and len(output) > 0: print output if run_on_diff != None: run_on_diff() return output if len(output) > 0 else None
def pingAndLog(logFilePath, serverAddress): logFile = open(logFilePath, 'a') proc = subprocess.Popen(['ping', '-c', '1', serverAddress], stdout=subprocess.PIPE, stderr=subprocess.PIPE) status = "" # Look for: # "1 packets transmitted, 1 received", # or "1 packets transmitted, 0 received", # or "ping: cannot resolve www.google.com: Unknown host" for line in proc.stdout: if ("1 received") in line: status = "1; Connected" elif ("0 received") in line: status = "0; Timeout" for line in proc.stderr: if ("Unknown") in line: status = "0; DNS unreachable" if ("failure") in line: status = "0; DNS unreachable" newLine = time.ctime() + "; " + status + "\n" print(newLine) logFile.write(newLine) logFile.close() threading.Timer(20, pingAndLog, [logFilePath, serverAddress]).start()
def wait_qsub(job_id): """wait for qsub to finish""" import time cmd = "qstat | grep %s > /dev/null" % job_id while os.system(cmd) == 0: sys.stderr.write("qsub jobs still running. --%s \r" % time.ctime()) time.sleep(60) sys.stderr.write("\n")
def main(size=(128, 128)): camcapture = cv.CreateCameraCapture(-1) cv.SetCaptureProperty(camcapture, cv.CV_CAP_PROP_FRAME_WIDTH, 640) cv.SetCaptureProperty(camcapture, cv.CV_CAP_PROP_FRAME_HEIGHT,480) if not camcapture: print "Error abriendo la camara" sys.exit(1) while False is not True: frame = cv.QueryFrame(camcapture) if frame is None: print "Error al leer el frame" break before = time() ################################################## size_frame = cv.GetSize(frame) # thumbnail = cv.CreateImage( calculate_resize(size_frame, size), frame.depth, frame.nChannels) # cv.Resize(frame, thumbnail) # size_thumbnail = cv.GetSize(thumbnail) # grayscale = cv.CreateImage(size_thumbnail, 8, 1) # cv.CvtColor(thumbnail, grayscale, cv.CV_RGB2GRAY) # equ = cv2.equalizeHist(np.asmatrix(cv.GetMat(grayscale))) # res = np.hstack((np.asmatrix(cv.GetMat(grayscale)), equ)) # res = cv.fromarray(equ) qr = QRScanner() qr.scan(frame) qr2 = QRScanner() # qr.scan(grayscale) # frame = thumbnail # frame = res ################################################## print (time()-before) cv.ShowImage('Max', frame) cv.ShowImage('Grayscale', grayscale) cv2.moveWindow('Max', 250, 50) command = cv.WaitKey(10) if command >= 0: if command == 115: image_name = (time.ctime().replace(" ", "_"))+".png" cv.SaveImage( image_name, frame_copy) print "Imagen guardada como: ", image_name del image_name elif command == 113: print "Saliendo." cv.DestroyAllWindows() exit(0)
def diff(oldfile, newfile, print_on_diff=True, move_on_diff=False, run_on_diff=None): print "diff %s %s" % (oldfile, newfile) fromfile = oldfile # Handle not existing old-file case fromdate = time.ctime(0) fromlines = "" if os.path.exists(fromfile): fromdate = time.ctime(os.stat(fromfile).st_mtime) fromlines = open(fromfile, 'U').readlines() tofile = newfile todate = time.ctime(os.stat(tofile).st_mtime) tolines = open(tofile, 'U').readlines() output = "".join( difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=3)) # Backup old file and move new file over if move_on_diff and (len(output) > 0 or os.stat(newfile).st_uid != os.stat(oldfile).st_uid or os.stat(newfile).st_gid != os.stat(oldfile).st_gid): copyfile(oldfile, oldfile + ".old") rename(newfile, oldfile) elif move_on_diff and len(output) == 0: os.remove(newfile) if print_on_diff and len(output) > 0: print output if run_on_diff != None: run_on_diff() return output if len(output) > 0 else None
def go(self): """Execution function: runs TAMO.MD.Meme.Meme and catches the output in self.output for access from MDAP.""" import time # write a temp fasta file of coregulated seqs to use as input to Meme(file=TempFasta) ctimeStr = time.ctime().replace(' ','_') fileName = 'tempFastaOfCoRegSeqs.MDAP.%s.fas' %(ctimeStr) tFasta = open(fileName, 'w') tFastaTxt = Fasta.text(self.coRegSeqs[0]) tFasta.write(tFastaTxt) # Call TAMO to do its thing: self.output = Meme(file=fileName, width='', extra_args=self.extra_args, bfile=self.bfile) # delete temp file os.remove(fileName)
def main(size=(128, 128)): # Se define la camara que se va a capturar y sus dimensiones camcapture = cv.CreateCameraCapture(-1) cv.SetCaptureProperty(camcapture, cv.CV_CAP_PROP_FRAME_WIDTH, 640) cv.SetCaptureProperty(camcapture, cv.CV_CAP_PROP_FRAME_HEIGHT,480) if not camcapture: print "Error abriendo la camara" sys.exit(1) while False is not True: frame = cv.QueryFrame(camcapture) if frame is None: print "Error al leer el frame" break before = time() ################################################## # Los procesos de vision computacional se lleban a # cabo en la siguiente fucion ################################################## frames = detection(frame, size = size) ################################################## print 1.0/(time()-before) for i in range(len(frames)): cv.ShowImage('Output'+str(i+1), frames[i]) # cv2.moveWindow('Max', 250, 50) command = cv.WaitKey(10) if command >= 0: if command == 115: image_name = (time.ctime().replace(" ", "_"))+".png" cv.SaveImage( image_name, frame_copy) print "Imagen guardada como: ", image_name del image_name elif command == 113: #print "Saliendo." cv.DestroyAllWindows() exit(0)
def go(self): """Execution function: coordinates options used and background GC calculation, then runs TAMO.MD.AlignAce.MetaAce and catches the output in self.output for access from MDAP. Output is TAMO.AligAce result object.""" import time # Calc GC background of genomic sequences representing the # entire data set if requested. if self.mdapOptions['background'] == 1: self.dataStats = seqStats.calcStats(self.mdapArgs[0]) self.gcback = self.dataStats['percentGC'] # write a temp fasta file of coregulated seqs to use as input to Meme(file=TempFasta) ctimeStr = time.ctime().replace(' ','_') fileName = 'tempFastaOfCoRegSeqs.MDAP.%s.fas' %(ctimeStr) tFasta = open(fileName, 'w') tFastaTxt = Fasta.text(self.coRegSeqs[0]) tFasta.write(tFastaTxt) # call TAMO to do its thing self.output = MetaAce(fileName, self.width, self.iterations, self.gcback) pass
def run(self): print 'starting', self.name, 'at:', time.ctime() self.res = apply(self.func, self.args) print self.name, 'finished at:', time.ctime()
training_iters = 50000 #number of steps after which accuracy is displayed displayStep = 1 #Number of training images trainSize = 20000 ############################################################################## #################################### AUXILIARY PARAMETERS ############################# #starting index, used in get images in batch start = 0 #logs the step accuracy with timestamp fname = "logs-" + str(time.ctime()).replace(" ", "_") + ".txt" flogs = open(fname,"w") imageLocation = 'ADEChallengeData2016/images/training/ADE_train_' annotationLocation = 'ADEChallengeData2016/annotations/training/ADE_train_' ####################################################################################### # distorted images, so ignored errorFiles = [1700,3019,8454,13507] dataIndices = [] for i in range(trainSize) : if not i in errorFiles : dataIndices.append(i) dataIndices = np.array(dataIndices)
iterations = 50 for iteration in range(1, iterations + 1): print() print('-' * 50) print('Iteration', iteration) model.fit(x_train, y_train, batch_size=BATCH_SIZE, epochs=1, validation_data=(x_val, y_val), verbose=verbose) # Select 10 samples from the validation set at random so we can visualize # errors. for i in range(10): ind = np.random.randint(0, len(x_val)) rowx, rowy = x_val[np.array([ind])], y_val[np.array([ind])] preds = model.predict_classes(rowx, verbose=0) # q = ctable.decode(rowx[0]) # correct = ctable.decode(rowy[0]) # guess = ctable.decode(preds[0], calc_argmax=False) # print('Q', q[::-1] if INVERT else q) # print('T', correct) # if correct == guess: # print('+', end=" ") # else: # print('-', end=" ") # print(guess) print('---') print() print("Ending:", time.ctime())