Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions optimizer/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def FourthStep(self,args={}):
for line in in_handler:
self.model_handler.spike_times.append(int(float(line) / (1000.0 / self.option_handler.input_freq)))
in_handler.close();
except OSError:
except (OSError, IOError):
pass


Expand Down Expand Up @@ -583,16 +583,3 @@ def callGrid(self,resolution):
self.grid_result=self.optimizer.final_pop
self.optimizer.final_pop=self.prev_result














9 changes: 5 additions & 4 deletions optimizer/fitnessFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ def modelRunner(self, candidates, act_trace_idx):
try:
in_handler = open(self.option.base_dir + "/spike.dat", "r")
self.model.spike_times = []
except OSError:

for line in in_handler:
self.model.spike_times.append(int(float(line) / (1000.0 / self.option.input_freq)))
#print self.model.spike_times[1:10]
except (OSError, IOError): # IOError for latest python versions
pass
for line in in_handler:
self.model.spike_times.append(int(float(line) / (1000.0 / self.option.input_freq)))
#print self.model.spike_times[1:10]

else:
section = self.option.GetObjTOOpt()
Expand Down
21 changes: 8 additions & 13 deletions optimizer/graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def __init__(self, parent, ID, size, title, core, path):
import optimizer
path = os.path.dirname(optimizer.__file__)

self.path = path
self.path = os.path.abspath(path)
self.layer = None
self.panel = wx.Panel(self)
self.Center()
Expand Down Expand Up @@ -721,23 +721,18 @@ def __init__(self, parent, ID, size, title, core, path):
self.parent = parent
self.core = core
self.layer = None

#this will need to be wrapped in a try statement later:
import optimizer
print optimizer.__file__
path = os.path.dirname(optimizer.__file__)
#path = os.path.dirname(optimizer.__file__)

self.path = path
#print "path",self.path
self.Center()
self.ToolbarCreator()
self.Design()
#self.is_loaded=False






def ToolbarCreator(self):

Expand All @@ -748,6 +743,7 @@ def ToolbarCreator(self):
self.Bind(wx.EVT_TOOL, self.Next, button_toolbar_fward)
self.Bind(wx.EVT_TOOL, self.Prev, button_toolbar_bward)
self.toolbar.EnableTool(button_toolbar_fward.GetId(), False)

def Design(self):

self.horizontal_box1 = wx.BoxSizer(wx.HORIZONTAL)
Expand Down Expand Up @@ -1104,7 +1100,7 @@ def __init__(self, parent, ID, size, title, core, path):
#this will need to be wrapped in a try statement later:
import optimizer
print optimizer.__file__
path = os.path.dirname(optimizer.__file__)
#path = os.path.dirname(optimizer.__file__)

self.path = path
#print "path",self.path
Expand Down Expand Up @@ -1381,15 +1377,14 @@ def __init__(self, parent, ID, size, title, core, path, kwargs):
#this will need to be wrapped in a try statement later:
import optimizer
print optimizer.__file__
path = os.path.dirname(optimizer.__file__)
#path = os.path.dirname(optimizer.__file__)

self.path = path
self.Center()
self.ToolbarCreator()
self.Design()
self.seed = None
self.kwargs = kwargs

#print "ffun",kwargs
self.layer = None

Expand Down Expand Up @@ -1815,7 +1810,7 @@ def __init__(self, parent, ID, size, title, core, path,kwargs):
#this will need to be wrapped in a try statement later:
import optimizer
print optimizer.__file__
path = os.path.dirname(optimizer.__file__)
#path = os.path.dirname(optimizer.__file__)

self.path = path
self.panel = wx.Panel(self)
Expand Down Expand Up @@ -1945,7 +1940,7 @@ def __init__(self, parent, ID, size, title, core, path):
#this will need to be wrapped in a try statement later:
import optimizer
print optimizer.__file__
path = os.path.dirname(optimizer.__file__)
#path = os.path.dirname(optimizer.__file__)

self.path = path
self.Center()
Expand Down
21 changes: 10 additions & 11 deletions optimizer/traceHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_type(self):



def detect_format(self,line):
def detect_format(self,line,contains_time):
"""
Automatically detects the format of the file and returns a reader functions which can process it correctly.
The recognized formats are the following:
Expand All @@ -206,11 +206,16 @@ def detect_format(self,line):
spike_times_rule=re.compile("# variable = spikes")
rules=[pynn_rule,neuron_rule_time,neuron_rule,spike_times_rule]
result=[n!=None for n in [re.match(k,line) for k in rules ] ]
#print line
#print result
#print result.index(True)
return [self.PyNNReader,self.traceReaderTime,self.traceReader,self.spikeTimeReader][result.index(True)]
# FIXED: if no time specified, the second true option
# (traceReader) should be chosen
index = result.index(True)
if not contains_time and index == 1:
index += 1
return [self.PyNNReader,self.traceReaderTime,self.traceReader,self.spikeTimeReader][index]

def Read(self,path=[os.getcwd()+"/inputTrace.txt"],no_traces=1,scale="mV",t_length=1000,freq=1000,trace_type="voltage"):
def Read(self,path=[os.getcwd()+"/inputTrace.txt"],no_traces=1,scale="mV",t_length=1000,freq=1000,trace_type="voltage", contains_time=False):
"""
The main reader function. This calls the recognition function ``detect_format``
and uses the obtained reader function to read the data.
Expand All @@ -232,7 +237,7 @@ def Read(self,path=[os.getcwd()+"/inputTrace.txt"],no_traces=1,scale="mV",t_leng
tmp.append(f.readline())
i+=1
if trace_type!="spike":
self.data=self.detect_format(tmp[4])(path,no_traces,scale,t_length,freq,trace_type)
self.data=self.detect_format(tmp[4],contains_time)(path,no_traces,scale,t_length,freq,trace_type)
else:
self.additional_data=self.spikeTimeReader(path, no_traces, scale, t_length, freq, trace_type)

Expand Down Expand Up @@ -436,9 +441,3 @@ def Write(self):
f.write(self.separator.join(string.strip(k,"[]") for k in temp))
f.write("\n")