Last active
June 11, 2017 02:57
-
-
Save cpelley/1116f1115508a2bad946337eb0c6d914 to your computer and use it in GitHub Desktop.
Some guideance on regrid testing and regrid UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:44ca4f80992b328dbe607f0caf37756bc6f0eea7df01508482f2eacac574e785" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Regridding interface" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"class ESMF(object):\n", | |
" def regridder(self, src_grid, tgt_grid):\n", | |
" _ESMFRegridder(src_grid, tgt_grid, method=self._method, extrapolation='self._extrapolation')\n", | |
"\n", | |
"\n", | |
"class LinearESMF(ESMF):\n", | |
" def __init__(self, extrapolation='linear'):\n", | |
" self._extrapolation = extrapolation\n", | |
" self._method = 'linear'\n", | |
"\n", | |
"\n", | |
"class ConservativeESMF(ESMF):\n", | |
" def __init__(self, extrapolation='linear'):\n", | |
" self._extrapolation = extrapolation\n", | |
" self._method = 'weightedArea'" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Calling a regridder directly (TwoStage, ConservativeESMF, Linear, AreaWeighted, ... etc.)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"result = source.regrid(target, TwoStage())" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Calling via the decomposition framework" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"operation = ConservativeESMF().regridder(source, target)\n", | |
"result = ants.decomposition.decompose(operation, source, target)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Calling the ants general regridder commandline application (choosing TwoStage, ConservativeESMF, Linear, AreaWeighted, ... etc.)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"$ ancil_generalised_regrid.py source_file --target-grid target_grid_file -o output_file --ants-config /path/to/config.cfg" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"$ cat /path/to/config.cfg:\n", | |
"\n", | |
" [decomposition]\n", | |
" target_split = 1, 1, 10, 10\n", | |
" processes = 10\n", | |
" framework = MultiprocessingDomainDecompose\n", | |
"\n", | |
" [regridding_horizontal]\n", | |
" scheme = TwoStage" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"How about a unittest for the regridder" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Example unittest for from the TwoStage regridder:\n", | |
"\n", | |
"`ants.tests.regrid.test_integration.TestTwoStage.test_api` \n", | |
"https://code.metoffice.gov.uk/trac/ancil/browser/ants/trunk/lib/ants/tests/regrid/test_integration.py?rev=3543#L73\n", | |
"\n", | |
"This test takes an OSGB source and regrids this to a lat-lon target. \n", | |
"https://code.metoffice.gov.uk/trac/ancil/browser/ants/trunk/lib/ants/tests/results/visual_tests/test_integration.TestTwoStage.test_api.0.png?rev=3543\n", | |
"\n", | |
"A graphical image is generated upon which future changes will be compared against." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Note: There are numerous useful target grids available, of which many of interest can be found here:\n", | |
" \n", | |
" https://code.metoffice.gov.uk/trac/ancil/browser/data/trunk/namelist/grids\n", | |
" \n", | |
"Variable resolution grids:\n", | |
" \n", | |
" https://code.metoffice.gov.uk/trac/ancil/browser/data/trunk/namelist/variable_grids\n", | |
" \n", | |
"These files can be loaded easily by `ants.load_grid(filenames)`" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"How about an integration test which demonstrates end-to-end usage" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The UI is explained most clearly in the docs on trunk here: https://code.metoffice.gov.uk/trac/ancil/browser/ants/trunk/doc/ants/source/running_applications.rst" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Create an 'application test'\n", | |
"\n", | |
"$ cat ants/bin/tests/test_generalised_regrid_rotated.py" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# (C) British Crown Copyright 2017, Met Office\n", | |
"# Refer to README.md of this project for license details.\n", | |
"#\n", | |
"# This file is part of ANTS.\n", | |
"import common\n", | |
"from ants.config import CONFIG\n", | |
"\n", | |
"\n", | |
"@common.skip_data\n", | |
"class TestAll(common.StaticTestCase):\n", | |
" def test_all(self):\n", | |
" CONFIG['regridding']['scheme'] = 'ConservativeESMF'\n", | |
"\n", | |
" source_filepath = common.get_data_path('river_routing_preprocessed.nc')\n", | |
" target_grid_path = common.get_data_path(\n", | |
" 'ukv_coarse_land_cover_fraction.nc')\n", | |
"\n", | |
" self.application_test('ancil_generalised_regrid',\n", | |
" source_filepath,\n", | |
" target_grid_path,\n", | |
" self.temporary_output(identifier='rotated'))\n", | |
"\n", | |
"\n", | |
"if __name__ == '__main__':\n", | |
" common.main()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"If you run this new application, it generates the following new reference files: \n", | |
"\n", | |
" bin/tests/results/ancil_generalised_regrid_rotated.ancil \n", | |
" bin/tests/results/ancil_generalised_regrid_rotated.cdl \n", | |
" bin/tests/results/visual_tests/test_generalised_regrid_rotated.TestAll.test_all.0.png \n", | |
" bin/tests/results/visual_tests/test_generalised_regrid_rotated.TestAll.test_all.1.png \n", | |
" \n", | |
"That is, an xml of the cubes, a dump of the ancillary metadata and lastly the graphical plots. On future running of these tests,\n", | |
"a change to the test results will result in a difference in one or more of these files and cause a failure indicating what is different." | |
] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @cpelley,
Thanks, good start.