def adaptiveIMF(minpoints, r2lim): #Starts with flush global interface devno = 0 ch1 = 16 Popen(["py", "-3", lib_p + os.sep + "Pump.py", "1", "0", "1"]) while True: print("Flush started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), ft) exp = filehandling.TjekRun() if not exp: break filehandling.PrintPeriod("F") while True: # # # # # # #check flush dpo2 / dt pass # Stop flushing - wait is always nescessary Popen(["py", "-3", lib_p + os.sep + "Pump.py", "0", "0", "1"]) print("Chamber closed: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), 30) filehandling.PrintPeriod("W") time.sleep(tw) # # # # # #Start new calculator, pass on minpoints while True: # check file for flush command if dpo2 > setp_dpo2: break # true -> end #Waiting one second time.sleep(1)
def ConventionalIMF(tf, tw, tm): #Experimental control for IMF starting with flush period. #Having only 1 channel to control the entire setup global interface devno = 0 ch1 = 16 exp = True while exp: Popen(["py", "-3", lib_p + os.sep + "Pump.py", "1", "0", "1"]) print("Flush started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), ft) exp = filehandling.TjekRun() if not exp: break filehandling.PrintPeriod("F") time.sleep(tf) Popen(["py", "-3", lib_p + os.sep + "oxygenserver.py"]) Popen(["py", "-3", lib_p + os.sep + "Pump.py", "0", "0", "1"]) print("Waiting period started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), wt) filehandling.PrintPeriod("W") exp = filehandling.TjekRun() if not exp: break time.sleep(tw) print("Measurement period started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), mt) filehandling.PrintPeriod("M") exp = filehandling.TjekRun() if not exp: break time.sleep(tm) Popen(["python", lib_p + os.sep + "Pump.py", "1", "0", "1"]) print("Experiment End")
def closedrespirometry_uhuh(mo2interval): global interface devno = 0 ch1 = 16 # Popen(["py","-3", lib_p + os.sep +"pump control"+os.sep+"FlushCle.py"]) Popen(["python", lib_p + os.sep + "Pump.py", "1", "0", "1"]) print("Experiment starting in 60s, time is now " + time.strftime("%H:%M:%S")) filehandling.PrintPeriod("W") time.sleep(60) # Stop flushing - wait is always nescessary Popen(["python", lib_p + os.sep + "Pump.py", "0", "0", "1"]) print("Experiment started, time is now " + time.strftime("%H:%M:%S")) #init calculator and experiment time filehandling.PrintPeriod("W") # call calculator Popen(["python", lib_p + os.sep + "oxygenserver.py"]) filehandling.SetperiodStart(int(time.time()), mo2interval) #wait one period before starting time.sleep(mo2interval) while True: exp = filehandling.TjekRun() if not exp: break #Start measuring filehandling.PrintPeriod("M") filehandling.SetperiodStart(int(time.time()), mo2interval) #wait interval time.sleep(mo2interval) #Set status to wait period to stop calculator filehandling.PrintPeriod("W") # A little wait period of 5 seconds to avoid using the same sensor values for following mo2 calculations time.sleep(5) # call calculator Popen(["python", lib_p + os.sep + "oxygenserver.py"]) # And another one to be sure time.sleep(5) print("Experiment ended: flushing starts") global interface devno = 0 ch1 = 16 Popen(["python", lib_p + os.sep + "Pump.py", "1", "0", "1"])
def Slave(): #Aquaresp acting as slave, listens to filehandling.TjekRun() for external setting of FWM status # Flushy.EmergencyFlush() exp = True while exp: whatperiod = filehandling.TjekPeriod() exp = filehandling.TjekRun() if not exp: break if whatperiod == "W": print("Wait period started") # Popen(["python", lib_p + os.sep +"oxygenserver.py"]) exp = filehandling.TjekRun() if not exp: break if whatperiod == "M": print("Measurement period registered") exp = filehandling.TjekRun() if not exp: break print("Experiment End")
def ClosedStartIMF(tf, tw, tm): #Experimental control for IMF starting with closed periods. #Having only 1 channel to control the entire setup global interface devno = 0 ch1 = 16 # Flushy.EmergencyFlush() while True: Popen(["py", "-3", lib_p + os.sep + "oxygenserver.py"]) Popen(["py", "-3", lib_p + os.sep + "Pump.py", "0", "0", "1"]) # Flushy.FlipOff(interface,devno,ch1) print("Waiting period started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), wt) exp = filehandling.TjekRun() if not exp: break filehandling.PrintPeriod("W") time.sleep(tw) print("Measurement period started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), mt) filehandling.PrintPeriod("M") exp = filehandling.TjekRun() if not exp: break time.sleep(tm) Popen(["py", "-3", lib_p + os.sep + "Pump.py", "1", "0", "1"]) print("Flush started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), ft) exp = filehandling.TjekRun() if not exp: break filehandling.PrintPeriod("F") time.sleep(tf)
def MeasurementPeriod(mainpath): # fn = oxygenpath + "firesting.txt" # presentfolder pf, slopefolder, expfolder = filehandling.presentfolderFunc() #Datacollection when it is measuring time measurementperiod1 = [] measurementperiod2 = [] measurementperiod3 = [] measurementperiod4 = [] timesec = [] timeabs = [] timeunix = [] pO2_1, pO2_2, pO2_3, pO2_4, oxtime = ["", "", "", "", ""] oxtimeold = datetime.datetime.strptime(time.strftime("%H:%M:%S"), "%H:%M:%S") unixtime = int(time.time()) unixtime2 = int(time.time()) timestartmeasurement = datetime.datetime.strptime( time.strftime("%H:%M:%S"), "%H:%M:%S") timestartmeasurement2 = datetime.datetime.strptime( time.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S") datadict = { 1: measurementperiod1, 2: measurementperiod2, 3: measurementperiod3, 4: measurementperiod4 } print("Start Data Acquisition - MO2") while 1: try: pO2_1, pO2_2, pO2_3, pO2_4, oxtime1 = aqdev.uniformoxygen() except: pO2_1, pO2_2, pO2_3, pO2_4, oxtime1 = [ 0, 0, 0, 0, datetime.datetime.strptime(time.strftime("%H:%M:%S"), "%H:%M:%S") ] # filehandling.ox2file(pO2_1,pO2_2,pO2_3,pO2_4,oxtime1) unixtime = int(time.time()) # Standard sampling rate for Aquaresp is .25 second time.sleep(.25) po2dict = {1: pO2_1, 2: pO2_2, 3: pO2_3, 4: pO2_4} try: oxtime = datetime.datetime.strptime(oxtime1, "%H:%M:%S") except: print("Missed a reading.") dtime = oxtime - oxtimeold stime = oxtime - timestartmeasurement if not dtime.total_seconds() == 0: # samplingrate in aquaresp is to high compared to the oxygenmeter. So if there is no time difference # between the samples, they are not logged. for i in range(1, 5): # inuse, volume, animalmass = filehandling.readrespirometerinfo(i) # if inuse =="y": try: datadict[i].append(float(po2dict[i])) except ValueError: datadict[i].append(float(9999)) except: datadict[i].append(float(9998)) timesec.append(float(stime.total_seconds())) timeabs.append(oxtime1) timeunix.append(unixtime) filehandling.ox2file(pO2_1, pO2_2, pO2_3, pO2_4, oxtime1) # print("her?",filehandling.TjekPeriod() ) oxtimeold = oxtime #When measurement period ends if filehandling.TjekPeriod() != "M": break # exp = filehandling.TjekRun() if not exp: break #Get measurement period duration duration = int(time.time()) - unixtime2 #Handle save data, and MO2 Calculation etc numfiles = len([ name for name in os.listdir(slopefolder) if os.path.isfile(os.path.join(slopefolder, name)) ]) with open(slopefolder + "Cycle_" + str(numfiles + 1) + ".txt", 'w') as f: f.write( "Time;Seconds from start for linreg;Unix Time;ch1 po2;ch2 po2;ch3 po2;ch4 po2;\n" ) for ii, l in enumerate(timesec): f.write("%s;%s;%s;%s;%s;%s;%s;\n" % (timeabs[ii], l, timeunix[ii], measurementperiod1[ii], measurementperiod2[ii], measurementperiod3[ii], measurementperiod4[ii])) measurementperiod1 = np.array(measurementperiod1) measurementperiod2 = np.array(measurementperiod2) measurementperiod3 = np.array(measurementperiod3) measurementperiod4 = np.array(measurementperiod4) datadict = { 1: measurementperiod1, 2: measurementperiod2, 3: measurementperiod3, 4: measurementperiod4 } timesec = np.array(timesec) sensor, AD, ExpType, ft, wt, mt, temperature, salinity, o2sol, UNIXtime, Dateime, IsSlave = filehandling.GetExperimentInfo( ) filehandling.updateLastmo2file(2, "-", "-") for ik in range(1, 5): inuse, volume, animalmass = filehandling.readrespirometerinfo(ik) if inuse == "y": slope, intercept, rr, p_value, std_err, avgpo2, medianpo2, minpo2, maxpo2 = AA.sloper( timesec, datadict[ik]) in_hours, in_minutes, in_seconds, in_days = filehandling.GetTimeStartExperiment( ) MO2, beta, rRespFish, MO2_TOT = AA.mo2maker( slope, float(temperature), float(salinity), 760, float(animalmass), float(volume)) print("Respirometer ", str(ik), "MO2: ", str(MO2), " r-squared: ", str(rr**2)) filehandling.updateLastmo2file(0, MO2, rr**2) filehandling.MO2Save(timestartmeasurement2, in_hours, unixtime, MO2, slope, intercept, rr, rr**2, p_value, std_err, duration, avgpo2, medianpo2, minpo2, maxpo2, maxpo2 - minpo2, beta, rRespFish, in_hours, in_minutes, in_seconds, in_days, ik) filehandling.MO2Save_TOT(timestartmeasurement, in_hours, unixtime, MO2_TOT, slope, intercept, rr, rr**2, p_value, ik) try: # AquaPlot.fakeJSdatasource() #Create copy data for data viewer # Popen(["python", mainpath +os.sep +"lib" + os.sep +"copytoGD.py"]) Popen([ "python", mainpath + os.sep + "lib" + os.sep + "Plotz.py" ]) except: pass filehandling.updateLastmo2file(1, "-", "-") Popen(["python", lib_p + os.sep + "Pump.py", "1", "0", "1"])
def deltaPO2IMF(setp_dpo2, tf): #Starts with flush global interface devno = 0 ch1 = 16 Popen(["py", "-3", lib_p + os.sep + "Pump.py", "1", "0", "1"]) while True: #Popen(["py","-3", lib_p + os.sep +"pump control"+ os.sep+"FlushCle.py"]) print("Flush started: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), ft) exp = filehandling.TjekRun() if not exp: break filehandling.PrintPeriod("F") lf = 0 while lf < int(tf): time.sleep(1) if filehandling.FORCEMEASUREMENTEND_REQ(): break lf += 1 lf = 0 # call calculator Popen(["py", "-3", lib_p + os.sep + "oxygenserver.py"]) exp = filehandling.TjekRun() if not exp: break # Stop flushing mandatorywait = 60 Popen(["py", "-3", lib_p + os.sep + "Pump.py", "0", "0", "1"]) print("Chamber closed: " + time.strftime("%Y-%m-%d %H:%M:%S")) filehandling.SetperiodStart(int(time.time()), mandatorywait) filehandling.PrintPeriod("W") time.sleep(mandatorywait - 30) print("Collecting data for start po2 - 30 sek to measurement start") # read po2 flush for 30 sec lf = 0 sumpo2 = 0.0 while lf < 30: # readpo2 # readpo2,readpo22,readpo23,readpo24,oxtime = filehandling.GetLastOxygen() try: readpo2, readpo22, readpo23, readpo24, oxtime = aqdev.uniformoxygen( ) except: pass sumpo2 = sumpo2 + float(readpo2) time.sleep(1) lf += 1 # get last wait po2 value po2flush = sumpo2 / 30.0 print("Start pO2: ", po2flush) print("Flush On at pO2: ", po2flush - setp_dpo2) exp = filehandling.TjekRun() if not exp: break #change to po2 percent filehandling.SetperiodStart(int(time.time()), mt) filehandling.PrintPeriod("M") while True: # readpo2 try: po2chamber, readpo22, readpo23, readpo24, oxtime = aqdev.uniformoxygen( ) except: pass #calc dpo2 dpo2 = po2flush - float(po2chamber) # check if dpo2 > setpoint if dpo2 > setp_dpo2: break # true -> end #Waiting one second time.sleep(1) if filehandling.FORCEMEASUREMENTEND_REQ(): break exp = filehandling.TjekRun() if not exp: break filehandling.PrintPeriod("F")