Exemplo n.º 1
0
	def InitMainFrame(self):

		#Populates fields in GUI
		mainpath = os.path.dirname(os.path.realpath(__file__)).split("lib")[0]
		temppath = mainpath + os.sep +"temp" + os.sep
		with open(temppath + "experiment.txt", 'r') as f:
			for i,l in enumerate(f.readlines()):
				if l.split(":")[0] == "O2 Sensor":
					try:
						self.sensorlabel.SetLabel("Sensor: "+l.split(":")[1].split(";")[1])
					except RuntimeError:
						return

				if l.split(":")[0] == "Experiment type":
					self.ExpTypeLabel.SetLabel(l.split(":")[1].split(";")[1])

				if l.split(":")[0] == "Flush":
					fl = "Flush: " + l.split(":")[1].split(";")[0] + "s, "

				if l.split(":")[0] == "wait":
					fl = fl + "Wait: " + l.split(":")[1].split(";")[0]+ "s, "

				if l.split(":")[0] == "measure":
					fl = fl + "Measure: " + l.split(":")[1].split(";")[0] + "s"
					self.times.SetLabel(fl)

		mainpath = os.path.dirname(os.path.realpath(__file__)).split("lib")[0]

		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,0]

		# pO2_1,pO2_2,pO2_3,pO2_4,oxtime1 = aqdev.ReadFiresting(mainpath + os.sep + "oxygen" + os.sep + "firesting.txt")
		# pO2_1,pO2_2,pO2_3,pO2_4,oxtime1 = filehandling.GetLastOxygen()
		# filehandling.ox2file(pO2_1,pO2_2,pO2_3,pO2_4,oxtime1)

		self.ch1label.SetLabel("Channel 1: " + str(pO2_1))
		self.ch2label.SetLabel("Channel 2: " + str(pO2_2))
		self.ch3label.SetLabel("Channel 3: " + str(pO2_3))
		self.ch4label.SetLabel("Channel 4: " + str(pO2_4))



		with open(temppath + "numresp.txt", 'r') as f:
			self.numberanimalslabel.SetLabel("Number of chambers: "+ str(f.readline()))

		wx.CallLater(int(2000), self.InitMainFrame)
Exemplo n.º 2
0
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"])
Exemplo n.º 3
0
	def UpdateGui(self):
		# currentperiod
		period = filehandling.TjekPeriod()
		if period =="F":
			real = "Flushing"
			self.currentperiod.SetForegroundColour("red")
		if period =="W":
			real = "Wait period"
			self.currentperiod.SetForegroundColour("yellow")
		if period =="M":
			real = "Measurement"
			self.currentperiod.SetForegroundColour("Green")
		try:
			self.currentperiod.SetLabel(real)
		except:
			pass

		# pO2_1,pO2_2,pO2_3,pO2_4,oxtime1 = filehandling.GetLastOxygen()
		# mainpath = os.path.dirname(os.path.realpath(__file__)).split("lib")[0]
		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,0]

		self.r211.SetLabel(str(pO2_1))
		self.r221.SetLabel(str(pO2_2))
		self.r231.SetLabel(str(pO2_3))
		self.r241.SetLabel(str(pO2_4))

		try:
			with open(temp_p + os.sep + "lastmo2.txt", 'r') as ffff:
				mo2ss = ffff.read.lines()[0].split(";")
		except: pass

		try:
			self.mo1.SetLabel(str(mo2ss[0]))
		except: pass

		try:
			self.mo1.SetLabel(str(mo2ss[1]))
		except: pass

		try:
			self.mo1.SetLabel(str(mo2ss[2]))
		except: pass

		try:
			self.mo1.SetLabel(str(mo2ss[3]))
		except: pass

		try:
			with open(temp_p + os.sep + "last2.txt", 'r') as ffff:
				r2ss = ffff.read.lines()[0].split(";")

			self.r21.SetLabel(str(r2ss[0]))
			self.r22.SetLabel(str(r2ss[1]))
			self.r23.SetLabel(str(r2ss[2]))
			self.r24.SetLabel(str(r2ss[3]))
		except: pass



		try:
			startperiod, time,timesince = filehandling.GetperiodStart()
			mypercent = 100*timesince / time
			self.PeriodStatus.SetValue(mypercent)
		except:
			self.PeriodStatus.SetValue(50)
		# self.PeriodStatus.SetFirstGradientColour(wx.Colour(0, 0, 0))

		wx.CallLater(int(1000), self.UpdateGui)
Exemplo n.º 4
0
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")