def V_sampchan(self, chan, gain, data_rate=RATE): ''' This routine returns a single reading of the voltage for the channel. Returns a tuple of the following 5 objects: V -- float, the measured voltage time_stamp -- float, the time of the measurement in seconds since the beginning of the epoch (OS dependent begin time) ref -- float, the reference voltage (Vdd) collected simultaneously. :param int chan: the channel number (0, 1, 2, 3, 4, 5, 6, 7, 8). NOTE: channel 8 returns a measurement of Vdd. :param gain: ignored by board. Defaults to 1. :param int data_rate: ignored by board. :returns: V_avg, stdev, stdev_avg, time_stamp, Vdd_avg :return float V: :return float time_stamp: :return float ref: ''' start = time.time() value = DAQC2plate.getADC(self.addr, chan) ref = DAQC2plate.getADC(self.addr, 8) end = time.time() time_stamp = (start + end) / 2 return value, time_stamp, ref
def V_oversampchan_stats(self, chan, gain, avg_sec, data_rate=RATE): ''' This routine returns the average voltage for the channel averaged at the maximum rate for the board. The standard deviation and the estimated deviation of the mean are also returned. Returns a tuple of the following 5 objects: V_avg -- float, the averaged voltage stdev -- float, the standard deviation of the measured values during the averaging interval stdev_avg -- float, the estimated standard deviation of the returned average time_stamp -- float, the time at halfway through the averaging interval in seconds since the beginning of the epoch (OS dependent begin time) Vdd_avg -- float, the reference voltage (Vdd) collected simultaneously. :param int chan: the channel number (0, 1, 2, 3, 4, 5, 6, 7, 8). NOTE: channel 8 returns a measurement of Vdd. :param gain: ignored by board. Defaults to 1. :param int data_rate: ignored by board. :param float avg_sec: seconds to average for, actual averaging interval will be as close as possible for an integer number of samples :returns: V_avg, stdev, stdev_avg, time_stamp, Vdd_avg :return float V_avg: description :return float stdev: :return float stdev_avg: :return float time_stamp: :return float Vdd_avg: ''' value = [] ref = [] starttime = time.time() endtime = starttime + avg_sec while time.time() < endtime: value.append(DAQC2plate.getADC(self.addr, chan)) ref.append(DAQC2plate.getADC(self.addr, 8)) time_stamp = (starttime + endtime) / 2 ndata = len(value) logging.debug('channel:' + str(chan) + ', starttime:' + str(starttime) + ', ' 'endtime:' + str(endtime) + ', ndata:' + str(ndata) + '.') V_avg = sum(value) / ndata Vdd_avg = sum(ref) / ndata stdev = np.std(value, ddof=1, dtype=np.float64) stdev_avg = stdev / np.sqrt(float(ndata)) return V_avg, stdev, stdev_avg, time_stamp, Vdd_avg
def V_oversampchan(self, chan, gain, avg_sec, data_rate=RATE): """ This routine returns the average voltage for the channel averaged at the default rate for the board and returns an average and observed range. Returns a tuple of the following 5 objects: V_avg -- float, the averaged voltage V_min -- float, the minimum voltage read during the interval V_max -- float, the maximum voltage read during the interval time_stamp -- float, the time at halfway through the averaging interval in seconds since the beginning of the epoch (OS dependent begin time) Vdd_avg -- float, the reference voltage (Vdd) collected simultaneously. :param int chan: the channel number (0, 1, 2, 3, 4, 5, 6, 7, 8). NOTE: channel 8 returns a measurement of Vdd. :param gain: ignored by board. Defaults to 1. :param int data_rate: ignored by board. :param float avg_sec: seconds to average for, actual averaging interval will be as close as possible for an integer number of samples :returns: V_avg, V_min, V_max, time_stamp, Vdd_avg :return float V_avg: description :return float V_min: :return float V_max: :return float time_stamp: :return float Vdd_avg: """ value = [] ref = [] starttime = time.time() endtime = starttime + avg_sec while time.time() < endtime: value.append(DAQC2plate.getADC(self.addr, chan)) ref.append(DAQC2plate.getADC(self.addr, 8)) time_stamp = (endtime + endtime) / 2 ndata = len(value) V_avg = sum(value) / ndata Vdd_avg = sum(ref) / ndata V_min = min(value) V_max = max(value) return V_avg, V_min, V_max, time_stamp, Vdd_avg
def exposeAndCollectData(): GPIO.output(methane_valve, GPIO.LOW) GPIO.output(ethane_valve, GPIO.LOW) GPIO.output(compressed_air_valve, GPIO.LOW) GPIO.output(chamber_venting_valve, GPIO.LOW) GPIO.output(mfc1_output_to_chamber_valve, GPIO.LOW) GPIO.output(mfc2_output_to_chamber_valve, GPIO.LOW) GPIO.output(mfc1_venting_valve, GPIO.LOW) GPIO.output(mfc2_venting_valve, GPIO.LOW) start_time = time.time() # capture the time at which the test began. All time values can use start_time as a reference dataVector1 = [] # data values to be returned from sensor 1 dataVector2 = [] # data values to be returned from sensor 2 tempDataVector = [] humidityDataVector = [] timeVector = [] # time values associated with data values sampling_time_index = 1 #sampling_time_index is used to ensure that sampling takes place every interval of sampling_time, without drifting. data_date_and_time = time.asctime( time.localtime(time.time()) ) print("Starting data capture") while (time.time() < (start_time + duration_of_signal)): # While time is less than duration of logged file if (time.time() > (start_time + (sampling_time * sampling_time_index))): # if time since last sample is more than the sampling time, take another sample dataVector1.append( DAQC.getADC(daqc_address, sensor_input_channel_1) ) # Perform analog to digital function, reading voltage from first sensor channel dataVector2.append( DAQC.getADC(daqc_address, sensor_input_channel_2) ) # Perform analog to digital function, reading voltage from second sensor channel timeVector.append( time.time() - start_time ) sampling_time_index += 1 # increment sampling_time_index to set awaited time for next data sample if ((sampling_time_index - 1) % 10 == 0): print(int(time.time() - start_time)) print(DAQC.getADC(daqc_address, linear_actuator_position_channel)) # If time is between 10-50 seconds and the Linear Actuator position sensor signal from DAQCplate indicates a retracted state, extend the sensor ## elif (time.time() >= (start_time + sensing_delay_time) and time.time() <= (sensing_retract_time + start_time) and DAQC.getADC(daqc_address, linear_actuator_position_channel) < extended_state ): elif (time.time() >= (start_time + sensing_delay_time) and time.time() <= (start_time + sensing_delay_time + 10) ): GPIO.output(linear_actuator_extend, GPIO.HIGH) # Actuate linear actuator to extended position GPIO.output(linear_actuator_unlock_retract, GPIO.LOW)# Energizing both control wires causes linear actuator to extend # If time is less than 10 seconds or greater than 50 seconds and linear actuator position sensor signal from DAQCplate indicates an extended state, retract the sensor elif ( ((time.time() < (sensing_delay_time + start_time)) or (time.time() > (sensing_retract_time + start_time)) ) and DAQC.getADC(daqc_address, linear_actuator_position_channel) > retracted_state): ## elif ( ((time.time() < (sensing_retract_time + start_time + 10)) and (time.time() > (sensing_retract_time + start_time)) )): GPIO.output(linear_actuator_unlock_retract, GPIO.HIGH) # Retract linear actuator to initial position. Energizing only the linear_actuator_unlock_retract wire causes the lineaer actuator to retract GPIO.output(linear_actuator_extend, GPIO.LOW) # Otherwise, keep outputs off else: GPIO.output(linear_actuator_unlock_retract, GPIO.LOW) GPIO.output(linear_actuator_extend, GPIO.LOW) ## print("blep") return dataVector1, dataVector2, timeVector
def sample_data(self): heading_indices = self.args['preferences']['headingString'].split(",") data_string = "" for idx in heading_indices: if idx[:2] == "ch": # Read the normal input pins if self.args['preferences']['headerIndices'][ idx] == "Anemometer(km/h)": # 1 tick per second = 2.4km/h data_string += "{:.1f},".format(self.args['anemometer']) elif self.args['preferences']['headerIndices'][ idx] == "RainGauge(mm)": # 1 tick = 0.2794mm rain data_string += "{:.4f},".format(self.args['rainGauge']) # Relative humidity is calculated using the formula: # RH = 0.0375 * Vout - 37.7 # Vout needs to be in mV and RH in % elif self.args['preferences']['headerIndices'][ idx] == "RelativeHumidity(%)": Vout = DAQC2.getADC( int(idx[2]), int(idx[3]) ) * 1000 # We have to convert voltage to mV as it is read in V RH = 0.0375 * Vout - 37.7 data_string += "{:.4f},".format(RH) elif self.args['preferences']['headerIndices'][ idx] == "RainGauge(mm)": # 1 tick = 0.2794mm rain data_string += "{:.4f},".format(self.args['rainGauge']) else: data_string += "{:.5f},".format( DAQC2.getADC(int(idx[2]), int(idx[3]))) data_string += "{},".format(datetime.now(timezone.utc).strftime('%Y')) data_string += "{},".format(datetime.now(timezone.utc).strftime('%m')) data_string += "{},".format(datetime.now(timezone.utc).strftime('%d')) data_string += "{},".format(datetime.now(timezone.utc).strftime('%H')) data_string += "{},".format(datetime.now(timezone.utc).strftime('%M')) data_string += "{}\n".format(datetime.now(timezone.utc).strftime('%S')) print(data_string, end='') self.filemanager.save_to_file(self.args['preferences']['savePath'], self.args['filename'], data_string) self.previous_time = self.current_time
def animate(i): # Left shift data data[0:-1] = data[1:] # Record current time data[-1] = v_to_dbm(DAQC2.getADC(0, 0), laser_cw * 1e-3) line.set_ydata(data) return [line]
def photoTest(): elapsedTime = 0 tMax = 25 startReadTime = time.time() onVolt = [] offVolt = [] ## tRead = 0 while (tMax >= elapsedTime): DAQC2.setDOUTbit(0, 7) #turn laser on time.sleep(1) tempVolt1 = [] tEnd1 = time.time() + 1 while (time.time() < tEnd1): tempVolt1.append(DAQC2.getADC(0, 0)) DAQC2.clrDOUTbit(0, 7) anaVolt = sum(tempVolt1) / len(tempVolt1) print("number of reads: ", len(tempVolt1)) print("Voltage('ON'): ", anaVolt) onVolt.append(anaVolt) tempVolt2 = [] tEnd2 = time.time() + 1 while (time.time() < tEnd2): tempVolt2.append(DAQC2.getADC(0, 0)) anaVolt = sum(tempVolt2) / len(tempVolt2) print("number of reads: ", len(tempVolt2)) print("Voltage('OFF'): ", anaVolt) offVolt.append(anaVolt) elapsedTime = time.time() - startReadTime print() avgON = sum(onVolt) / len(onVolt) avgOFF = sum(offVolt) / len(offVolt) print("average ON volt: ", avgON) print("avgerage OFF volt: ", avgOFF) print()
def read_rain_gauge(self): current_time = time.time() elapsed_time = current_time - self.gauges['rainGauge']['previousTime'] if elapsed_time >= 1: self.args['rainGauge'] = (self.gauges['rainGauge']['numberTicks'] * self.args['preferences']['rainConstant']) self.gauges['rainGauge']['numberTicks'] = 0 self.gauges['rainGauge']['previousTime'] = current_time temp_val = DAQC2.getADC(int(self.gauges['rainGauge']['channel'][2]), int(self.gauges['rainGauge']['channel'][3])) if temp_val > 4: if not self.gauges['rainGauge']['recordedTick']: self.gauges['rainGauge']['numberTicks'] += 1 self.gauges['rainGauge']['recordedTick'] = True else: self.gauges['rainGauge']['recordedTick'] = False
def readOD(): DAQC2.setDOUTbit(0, 7) time.sleep(1) rowVolts = [] j = 0 k = 0 num = 1 while (k <= 5): tempVolt = [] tEnd = time.time() + .5 while (time.time() < tEnd): tempVolt.append(DAQC2.getADC(j, k)) currAvgVolt = sum(tempVolt) / len(tempVolt) rowVolts.append(currAvgVolt) print("Avg voltage for ", num, ": ", currAvgVolt) k = k + 1 num = num + 1 if (k == 6 and j == 0): j = 1 k = 0 elif (k == 2 and j == 1): k = 10 DAQC2.clrDOUTbit(0, 7)
"Failed to import library from parent folder") ####### zet de LED uit DAQC.setLED(0, 'off') ####### stuur de analoge output aan DAQC.setDAC(0, 1, 2.64) # DAQ 0, adres analog-output 1, voltage 2.64 V ###### stuur 0, 1, 2, 3 volt naar analog-output 1 for i in range(10): volt = i % 4 # i modulo 4 DAQC.setDAC(0, 1, volt) time.sleep(0.1) ####### Lees data van Analoge Input val = DAQC.getADC(0, 1) # DAQC 0, adres Analog-Input 1 print(val) val8 = DAQC.getADCall(0) # lees alle 8 Analog-Inputs print(val8) ######## Lees meerdere data punten data = get_data.readPiPlate(DAQC, 3) # kanaal 0, 1000 punten, ADC 0 # maak een (unieke) filenaam aan filename = 'meting_test1_%s.txt' % (int(time.time())) write_data.saveArray(data, filename)
def readPressureMC(): voltage = DAQ.getADC(0, 2) - DAQ.getADC(0, 3) vadj = 1.004029 * voltage - 0.000386 # Calibrated for Pi Plate Error return 10**(1.66666667 * vadj - 11.46) #Pressure in Torr returned
def chemostat(timeL, pumpPeriod): elapsedTime = 0 tMax = timeL + 11 min = timeL / 60 pumpTime = pumpPeriod startReadTime = time.time() tStart = 0 tPump = time.time() volts = np.zeros(shape=(min + 1, 8)) counter = 0 currTime = time.time() print("\n") while (tMax >= elapsedTime): if (currTime - tStart > 60): #58 b/c lose two seconds with sleep and measure tStart = time.time() readTimeS = (tStart - startReadTime) / 60 print("Read ", counter, " at ", readTimeS, " min.") ### DAQC2.setDOUTbit(0, 7) time.sleep(1) rowVolts = [] j = 0 k = 0 num = 1 while (k <= 5): tempVolt = [] tEnd = time.time() + .5 while (time.time() < tEnd): tempVolt.append(DAQC2.getADC(j, k)) currAvgVolt = sum(tempVolt) / len(tempVolt) rowVolts.append(currAvgVolt) print("Avg voltage for ", num, ": ", currAvgVolt) k = k + 1 num = num + 1 if (k == 6 and j == 0): j = 1 k = 0 elif (k == 2 and j == 1): k = 10 DAQC2.clrDOUTbit(0, 7) print("\n") volts[counter] = rowVolts counter = counter + 1 ### measureTime = (tStart - startReadTime) / 60.0 measureDateTime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') dateTime.append(measureDateTime) readTime.append(measureTime) if ((currTime - tPump - 1) > pumpTime * 60): print("pump on/valves open") tPump = (time.time() - startReadTime) / 60 print("pump on at: ", tPump) j = 0 i = 0 while (i <= 5): DAQC2.setDOUTbit(j, i) DAQC2.setDOUTbit(0, 6) time.sleep(2) DAQC2.clrDOUTbit(0, 6) DAQC2.clrDOUTbit(j, i) time.sleep(.5) i = i + 1 if (i == 6 and j == 0): j = 1 i = 0 elif (i == 2 and j == 1): i = 10 tPump = time.time() print("pump off \n") currTime = time.time() elapsedTime = time.time() - startReadTime morbido1 = volts[:, 0].tolist() morbido2 = volts[:, 1].tolist() morbido3 = volts[:, 2].tolist() morbido4 = volts[:, 3].tolist() morbido5 = volts[:, 4].tolist() morbido6 = volts[:, 5].tolist() morbido7 = volts[:, 6].tolist() morbido8 = volts[:, 7].tolist() OD1 = (((np.log10(morbido1) / logBlankVolts[0]) - .71891) / -2.1235).tolist() OD2 = (((np.log10(morbido2) / logBlankVolts[1]) - .71891) / -2.1235).tolist() OD3 = (((np.log10(morbido3) / logBlankVolts[2]) - .71891) / -2.1235).tolist() OD4 = (((np.log10(morbido4) / logBlankVolts[3]) - .71891) / -2.1235).tolist() OD5 = (((np.log10(morbido5) / logBlankVolts[4]) - .71891) / -2.1235).tolist() OD6 = (((np.log10(morbido6) / logBlankVolts[5]) - .71891) / -2.1235).tolist() OD7 = (((np.log10(morbido7) / logBlankVolts[6]) - .71891) / -2.1235).tolist() OD8 = (((np.log10(morbido8) / logBlankVolts[7]) - .71891) / -2.1235).tolist() df = [ dateTime, readTime, morbido1, morbido2, morbido3, morbido4, morbido5, morbido6, morbido7, morbido8, OD1, OD2, OD3, OD4, OD5, OD6, OD7, OD8 ] my_df = pd.DataFrame(df) my_df = my_df.T global globalDF globalDF = my_df csvTitle = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + '.csv' my_df.to_csv(csvTitle, index=True, header=[ 'DateTime', 'Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'OD1', 'OD2', 'OD3', 'OD4', 'OD5', 'OD6', 'OD7', 'OD8' ]) print(my_df) print() print("new csv file on Desktop: ", csvTitle) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.scatter(readTime, morbido1, s=10, c='b', marker="s", label='Culture#1') ax1.scatter(readTime, morbido2, s=10, c='g', marker="o", label='Culture#2') ax1.scatter(readTime, morbido3, s=10, c='r', marker="^", label='Culture#3') ax1.scatter(readTime, morbido4, s=10, c='c', marker="p", label='Culture#4') ax1.scatter(readTime, morbido5, s=10, c='m', marker="D", label='Culture#5') ax1.scatter(readTime, morbido6, s=10, c='y', marker="v", label='Culture#6') ax1.scatter(readTime, morbido7, s=10, c='k', marker="h", label='Culture#7') ax1.scatter(readTime, morbido8, s=10, c='violet', marker="8", label='Culture#8') plt.ylabel('Voltage') plt.xlabel('Time (min)') Volttitle = datetime.now().strftime('%Y-%m-%d_%H-%M') + ' Voltage plot' plt.title(Volttitle) plt.legend(loc='upper right') plt.show() fig = plt.figure() ax1 = fig.add_subplot(111) ax1.scatter(readTime, OD1, s=10, c='b', marker="s", label='Culture#1') ax1.scatter(readTime, OD2, s=10, c='g', marker="o", label='Culture#2') ax1.scatter(readTime, OD3, s=10, c='r', marker="^", label='Culture#3') ax1.scatter(readTime, OD4, s=10, c='c', marker="p", label='Culture#4') ax1.scatter(readTime, OD5, s=10, c='m', marker="D", label='Culture#5') ax1.scatter(readTime, OD6, s=10, c='y', marker="v", label='Culture#6') ax1.scatter(readTime, OD7, s=10, c='k', marker="h", label='Culture#7') ax1.scatter(readTime, OD8, s=10, c='violet', marker="8", label='Culture#8') plt.ylabel('OD600') plt.xlabel('Time (min)') ODtitle = datetime.now().strftime('%Y-%m-%d_%H-%M') + ' OD plot' plt.title(ODtitle) plt.legend(loc='upper left') plt.show()
def Turbido(timeL, pumpPeriod, NormVolt): elapsedTime = 0 tMax = timeL + 45 min = timeL / 60 pumpTime = pumpPeriod startReadTime = time.time() tStart = 0 tPump = time.time() volts = np.zeros(shape=(min + 1, 8)) setVolt = NormVolt counter = 0 currTime = time.time() print("\n") currVolts = [] while (tMax >= elapsedTime): if (currTime - tStart > 60): tStart = time.time() readTimeS = (currTime - startReadTime) / 60 print("Read ", counter, " at ", readTimeS, " min.") DAQC2.setDOUTbit(0, 7) time.sleep(1) rowVolts = [] j = 0 k = 0 num = 1 while (k <= 5): tempVolt = [] tEnd = time.time() + .5 while (time.time() < tEnd): tempVolt.append(DAQC2.getADC(j, k)) currAvgVolt = sum(tempVolt) / len(tempVolt) rowVolts.append(currAvgVolt) print("Avg voltage for ", num, ": ", currAvgVolt) k = k + 1 num = num + 1 if (k == 6 and j == 0): j = 1 k = 0 elif (k == 2 and j == 1): k = 10 DAQC2.clrDOUTbit(0, 7) currVolts = rowVolts volts[counter] = rowVolts counter = counter + 1 measureTime = (tStart - startReadTime) / 60.0 measureDateTime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') dateTime.append(measureDateTime) readTime.append(measureTime) print("\n") if ((currTime - tPump - .05) > pumpTime * 60): tPump = time.time() timePump = (currTime - startReadTime) / 60 print("pump check at: ", timePump) tempLog = 0 currLogVolts = [] f = 0 while (f < 8): print(f) tempLog = np.log10(currVolts[f]) / logBlankVolts[f] print(tempLog) currLogVolts.append(tempLog) f = f + 1 print("CurrLogVolts: ", currLogVolts) j = 0 i = 0 iter = 0 currHighVolt = 10 while (iter < 8): print("iter: ", iter) currHighVolt = currLogVolts[iter] if (currHighVolt < setVolt): count = 0 while (currHighVolt < setVolt): DAQC2.setDOUTbit(j, i) DAQC2.setDOUTbit(0, 6) DAQC2.setDOUTbit(0, 7) time.sleep(.25) count = count + 1 avgV = 0 currHighVolt = 0 tVolt = [] tEnd = time.time() + .25 ## print("tmie read: ", tEnd) while (time.time() < tEnd): tVolt.append(DAQC2.getADC(j, i)) avgV = sum(tVolt) / len(tVolt) print("avg. volt: ", avgV) currHighVolt = np.log10(avgV) / logBlankVolts[iter] print("New currHighVolt: ", currHighVolt) print(count) DAQC2.clrDOUTbit(0, 7) DAQC2.clrDOUTbit(0, 6) DAQC2.clrDOUTbit(j, i) iter = iter + 1 i = i + 1 if (i == 6 and j == 0): j = 1 i = 0 elif (i == 2 and j == 1): i = 10 print("pump off \n") currTime = time.time() elapsedTime = time.time() - startReadTime morbido1 = volts[:, 0].tolist() morbido2 = volts[:, 1].tolist() morbido3 = volts[:, 2].tolist() morbido4 = volts[:, 3].tolist() morbido5 = volts[:, 4].tolist() morbido6 = volts[:, 5].tolist() morbido7 = volts[:, 6].tolist() morbido8 = volts[:, 7].tolist() OD1 = (((np.log10(morbido1) / logBlankVolts[0]) - .71891) / -2.1235).tolist() OD2 = (((np.log10(morbido2) / logBlankVolts[1]) - .71891) / -2.1235).tolist() OD3 = (((np.log10(morbido3) / logBlankVolts[2]) - .71891) / -2.1235).tolist() OD4 = (((np.log10(morbido4) / logBlankVolts[3]) - .71891) / -2.1235).tolist() OD5 = (((np.log10(morbido5) / logBlankVolts[4]) - .71891) / -2.1235).tolist() OD6 = (((np.log10(morbido6) / logBlankVolts[5]) - .71891) / -2.1235).tolist() OD7 = (((np.log10(morbido7) / logBlankVolts[6]) - .71891) / -2.1235).tolist() OD8 = (((np.log10(morbido8) / logBlankVolts[7]) - .71891) / -2.1235).tolist() df = [ dateTime, readTime, morbido1, morbido2, morbido3, morbido4, morbido5, morbido6, morbido7, morbido8, OD1, OD2, OD3, OD4, OD5, OD6, OD7, OD8 ] my_df = pd.DataFrame(df) my_df = my_df.T global globalDF globalDF = my_df csvTitle = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + '.csv' my_df.to_csv(csvTitle, index=True, header=[ 'DateTime', 'Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'OD1', 'OD2', 'OD3', 'OD4', 'OD5', 'OD6', 'OD7', 'OD8' ]) print(my_df) print() print("new csv file on Desktop: ", csvTitle) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.scatter(readTime, morbido1, s=10, c='b', marker="s", label='Culture#1') ax1.scatter(readTime, morbido2, s=10, c='g', marker="o", label='Culture#2') ax1.scatter(readTime, morbido3, s=10, c='r', marker="^", label='Culture#3') ax1.scatter(readTime, morbido4, s=10, c='c', marker="p", label='Culture#4') ax1.scatter(readTime, morbido5, s=10, c='m', marker="D", label='Culture#5') ax1.scatter(readTime, morbido6, s=10, c='y', marker="v", label='Culture#6') ax1.scatter(readTime, morbido7, s=10, c='k', marker="h", label='Culture#7') ax1.scatter(readTime, morbido8, s=10, c='violet', marker="8", label='Culture#8') plt.ylabel('Voltage') plt.xlabel('Time (min)') Volttitle = datetime.now().strftime('%Y-%m-%d_%H-%M') + ' Voltage plot' plt.title(Volttitle) plt.legend(loc='upper right') plt.show() fig = plt.figure() ax1 = fig.add_subplot(111) ax1.scatter(readTime, OD1, s=10, c='b', marker="s", label='Culture#1') ax1.scatter(readTime, OD2, s=10, c='g', marker="o", label='Culture#2') ax1.scatter(readTime, OD3, s=10, c='r', marker="^", label='Culture#3') ax1.scatter(readTime, OD4, s=10, c='c', marker="p", label='Culture#4') ax1.scatter(readTime, OD5, s=10, c='m', marker="D", label='Culture#5') ax1.scatter(readTime, OD6, s=10, c='y', marker="v", label='Culture#6') ax1.scatter(readTime, OD7, s=10, c='k', marker="h", label='Culture#7') ax1.scatter(readTime, OD8, s=10, c='violet', marker="8", label='Culture#8') plt.ylabel('OD600') plt.xlabel('Time (min)') ODtitle = datetime.now().strftime('%Y-%m-%d_%H-%M') + ' OD plot' plt.title(ODtitle) plt.legend(loc='upper left') plt.show()
def sysTest(): print("testing parts") i = 0 while (i < 1): print("\n") print("quit: 0") print("pumps: 1") print("valves:2") print("Photodiodes: 3") print("lasers: 4") var = input(": ") currInput = int(var) print("current input: ", currInput) if (currInput == 0): print( "turning off pump, closing all valves, turning off lasers, quitting" ) DAQC2.clrDOUTbit(0, 6) #turn off pump1 DAQC2.clrDOUTbit(1, 6) #turn off pump2 DAQC2.clrDOUTbit(0, 0) #turn off valves DAQC2.clrDOUTbit(0, 1) DAQC2.clrDOUTbit(0, 2) DAQC2.clrDOUTbit(0, 3) DAQC2.clrDOUTbit(0, 4) DAQC2.clrDOUTbit(0, 5) DAQC2.clrDOUTbit(1, 0) DAQC2.clrDOUTbit(1, 1) DAQC2.clrDOUTbit(1, 2) DAQC2.clrDOUTbit(1, 3) DAQC2.clrDOUTbit(1, 4) DAQC2.clrDOUTbit(1, 5) DAQC2.clrDOUTbit(0, 7) #turn off lasers i = 5 print("quitting") break elif (currInput == 1): print("pumps") j = 0 while (j < 1): print("\n") print("to go back: 0") print("turn on pump#1: 1") print("turn on pump#2: 2") print("turn off pump#1: 3") print("turn off pump#2: 4") var = input(": ") currInput1 = int(var) print("current input: ", currInput1) if (currInput1 == 0): print("back to main test menu") j = 5 elif (currInput1 == 1): print("turning on pump#1") DAQC2.setDOUTbit(0, 6) elif (currInput1 == 2): print("turning on pump#2") DAQC2.setDOUTbit(1, 6) elif (currInput1 == 3): print("turning off pump#1") DAQC2.clrDOUTbit(0, 6) elif (currInput1 == 4): print("turning off pump#1") DAQC2.clrDOUTbit(1, 6) elif (currInput == 4): print("Lasers") j = 0 while (j < 1): print("\n") print("turn lasers on: 1") print("turn lasers off: 2") print("go back to test menu: 0") var = input(": ") currInput2 = int(var) print("current input: ", currInput2) if (currInput2 == 0): print("back to main test menu") j = 5 elif (currInput2 == 1): print("lasers on") DAQC2.setDOUTbit(0, 7) elif (currInput2 == 2): print("lasers off") DAQC2.clrDOUTbit(0, 7) elif (currInput == 2): print("Valves") j = 0 while (j < 1): print("\n") print("to go back: 0") print("to open individual valves: 1-12") print("to close individual valves 21-32") print("to open all valves: 13") print("to close all valves: 14") var = input(": ") currInput3 = int(var) print("current input: ", currInput3) if (currInput3 == 0): print("back to main test menu") j = 5 elif (currInput3 == 13): print("opening all valves") DAQC2.setDOUTbit(0, 0) #open all valves DAQC2.setDOUTbit(0, 1) DAQC2.setDOUTbit(0, 2) DAQC2.setDOUTbit(0, 3) DAQC2.setDOUTbit(0, 4) DAQC2.setDOUTbit(0, 5) DAQC2.setDOUTbit(1, 0) DAQC2.setDOUTbit(1, 1) DAQC2.setDOUTbit(1, 2) DAQC2.setDOUTbit(1, 3) DAQC2.setDOUTbit(1, 4) DAQC2.setDOUTbit(1, 5) elif (currInput3 == 14): print("closing all valves") DAQC2.clrDOUTbit(0, 0) #close all valves DAQC2.clrDOUTbit(0, 1) DAQC2.clrDOUTbit(0, 2) DAQC2.clrDOUTbit(0, 3) DAQC2.clrDOUTbit(0, 4) DAQC2.clrDOUTbit(0, 5) DAQC2.clrDOUTbit(1, 0) DAQC2.clrDOUTbit(1, 1) DAQC2.clrDOUTbit(1, 2) DAQC2.clrDOUTbit(1, 3) DAQC2.clrDOUTbit(1, 4) DAQC2.clrDOUTbit(1, 5) elif (currInput3 == 1): print("opening valve #1") DAQC2.setDOUTbit(0, 0) elif (currInput3 == 2): print("opening valve #2") DAQC2.setDOUTbit(0, 1) elif (currInput3 == 3): print("opening valve #3") DAQC2.setDOUTbit(0, 2) elif (currInput3 == 4): print("opening valve #4") DAQC2.setDOUTbit(0, 3) elif (currInput3 == 5): print("opening valve #5") DAQC2.setDOUTbit(0, 4) elif (currInput3 == 6): print("opening valve #6") DAQC2.setDOUTbit(0, 5) elif (currInput3 == 7): print("opening valve #7") DAQC2.setDOUTbit(1, 0) elif (currInput3 == 8): print("opening valve #8") DAQC2.setDOUTbit(1, 1) elif (currInput3 == 9): print("opening valve #9") DAQC2.setDOUTbit(1, 2) elif (currInput3 == 10): print("opening valve #10") DAQC2.setDOUTbit(1, 3) elif (currInput3 == 11): print("opening valve #11") DAQC2.setDOUTbit(1, 4) elif (currInput3 == 12): print("opening valve #12") DAQC2.setDOUTbit(1, 5) elif (currInput3 == 21): print("closing valve #1") DAQC2.clrDOUTbit(0, 0) elif (currInput3 == 22): print("closing valve #2") DAQC2.clrDOUTbit(0, 1) elif (currInput3 == 23): print("closing valve #3") DAQC2.clrDOUTbit(0, 2) elif (currInput3 == 24): print("closing valve #4") DAQC2.clrDOUTbit(0, 3) elif (currInput3 == 25): print("closing valve #5") DAQC2.clrDOUTbit(0, 4) elif (currInput3 == 26): print("closing valve #6") DAQC2.clrDOUTbit(0, 5) elif (currInput3 == 27): print("closing valve #7") DAQC2.clrDOUTbit(1, 0) elif (currInput3 == 28): print("closing valve #8") DAQC2.clrDOUTbit(1, 1) elif (currInput3 == 29): print("closing valve #9") DAQC2.clrDOUTbit(1, 2) elif (currInput3 == 30): print("closing valve #10") DAQC2.clrDOUTbit(1, 3) elif (currInput3 == 31): print("closing valve #11") DAQC2.clrDOUTbit(1, 4) elif (currInput3 == 32): print("closing valve #12") DAQC2.clrDOUTbit(1, 5) elif (currInput == 3): print("Photodiodes") j = 0 while (j < 1): print("\n") print("to go back: 0") print("to take a reading from a single morbidostat: 1-12") print("to take a reading from all morbidostats: 13") var = input(": ") currInput4 = int(var) print("current input: ", currInput4) if (currInput4 == 0): print("back to main test menu") j = 5 elif (currInput4 == 13): print("reading from all morbidostats") plate1 = DAQC2.getADCall(0) plate2 = DAQC2.getADCall(1) j = 0 k = 0 num = 1 while (k < 12): if (k <= 5): currVolt = plate1[k] print(num, ": ", currVolt) k = k + 1 num = num + 1 elif (k > 5): a = k - 6 currVolt = plate2[a] print(num, ": ", currVolt) k = k + 1 num = num + 1 elif (currInput4 == 1): currVolt = DAQC2.getADC(0, 0) print("Morbidostat#1: ", currVolt) elif (currInput4 == 2): currVolt = DAQC2.getADC(0, 1) print("Morbidostat#2: ", currVolt) elif (currInput4 == 3): currVolt = DAQC2.getADC(0, 2) print("Morbidostat#3: ", currVolt) elif (currInput4 == 4): currVolt = DAQC2.getADC(0, 3) print("Morbidostat#4: ", currVolt) elif (currInput4 == 5): currVolt = DAQC2.getADC(0, 4) print("Morbidostat#4: ", currVolt) elif (currInput4 == 6): currVolt = DAQC2.getADC(0, 5) print("Morbidostat#6: ", currVolt) elif (currInput4 == 7): currVolt = DAQC2.getADC(1, 0) print("Morbidostat#7: ", currVolt) elif (currInput4 == 8): currVolt = DAQC2.getADC(1, 1) print("Morbidostat#8: ", currVolt) elif (currInput4 == 9): currVolt = DAQC2.getADC(1, 2) print("Morbidostat#9: ", currVolt) elif (currInput4 == 10): currVolt = DAQC2.getADC(1, 3) print("Morbidostat#10: ", currVolt) elif (currInput4 == 11): currVolt = DAQC2.getADC(1, 4) print("Morbidostat#11: ", currVolt) elif (currInput4 == 12): currVolt = DAQC2.getADC(1, 5) print("Morbidostat#12: ", currVolt)
index = -1 for i in range(photocurrent.size): if (photocurrent[i] >= 0): index = i break V_s = retarding_voltage[index][0] print('V_s = {:.4f} V'.format(V_s)) return V_s ### MAIN ### voltages = np.arange(0, 0.7, 0.001) np.random.shuffle(voltages) led_data = np.zeros((voltages.size, 3)) dark_current = 1.3e-03 for i in range(voltages.size): Vr = voltages[i] led_data[i, 0] = Vr DAQC2.setDAC(0, 0, Vr) Vp = DAQC2.getADC(0, 0) - DAQC2.getADC(0, 1) led_data[i, 1] = Vp led_data[i, 2] = dark_current wavelength = 654.9 led_df = create_LED_df(led_data) filename = "data/laser_{λ}nm.csv".format(λ=wavelength) led_df.to_csv(filename, encoding='utf-8', index=False) plot_LED_data(led_df, np.array(wavelength))
resp['bit'] = bit resp['state'] = 0 elif (cmd == "toggleDOUTbit"): bit = args['bit'] try: DP.toggleDOUTbit(addr, bit) except AssertionError: DP2.toggleDOUTbit(addr, bit) resp['bit'] = bit resp['state'] = 'UNKNOWN' elif (cmd == "getADC"): channel = args['channel'] try: voltage = DP.getADC(addr, channel) except AssertionError: voltage = DP2.getADC(addr, channel) resp['channel'] = channel resp['voltage'] = voltage elif (cmd == "getTEMP"): bit = args['bit'] scale = args['scale'] try: temp = DP.getTEMP(addr, bit, scale) except AssertionError: temp = DP2.getTEMP(addr, bit, scale) resp['temp'] = temp resp['bit'] = bit else: sys.stderr.write("unknown daqc cmd: " + cmd) print(json.dumps(resp)) elif (plate_type == "MOTOR"):
def get_value(self): return DQ.getADC(self.piid, self.tid)
import piplates.DAQC2plate as DAQC2 import time DAQC2.setDAC(0, 0, 2.5) time.sleep(0.25) AIN = DAQC2.getADC(0, 0) time.sleep(0.25) DAQC2.setDAC(0, 0, 0) print("AIN =", AIN, "volts")
from tsl200 import laser_init import numpy as np import time from matplotlib import pyplot as plt import piplates.DAQC2plate as DAQC2 from v_to_dbm import v_to_dbm from tsl_offset import tsl_offset sleep = 50e-3 my_laser = laser_init() my_laser.on() N = 300 wavelength = np.linspace(1530,1600,N) data = [None]*N power = [None]*N my_laser.set_wavelength(1530) time.sleep(4) for wn,w in enumerate(wavelength): my_laser.set_wavelength(w) time.sleep(sleep) data[wn] = v_to_dbm(DAQC2.getADC(0,0),w*1e-3) data[wn] = tsl_offset(data[wn],w) power[wn] = my_laser.set_power_dBm(0) print("Data recorded") plt.figure() plt.plot(wavelength,data) plt.show()