Changes between Version 6 and Version 7 of FpCtbtoOverview


Ignore:
Timestamp:
Jul 1, 2015, 1:56:03 PM (9 years ago)
Author:
dearn
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FpCtbtoOverview

    v6 v7  
    4848
    4949
     50----
     51'''EXAMPLE ON USAGE OF THE TEST ENVIONMENT''' ''''
     52
     53   The file '''{{{FlexpartErrors/test/test_FlexpartErrors.py}}}''' contains a variety of test cases which can serve as examples on how to use this class.  However, the following is intended to be a more user-friendly introduction.  Be sure fist to set your '''{{{$PYTHONPATH}}}''' correctly.  If you have put the testing environment in directory {{{/home/mememe/flexpart-testing}}} you would set your '''{{{$PYTHONPATH}}}''' in the bash shell as follows
     54
     55{{{
     56export PYTHONPATH=/home/mememe/flexpart-testing:$PYTHONPATH
     57}}}
     58
     59   The data used in these examples come from a tiny, nested outgrid of 4 rows, 3 columns, 5 levels, 2 species, 6 releases and 1 age class in the mother domain. In the nest, there are 10 rows and 5 columns of grid points. The control model comes from a simulation using ECMWF met data, and the test run comes from the same simulation using NCEP met data.  There are three timestamps:
     60
     61{{{
     62['20140919010000', '20140919020000', '20140919030000']
     63}}}
     64
     65   The test data here is available in the '''{{{unittest_data}}}''' directory of the code distribution.  As a first example, let's get a grid that represents the difference (test minus control) between the two datasets, under various conditions.  First, we create the !FlexpartOutput objects as follows.  You will need to change the value of '''{{{DATA_DIR}}}''' to the location of your distribution.
     66
     67{{{
     68import flexread.FlexpartOutput as flexout
     69import FlexpartErrors as flexerr
     70
     71DATA_DIR='/u1/uaf/morton/flexpart-testing/unittest_data'
     72
     73CONTROL_OUTPUT_DIR = DATA_DIR + '/flexout_forward_tiny_complex_withnest'
     74TEST_OUTPUT_DIR = DATA_DIR + '/ncepflexout_forward_tiny_complex_withnest'
     75
     76# Create the two objects used for containing the FLEXPART output
     77# By default, this will point to the mother nest of the domains.
     78control_output = flexout.FlexpartOutput(output_dir=CONTROL_OUTPUT_DIR)
     79test_output = flexout.FlexpartOutput(output_dir=TEST_OUTPUT_DIR)
     80
     81# Create the error object
     82error_obj = flexerr.FlexpartErrors(control=control_output,
     83                                   test=test_output)
     84
     85# Get the diff_grid from default parameters
     86diff_grid = error_obj.get_diff_grid()
     87
     88print diff_grid
     89}}}
     90
     91   In the above, we create '''{{{control_output}}}''' and '''{{{test_output}}}''' objects, then create an '''{{{error_obj}}}''' object by initialising with these two objects.  With no arguments to the '''{{{diff_grid}}}''' method, we use default values, giving us a horizontal slice at level 1, for a roughly middle timestamp
     92
     93{{{
     94[[ 0.          0.          0.        ]
     95 [ 0.         -0.09765793  0.        ]
     96 [ 0.          0.18723705  0.        ]
     97 [ 0.          0.          0.        ]]
     98}}}
     99
     100  Exercising a little more specificity, in the next case we get the diff grid from last timestamp, 20140919030000, level 2, species 1, release 5, as follows
     101
     102{{{
     103diff_grid = error_obj.get_diff_grid(timestamp='20140919030000',
     104                                    level=2,
     105                                    species=1,
     106                                    release=5
     107                                     )
     108
     109print diff_grid
     110}}}
     111
     112
     113{{{
     114[[  0.00000000e+00   0.00000000e+00   0.00000000e+00]
     115 [ -2.90811108e-02  -6.62608682e-05   0.00000000e+00]
     116 [ -1.18361338e-01  -8.55133458e-05   0.00000000e+00]
     117 [  0.00000000e+00   0.00000000e+00   0.00000000e+00]]
     118}}}
     119
     120   Up to now, we have used the ''get_diff_grid()'' method to illustrate how to access different components of the output files.  In most cases, the user will not even use ''get_diff_grid()'' unless he or she wants more detail.  This !FlexpartErrors class is used primarly to calculate the error between two grids.  The available methods are described in http://flexpart.eu:8088/svn/CTBTOdevel/trunk/flexpart-testing/doc
     121
     122   In the following example we go through the calculation of errors on different portions of the output grids for the nest
     123
     124{{{
     125import flexread.FlexpartOutput as flexout
     126import FlexpartErrors as flexerr
     127
     128DATA_DIR='/u1/uaf/morton/flexpart-testing/unittest_data'
     129
     130CONTROL_OUTPUT_DIR = DATA_DIR + '/flexout_forward_tiny_complex_withnest'
     131TEST_OUTPUT_DIR = DATA_DIR + '/ncepflexout_forward_tiny_complex_withnest'
     132
     133# Create the two objects used for containing the FLEXPART output
     134# By default, this will point to the mother nest of the domains.
     135control_output = flexout.FlexpartOutput(output_dir=CONTROL_OUTPUT_DIR,
     136                                        nest=True)
     137test_output = flexout.FlexpartOutput(output_dir=TEST_OUTPUT_DIR,
     138                                     nest=True)
     139
     140# Create the error object
     141error_obj = flexerr.FlexpartErrors(control=control_output,
     142                                   test=test_output)
     143
     144# Calculate mean bias for the default time and horizontal slice of the next
     145bias = error_obj.mean_bias()
     146print 'Mean bias for default horizontal slice: ' + str(bias)
     147
     148# Calculate the max error (max magnitude, whether positive or negative) of
     149# the entire time series and entire volume for species 2, release 1
     150maxerr = error_obj.max_error(species=2, release=1,
     151                             volume=True, timeseries=True)
     152print 'Max error for full timeseries and volume, species 2, release 1: ' + \
     153        str(maxerr)
     154
     155# Calculate the RMSE of last timestep, level 2, for species 1, release 2
     156rmse = error_obj.rmse(timestamp='20140919030000', level=2,
     157                        species=1, release=2)
     158print 'RMSE for level 2, species 1, release 2, last timestamp: ' + \
     159        str(rmse)
     160}}}
     161
     162
     163{{{
     164Mean bias for default horizontal slice: 0.0449703330779
     165Max error for full timeseries and volume, species 2, release 1: 3.79051153362
     166RMSE for level 2, species 1, release 2, last timestamp: 0.146961582495
     167}}}
     168
     169
     170
     171
    50172FlexpartErrorsTemporaryDocumentation
    51173