source: TI04-geosplat/trunk/pygss/CombinedPlotManager.py @ 1660

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

Version with overlay of trajectories on top of model fields draft version working before any rigourous testing.

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"""
6CombinedPlotManager.py
7======================
8
9Holds the CombinedPlotManager class that is used to work out if
10any plot types can be overlayed.
11
12"""
13
14# Import required modules
15import os, re
16import cdms
17import vcs
18import sys
19
20# Import package modules including global variables
21from common import *
22from serverConfig import *
23from GSErrors import *
24from VariableAnalyser import *
25
26
27class CombinedPlotManager(VariableAnalyser):
28    """
29    Works out which plot types can be combined. This sub-classes
30    VariableAnalyser as plot configuration stuff is all dealt with there.
31    """
32    currentlyIdentifiedCombinations="""1. Multiple traj over linear boxfill,
33        - Finds by looking at varDict, looping through variables and matching
34        them up."""
35       
36
37    def __init__(self, varDict, fileList=None, required="graphicalOutputTypes", graphicalOutputType=None):
38        """
39        Method to initialise class.
40        """
41        self.varDict=varDict
42        grot=graphicalOutputType
43       
44        if required=="graphicalOutputTypes":
45            self._getOutputTypeCombinations(fileList)
46        else:  # required=="plotConfigurationDict": # need to analyse and give back options
47            self.plotConfigurationDict=self._getPlotConfigurationDetails(grot)
48
49 
50    def _getOutputTypeCombinations(self, fileList):
51        """
52        Analyses varDict to work out if any new graphical output
53        types can be added using multiple variables.
54        Also sets self.varDict so that external caller can get extra
55        combined plot types and save them to session object.
56        """
57        varKeys=self.varDict.keys()
58        varKeys.sort()
59       
60        trajVars={}
61        latLonVars={}
62
63        for vk in varKeys:
64            # vk part 1 is the position in the fileList
65            fileNum=int(vk.split(".")[0])-1
66            d=self.varDict[vk]
67            dom=d["domain"]
68            id=d["id"]
69            grots=[i[0] for i in dom["grots"]]
70            orderedAxes=dom["ordered_axes"]
71           
72            print grots
73            for grot in grots:
74                if grot in ("TrajectoriesOverMap",):
75                    bbox=dom["bbox"]
76                    print bbox
77                    trajVars[id,fileNum]=(vk, bbox)
78                elif grot in ("2DLatLonPlot",):
79                    for ax in orderedAxes:
80                        [axid,knownAs,[low,high]]=dom[ax]
81                        if knownAs=="latitude":
82                            y1,y2=low,high
83                        elif knownAs=="longitude":
84                            x1,x2=low,high
85                    latLonVars[id,fileNum]=(vk, [y1,x1,y2,x2]) 
86       
87        # Now analyse new dictionaries
88        self.combinedPlotOptions=[]
89        for tkey,tvalue in trajVars.items():
90            tvarIndex,bbox1=tvalue
91            trajVarID,trajFileNum=tkey
92           
93            for llkey,llvalue in latLonVars.items():
94                llVarID,llFileNum=llkey
95                llvarIndex,bbox2=llvalue
96               
97                # See if they overlap
98                overlapTest=getSpatialOverlap(bbox1, bbox2)
99                if overlapTest:
100                    trajFileName=fileList[trajFileNum]
101                    llFileName=fileList[llFileNum]
102                    newbbox=overlapTest
103                    comboKey="%s-%s" % (tvarIndex,llvarIndex)
104                    plotType="MultipleTrajectoriesOver2DLatLonPlot"
105                    plotTypeString="""Multiple Trajectories for variable '%s' plotted over 2D Plot for variable '%s' (from files: %s, %s)""" % (trajVarID, llVarID, trajFileName, llFileName) #(tkey,llkey)
106                    self.varDict[comboKey]={"domain":{"bbox":newbbox, "grots":[[plotType, plotTypeString]]}}
107                    self.combinedPlotOptions.append(["graphicalOutputType_%s" % comboKey, [plotType], [plotTypeString]])       
108                    print self.combinedPlotOptions
109
110
111if __name__=="__main__":
112    varDict={'1.5': {'domain':{'bbox': (67.399993896484375, 22.500001907348633, 42.299999237060547, 126.36080169677734), 'grots': [['TrajectoriesOverMap', "Trajectories plotted on map for variable 'temp' from file: '/data/traj.nc'"], ['2DPlot', "2D Plot for variable 'temp' from file: '/data/traj.nc'"]], 'parcel': ['parcel', 'unrecognised', [0.0, 1.0]], 'ordered_axes': ['time', 'parcel'], 'time': ['time', 'time', [0.0, 432000.0]]}, 'id': 'temp'}, '2.1': {'domain': {'latitude': ['latitude', 'latitude', [-90, 90]], 'grots': [['2DLatLonPlot', "2D Lat-Lon Plot for variable 'var2' from file: '/data/var2.nc'"]], 'ordered_axes': ['time', 'latitude', 'longitude'], 'longitude': ['longitude', 'longitude', [0, 355]], 'time': ['time', 'time', [0, 0]]}, 'id': 'var2'}}
113
114       
115    b=CombinedPlotManager(varDict, fileList=["/var/trajbadc.nc", "/data/var2.nc"], required="graphicalOutputTypes")
116    a=CombinedPlotManager(varDict={}, required="plotConfigurationDict")
Note: See TracBrowser for help on using the repository browser.