1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
20 def _generate_vectors(self):
22 Here we parse the data and generate the raw vectors. This
23 method has only to do with the peculiar file format here, so
24 it's of no big interest (I just wrote it to present a
27 Only thing to remember, it can be nice to call methods that
28 are used only "internally" by the driver (or by plugins) with
29 a "_" prefix, so to have a visual remark. But it's just an
32 vectors={'PLOT1':[[],[],[],[]] , 'PLOT2':[[],[],[],[]]}
33 positions={'X1':0,'Y1':1,'X2':2,'Y2':3}
36 for item in self.data:
39 vectors[whatplot][pos].append(num)
41 if item[:-1]=='PLOT1':
43 elif item[:-1]=='PLOT2':
45 elif item[0]=='X' or item[0]=='Y':
46 pos=positions[item[:-1]]
52 def default_plots(self):
54 THIS METHOD MUST BE DEFINED.
55 RETURNS: [ lhc.PlotObject ] or [ lhc.PlotObject, lhc.PlotObject]
57 This is the method that returns the plots to Hooke.
58 It must return a list with *one* or *two* PlotObjects.
60 See the curve.py source code to see how PlotObjects are defined and work in detail.
62 gen_vectors=self._generate_vectors()
64 #Here we create the main plot PlotObject and initialize its vectors.
65 main_plot=lhc.PlotObject()
67 #The same for the other plot.
68 other_plot=lhc.PlotObject()
72 Now we fill the plot vectors with our data.
74 The "correct" shape of the vector is [ [[x1,x2,x3...],[y1,y2,y3...]] , [[x1,x2,x3...],[y1,y2,y3...]] ], so we have to put stuff in this way into it.
76 The add_set() method takes care of this , just use plot.add_set(x,y).
78 main_plot.add_set(gen_vectors['PLOT1'][0],gen_vectors['PLOT1'][1])
79 main_plot.add_set(gen_vectors['PLOT1'][2],gen_vectors['PLOT1'][3])
81 other_plot.add_set(gen_vectors['PLOT2'][0],gen_vectors['PLOT2'][1])
82 other_plot.add_set(gen_vectors['PLOT2'][2],gen_vectors['PLOT2'][3])
85 normalize_vectors() trims the vectors, so that if two x/y couples are of different lengths, the latest
86 points are trimmed (otherwise we have a python error). Always a good idea to run it, to avoid crashes.
88 main_plot.normalize_vectors()
89 other_plot.normalize_vectors()
93 - units: [string, string], define the measure units of X and Y axes
94 - destination: 0/1 , defines where to plot the plot (0=top, 1=bottom), default=0
95 - title: string , the plot title.
98 Again, see curve.py comments for details.
100 main_plot.units=['unit of x','unit of y']
101 main_plot.destination=0
102 main_plot.title=self.filename+' main'
104 other_plot.units=['unit of x','unit of y']
105 other_plot.destination=1
106 other_plot.title=self.filename+' other'
108 return [main_plot, other_plot]