Skip to content

Commit 066d185

Browse files
committed
Add CI testing that makes use of a variable map
This also tests the new openMultifileDataset function.
1 parent 63494c4 commit 066d185

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

mpas_analysis/test/test_var_map.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Unit test infrastructure for variable mapping.
3+
4+
Xylar Asay-Davis
5+
02/08/2017
6+
"""
7+
8+
import pytest
9+
from mpas_analysis.test import TestCase, loaddatadir
10+
from mpas_analysis.shared.dataset.utility import openMultifileDataset
11+
12+
13+
@pytest.mark.usefixtures("loaddatadir")
14+
class TestVariableMapping(TestCase):
15+
16+
def test_variable_map(self):
17+
fileName = str(self.datadir.join('example_jan.nc'))
18+
varMap = {
19+
'avgSurfaceTemperature':
20+
['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature',
21+
'other_string',
22+
'yet_another_string'],
23+
'daysSinceStartOfSim':
24+
['time_avg_daysSinceStartOfSim',
25+
'xtime',
26+
'something_else'],
27+
'avgLayerTemperature':
28+
['time_avg_avgValueWithinOceanLayerRegion_avgLayerTemperature',
29+
'test1',
30+
'test2'],
31+
'Time': [['xtime_start', 'xtime_end'],
32+
'time_avg_daysSinceStartOfSim']}
33+
34+
varList = ['avgSurfaceTemperature', 'avgLayerTemperature',
35+
'refBottomDepth', 'daysSinceStartOfSim']
36+
37+
# preprocess_mpas will use varMap to map the variable names from their
38+
# values in the file to the desired values in varList
39+
ds = openMultifileDataset(fileName, calendar='gregorian',
40+
timeVariableName='Time',
41+
variableList=varList, variableMap=varMap,
42+
yearOffset=1850)
43+
44+
# make sure the remapping happened as expected
45+
self.assertEqual(sorted(ds.data_vars.keys()), sorted(varList))
46+
47+
# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_mpas_xarray/example_jan.nc

0 commit comments

Comments
 (0)