|
3 | 3 | import os |
4 | 4 | import unittest |
5 | 5 |
|
| 6 | +import numpy as np |
6 | 7 | from netCDF4 import Dataset, chartostring |
7 | 8 |
|
8 | 9 | from aodntools import __version__ |
|
19 | 20 | BAD_FILE |
20 | 21 | ] |
21 | 22 | EXPECTED_OUTPUT_FILE = os.path.join( |
22 | | - TEST_ROOT, 'IMOS_ANMN-NRS_TZ_20181213_NRSROT_FV01_TEMP-aggregated-timeseries_END-20190523_C-20200622.nc' |
| 23 | + TEST_ROOT, 'IMOS_ANMN-NRS_TZ_20181213_NRSROT_FV01_TEMP-aggregated-timeseries_END-20190523_C-20220607.nc' |
23 | 24 | ) |
24 | 25 |
|
25 | 26 |
|
@@ -69,13 +70,29 @@ def test_main_aggregator(self): |
69 | 70 | self.assertIn(__version__, dataset.lineage) |
70 | 71 | self.assertIn(BAD_FILE, dataset.rejected_files) |
71 | 72 |
|
72 | | - # check aggregated variable values |
| 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 | + ) |
73 | 78 | expected = Dataset(EXPECTED_OUTPUT_FILE) |
74 | | - compare_vars = ('TIME', 'TEMP', 'TEMP_quality_control', 'NOMINAL_DEPTH', 'instrument_index') |
75 | | - non_match_vars = [var for var in compare_vars |
76 | | - if not all(dataset[var][:] == expected[var][:]) |
77 | | - ] |
78 | | - self.assertEqual(non_match_vars, []) |
| 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) |
79 | 96 |
|
80 | 97 | def test_source_file_attributes(self): |
81 | 98 | output_file, bad_files = main_aggregator(INPUT_FILES, 'PSAL', 'NRSROT', input_dir=TEST_ROOT, |
|
0 commit comments