From 46075580a1ef3990b8fee4e6921f2c7b3eac17a2 Mon Sep 17 00:00:00 2001 From: mhidas Date: Thu, 4 Aug 2016 17:25:42 +1000 Subject: [PATCH] WIP: add unittest for pressure vertical coordinate (https://github.com/aodn/compliance-checker/issues/102) --- .../tests/data/imos_pressure_coord.cdl | 81 +++++++++++++++++++ .../cc_plugin_imos/tests/resources.py | 1 + .../cc_plugin_imos/tests/test_imos.py | 15 ++++ 3 files changed, 97 insertions(+) create mode 100644 lib/cc_plugin_imos/cc_plugin_imos/tests/data/imos_pressure_coord.cdl diff --git a/lib/cc_plugin_imos/cc_plugin_imos/tests/data/imos_pressure_coord.cdl b/lib/cc_plugin_imos/cc_plugin_imos/tests/data/imos_pressure_coord.cdl new file mode 100644 index 000000000..347b8c5a3 --- /dev/null +++ b/lib/cc_plugin_imos/cc_plugin_imos/tests/data/imos_pressure_coord.cdl @@ -0,0 +1,81 @@ +netcdf test { +dimensions: + PRES = 16 ; +variables: + double TIME ; + TIME:standard_name = "time" ; + TIME:units = "days since 1950-01-01 00:00:00 UTC" ; + TIME:axis = "T" ; + double LATITUDE ; + LATITUDE:standard_name = "latitude" ; + LATITUDE:units = "degrees_north" ; + LATITUDE:axis = "Y" ; + double LONGITUDE ; + LONGITUDE:standard_name = "longitude" ; + LONGITUDE:units = "degrees_east" ; + LONGITUDE:axis = "X" ; + double PRES(PRES) ; + PRES:standard_name = "sea_water_pressure" ; + PRES:units = "dbar" ; + PRES:axis = "Z" ; + double TEMP(PRES) ; + TEMP:standard_name = "sea_water_temperature" ; + TEMP:units = "Celsius" ; + TEMP:_FillValue = 999999. ; + TEMP:coordinates = "TIME LATITUDE LONGITUDE PRES" ; + +// global attributes: + :geospatial_lat_min = -64.0937 ; + :geospatial_lat_max = -64.0937 ; + :geospatial_lon_min = 91.0651 ; + :geospatial_lon_max = 91.0651 ; + :geospatial_vertical_min = 4. ; + :geospatial_vertical_max = 502. ; + :geospatial_vertical_units = "dbar" ; + :time_coverage_start = "2013-03-02T01:20:00Z" ; + :time_coverage_end = "2013-03-02T01:20:00Z" ; + +data: + + TIME = 23071.0555555556 ; + + LATITUDE = -64.0937 ; + + LONGITUDE = 91.0651 ; + + PRES = + 4, + 10, + 20, + 30, + 42, + 50, + 62, + 100, + 122, + 200, + 230, + 300, + 354, + 400, + 500, + 502 ; + + TEMP = + 0.4852, + 0.4903, + 0.5082, + 0.3958, + -0.6897, + -1.0447, + -1.249, + -1.1698, + -1.2056, + 0.0152, + 0.5848, + 0.973, + 1.305, + 1.2744, + 1.2207, + 1.2207 ; +} diff --git a/lib/cc_plugin_imos/cc_plugin_imos/tests/resources.py b/lib/cc_plugin_imos/cc_plugin_imos/tests/resources.py index d6de4c65d..ffb6e3490 100644 --- a/lib/cc_plugin_imos/cc_plugin_imos/tests/resources.py +++ b/lib/cc_plugin_imos/cc_plugin_imos/tests/resources.py @@ -23,4 +23,5 @@ def generate_dataset(cdl_path, nc_path): 'data_var' : get_filename('tests/data/imos_data_var.nc'), 'bad_coords' : get_filename('tests/data/imos_bad_coords.nc'), 'new_data' : get_filename('tests/data/imos_new_data.nc'), + 'pressure_coord': get_filename('tests/data/imos_pressure_coord.nc'), } diff --git a/lib/cc_plugin_imos/cc_plugin_imos/tests/test_imos.py b/lib/cc_plugin_imos/cc_plugin_imos/tests/test_imos.py index 39dc8bf53..eb26d4e88 100644 --- a/lib/cc_plugin_imos/cc_plugin_imos/tests/test_imos.py +++ b/lib/cc_plugin_imos/cc_plugin_imos/tests/test_imos.py @@ -62,6 +62,7 @@ def setUp(self): self.data_variable_dataset = self.load_dataset(STATIC_FILES['data_var']) self.bad_coords_dataset = self.load_dataset(STATIC_FILES['bad_coords']) self.new_dataset = self.load_dataset(STATIC_FILES['new_data']) + self.pressure_coord_dataset = self.load_dataset(STATIC_FILES['pressure_coord']) #-------------------------------------------------------------------------------- # Compliance Tests @@ -297,6 +298,14 @@ def test_vertical_coordinate_type(self): var = MockVariable('NONAME', axis='Z') self.assertEqual(util.vertical_coordinate_type(self.good_dataset, var), 'unknown') + def test_vertical_coordinate_type_pressure(self): + var = MockVariable('NONAME', standard_name='sea_water_pressure') + self.assertIsNone(util.vertical_coordinate_type(self.pressure_coord_dataset, var)) + var = MockVariable('NONAME', standard_name='sea_water_pressure', axis='Z') + self.assertEqual(util.vertical_coordinate_type(self.pressure_coord_dataset, var), 'pressure') + var = self.pressure_coord_dataset.variables['PRES'] + self.assertEqual(util.vertical_coordinate_type(self.pressure_coord_dataset, var), 'pressure') + ### Test compliance checks @@ -638,6 +647,12 @@ def test_check_vertical_variable(self): self.assertIn(result.name[1], ('DEPTH', 'NOMINAL_DEPTH')) self.assertTrue(result.value) + ret_val = self.imos.check_vertical_variable(self.pressure_coord_dataset) + self.assertGreater(len(ret_val), 0) + for result in ret_val: + self.assertEqual(result.name[1], 'PRES') + self.assertTrue(result.value) + ret_val = self.imos.check_vertical_variable(self.bad_coords_dataset) self.assertEqual(len(ret_val), 23) for result in ret_val: