diff --git a/mpas_analysis/test/test_generalized_reader.py b/mpas_analysis/test/test_generalized_reader.py index 65b2f140f..f83aeeb5b 100644 --- a/mpas_analysis/test/test_generalized_reader.py +++ b/mpas_analysis/test/test_generalized_reader.py @@ -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): @@ -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 diff --git a/mpas_analysis/test/test_generalized_reader/mpasMesh.nc b/mpas_analysis/test/test_generalized_reader/mpasMesh.nc new file mode 120000 index 000000000..880a52c2e --- /dev/null +++ b/mpas_analysis/test/test_generalized_reader/mpasMesh.nc @@ -0,0 +1 @@ +../test_interpolate/mpasMesh.nc \ No newline at end of file diff --git a/mpas_analysis/test/test_generalized_reader/timeSeries.0002-01-01.nc b/mpas_analysis/test/test_generalized_reader/timeSeries.0002-01-01.nc new file mode 120000 index 000000000..6c56dfeb4 --- /dev/null +++ b/mpas_analysis/test/test_generalized_reader/timeSeries.0002-01-01.nc @@ -0,0 +1 @@ +../test_interpolate/timeSeries.0002-01-01.nc \ No newline at end of file diff --git a/mpas_analysis/test/test_generalized_reader/timeSeries.0002-02-01.nc b/mpas_analysis/test/test_generalized_reader/timeSeries.0002-02-01.nc new file mode 120000 index 000000000..7d127a423 --- /dev/null +++ b/mpas_analysis/test/test_generalized_reader/timeSeries.0002-02-01.nc @@ -0,0 +1 @@ +../test_interpolate/timeSeries.0002-02-01.nc \ No newline at end of file diff --git a/mpas_analysis/test/test_generalized_reader/timeSeries.0002-03-01.nc b/mpas_analysis/test/test_generalized_reader/timeSeries.0002-03-01.nc new file mode 120000 index 000000000..a7e210ef8 --- /dev/null +++ b/mpas_analysis/test/test_generalized_reader/timeSeries.0002-03-01.nc @@ -0,0 +1 @@ +../test_interpolate/timeSeries.0002-03-01.nc \ No newline at end of file diff --git a/mpas_analysis/test/test_interpolate.py b/mpas_analysis/test/test_interpolate.py index 63174a944..c7bd72299 100644 --- a/mpas_analysis/test/test_interpolate.py +++ b/mpas_analysis/test/test_interpolate.py @@ -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) @@ -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) diff --git a/mpas_analysis/test/test_interpolate/timeSeries.0002-01-01.nc b/mpas_analysis/test/test_interpolate/timeSeries.0002-01-01.nc new file mode 100644 index 000000000..86da95247 Binary files /dev/null and b/mpas_analysis/test/test_interpolate/timeSeries.0002-01-01.nc differ diff --git a/mpas_analysis/test/test_interpolate/timeSeries.0002-02-01.nc b/mpas_analysis/test/test_interpolate/timeSeries.0002-02-01.nc new file mode 100644 index 000000000..6b2c2f3cc Binary files /dev/null and b/mpas_analysis/test/test_interpolate/timeSeries.0002-02-01.nc differ diff --git a/mpas_analysis/test/test_interpolate/timeSeries.0002-03-01.nc b/mpas_analysis/test/test_interpolate/timeSeries.0002-03-01.nc new file mode 100644 index 000000000..fedaf550c Binary files /dev/null and b/mpas_analysis/test/test_interpolate/timeSeries.0002-03-01.nc differ diff --git a/mpas_analysis/test/test_interpolate/timeSeries.nc b/mpas_analysis/test/test_interpolate/timeSeries.nc deleted file mode 100644 index 4d53ec27f..000000000 Binary files a/mpas_analysis/test/test_interpolate/timeSeries.nc and /dev/null differ