config file of base directory in loaded, correct folder is initialized
This commit is contained in:
parent
165d359fee
commit
4a72293981
146
rasp_grid.py
146
rasp_grid.py
@ -1,6 +1,12 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
import RPi.GPIO as GPIO
|
import os
|
||||||
|
import datetime
|
||||||
|
from shutil import copyfile
|
||||||
|
try:
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
except:
|
||||||
|
pass
|
||||||
import subprocess
|
import subprocess
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -30,7 +36,145 @@ def GPIO_setup():
|
|||||||
return LED_status
|
return LED_status
|
||||||
|
|
||||||
|
|
||||||
|
def read_cfg(cfg_file, now, init_read=False):
|
||||||
|
cfg_f = open(cfg_file, 'r+')
|
||||||
|
cfg = cfg_f.readlines()
|
||||||
|
|
||||||
|
### read cfg information ###
|
||||||
|
if init_read:
|
||||||
|
for line in cfg:
|
||||||
|
if "PathFormat" in line:
|
||||||
|
path_format = ':'.join(line.split(':')[1:]).strip().replace('"', '').replace("'", "")
|
||||||
|
cfg_f.close()
|
||||||
|
return path_format
|
||||||
|
|
||||||
|
for line in cfg:
|
||||||
|
if 'Columns1' in line:
|
||||||
|
n_cols = int(line.split(':')[1].strip())
|
||||||
|
elif 'Rows1' in line:
|
||||||
|
n_rows = int(line.split(':')[1].strip())
|
||||||
|
elif "AISampleRate" in line:
|
||||||
|
samplerate = int(float(line.split(':')[-1].strip().replace('kHz', '')) * 1000)
|
||||||
|
|
||||||
|
### alter information and re-write ###
|
||||||
|
for enu, line in enumerate(cfg):
|
||||||
|
if "StartDate" in line:
|
||||||
|
cfg[enu] = (' StartDate : %s\n' % now.strftime('%Y-%m-%d'))
|
||||||
|
elif "StartTime" in line:
|
||||||
|
cfg[enu] = (' StartTime : %s\n' % (now.strftime('%H:%M:%S') + now.strftime(".%f")[:4]))
|
||||||
|
cfg_f.close()
|
||||||
|
|
||||||
|
cfg_f = open(cfg_file, 'w+')
|
||||||
|
for line in cfg:
|
||||||
|
cfg_f.write(line)
|
||||||
|
cfg_f.close()
|
||||||
|
|
||||||
|
return n_cols * n_rows, samplerate
|
||||||
|
|
||||||
|
# for line in cfg:
|
||||||
|
# if 'Columns1' in line:
|
||||||
|
# self.Grid.columns_val = int(line.split(':')[1].strip())
|
||||||
|
# elif 'Rows1' in line:
|
||||||
|
# self.Grid.rows_val = int(line.split(':')[1].strip())
|
||||||
|
# elif "ColumnDistance1" in line:
|
||||||
|
# self.Grid.col_dist_val = float(line.split(':')[-1].strip().replace('cm', ''))
|
||||||
|
# elif "RowDistance1" in line:
|
||||||
|
# self.Grid.row_dist_val = float(line.split(':')[-1].strip().replace('cm', ''))
|
||||||
|
# elif "ChannelOffset1" in line:
|
||||||
|
# self.Grid.channel_offset_val = int(line.split(':')[-1].strip())
|
||||||
|
# elif "ElectrodeType1" in line:
|
||||||
|
# self.Grid.elec_type_val = line.split(':')[-1].strip()
|
||||||
|
# elif "RefElectrodeType1" in line:
|
||||||
|
# self.Grid.ref_elec_type_val = line.split(":")[-1].strip()
|
||||||
|
# elif "RefElectrodePosX1" in line:
|
||||||
|
# self.Grid.ref_elec_posx_val = float(line.split(':')[-1].strip().replace('m', ''))
|
||||||
|
# elif 'RefElectrodePosY1' in line:
|
||||||
|
# self.Grid.ref_elec_posy_val = float(line.split(':')[-1].strip().replace('m', ''))
|
||||||
|
# elif 'WaterDepth1' in line:
|
||||||
|
# self.Grid.water_depth_val = float(line.split(':')[-1].strip().replace('m', ''))
|
||||||
|
#
|
||||||
|
# elif "AISampleRate" in line:
|
||||||
|
# self.HardWare.ai_sr_val = float(line.split(':')[-1].strip().replace('kHz', ''))
|
||||||
|
# elif "AIMaxVolt" in line:
|
||||||
|
# self.HardWare.ai_max_vol_val = float(line.split(':')[-1].strip().replace('mV', ''))
|
||||||
|
# elif "AmplName" in line:
|
||||||
|
# self.HardWare.amp_name_val = line.split(':')[-1].strip()
|
||||||
|
# elif "AmplModel" in line:
|
||||||
|
# self.HardWare.amp_model_val = line.split(':')[-1].strip()
|
||||||
|
# elif ' Type ' in line:
|
||||||
|
# self.HardWare.amp_type_val = line.split(':')[-1].strip()
|
||||||
|
# elif 'Gain' in line:
|
||||||
|
# self.HardWare.gain_val = line.split(':')[-1].strip()
|
||||||
|
# elif "HighpassCutoff" in line:
|
||||||
|
# self.HardWare.highpass_cutoff_val = int(line.split(':')[-1].strip().replace('Hz', ''))
|
||||||
|
# elif 'LowpassCutoff' in line:
|
||||||
|
# self.HardWare.lowpass_cutoff_val = float(line.split(':')[-1].strip().replace('kHz', ''))
|
||||||
|
#
|
||||||
|
# elif "Experiment.Name" in line:
|
||||||
|
# self.Recording.experiment_name_val = line.split(':')[-1].strip()
|
||||||
|
# elif "StartDate" in line:
|
||||||
|
# self.Recording.startdate_val = line.split(':')[-1].strip()
|
||||||
|
# elif "StartTime" in line:
|
||||||
|
# self.Recording.starttime_val = ':'.join(line.split(':')[1:]).strip()
|
||||||
|
# elif "Location" in line:
|
||||||
|
# self.Recording.location_val = line.split(':')[-1].strip()
|
||||||
|
# elif "Position" in line:
|
||||||
|
# self.Recording.position_val = line.split(':')[-1].strip()
|
||||||
|
# elif "WaterTemperature" in line:
|
||||||
|
# self.Recording.water_temp_val = float(line.split(':')[-1].strip().replace('C', ''))
|
||||||
|
# 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', ''))
|
||||||
|
# elif "WaterOxygen" in line:
|
||||||
|
# self.Recording.water_oxy_val = float(line.split(':')[-1].strip().replace('mg/l', ''))
|
||||||
|
# elif "Comment" in line:
|
||||||
|
# self.Recording.comment_val = ':'.join(line.split(':')[1:]).strip()
|
||||||
|
# elif "Experimenter" in line:
|
||||||
|
# self.Recording.experimenter_val = ':'.join(line.split(':')[1:]).strip()
|
||||||
|
# elif "DataTime" in line:
|
||||||
|
# self.Recording.datatime_val = int(line.split(':')[-1].strip().replace('ms', ''))
|
||||||
|
# elif "DataInterval" in line:
|
||||||
|
# self.Recording.datainterval_val = int(line.split(':')[-1].strip().replace('ms', ''))
|
||||||
|
# elif "BufferTime" in line:
|
||||||
|
# self.Recording.buffertime_val = int(line.split(':')[-1].strip().replace('s', ''))
|
||||||
|
# else:
|
||||||
|
# continue
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
|
# get init cfg
|
||||||
|
if os.path.exists('/media/pi/data1'):
|
||||||
|
init_path = '/media/pi/data1'
|
||||||
|
else:
|
||||||
|
init_path = '/home/raab/data/rasp_test'
|
||||||
|
|
||||||
|
init_cfgfile = os.path.join(init_path, 'fishgrid.cfg')
|
||||||
|
if os.path.exists(init_cfgfile):
|
||||||
|
path_format = read_cfg(init_cfgfile, now, init_read = True)
|
||||||
|
else:
|
||||||
|
print('cfg file missing !!!')
|
||||||
|
quit()
|
||||||
|
|
||||||
|
# create save folder and copy cfg file
|
||||||
|
path = os.path.join(init_path, now.strftime(path_format))
|
||||||
|
os.makedirs(path)
|
||||||
|
copyfile(os.path.join(os.path.split(path)[0], 'fishgrid.cfg'), os.path.join(path, 'fishgrid.cfg'))
|
||||||
|
cfgfile = os.path.join(path, 'fishgrid.cfg')
|
||||||
|
|
||||||
|
# read and edit config file
|
||||||
|
channels, rate = read_cfg(cfgfile, now)
|
||||||
|
|
||||||
|
file = os.path.join(path, 'traces-grid1.raw')
|
||||||
|
f = open(file, 'wb')
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
embed()
|
||||||
|
quit()
|
||||||
|
|
||||||
LED_status = GPIO_setup()
|
LED_status = GPIO_setup()
|
||||||
|
|
||||||
# DAQ setup
|
# DAQ setup
|
||||||
|
Loading…
Reference in New Issue
Block a user