+import os.path
+
class HookeCurve(object):
- def __init__(self,path):
- self.path=path
- self.curve=Driver()
- self.notes=''
+ def __init__(self, path):
+ #the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
+ self.data = {}
+ self.driver = Driver()
+ self.path = path
+ self.fits = {}
+ self.name = os.path.basename(path)
+ self.notes = ''
+ self.plots = None
+
+ def add_data(self, name, x, y, color=None, result=None, style=None, visible=True):
+ data = {'x': x, 'y': y, 'color': color, 'result': result, 'style': style, 'visible': visible}
+ if self.data.has_key(name):
+ #get the existing list of xydata
+ list_data = self.data[name]
+ else:
+ #we need a new list of xydata
+ list_data = []
+ #append the xydata to the list
+ list_data.append(data)
+ #append or change the corresponding dictionary entry
+ self.data[name] = list_data
+
+ #def add_result(self, name, index, result):
+ #if self.data.has_key(name):
+ ##get the existing list of xydata
+ #list_data = self.data[name][index]
+ #list_data['result'] = result
+
+ def delete_data(self, name):
+ if self.data.has_key(name):
+ del self.data[name]
def identify(self, drivers):
'''
identifies a curve and returns the corresponding object
'''
for driver in drivers:
- tempcurve=driver(self.path)
- if tempcurve.is_me():
- #bring on all the driver, with his load of methods etc.
+ current_driver = driver(self.filename)
+ if current_driver.is_me():
+ #bring on all the driver, with its load of methods etc.
#so we can access the whole of it.
- self.curve=tempcurve
- del tempcurve
+ self.driver = current_driver
return True
-
- print 'Not a recognizable curve format.'
+ print 'Not a recognizable curve format: ', self.path
return False
+ def set_data(self, name, x, y, color=None, result=None, style=None, visible=True):
+ data = {'x': x, 'y': y, 'color': color, 'result': result, 'style': style, 'visible': visible}
+ #append the xydata to the list
+ list_data = [data]
+ #append or change the corresponding dictionary entry
+ self.data[name] = list_data
-class Driver:
+
+class Driver(object):
'''
Base class for file format drivers.
To be overridden
'''
def __init__(self):
- self.experiment=''
- self.filetype=''
+ self.experiment = ''
+ self.filetype = ''
def is_me(self):
'''
return None
def default_plots(self):
- dummy_default=PlotObject()
+ dummy_default = PlotObject()
dummy_default.vectors.append([[[0]],[[0]]])
return [dummy_default]
-class PlotObject:
+class PlotObject(object):
def __init__(self):
units are strings
'''
- self.units=['','']
+ self.units=['', '']
'''
- xaxes and yaxes directions. 0,0 means the common +X=right, +Y=top directions
+ xaxes and yaxes directions. 0, 0 means the common +X=right, +Y=top directions
'''
- self.xaxes=0
- self.yaxes=0
+ self.xaxes = 0
+ self.yaxes = 0
- self.title='' #title
+ self.filename = ''
+ self.title = '' #title
'''
styles: defines what is the style of the current plots. If undefined or None, it is line plot.
If an element of the list is 'scatter', the corresponding dataset
is drawn with scattered points and not a continuous line.
'''
- self.styles=[]
+ self.styles = []
'''
colors: define what is the colour of the current plots
'''
- self.colors=[]
+ self.colors = []
- def add_set(self,x,y):
+ def add_set(self, x, y):
'''
- Adds an x,y data set to the vectors.
+ Adds an x, y data set to the vectors.
'''
self.vectors.append([])
self.vectors[-1].append(x)
self.vectors[-1].append(y)
- return
- def remove_set(self,whichset):
+ def remove_set(self, whichset):
'''
Removes a set
'''
- waste=self.vectors.pop(whichset)
- return
+ #TODO: do we need 'waste' here?
+ waste = self.vectors.pop(whichset)
def normalize_vectors(self):
'''
Trims the vector lengths as to be equal in a plot.
'''
-
for index in range(0,len(self.vectors)):
vectors_to_plot=self.vectors[index]
lengths=[len(vector) for vector in vectors_to_plot]