1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | Created on Fri Sep 4 18:19:06 2015 |
---|
4 | |
---|
5 | @author: morton |
---|
6 | |
---|
7 | Don Morton |
---|
8 | Boreal Scientific Computing LLC, Fairbanks, Alaska, USA |
---|
9 | Don.Morton@borealscicomp.com |
---|
10 | http://www.borealscicomp.com/ |
---|
11 | """ |
---|
12 | |
---|
13 | import os |
---|
14 | |
---|
15 | import flextest.flexread.FlexpartOutput as FlexpartOutput |
---|
16 | import flextest.FlexpartErrors as FlexpartErrors |
---|
17 | |
---|
18 | |
---|
19 | class 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 | |
---|