Package PyFoam :: Package Applications :: Module PrintData2DStatistics
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.PrintData2DStatistics

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Applications/PrintData2DStatistics.py 7729 2012-01-19T12:12:30.369763Z bgschaid  $  
  2  """ 
  3  Application class that implements pyFoamPrintData2DStatistics 
  4  """ 
  5   
  6  import sys,re 
  7  from optparse import OptionGroup 
  8   
  9  from PyFoamApplication import PyFoamApplication 
 10   
 11  from CommonPickledDataInput import CommonPickledDataInput 
 12   
 13  from PyFoam.Error import PyFoamException 
 14   
 15  from PyFoam.Basics.Data2DStatistics import Data2DStatistics 
 16   
17 -class PrintData2DStatistics(PyFoamApplication, 18 CommonPickledDataInput):
19 - def __init__(self,args=None,inputApp=None):
20 description="""\ 21 Reads a file with pickled information with statistics about data 22 series (as it is usually gnerated by pyFoamTimelinePlot.py and 23 pyFoamSamplePlot.py) and prints it in a human-readable form. 24 """ 25 26 PyFoamApplication.__init__(self, 27 args=args, 28 description=description, 29 usage="%prog [options]", 30 nr=0, 31 changeVersion=False, 32 interspersed=True, 33 inputApp=inputApp)
34
35 - def addOptions(self):
36 CommonPickledDataInput.addOptions(self) 37 38 output=OptionGroup(self.parser, 39 "2D Statistics output", 40 "Options that determine what should be output") 41 self.parser.add_option_group(output) 42 output.add_option("--field", 43 action="append", 44 default=[], 45 dest="field", 46 help="""\ 47 Name of the field that should be printed. Can be specified more than once 48 """) 49 output.add_option("--function", 50 action="append", 51 default=[], 52 dest="function", 53 help="""\ Name of a function that should be 54 calculated on the data. Either a function in the lambda-syntax or a 55 function from the math-module 56 """) 57 output.add_option("--relative-error", 58 action="store_true", 59 default=False, 60 dest="relativeError", 61 help="""\ 62 Print the relative error as calculated from the metrics and the compare-data 63 """) 64 output.add_option("--range", 65 action="store_true", 66 default=False, 67 dest="range", 68 help="""\ 69 Print the range (minimum and maximum) of the data 70 """) 71 72 input=OptionGroup(self.parser, 73 "2D Statistics intput", 74 "Options that determine what should be used as input") 75 self.parser.add_option_group(input) 76 input.add_option("--metrics-name", 77 action="store", 78 default="metrics", 79 dest="metricsName", 80 help="""\ 81 Name of the data metric (the main input). Default: %default 82 """) 83 input.add_option("--compare-name", 84 action="store", 85 default="compare", 86 dest="compareName", 87 help="""\ 88 Name of the comparison metric (the secondary input). Default: 89 %default. Ignored if not present in the data 90 """) 91 92 parameters=OptionGroup(self.parser, 93 "2D Statistics Paramters", 94 "Options that determine the behaviour of the 2D statistics") 95 self.parser.add_option_group(parameters) 96 parameters.add_option("--small-threshold", 97 action="store", 98 default=1e-10, 99 type="float", 100 dest="smallThreshold", 101 help="""\ 102 Value that is considered to be close enough to 0. Default: 103 %default. Used for instance for the relative error calculations 104 """)
105 106
107 - def run(self):
108 data=self.readPickledData() 109 result={"originalData":data} 110 if self.opts.metricsName in data: 111 metrics=data[self.opts.metricsName] 112 else: 113 self.error("Metrics set",self.opts.metricsName,"not in",data.keys()) 114 if self.opts.metricsName==self.opts.compareName: 115 self.warning("Metrics and comparison",self.opts.compareName, 116 "are the same. No comparison used") 117 self.opts.compareName=None 118 119 if self.opts.compareName==None: 120 compare=None 121 elif self.opts.compareName in data: 122 compare=data[self.opts.compareName] 123 else: 124 self.error("Compare set",self.opts.compareName,"not in",data.keys()) 125 126 stat=Data2DStatistics(metrics, 127 compare=compare, 128 small=self.opts.smallThreshold) 129 130 result["statistics"]=stat 131 132 for f in self.opts.field: 133 print "\nField",f 134 try: 135 val=stat[f] 136 print val 137 result[f]=val 138 except KeyError: 139 print " .... not present in",stat.names() 140 141 for f in self.opts.function: 142 for v in self.opts.field: 143 print "\nFunction",f,"on field",v 144 try: 145 val=stat.func(f,v) 146 print val 147 result["%s on %s" % (f,v)]=val 148 except KeyError: 149 print " .... not present in",stat.names() 150 151 if self.opts.relativeError: 152 print "\nRelative Error" 153 val=stat.relativeError() 154 print val 155 result["relativeError"]=val 156 157 if self.opts.range: 158 print "\nData range" 159 val=stat.range() 160 print val 161 result["dataRange"]=val 162 163 self.setData(result)
164