source: TI04-geosplat/trunk/pygss/Animator.py @ 798

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI04-geosplat/trunk/pygss/Animator.py@6809
Revision 798, 2.6 KB checked in by astephen, 14 years ago (diff)

Latest working version with install method.
Can accept more than one file but doesn't combine variables yet.

Line 
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"""
6Animator.py
7===========
8
9Holds the Animator class used to create animations in the
10geosplat package.
11
12"""
13
14# Import standard library modules
15import os 
16
17# Import package modules
18from serverConfig import *
19from PlotClasses import *
20
21
22class Animator:
23    """
24    Class used to create Animations in geosplat.
25    """
26
27    def __init__(self, data, plotClass, geometry, outfile):
28        """
29        Method to take in canvas type and data type to be animated.
30        """
31        self.data=data
32        # plotClass is an instance of the required plotting class
33        self.plotter=plotClass
34        self.geometry=geometry
35        self.outfile=outfile
36       
37        self._getLoopAxis()
38        self._getRangeScale()
39       
40    def _getLoopAxis(self):
41        """
42        Method to determine and set up the axis to loop over.
43        This can either be level or time at present.
44        """
45        time_axis = self.data.getTime() 
46        lev_axis = self.data.getLevel() 
47        lat_axis = self.data.getLatitude() 
48        lon_axis = self.data.getLongitude()
49 
50        loop_num=1 
51        if time_axis!=None: 
52            loop_flag = 'time' 
53            loop_num = len(time_axis) 
54        if loop_num==1 and lev_axis!=None: 
55            loop_num = len(lev_axis) 
56            loop_flag = 'level' 
57        if loop_num==1 and lat_axis!=None: 
58            loop_num=len(lat_axis) 
59            loop_flag='lat' 
60        if loop_num==1 and lon_axis!=None: 
61            loop_num=len(lon_axis) 
62            loop_flag='lon' 
63       
64        self.loop_num=loop_num
65        self.loop_flag=loop_flag
66       
67    def _getRangeScale(self):
68        """
69        Get range of values in data so that scale is same for all frames.
70        """
71        # Import VCS module
72        import vcs
73        (self.dmin, self.dmax)=vcs.minmax(self.data) 
74
75    def createAnimation(self):
76        """
77        Method to create animation. This is called externally by the user.
78        """
79        # Import VCS module
80        import vcs
81        # Get the colour range for the legend
82        levs=vcs.mkscale(self.dmin, self.dmax)
83        lst=[] 
84        rcolors = [] 
85        try: 
86            d = int(222/(len(levs)-1)) 
87        except: 
88            d = 1 
89                   
90        for a in range(len(levs)):
91            rcolors.append(16 + a*d)
92            lst.append(levs[a])
93       
94        pt=self.plotter.plot_type   
95        pt.levels=lst
96        pt.fillareacolors = rcolors
97 
98        for i in range(self.loop_num): 
99             self.plotter.canvas.clear() 
100             self.plotter.createPlot((self.loop_flag,(i,i+1)))
101             self.plotter.canvas.gif(self.outfile, geometry=self.geometry) 
Note: See TracBrowser for help on using the repository browser.