def main(): if (len(sys.argv) > 1 and os.path.exists(sys.argv[1]) and os.path.isfile(sys.argv[1])): filename = sys.argv[1] else: filename = gui.get_path("*.csv",defaultFile="data.csv") commonPath = os.path.abspath(os.path.split(filename)[0]) outputFile = os.path.join(commonPath, "odmanalysis.csv") print "Now watching %s for changes" % filename handler = OMDCsvChunkHandler(filename,outputFile) observer = Observer() observer.schedule(handler, path=commonPath, recursive=False) handler.startPCChain() observer.start() try: while True: time.sleep(1) except (KeyboardInterrupt, SystemExit): print "Stopping..." observer.stop() time.sleep(1) observer.join()
def main(): if (len(_sys.argv) > 1 and _os.path.exists(_sys.argv[1]) and _os.path.isfile(_sys.argv[1])): filename = _sys.argv[1] else: filename = _gui.get_path("*.csv",defaultFile="odmanalysis.csv") commonPath = _os.path.abspath(_os.path.split(filename)[0]) measurementName = _os.path.split(_os.path.split(filename)[0])[1] try: settings = _odm.CurveFitSettings.loadFromFile(commonPath + '/odmSettings.ini') print "settings loaded from local odmSettings.ini" except: settings = _gui.getSettingsFromUser(None) settings.saveToFile(commonPath + '/odmSettings.ini') print "settings saved to local odmSettings.ini" df = _odm.readAnalysisData(filename) makeDisplacementPlots(df,commonPath, measurementName = measurementName, nmPerPx = settings.pxToNm) _plt.show()
def main(): parser = argparse.ArgumentParser() parser.add_argument("datafile",type=str,nargs="?",default=None) parser.add_argument("--settings-file",dest="odm_settings_file",type=str,default=None, help="an odmSettings.ini file to get the settings from") parser.add_argument("--fitfunction-params-file",dest="fitfunction_params_file",type=str,default=None, help="a json file with the fitfunction parameters to use") args = parser.parse_args() if (not args.datafile is None and os.path.exists(args.datafile) and os.path.isfile(args.datafile)): datafile = args.datafile else: datafile = gui.get_path("*.csv",defaultFile="data.csv") if (not args.odm_settings_file is None and os.path.exists(args.odm_settings_file) and os.path.isfile(args.odm_settings_file)): odmSettingsFile = args.odm_settings_file else: odmSettingsFile = None if (not args.fitfunction_params_file is None and os.path.exists(args.fitfunction_params_file) and os.path.isfile(args.fitfunction_params_file)): ffSettingsFile = args.fitfunction_params_file else: ffSettingsFile = None df,movingPeakFitSettings,referencePeakFitSettings,measurementName = fitRawODMData(datafile,settingsFile=odmSettingsFile,fitSettingsFile=ffSettingsFile)
def main(): if (len(sys.argv) > 1 and os.path.exists(sys.argv[1]) and os.path.isfile(sys.argv[1])): filename = sys.argv[1] else: filename = gui.get_path("*.csv",defaultFile="data.csv") commonPath = os.path.abspath(os.path.split(filename)[0]) measurementName = os.path.split(os.path.split(filename)[0])[1] outputFilename = commonPath + "/odmanalysis.csv" readerProcess, readerQueue = startReadAsync(filename) dataProcessor = ChunkedODMDataProcessor(commonPath) chunkWriter = ChunkWriter(outputFilename) while True: try: rawChunk = readerQueue.get(timeout=10) except: #done break rawChunk = rawChunk[rawChunk.intensityProfile.map(len) > 0] if len(rawChunk) is not 0: processedChunk = dataProcessor.processDataFrame(rawChunk) chunkWriter.writeDataFrame(processedChunk) readerProcess.join() #make plots df = odm.readAnalysisData(outputFilename) settings = odm.CurveFitSettings.loadFromFile(commonPath + '/odmSettings.ini') makeDisplacementPlots(df,commonPath,measurementName,settings.pxToNm)
def main(): if (len(_sys.argv) > 1 and _os.path.exists(_sys.argv[1]) and _os.path.isfile(_sys.argv[1])): filename = _sys.argv[1] else: filename = _gui.get_path("*.csv",defaultFile="data.csv") commonPath = _os.path.abspath(_os.path.split(filename)[0]) measurementName = _os.path.split(_os.path.split(filename)[0])[1] df = _odm.readODMData(filename) app = qt.QApplication(_sys.argv) stepViewer = InteractiveStepViewer(df) stepViewer.show() app.exec_()
def main(): if (len(sys.argv) > 1 and os.path.exists(sys.argv[1]) and os.path.isfile(sys.argv[1])): filename = sys.argv[1] else: filename = gui.get_path("*.csv",defaultFile="data.csv") commonPath = os.path.abspath(os.path.split(filename)[0]) with file(filename,'r') as fIn: with file(filename+'new','w') as fOut: for line in fIn: fOut.write(line.replace(" s","").replace(" V","")) os.rename(filename,filename+".old") os.rename(filename+"new",filename) os.remove(filename+".old") print "DONE"
def main(): if (len(_sys.argv) > 1 and _os.path.exists(_sys.argv[1]) and _os.path.isfile(_sys.argv[1])): filename = _sys.argv[1] else: filename = _gui.get_path("*.csv",defaultFile="odmanalysis.csv") commonPath = _os.path.abspath(_os.path.split(filename)[0]) measurementName = _os.path.split(_os.path.split(filename)[0])[1] print "loading settings from " + commonPath + "/odmSettings.ini" settings = _odm.CurveFitSettings.loadFromFile(commonPath+"/odmSettings.ini") df = _odm.readAnalysisData(filename) df['displacement_nm'] = df.displacement * settings.pxToNm app = qt.QApplication(_sys.argv) cycleViewer = InteractiveCycleViewer(df) cycleViewer.show() app.exec_()
def main(): parser = argparse.ArgumentParser(description='Pivots the odmanalysis output file to produce and excel file with all cycles in different columns') parser.add_argument('filename', nargs='?', default="", help="The odmanalysis.csv file to tabulate", type=str) parser.add_argument('--split-direction','-d', type=bool, help='split the actuation directions into different columns', metavar='') args = parser.parse_args() if not os.path.isfile(args.filename): args.filename = gui.get_path("*.csv",defaultFile="odmanalysis.csv") commonPath = os.path.abspath(os.path.split(args.filename)[0]) df = odm.readAnalysisData(args.filename) cycleFrames = [] keys = ['cycleNumber'] if args.split_direction == True: keys.append('direction') grouped = df.groupby(keys) for keys, group in grouped: if not hasattr(keys, '__iter__'): keys = tuple([keys]) dfTemp = group[['actuatorVoltage','displacement']] dfTemp = dfTemp.reset_index().drop('timestamp',axis=1) name = 'cycle_%i' % keys[0] for k in keys[1:]: name += "_%s" % k cycleFrames.append(pd.concat({name: dfTemp}, axis=1)) dfCombined = pd.concat(cycleFrames,axis=1) dfCombined.to_excel(os.path.join(commonPath,'odmanalysis_tabulated.xlsx'),index=False) print os.path.join(commonPath,'odmanalysis_tabulated.xlsx')
def main(): if (len(sys.argv) > 1 and os.path.exists(sys.argv[1]) and os.path.isfile(sys.argv[1])): filename = sys.argv[1] else: filename = gui.get_path("*.csv",defaultFile="data.csv") commonPath = os.path.abspath(os.path.split(filename)[0]) measurementName = os.path.split(os.path.split(filename)[0])[1] settings = odm.CurveFitSettings.loadFromFileOrCreateDefault(commonPath + '/odmSettings.ini') df,movingPeakFitSettings,referencePeakFitSettings,measurementName = fitRawODMData(filename) settings = odm.CurveFitSettings.loadFromFileOrCreateDefault(commonPath + '/odmSettings.ini') plotKwargs = {'savePath' : commonPath, 'measurementName' : measurementName, 'nmPerPx' : settings.pxToNm} print "creating plots..." makeDisplacementPlots(df, **plotKwargs) makeIntensityProfilePlots(df, movingPeakFitSettings,referencePeakFitSettings, **plotKwargs) print "ALL DONE" plt.show()
def main(): if len(sys.argv) > 1 and os.path.exists(sys.argv[1]) and os.path.isfile(sys.argv[1]): filename = sys.argv[1] else: filename = gui.get_path("*.csv", defaultFile="odmanalysis.csv") commonPath = os.path.abspath(os.path.split(filename)[0]) try: settings = odm.CurveFitSettings.loadFromFile(commonPath + "/odmSettings.ini") print "settings loaded from local odmSettings.ini" except: settings = gui.getSettingsFromUser(None) settings.saveToFile(commonPath + "/odmSettings.ini") print "settings saved to local odmSettings.ini" nmPerPx = settings.pxToNm df = odm.readAnalysisData(filename) plt.plot(np.arange(len(df.displacement)), df.displacement * nmPerPx) plt.interactive(False) coordinateGrabber = gui.InteractiveCoordinateGrabber(plt.gcf(), 2, "Select range for fitting a polynomial...") coordinateGrabber.promptMessages = ["Select lower limit...", "Select upper limit..."] coordinates = coordinateGrabber.getValuesFromUser() xLimits = [int(c[0]) for c in coordinates] dfs = df.iloc[slice(*xLimits)] validInput = False while validInput == False: try: deg = int(raw_input("Polynomial degree: ")) validInput = True except: pass xValues = np.arange(len(dfs.displacement)) p = cp.polyfit(xValues, dfs.displacement, deg) noise = (dfs.displacement - cp.polyval(p, xValues)) * nmPerPx ax = plt.subplot(111) ax.plot(xValues, dfs.displacement * nmPerPx) ax.plot(xValues, cp.polyval(p, xValues) * nmPerPx, "r--") ax.set_xlabel("Actuator Voltage (V)") ax.set_ylabel("Displacement (nm)") fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, sharex=False, sharey=True, squeeze=True) ax1.plot(np.arange(len(noise)), noise, "o") ax2.hist(noise, bins=50, orientation="horizontal", facecolor="green", alpha=0.5) sd = ODMStats.makeStatsDescriptionDict(nmPerPx * dfs.displacement) peakDistanceToEdge = [abs(sd["mean"] - x * nmPerPx) for x in ax2.get_xlim()] xtext = 0.1 if peakDistanceToEdge[0] > peakDistanceToEdge[1] else 0.7 ax2.text(xtext, 0.7, ODMStats.printStatsDescriptionDict(sd), transform=ax2.transAxes) ax1.set_ylabel("Displacement (nm)") ax2.set_xlabel("Count") fig.savefig(os.path.join(commonPath, "Displacement noise.png"), dpi=150) stats = noise.describe() with open(os.path.join(commonPath, "position_noise_stats.txt"), "w") as f: f.write(str(stats)) plt.show()