From e5efa3187bc212d48e731846e670277b5f74f3d8 Mon Sep 17 00:00:00 2001 From: tillraab Date: Wed, 4 May 2022 14:11:59 +0200 Subject: [PATCH] imporoving code style. grid_recorder.py is the new main recording file --- fishgrid.cfg | 13 +- grid_main.py | 3 +- grid_recorder.py | 459 +++++++++++++++++++++++++++++++++++++++++++++++ rasp_grid.py | 23 ++- rasp_grid_cfg.py | 87 +++++---- 5 files changed, 532 insertions(+), 53 deletions(-) create mode 100644 grid_recorder.py diff --git a/fishgrid.cfg b/fishgrid.cfg index 3f8c7e9..bb45e6a 100644 --- a/fishgrid.cfg +++ b/fishgrid.cfg @@ -28,13 +28,14 @@ General: Experiment.Name : tube competition StartDate : ~ - StartTime : ~ - Location : Colombia - leticia + StartTime : 10:00 + EndTime : 14:00 + Location : Tuebingen Position : ~N, ~W - WaterTemperature : 20.0C - WaterConductivity: 5.0uS/cm - WaterpH : 7.0pH - WaterOxygen : 0.0mg/l + WaterTemperature : 25.0C + WaterConductivity: 200.0uS/cm + WaterpH : ~pH + WaterOxygen : ~mg/l Comment : ~ Experimenter : T. Raab et al. :) *Recording diff --git a/grid_main.py b/grid_main.py index 716041f..58cff62 100644 --- a/grid_main.py +++ b/grid_main.py @@ -45,7 +45,8 @@ def main(): GPIO.output(LED2_pin, GPIO.LOW) GPIO.cleanup() - os.system('python3 /home/pi/code/Rasp_grid/rasp_grid.py') + # os.system('python3 /home/pi/code/Rasp_grid/rasp_grid.py') + os.system('python3 /home/pi/code/Rasp_grid/grid_recorder.py') sleep(5) diff --git a/grid_recorder.py b/grid_recorder.py new file mode 100644 index 0000000..5ced541 --- /dev/null +++ b/grid_recorder.py @@ -0,0 +1,459 @@ +from __future__ import print_function +import os +import sys +import glob +import datetime +from shutil import copyfile +import subprocess +import numpy as np +import threading +import multiprocessing as mp +from time import sleep, time +from IPython import embed +from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus, + ScanOption, create_float_buffer, InterfaceType, AiInputMode) +try: + import RPi.GPIO as GPIO +except: + pass + +class Configuration(): + def __init__(self): + # recording setup + self.channels = None + self.samplerate = None + self.max_v = None + self.gain = None + self.record_temp = False + + # electrodes + self.n_cols = 0 + self.n_rows = 0 + self.n_extra = 0 + + # timestamps + self._now = datetime.datetime.now() + self._start_clock = None + self._end_clock = None + + # paths + self.path = './' + self.path_format = '%04Y-%02m-%02d-%02H_%02M' + self._base_path = '/media/pi/data1' + + # files (paths) + self.file = os.path.join('.', 'traces-grid1.raw') + self.temp_file = os.path.join('.', 'temperatures.csv') + self.led_file = os.path.join('.', 'led_times.csv') + self.led_file2 = os.path.join('.', 'led_idxs.csv') + + # init calls + self.read_cfg() + self.create_file_structure() + + def GPIO_setup(self, LED1_pin, LED2_pin, LED_out_pin, Button1_pin, Button2_pin, power_controll_pin): + GPIO.setmode(GPIO.BOARD) + + GPIO.setup(LED1_pin, GPIO.OUT) # 1 + GPIO.output(LED1_pin, GPIO.LOW) + + GPIO.setup(LED2_pin, GPIO.OUT) # 2 + GPIO.output(LED2_pin, GPIO.LOW) + + GPIO.setup(LED_out_pin, GPIO.OUT) + GPIO.output(LED_out_pin, GPIO.LOW) + + LED_status = [False, False, False] + + GPIO.setup(power_controll_pin, GPIO.IN) + GPIO.setup(Button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + GPIO.setup(Button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + + return LED_status + + def read_cfg(self): + cfg_file = os.path.join(self._base_path, 'fishgrid.cfg') + cfg_f = open(cfg_file, 'r+') + cfg = cfg_f.readlines() + + for line in cfg: + if 'Columns1' in line: + self.n_cols = int(line.split(':')[1].strip()) + elif 'Rows1' in line: + self.n_rows = int(line.split(':')[1].strip()) + elif 'Extra1' in line: + self.n_extra = int(line.split(':')[1].strip()) + elif "AISampleRate" in line: + self.samplerate = int(float(line.split(':')[-1].strip().replace('kHz', '')) * 1000) + elif "AIMaxVolt" in line: + self.max_v = float(line.split(':')[1].strip().replace('mV', '')) + elif 'Gain' in line: + self.gain = int(line.split(':')[1].strip()) + # ToDo: add option to start now !!! + elif 'StartTime' in line: + self.start_clock = np.array(line.strip().replace(' ', '').split(':')[1:], dtype=int) + elif 'EndTime' in line: + self.end_clock = np.array(line.strip().replace(' ', '').split(':')[1:], dtype=int) + elif 'Gain' in line: + self.gain = int(line.split(':')[1].strip()) + self.channels = self.n_rows * self.n_cols + self.n_extra + + def create_file_structure(self): + start_str = ('%2.f_%2.f' % (self.start_clock[0], self.start_clock[1])).replace(' ', '0') + self.path = os.path.join(self._base_path, self._now.strftime('-'.join(self.path_format.split('-')[:3])) + start_str) # ToDo: Edit here + if not os.path.exists(self.path): + os.makedirs(self.path) + + copyfile(os.path.join(self._base_path, 'fishgrid.cfg'), os.path.join(self.path, 'fishgrid.cfg')) + cfg_file = os.path.join(self.path, 'fishgrid.cfg') + + cfg_f = open(cfg_file, 'r+') + cfg = cfg_f.readlines() + for enu, line in enumerate(cfg): + if "StartDate" in line: + cfg[enu] = (' StartDate : %s\n' % self._now.strftime('-'.join(self.path_format.split('-')[:3]))) + elif "StartTime" in line: + if not hasattr(self.start_clock, '__len__'): + cfg[enu] = (' StartTime : %s\n' % (self._now.strftime('%H:%M:%S') + self._now.strftime(".%f")[:4])) + else: + cfg[enu] = (' StartTime : %s\n' % ('%2.f:%2.f:00' % (self.start_clock[0], self.start_clock[1]))) + cfg_f.close() + cfg_f = open(cfg_file, 'w+') + for line in cfg: + cfg_f.write(line) + cfg_f.close() + + self.file = os.path.join(self.path, 'traces-grid1.raw') + self.temp_file = os.path.join(self.path, 'temperatures.csv') + self.led_file = os.path.join(self.path, 'led_times.csv') + self.led_file2 = os.path.join(self.path, 'led_idxs.csv') + + # @property + # def start_clock(self): + # return self._start_clock + # + # @start_clock.setter + # def start_clock(self, val): + # try: + # h, s = int(val[:2]), int(val[2:]) + # self._start_clock = [h, s] + # except ValueError: + # self._start_clock = [10, 0] + # + # @property + # def end_clock(self): + # return self._end_clock + # + # @end_clock.setter + # def end_clock(self, val): + # try: + # h, s = int(val[:2]), int(val[2:]) + # self._end_clock = [h, s] + # except ValueError: + # self._end_clock = [16, 0] + +class Recorder(): + def __init__(self, config): + self.config = config + + self._last_button_2_t = time() + self.config._now = self._now + + self.LED1_pin = 11 + self.Button1_pin = 16 + self.LED2_pin = 13 + self.Button2_pin = 18 + self.LED_out_pin = 35 + self.power_controll_pin = 37 + + self.LED_status = self.config.GPIO_setup(LED1_pin = self.LED1_pin, Button1_pin = self.Button1_pin, + LED2_pin = self.LED2_pin, Button2_pin = self.Button2_pin, + LED_out_pin = self.LED_out_pin, power_controll_pin = self.power_controll_pin) + + def DAQ_setup(self): + status = ScanStatus.IDLE + + descriptor_index = 0 + self.range_index = 0 + + interface_type = InterfaceType.USB + self.low_channel = 0 + self.high_channel = self.config.channels - 1 + + self.buffer_sec = 20 + self.samples_per_channel = self.samplerate * self.buffer_sec # * channels = Buffer size + self.buffer_size = self.samples_per_channel * self.config.channels + print('\nChannels: %.0f' % self.config.channels) + # rate = 20000 + + self.scan_options = ScanOption.CONTINUOUS + self.flags = AInScanFlag.DEFAULT + + # Get descriptors for all of the available DAQ devices. + devices = get_daq_device_inventory(interface_type) + number_of_devices = len(devices) + if number_of_devices == 0: + raise Exception('Error: No DAQ devices found') + + print('Found', number_of_devices, 'DAQ device(s):') + for i in range(number_of_devices): + print(' ', devices[i].product_name, ' (', devices[i].unique_id, ')', sep='') + + # Create the DAQ device object associated with the specified descriptor index. + self.daq_device = None + self.daq_device = DaqDevice(devices[descriptor_index]) + + # Get the AiDevice object and verify that it is valid. + self.ai_device = None + self.ai_device = self.daq_device.get_ai_device() + if self.ai_device is None: + raise Exception('Error: The DAQ device does not support analog input') + + # Verify that the specified device supports hardware pacing for analog input. + ai_info = self.ai_device.get_info() + if not ai_info.has_pacer(): + raise Exception('\nError: The specified DAQ device does not support hardware paced analog input') + + # Establish a connection to the DAQ device. + descriptor = self.daq_device.get_descriptor() + print('\nConnecting to', descriptor.dev_string, '- please wait...') + self.daq_device.connect() + + # The default input mode is SINGLE_ENDED. + self.input_mode = AiInputMode.SINGLE_ENDED + # If SINGLE_ENDED input mode is not supported, set to DIFFERENTIAL. + if ai_info.get_num_chans_by_mode(AiInputMode.SINGLE_ENDED) <= 0: + self.input_mode = AiInputMode.DIFFERENTIAL + + # Get the number of channels and validate the high channel number. + number_of_channels = ai_info.get_num_chans_by_mode(self.input_mode) + if self.high_channel >= number_of_channels: + self.high_channel = number_of_channels - 1 + self.channel_count = self.high_channel - self.low_channel + 1 + + # Get a list of supported ranges and validate the range index. + self.ranges = ai_info.get_ranges(self.input_mode) + int_ranges = [] + for r in self.ranges: + int_ranges.append(int(r.name.replace('BIP', '').replace('VOLTS', ''))) + + for idx in np.argsort(int_ranges): + if self.config.max_v * self.config.gain / 1000 <= int_ranges[idx]: + self.range_index = idx + break + print(self.ranges[self.range_index]) + + def open_recording_files(self, file, temp_file, led_file, led_file2): + self.temp_f = None + w1_bus_path = glob.glob('/sys/bus/w1/devices/28*/w1_slave') + if len(w1_bus_path) > 0: + self.w1_bus_path = w1_bus_path[0] + self.record_temp = True + self.temp_f = open(temp_file, 'w') + self.temp_f.write('%-6s; %-7s\n' % ('time/s', 'T/C')) + + self.f = open(file, 'wb') + self.led_f = open(led_file, 'w') + self.led_f2 = open(led_file2, 'w') + + def run(self): + self.open_recording_files(self.config.file, self.config.temp_file, self.config.led_file, self.config.led_file2) + + self.DAQ_setup() + + GPIO.output(self.LED1_pin, GPIO.HIGH) + self.LED_status[0] = True + GPIO.output(self.LED2_pin, GPIO.LOW) + self.LED_status[1] = False + sleep(.5) + + GPIO.output(self.LED1_pin, GPIO.LOW) + self.LED_status[0] = False + GPIO.output(self.LED2_pin, GPIO.HIGH) + self.LED_status[1] = True + sleep(.5) + + GPIO.output(self.LED1_pin, GPIO.HIGH) + self.LED_status[0] = True + GPIO.output(self.LED2_pin, GPIO.LOW) + self.LED_status[1] = False + sleep(.5) + + GPIO.output(self.LED1_pin, GPIO.LOW) + self.LED_status[0] = False + GPIO.output(self.LED2_pin, GPIO.HIGH) + self.LED_status[1] = True + sleep(.5) + + GPIO.output(self.LED2_pin, GPIO.LOW) + self.LED_status[1] = False + + self.record() + + def record(self): + while True: + if datetime.datetime.now().hour == self.config.start_clock[0] and datetime.datetime.now().minute == self.config.start_clock[1]: + break + elif datetime.datetime.now().hour * 60 + datetime.datetime.now().minute > \ + self.config.start_clock[0] * 60 + self.config.start_clock[1]: + h = datetime.datetime.now().hour + m = datetime.datetime.now().minute + self.config.start_clock = ('%2.f%2.f' % (h, m)).replace(' ', '0') + + GPIO.output(self.LED2_pin, GPIO.HIGH) + self.LED_status[1] = True + + print('\nRecording started.') + data = create_float_buffer(self.channel_count, self.samples_per_channel) + print('----') + print('Buffer size: %.0fn; %.0fsec' % (len(data), self.buffer_sec)) + print('Channels: %.0f' % self.channel_count) + print('Samples per channel: %.0f' % self.samples_per_channel) + print('----') + + LED_t0 = time() + LED_t_interval = 5 + + sync_LED_t_interval = 1 + + temp_t0 = time() + next_temp_t = 0 + temp_interval = 300 # sec --> 5 min + + disp_eth_power = True + self.samplerate = self.ai_device.a_in_scan(self.low_channel, self.high_channel, self.input_mode, self.ranges[self.range_index], self.samples_per_channel, + self.samplerate, self.scan_options, self.flags, data) + + status, transfer_status = self.ai_device.get_scan_status() + last_idx = 0 + buffer_no = 0 + + while GPIO.input(self.Button1_pin) == GPIO.LOW: + + if GPIO.input(self.Button2_pin) == GPIO.HIGH: + if (time() - self._last_button_2_t) > 5: + if disp_eth_power == True: + subprocess.run(['tvservice', '-o']) + subprocess.run(['vcgencmd', 'display_power', '0']) # + + subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down']) + GPIO.output(self.LED2_pin, GPIO.LOW) + disp_eth_power = False + + elif disp_eth_power == False: + subprocess.run(['tvservice', '-p']) + subprocess.run(['vcgencmd', 'display_power', '1']) + subprocess.run(['sudo', '/bin/chvt', '6']) + subprocess.run(['sudo', '/bin/chvt', '7']) # + + subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) + GPIO.output(self.LED2_pin, GPIO.HIGH) + disp_eth_power = True + last_button_2_t = time() + + if self.record_temp == True: + if time() - temp_t0 > next_temp_t: + w1_f = open(self.w1_bus_path, 'r') + w1_file = w1_f.readlines() + for line in w1_file: + if 't=' in line: + temp = float((line.split('=')[-1].strip())) / 1000 + self.temp_f.write('%6.0f; %7.3f\n' % (next_temp_t, temp)) + self.temp_f.flush() + break + + w1_f.close() + next_temp_t += temp_interval + + # blinking LED (run) + if (time() - LED_t0) % LED_t_interval < .5 and self.LED_status[0] == False: + self.LED_status[0] = True + GPIO.output(self.LED1_pin, GPIO.HIGH) + elif (time() - LED_t0) % LED_t_interval >= .5 and self.LED_status[0] == True: + self.LED_status[0] = False + GPIO.output(self.LED1_pin, GPIO.LOW) + else: + pass + # sync LED + if (time() - LED_t0) % sync_LED_t_interval < .1 and self.LED_status[2] == False: + if self.led_f != None: + Cidx = int((self.buffer_size * buffer_no + last_idx) / self.channels) + self.led_f.write('%.4f\n' % (time() - LED_t0)) + self.led_f.flush() + self.led_f2.write('%.0f\n' % Cidx) + self.led_f2.flush() + + self.LED_status[2] = True + GPIO.output(self.LED_out_pin, GPIO.HIGH) + elif (time() - LED_t0) % sync_LED_t_interval >= .1 and self.LED_status[2] == True: + self.LED_status[2] = False + GPIO.output(self.LED_out_pin, GPIO.LOW) + else: + pass + + ########################################## + # Get the status of the background operation + status, transfer_status = self.ai_device.get_scan_status() + + index = transfer_status.current_index + # print(index) + + if index < 0 or index == last_idx: + continue + + if index > last_idx: + (np.array(data[last_idx:index], dtype=np.float32) / self.config.gain).tofile(self.f) + + else: + (np.array(data[last_idx:], dtype=np.float32) / self.config.gain).tofile(self.f) + if datetime.datetime.now().hour * 60 + datetime.datetime.now().minute >= self.end_clock[0] * 60 + self.end_clock[1]: + self.f.flush() + GPIO.output(self.LED1_pin, GPIO.LOW) + GPIO.output(self.LED_out_pin, GPIO.LOW) + break + + (np.array(data[:index], dtype=np.float32) / self.config.gain).tofile(self.f) + self.f.flush() + + buffer_no += 1 + last_idx = index + print('\nDone!') + + self.f.close() + self.temp_f.close() + self.led_f.close() + + GPIO.output(self.LED1_pin, GPIO.HIGH) + GPIO.output(self.LED2_pin, GPIO.HIGH) + + sleep(2) + + GPIO.output(self.LED1_pin, GPIO.LOW) + GPIO.output(self.LED2_pin, GPIO.LOW) + + if self.daq_device: + # Stop the acquisition if it is still running. + if status == ScanStatus.RUNNING: + self.ai_device.scan_stop() + if self.daq_device.is_connected(): + self.daq_device.disconnect() + self.daq_device.release() + + if disp_eth_power == False: + subprocess.run(['tvservice', '-p']) + subprocess.run(['vcgencmd', 'display_power', '1']) + subprocess.run(['sudo', '/bin/chvt', '6']) + subprocess.run(['sudo', '/bin/chvt', '7']) + + GPIO.cleanup() + + +def main(): + config = Configuration() + + rc = Recorder(config) + + rc.run() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/rasp_grid.py b/rasp_grid.py index f58ec20..5e106a8 100644 --- a/rasp_grid.py +++ b/rasp_grid.py @@ -14,10 +14,10 @@ import threading import multiprocessing as mp from time import sleep, time from IPython import embed - from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus, ScanOption, create_float_buffer, InterfaceType, AiInputMode) + def GPIO_setup(LED1_pin, LED2_pin, LED_out_pin, Button1_pin, Button2_pin, power_controll_pin): # LED output pins GPIO.setmode(GPIO.BOARD) @@ -143,6 +143,7 @@ def clock_process(end_clock, run_led_pin, sync_led_pin, w1_bus_path, temp_f, led else: pass + def save_process(q, f, gain): while True: if q.empty(): @@ -155,6 +156,7 @@ def save_process(q, f, gain): Cdata.tofile(f) f.flush() + def save_controll(q, pin): while True: if q.empty(): @@ -198,7 +200,6 @@ def main(): start_clock = [10, 0] end_clock = [16, 0] - # get init cfg if os.path.exists('/media/pi/data1'): init_path = '/media/pi/data1' @@ -238,7 +239,6 @@ def main(): led_file = os.path.join(path, 'led_times.csv') led_file2 = os.path.join(path, 'led_idxs.csv') - # find w1bus for temp record_temp = False temp_f = None @@ -256,11 +256,12 @@ def main(): # f.close() # DAQ setup + if True: status = ScanStatus.IDLE - descriptor_index = 0 # ToDo: ???? - range_index = 0 # ToDo: ???? + descriptor_index = 0 + range_index = 0 interface_type = InterfaceType.USB low_channel = 0 @@ -328,7 +329,6 @@ def main(): break print(ranges[range_index]) - GPIO.output(LED1_pin, GPIO.HIGH) LED_status[0] = True GPIO.output(LED2_pin, GPIO.LOW) @@ -356,6 +356,11 @@ def main(): GPIO.output(LED2_pin, GPIO.LOW) LED_status[1] = False + + + ########################## ToDo: continue here !!! + + disp_eth_power = True stop_flag = False @@ -396,7 +401,7 @@ def main(): LED_t0 = time() LED_t_interval = 5 - sync_LED_t_interval = 5 + sync_LED_t_interval = 1 temp_t0 = time() next_temp_t = 0 @@ -469,7 +474,7 @@ def main(): else: pass - if (time() - LED_t0) % sync_LED_t_interval < .5 and LED_status[2] == False: + if (time() - LED_t0) % sync_LED_t_interval < .1 and LED_status[2] == False: if led_f != None: Cidx = int((buffer_size * buffer_no + last_idx) / channels) led_f.write('%.4f\n' % (time()-LED_t0)) @@ -480,7 +485,7 @@ def main(): LED_status[2] = True GPIO.output(LED_out_pin, GPIO.HIGH) - elif (time() - LED_t0) % sync_LED_t_interval >= .5 and LED_status[2] == True: + elif (time() - LED_t0) % sync_LED_t_interval >= .1 and LED_status[2] == True: LED_status[2] = False GPIO.output(LED_out_pin, GPIO.LOW) else: diff --git a/rasp_grid_cfg.py b/rasp_grid_cfg.py index 7f5e4d7..37aea67 100644 --- a/rasp_grid_cfg.py +++ b/rasp_grid_cfg.py @@ -197,12 +197,13 @@ class Recording_settings(QWidget): self.experiment_name_val = 'recording fish behavior' self.startdate_val = '~' self.starttime_val = '~' - self.location_val = 'Colombia - Los Llanos' + self.endtime_val = '~' + self.location_val = '~' self.position_val = '~N, ~W' - self.water_temp_val = 20 - self.water_cond_val = 5 - self.water_ph_val = 7 - self.water_oxy_val = 0 + self.water_temp_val = '~' + self.water_cond_val = '~' + self.water_ph_val = '~' + self.water_oxy_val = '~' self.comment_val = '~' self.experimenter_val = 'T. Raab et al. :)' self.datatime_val = 100 @@ -231,60 +232,69 @@ class Recording_settings(QWidget): self.gridlayout.addWidget(self.start_date, 1, 1) start_timeL = QLabel('Start Time:', self) + start_timeU = QLabel('HH:MM', self) self.start_time = QLineEdit(self.starttime_val, self) self.gridlayout.addWidget(start_timeL, 2, 0) self.gridlayout.addWidget(self.start_time, 2, 1) + self.gridlayout.addWidget(start_timeU, 2, 2) + + end_timeL = QLabel('End Time:', self) + end_timeU = QLabel('HH:MM', self) + self.end_time = QLineEdit(self.endtime_val, self) + self.gridlayout.addWidget(end_timeL, 3, 0) + self.gridlayout.addWidget(self.end_time, 3, 1) + self.gridlayout.addWidget(end_timeU, 3, 2) locationL = QLabel('Location:', self) self.location = QLineEdit(self.location_val, self) - self.gridlayout.addWidget(locationL, 3, 0) - self.gridlayout.addWidget(self.location, 3, 1) + self.gridlayout.addWidget(locationL, 4, 0) + self.gridlayout.addWidget(self.location, 4, 1) positionL = QLabel('Position:', self) self.position = QLineEdit(self.position_val, self) - self.gridlayout.addWidget(positionL, 4, 0) - self.gridlayout.addWidget(self.position, 4, 1) + self.gridlayout.addWidget(positionL, 5, 0) + self.gridlayout.addWidget(self.position, 5, 1) waterTempU = QLabel('C', self) waterTempL = QLabel('Water Temp:', self) - self.waterTemp = QLineEdit('%.1f' % self.water_temp_val, self) - self.gridlayout.addWidget(waterTempL, 5, 0) - self.gridlayout.addWidget(self.waterTemp, 5, 1) - self.gridlayout.addWidget(waterTempU, 5, 2) + self.waterTemp = QLineEdit('%s' % self.water_temp_val, self) + self.gridlayout.addWidget(waterTempL, 6, 0) + self.gridlayout.addWidget(self.waterTemp, 6, 1) + self.gridlayout.addWidget(waterTempU, 6, 2) waterCondU = QLabel('uS/cm', self) waterCondL = QLabel('Water cond.:', self) - self.waterCond = QLineEdit('%.1f' % self.water_cond_val, self) - self.gridlayout.addWidget(waterCondL, 6, 0) - self.gridlayout.addWidget(self.waterCond, 6, 1) - self.gridlayout.addWidget(waterCondU, 6, 2) + self.waterCond = QLineEdit('%s' % self.water_cond_val, self) + self.gridlayout.addWidget(waterCondL, 7, 0) + self.gridlayout.addWidget(self.waterCond, 7, 1) + self.gridlayout.addWidget(waterCondU, 7, 2) waterpHU = QLabel('pH') waterpHL = QLabel('Water-pH:') - self.waterpH = QLineEdit('%.1f' % self.water_ph_val, self) - self.gridlayout.addWidget(waterpHL, 7, 0) - self.gridlayout.addWidget(self.waterpH, 7, 1) - self.gridlayout.addWidget(waterpHU, 7, 2) + self.waterpH = QLineEdit('%s' % self.water_ph_val, self) + self.gridlayout.addWidget(waterpHL, 8, 0) + self.gridlayout.addWidget(self.waterpH, 8, 1) + self.gridlayout.addWidget(waterpHU, 8, 2) waterOxyU = QLabel('mg/l', self) waterOxyL = QLabel('Water Oxygen:', self) - self.waterOxy = QLineEdit('%.1f' % self.water_oxy_val, self) - self.gridlayout.addWidget(waterOxyL, 8, 0) - self.gridlayout.addWidget(self.waterOxy, 8, 1) - self.gridlayout.addWidget(waterOxyU, 8, 2) + self.waterOxy = QLineEdit('%s' % self.water_oxy_val, self) + self.gridlayout.addWidget(waterOxyL, 9, 0) + self.gridlayout.addWidget(self.waterOxy, 9, 1) + self.gridlayout.addWidget(waterOxyU, 9, 2) commentL = QLabel('Comment:', self) self.comment = QLineEdit(self.comment_val, self) - self.gridlayout.addWidget(commentL, 9, 0) - self.gridlayout.addWidget(self.comment, 9, 1) + self.gridlayout.addWidget(commentL, 10, 0) + self.gridlayout.addWidget(self.comment, 10, 1) experimenterL = QLabel('Experimenter:', self) self.experimenter = QLineEdit(self.experimenter_val, self) - self.gridlayout.addWidget(experimenterL, 10, 0) - self.gridlayout.addWidget(self.experimenter, 10, 1) + self.gridlayout.addWidget(experimenterL, 11, 0) + self.gridlayout.addWidget(self.experimenter, 11, 1) space = QLabel('', self) - self.gridlayout.addWidget(space, 11, 0) + self.gridlayout.addWidget(space, 12, 0) class MainWindow(QTabWidget): @@ -294,7 +304,6 @@ class MainWindow(QTabWidget): def initMe(self): - self.setGeometry(300, 150, 500, 600) self.setWindowTitle('Fishgrid.cfg') @@ -361,6 +370,7 @@ class MainWindow(QTabWidget): self.Recording.experiment_name_val = 'recording fish behavior' self.Recording.startdate_val = '~' self.Recording.starttime_val = '~' + self.Recording.endtime_val = '~' self.Recording.location_val = 'Colombia - Los Llanos' self.Recording.position_val = '~N, ~W' self.Recording.water_temp_val = 20 @@ -431,6 +441,8 @@ class MainWindow(QTabWidget): self.Recording.startdate_val = line.split(':')[-1].strip() elif "StartTime" in line: self.Recording.starttime_val = ':'.join(line.split(':')[1:]).strip() + elif "EndTime" in line: + self.Recording.endtime_val = ':'.join(line.split(':')[1:]).strip() elif "Location" in line: self.Recording.location_val = line.split(':')[-1].strip() elif "Position" in line: @@ -440,9 +452,9 @@ class MainWindow(QTabWidget): elif "WaterConductivity" in line: self.Recording.water_cond_val = float(line.split(':')[-1].strip().replace('uS/cm', '')) elif 'WaterpH' in line: - self.Recording.water_ph_val = float(line.split(':')[-1].strip().replace('pH', '')) + self.Recording.water_ph_val = line.split(':')[-1].strip().replace('pH', '') elif "WaterOxygen" in line: - self.Recording.water_oxy_val = float(line.split(':')[-1].strip().replace('mg/l', '')) + self.Recording.water_oxy_val = line.split(':')[-1].strip().replace('mg/l', '') elif "Comment" in line: self.Recording.comment_val = ':'.join(line.split(':')[1:]).strip() elif "Experimenter" in line: @@ -494,12 +506,13 @@ class MainWindow(QTabWidget): f.write(' Experiment.Name : %s\n' % self.Recording.exp_name.text()) f.write(' StartDate : %s\n' % self.Recording.start_date.text()) f.write(' StartTime : %s\n' % self.Recording.start_time.text()) + f.write(' EndTime : %s\n' % self.Recording.end_time.text()) f.write(' Location : %s\n' % self.Recording.location.text()) f.write(' Position : %s\n' % self.Recording.position.text()) - f.write(' WaterTemperature : %.1fC\n' % float(self.Recording.waterTemp.text())) - f.write(' WaterConductivity: %.1fuS/cm\n' % float(self.Recording.waterCond.text())) - f.write(' WaterpH : %.1fpH\n' % float(self.Recording.waterpH.text())) - f.write(' WaterOxygen : %.1fmg/l\n' % float(self.Recording.waterOxy.text())) + f.write(' WaterTemperature : %sC\n' % self.Recording.waterTemp.text()) + f.write(' WaterConductivity: %suS/cm\n' % self.Recording.waterCond.text()) + f.write(' WaterpH : %spH\n' % self.Recording.waterpH.text()) + f.write(' WaterOxygen : %smg/l\n' % self.Recording.waterOxy.text()) f.write(' Comment : %s\n' % self.Recording.comment.text()) f.write(' Experimenter : %s\n' % self.Recording.experimenter.text()) # f.write(' Buffers and timing:\n')