1 | # Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ). |
---|
2 | # This software may be distributed under the terms of the |
---|
3 | # Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt |
---|
4 | |
---|
5 | """ |
---|
6 | PlotClasses.py |
---|
7 | ============== |
---|
8 | |
---|
9 | Holds classes used for each plot type. |
---|
10 | |
---|
11 | """ |
---|
12 | |
---|
13 | # Import standard libary modules |
---|
14 | |
---|
15 | |
---|
16 | # Import local modules |
---|
17 | from serverConfig import * |
---|
18 | |
---|
19 | class YvsXGraph: |
---|
20 | """ |
---|
21 | Used for plotting 1D variables as graphs. |
---|
22 | """ |
---|
23 | |
---|
24 | def __init__(self, canvas, data): |
---|
25 | """ |
---|
26 | Takes canvas and data and calls other relevant methods. |
---|
27 | """ |
---|
28 | self.canvas=canvas |
---|
29 | try: |
---|
30 | self.plot_type=canvas.createyxvsx("new_yxvsx","default") |
---|
31 | except: |
---|
32 | self.plot_type=canvas.getyxvsx("new_yxvsx") |
---|
33 | self._extractData(data) |
---|
34 | self._getTemplate() |
---|
35 | |
---|
36 | def _extractData(self, data): |
---|
37 | """ |
---|
38 | Used to extract the appropriate data object. |
---|
39 | """ |
---|
40 | self.data=data(squeeze=1) |
---|
41 | |
---|
42 | def _getTemplate(self): |
---|
43 | """ |
---|
44 | Sets up the appropriate template for a plot type. |
---|
45 | """ |
---|
46 | try: |
---|
47 | self.template=self.canvas.gettemplate(VCS_TEMPLATES["no_levels"]) |
---|
48 | except: |
---|
49 | self.template=self.canvas.gettemplate("AMIP") |
---|
50 | |
---|
51 | def createPlot(self): |
---|
52 | """ |
---|
53 | Plots the output and saves to a file. |
---|
54 | """ |
---|
55 | # The next line is a bug fix to stop part of the plot being chopped when background plot is set to 1 (on). |
---|
56 | # self.canvas.open() |
---|
57 | if hasattr(self.data, "title"): |
---|
58 | fileComment="Dataset: "+self.data.title |
---|
59 | else: |
---|
60 | fileComment="" |
---|
61 | self.canvas.plot(self.data, self.template, self.plot_type, bg=1, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | class SimplePlot: |
---|
66 | """ |
---|
67 | SimplePlot class - used for non-XY plots. |
---|
68 | """ |
---|
69 | |
---|
70 | def __init__(self, canvas, data): |
---|
71 | """ |
---|
72 | Takes canvas and data and calls other relevant methods. |
---|
73 | """ |
---|
74 | self.canvas=canvas |
---|
75 | self._extractData(data) |
---|
76 | self._getTemplate() |
---|
77 | |
---|
78 | def _extractData(self, data): |
---|
79 | """ |
---|
80 | Used to extract the appropriate data object. |
---|
81 | """ |
---|
82 | self.data=data(squeeze=1) |
---|
83 | |
---|
84 | def _getTemplate(self): |
---|
85 | """ |
---|
86 | Sets up the appropriate template for a plot type. |
---|
87 | """ |
---|
88 | try: |
---|
89 | self.template=self.canvas.gettemplate(VCS_TEMPLATES["no_levels"]) |
---|
90 | except: |
---|
91 | self.template=self.canvas.gettemplate("AMIP") |
---|
92 | |
---|
93 | def createPlot(self, animationArgs=None, continentsSwitch=0): |
---|
94 | """ |
---|
95 | Plots the output and saves to a file. |
---|
96 | """ |
---|
97 | # The next line is a bug fix to stop part of the plot being chopped when background plot is set to 1 (on). |
---|
98 | # self.canvas.open() |
---|
99 | if hasattr(self.data, "title"): |
---|
100 | fileComment="Dataset: "+self.data.title |
---|
101 | else: |
---|
102 | fileComment="" |
---|
103 | if animationArgs==None: |
---|
104 | self.canvas.plot(self.data, self.template, bg=1, continents=continentsSwitch, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
105 | else: # animationArgs is the slice indices of the data to plot converted to a string |
---|
106 | dataSlice=eval("self.data%s" % animationArgs) |
---|
107 | dataSlice=dataSlice(squeeze=1) |
---|
108 | #print dataSlice.shape, dataSlice.getAxisIds() |
---|
109 | #print dataSlice |
---|
110 | self.canvas.plot(dataSlice, self.template, self.plot_type, continents=continentsSwitch, bg=1, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
111 | |
---|
112 | |
---|
113 | # elif animationArgs[0]=="time": |
---|
114 | # self.canvas.plot(self.data(time=slice(animationArgs[1][0],animationArgs[1][1])), self.template, bg=1, continents=continentsSwitch, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
115 | # elif animationArgs[0]=="level": |
---|
116 | # self.canvas.plot(self.data(level=slice(animationArgs[1][0],animationArgs[1][1])), self.template, bg=1, continents=continentsSwitch, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
117 | |
---|
118 | |
---|
119 | class Boxfill(SimplePlot): |
---|
120 | """ |
---|
121 | Boxfill class - base class for all Boxfill types. |
---|
122 | """ |
---|
123 | |
---|
124 | def __init__(self, canvas, data): |
---|
125 | self.canvas=canvas |
---|
126 | try: |
---|
127 | self.plot_type=canvas.createboxfill("new_boxfill","default") |
---|
128 | except: |
---|
129 | self.plot_type=canvas.getboxfill("new_boxfill") |
---|
130 | self._extractData(data) |
---|
131 | self._getProjection() |
---|
132 | self._getTemplate() |
---|
133 | |
---|
134 | def _extractData(self, data): |
---|
135 | """ |
---|
136 | _extractData method - used to extract the appropriate data object. |
---|
137 | """ |
---|
138 | self.data=data |
---|
139 | |
---|
140 | def _getTemplate(self): |
---|
141 | """ |
---|
142 | _getTemplate method - sets up the appropriate template for a plot type. |
---|
143 | """ |
---|
144 | try: |
---|
145 | if not self.data.getLevel(): |
---|
146 | self.template=self.canvas.gettemplate(VCS_TEMPLATES["no_levels"]) |
---|
147 | else: |
---|
148 | self.template=self.canvas.gettemplate(VCS_TEMPLATES["with_levels"]) |
---|
149 | except: |
---|
150 | self.template=self.canvas.gettemplate("AMIP") |
---|
151 | |
---|
152 | def createPlot(self, animationArgs=None, continentsSwitch=1): |
---|
153 | """ |
---|
154 | createPlot method - plots the output. |
---|
155 | """ |
---|
156 | # The next line is a bug fix to stop part of the plot being chopped when background plot is set to 1 (on). |
---|
157 | # self.canvas.open() |
---|
158 | if hasattr(self.data, "title"): |
---|
159 | fileComment="Dataset: "+self.data.title |
---|
160 | else: |
---|
161 | fileComment="" |
---|
162 | if animationArgs==None: |
---|
163 | self.canvas.plot(self.data, self.template, self.plot_type, bg=1, continents=continentsSwitch, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
164 | else: # animationArgs is the slice indices of the data to plot converted to a string |
---|
165 | dataSlice=eval("self.data%s" % animationArgs) |
---|
166 | dataSlice=dataSlice(squeeze=1) |
---|
167 | #print dataSlice.shape, dataSlice.getAxisIds() |
---|
168 | #print dataSlice |
---|
169 | self.canvas.plot(dataSlice, self.template, self.plot_type, continents=continentsSwitch, bg=1, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
170 | |
---|
171 | #elif animationArgs[0]=="time": |
---|
172 | # self.canvas.plot(self.data(time=slice(animationArgs[1][0],animationArgs[1][1])), self.template, self.plot_type, continents=continentsSwitch, bg=1, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
173 | #elif animationArgs[0]=="level": |
---|
174 | # self.canvas.plot(self.data(level=slice(animationArgs[1][0],animationArgs[1][1])), self.template, self.plot_type, continents=continentsSwitch, bg=1, file_comment=fileComment, comment1=SOURCE_NAME) |
---|
175 | |
---|
176 | class BoxfillLinear(Boxfill): |
---|
177 | def _getProjection(self): |
---|
178 | self.plot_type.projection="linear" |
---|
179 | |
---|
180 | |
---|
181 | class BoxfillMollweide(Boxfill): |
---|
182 | def _getProjection(self): |
---|
183 | self.plot_type.projection="mollweide" |
---|
184 | |
---|
185 | |
---|
186 | class BoxfillPolarNorth(Boxfill): |
---|
187 | def _extractData(self, data): |
---|
188 | "Extracts only northern hemisphere." |
---|
189 | self.data=data(latitude=(90,0)) |
---|
190 | |
---|
191 | def _getProjection(self): |
---|
192 | self.plot_type.projection="polar" |
---|
193 | |
---|
194 | |
---|
195 | class BoxfillPolarSouth(BoxfillPolarNorth): |
---|
196 | def _extractData(self, data): |
---|
197 | "Extracts only southern hemisphere." |
---|
198 | self.data=data(latitude=(-90,0)) |
---|
199 | |
---|
200 | |
---|
201 | class BoxfillRobinson(Boxfill): |
---|
202 | def _getProjection(self): |
---|
203 | self.plot_type.projection="robinson" |
---|
204 | |
---|
205 | |
---|
206 | class Isofill(Boxfill): |
---|
207 | def __init__(self, canvas, data): |
---|
208 | self.canvas=canvas |
---|
209 | try: |
---|
210 | self.plot_type=canvas.createisofill("new_isofill","default") |
---|
211 | except: |
---|
212 | self.plot_type=canvas.getisofill("new_isofill") |
---|
213 | self._extractData(data) |
---|
214 | self._getProjection() |
---|
215 | self._getTemplate() |
---|
216 | |
---|
217 | |
---|
218 | class IsofillLinear(Isofill): |
---|
219 | def _getProjection(self): |
---|
220 | self.plot_type.projection="linear" |
---|
221 | |
---|
222 | |
---|
223 | class IsofillMollweide(Isofill): |
---|
224 | def _getProjection(self): |
---|
225 | self.plot_type.projection="mollweide" |
---|
226 | |
---|
227 | |
---|
228 | class IsofillPolarNorth(Isofill): |
---|
229 | def _extractData(self, data): |
---|
230 | "Extracts only northern hemisphere." |
---|
231 | self.data=data(latitude=(90,0)) |
---|
232 | |
---|
233 | def _getProjection(self): |
---|
234 | self.plot_type.projection="polar" |
---|
235 | |
---|
236 | |
---|
237 | class IsofillPolarSouth(IsofillPolarNorth): |
---|
238 | def _extractData(self, data): |
---|
239 | "Extracts only southern hemisphere." |
---|
240 | self.data=data(latitude=(0,-90)) |
---|
241 | |
---|
242 | |
---|
243 | class IsofillRobinson(Isofill): |
---|
244 | def _getProjection(self): |
---|
245 | self.plot_type.projection="robinson" |
---|
246 | |
---|
247 | |
---|
248 | class Isoline(Isofill): |
---|
249 | def __init__(self, canvas, data): |
---|
250 | self.canvas=canvas |
---|
251 | try: |
---|
252 | self.plot_type=canvas.createisoline("new_isoline","default") |
---|
253 | except: |
---|
254 | self.plot_type=canvas.getisoline("new_isoline") |
---|
255 | self.plot_type.label="y" |
---|
256 | self._extractData(data) |
---|
257 | self._getProjection() |
---|
258 | self._getTemplate() |
---|
259 | |
---|
260 | |
---|
261 | class IsolineLinear(Isoline): |
---|
262 | def _getProjection(self): |
---|
263 | self.plot_type.projection="linear" |
---|
264 | |
---|
265 | |
---|
266 | class IsolineMollweide(Isoline): |
---|
267 | def _getProjection(self): |
---|
268 | self.plot_type.projection="mollweide" |
---|
269 | |
---|
270 | |
---|
271 | class IsolinePolarNorth(Isoline): |
---|
272 | def _extractData(self, data): |
---|
273 | "Extracts only northern hemisphere." |
---|
274 | self.data=data(latitude=(90,0)) |
---|
275 | |
---|
276 | def _getProjection(self): |
---|
277 | self.plot_type.projection="polar" |
---|
278 | |
---|
279 | |
---|
280 | class IsolinePolarSouth(IsolinePolarNorth): |
---|
281 | def _extractData(self, data): |
---|
282 | "Extracts only southern hemisphere." |
---|
283 | self.data=data(latitude=(0,-90)) |
---|
284 | |
---|
285 | |
---|
286 | class IsolineRobinson(Isoline): |
---|
287 | def _getProjection(self): |
---|
288 | self.plot_type.projection="robinson" |
---|
289 | |
---|
290 | |
---|
291 | |
---|