|
3 | 3 | import os |
4 | 4 | import unittest |
5 | 5 |
|
6 | | -import numpy as np |
7 | 6 | from netCDF4 import Dataset, chartostring |
8 | 7 |
|
9 | 8 | from aodntools import __version__ |
|
19 | 18 | 'IMOS_ANMN-NRS_BCKOSTUZ_20181213T080038Z_NRSROT_FV01_NRSROT-1812-WQM-55_END-20181215T013118Z_C-20190828T000000Z.nc', |
20 | 19 | BAD_FILE |
21 | 20 | ] |
22 | | -EXPECTED_OUTPUT_FILE = os.path.join( |
23 | | - TEST_ROOT, 'IMOS_ANMN-NRS_TZ_20181213_NRSROT_FV01_TEMP-aggregated-timeseries_END-20190523_C-20220607.nc' |
24 | | -) |
25 | 21 |
|
26 | 22 |
|
27 | 23 | class TestAggregatedTimeseries(BaseTestCase): |
| 24 | + EXPECTED_OUTPUT_FILE = os.path.join( |
| 25 | + TEST_ROOT, 'IMOS_ANMN-NRS_TZ_20181213_NRSROT_FV01_TEMP-aggregated-timeseries_END-20190523_C-20220607.nc' |
| 26 | + ) |
| 27 | + |
28 | 28 | def test_main_aggregator(self): |
29 | 29 | output_file, bad_files = main_aggregator(INPUT_FILES, 'TEMP', 'NRSROT', input_dir=TEST_ROOT, |
30 | 30 | output_dir='/tmp') |
@@ -70,29 +70,11 @@ def test_main_aggregator(self): |
70 | 70 | self.assertIn(__version__, dataset.lineage) |
71 | 71 | self.assertIn(BAD_FILE, dataset.rejected_files) |
72 | 72 |
|
73 | | - compare_attrs = ('Conventions', 'feature_type', 'author', 'author_email', 'file_version', |
74 | | - 'geospatial_lat_max', 'geospatial_lat_min', 'geospatial_lon_max', 'geospatial_lon_min', |
75 | | - 'geospatial_vertical_max', 'geospatial_vertical_min', 'naming_authority', 'project', |
76 | | - 'time_coverage_start', 'time_coverage_end' |
77 | | - ) |
78 | | - expected = Dataset(EXPECTED_OUTPUT_FILE) |
79 | | - for attr in compare_attrs: |
80 | | - self.assertEqual(dataset.getncattr(attr), expected.getncattr(attr)) |
81 | | - |
82 | | - # check that there are no NaN values in any variable (they should be fill values instead) |
83 | | - nan_vars = [name |
84 | | - for name, var in dataset.variables.items() |
85 | | - if var.dtype in (np.dtype('float32'), np.dtype('float64')) and any(np.isnan(var[:])) |
86 | | - ] |
87 | | - self.assertEqual([], nan_vars) |
88 | | - |
89 | | - # check aggregated variable values |
90 | | - non_match_vars = [] |
91 | | - for var in set(expected.variables.keys()) - string_vars: |
92 | | - # compare the raw data arrays (not the masked_array) |
93 | | - if not all(dataset[var][:].data == expected[var][:].data): |
94 | | - non_match_vars.append(var) |
95 | | - self.assertEqual([], non_match_vars) |
| 73 | + self.compare_global_attributes(dataset) |
| 74 | + |
| 75 | + self.check_nan_values(dataset) |
| 76 | + |
| 77 | + self.compare_variables(dataset) |
96 | 78 |
|
97 | 79 | def test_source_file_attributes(self): |
98 | 80 | output_file, bad_files = main_aggregator(INPUT_FILES, 'PSAL', 'NRSROT', input_dir=TEST_ROOT, |
|
0 commit comments