source: flexpart.git/flexpart-testing/flextest/OutputCompare.py @ 29feaef

FPv9.3.1FPv9.3.1b_testingFPv9.3.2fp9.3.1-20161214-nc4grib2nc4_repair
Last change on this file since 29feaef was 496c607, checked in by Don Morton <Don.Morton@…>, 8 years ago

Initial commit of FPv9.3.1

Currently, this is a clone of snapshot FPv9.3.0

  • Property mode set to 100644
File size: 2.8 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3Created on Fri Sep  4 18:19:06 2015
4
5@author: morton
6
7Don Morton
8Boreal Scientific Computing LLC, Fairbanks, Alaska, USA
9Don.Morton@borealscicomp.com
10http://www.borealscicomp.com/
11"""
12
13import os
14
15import flextest.flexread.FlexpartOutput as FlexpartOutput
16import flextest.FlexpartErrors as FlexpartErrors
17
18
19class OutputCompare(object):
20   
21
22
23    _VALID_TESTS = [
24                    'mother_all_vars_rmse',
25                    'nest_all_vars_rmse',
26                    'mother_all_vars_maxabserr',
27                    'nest_all_vars_maxabserr'
28                    ]
29               
30
31    def __init__(self, output_dir=None, control_output_dir=None):
32       
33        if output_dir:
34            if os.path.isdir(output_dir):
35                self._output_dir = output_dir
36            else:
37                raise Exception('Unable to find output_dir: ' + output_dir)               
38        else:
39            raise Exception('No output_dir defined')
40           
41        if control_output_dir:
42            if os.path.isdir(control_output_dir):
43                self._control_output_dir = control_output_dir
44            else:
45                raise Exception('Unable to find control_output_dir: ' + control_output_dir)               
46        else:
47            raise Exception('No control_output_dir defined')
48
49
50
51               
52    def query_test_types(self):
53       
54        """ Return list of the valid test types """
55        return self._VALID_TESTS
56       
57       
58    def calculate_test_minus_control(self, test_type=None):
59       
60   
61        if test_type not in self._VALID_TESTS:
62            raise Exception('Invalid test_type: ' + str(test_type))
63           
64        else:
65   
66            if test_type in ['nest_all_vars_rmse', 'nest_all_vars_maxabserr']:
67                nest = True
68            else:
69                nest = False
70   
71   
72        # Create FlexpartOutput objects
73        control_output = FlexpartOutput.FlexpartOutput(
74                           output_dir=self._control_output_dir,
75                           nest=nest)
76        test_output = FlexpartOutput.FlexpartOutput(
77                           output_dir=self._output_dir,
78                           nest=nest)
79        # Create FlexpartError object   
80        error_object = FlexpartErrors.FlexpartErrors(control=control_output,
81                                                     test=test_output)
82           
83   
84        # Select and perform the test, returning the error
85   
86        if test_type in ['mother_all_vars_rmse', 'nest_all_vars_rmse']:
87            err_val = error_object.rmse()
88        elif test_type in ['mother_all_vars_maxabserr', 'nest_all_vars_maxabserr']:
89            err_val = error_object.max_absolute_error()
90        else:
91            err_val = None
92           
93        return err_val
94   
95   
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG