Skip to content

Commit

Permalink
Add climatology test of the generalized_reader
Browse files Browse the repository at this point in the history
This test loads a 3-file data set both with and without autoclose.

Also, added more time series files to interpolate test, which are
then used by generalized_reader as well
  • Loading branch information
xylar committed Mar 23, 2017
1 parent d15e7c0 commit 15068a6
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 4 deletions.
31 changes: 29 additions & 2 deletions mpas_analysis/test/test_generalized_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
@pytest.mark.usefixtures("loaddatadir")
class TestGeneralizedReader(TestCase):

def setup_config(self):
def setup_config(self, autocloseFileLimitFraction=0.5):
config = MpasAnalysisConfigParser()
config.add_section('input')
config.set('input', 'autocloseFileLimitFraction', '0.5')
config.set('input', 'autocloseFileLimitFraction',
str(autocloseFileLimitFraction))
return config

def test_variableMap(self):
Expand Down Expand Up @@ -118,4 +119,30 @@ def test_start_end(self):
endDate='0005-03-01')
self.assertEqual(len(ds.Time), 1)

def test_open_process_climatology(self):
fileNames = [str(self.datadir.join('timeSeries.0002-{:02d}-01.nc'.format(month)))
for month in [1, 2, 3]]
calendar = 'gregorian_noleap'
variableMap = {'mld': ['timeMonthly_avg_tThreshMLD'],
'Time': [['xtime_startMonthly', 'xtime_endMonthly']]}
annualClimatologies = []
for frac, autoclose in zip([1.0, 0.], [False, True]):
# effectively, test with autoclose=False and autoclose=True
config = self.setup_config(autocloseFileLimitFraction=frac)
ds = open_multifile_dataset(
fileNames=fileNames,
calendar=calendar,
config=config,
timeVariableName='Time',
variableList=['mld'],
variableMap=variableMap)

if hasattr(ds, '_autoclose'):
assert(ds._autoclose == autoclose)

annualClimatologies.append(ds.mean(dim='Time'))

self.assertArrayEqual(annualClimatologies[0].mld.values,
annualClimatologies[1].mld.values)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
1 change: 1 addition & 0 deletions mpas_analysis/test/test_generalized_reader/mpasMesh.nc
4 changes: 2 additions & 2 deletions mpas_analysis/test/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_destination_from_grid_file(self):

mpasMeshFileName = str(self.datadir.join('mpasMesh.nc'))
latLonGridFileName = str(self.datadir.join('SST_annual_1870-1900.nc'))
timeSeriesFileName = str(self.datadir.join('timeSeries.nc'))
timeSeriesFileName = str(self.datadir.join('timeSeries.0002-01-01.nc'))

suffix = 'destination_from_grid_file'
weightFileName = '{}/weights_{}.nc'.format(self.test_dir, suffix)
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_destination_from_numpy_lat_lon(self):
usenumpyfunc=True))

mpasMeshFileName = str(self.datadir.join('mpasMesh.nc'))
timeSeriesFileName = str(self.datadir.join('timeSeries.nc'))
timeSeriesFileName = str(self.datadir.join('timeSeries.0002-01-01.nc'))

suffix = 'destination_from_config_options'
weightFileName = '{}/weights_{}.nc'.format(self.test_dir, suffix)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed mpas_analysis/test/test_interpolate/timeSeries.nc
Binary file not shown.

0 comments on commit 15068a6

Please sign in to comment.