def test_check_geospatial_vars_have_attrs(self):

        # create geophysical variable
        ds = MockTimeSeries()  # time, lat, lon, depth
        temp = ds.createVariable("temp", np.float64, dimensions=("time", ))

        # should fail here
        results = self.ioos.check_geospatial_vars_have_attrs(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # should pass - default_fill_value sets _FillValue attr
        ds = MockTimeSeries(
            default_fill_value=9999999999.0)  # time, lat, lon, depth

        ds.variables["time"].setncattr("standard_name", "time")
        ds.variables["time"].setncattr(
            "standard_name_url",
            "http://cfconventions.org/Data/cf-standard-names/64/build/cf-standard-name-table.html",
        )
        ds.variables["time"].setncattr("units",
                                       "hours since 1970-01-01T00:00:00")
        ds.variables["time"].setncattr("missing_value", 9999999999.0)

        results = self.ioos.check_geospatial_vars_have_attrs(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)
    def test_check_standard_name(self):
        ds = MockTimeSeries()  # time, lat, lon, depth

        # no standard names
        results = self.ioos.check_standard_name(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # give standard names to all variables
        ds.variables["time"].setncattr("standard_name", "time")
        ds.variables["lon"].setncattr("standard_name", "longitude")
        ds.variables["lat"].setncattr("standard_name", "latitude")
        ds.variables["depth"].setncattr("standard_name", "depth")
        results = self.ioos.check_standard_name(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # add a QARTOD variable, no standard name - should fail
        qr = ds.createVariable("depth_qc", np.byte)
        qr.setncattr("flag_meanings", "blah")
        results = self.ioos.check_standard_name(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # bad standard name
        qr.setncattr("standard_name", "blah")
        results = self.ioos.check_standard_name(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # good standard name
        qr.setncattr("standard_name", "spike_test_quality_flag")
        results = self.ioos.check_standard_name(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)
    def test_check_geophysical_vars_have_attrs(self):

        # create geophysical variable
        ds = MockTimeSeries()  # time, lat, lon, depth
        temp = ds.createVariable("temp", np.float64, dimensions=("time", ))

        # should fail here
        results = self.ioos.check_geophysical_vars_have_attrs(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # set the necessary attributes
        ds = MockTimeSeries(
            default_fill_value=9999999999.0)  # time, lat, lon, depth
        temp = ds.createVariable("temp", np.float64,
                                 fill_value=9999999999.0)  # _FillValue
        temp.setncattr("missing_value", 9999999999.0)
        temp.setncattr("standard_name", "sea_surface_temperature")
        temp.setncattr(
            "standard_name_url",
            "http://cfconventions.org/Data/cf-standard-names/64/build/cf-standard-name-table.html",
        )
        temp.setncattr("units", "degree_C")
        temp.setncattr("platform", "myPlatform")

        results = self.ioos.check_geophysical_vars_have_attrs(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)
Пример #4
0
    def test_check_accuracy(self):
        ds = MockTimeSeries()  # time, lat, lon, depth
        temp = ds.createVariable("temp",
                                 np.float64,
                                 dimensions=("time", ),
                                 fill_value=9999999999.0)  # _FillValue
        temp.setncattr("standard_name", "sea_water_temperature")
        results = self.ioos.check_accuracy(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # add non-numeric vals for accuracy
        # no gts_ingest attr, so only existence tested
        temp.setncattr("accuracy", "bad")
        results = self.ioos.check_accuracy(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # add gts_ingest, accuracy should be numeric
        temp.setncattr("gts_ingest", "true")
        temp.setncattr("standard_name", "sea_water_practical_salinity")
        temp.setncattr("accuracy", "45")
        results = self.ioos.check_accuracy(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # add numeric for accuracy
        temp.setncattr("gts_ingest", "true")
        temp.setncattr("standard_name", "sea_water_practical_salinity")
        temp.setncattr("accuracy", 45)
        results = self.ioos.check_accuracy(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)
    def test_check_instrument_variables(self):

        ds = MockTimeSeries()  # time, lat, lon, depth

        # no instrument variable, should pass
        results = self.ioos.check_instrument_variables(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        temp = ds.createVariable("temp", np.float64, dimensions=("time",))
        temp.setncattr("cf_role", "timeseries")
        temp.setncattr("standard_name", "sea_surface_temperature")
        temp.setncattr("units", "degree_C")
        temp.setncattr("axis", "Y")
        temp.setncattr("instrument", "myInstrument")
        temp[:] = 45.0
        instr = ds.createVariable("myInstrument", np.float64, dimensions=("time",))

        # give instrument variable with component
        instr.setncattr("component", "someComponent")
        results = self.ioos.check_instrument_variables(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # give discriminant
        instr.setncattr("discriminant", "someDiscriminant")
        results = self.ioos.check_instrument_variables(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # bad component
        instr.setncattr("component", 45)
        results = self.ioos.check_instrument_variables(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)
    def test_check_qartod_variables_references(self):
        ds = MockTimeSeries()  # time, lat, lon, depth

        # no QARTOD variables
        results = self.ioos.check_qartod_variables_references(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # QARTOD variable without references (fail)
        qr = ds.createVariable("depth_qc", np.byte)
        qr.setncattr("flag_meanings", "blah")
        qr.setncattr("standard_name", "spike_test_quality_flag")
        results = self.ioos.check_qartod_variables_references(ds)
        self.assertFalse(all(r.value for r in results))

        # QARTOD variable with references (pass)
        qr.setncattr("references", "http://services.cormp.org/quality.php")
        results = self.ioos.check_qartod_variables_references(ds)
        self.assertTrue(all(r.value for r in results))
        self.assertEqual(results[0].msgs, [])  # only one Result to test

        # QARTOD variable with bad references (fail)
        qr.setncattr("references",
                     r"p9q384ht09q38@@####???????////??//\/\/\/\//\/\74ht")
        results = self.ioos.check_qartod_variables_references(ds)
        self.assertFalse(all(r.value for r in results))
Пример #7
0
    def test_check_contributor_role_and_vocabulary(self):
        ds = MockTimeSeries()

        # no values, fail
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # valid role, no vocab, fail
        ds.setncattr("contributor_role", "editor")
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # valid role, valid vocab, pass
        ds.setncattr(
            "contributor_role_vocabulary",
            "https://vocab.nerc.ac.uk/collection/G04/current/",
        )
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # one valid role, one valid vocab, should fail
        ds.setncattr("contributor_role", "editor,notvalid")
        ds.setncattr(
            "contributor_role_vocabulary",
            "https://vocab.nerc.ac.uk/collection/G04/current/,notvalid",
        )
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # both valid
        ds.setncattr("contributor_role", "editor,coAuthor")
        ds.setncattr(
            "contributor_role_vocabulary",
            "https://vocab.nerc.ac.uk/collection/G04/current/,https://www.ngdc.noaa.gov/wiki/index.php?title=ISO_19115_and_19115-2_CodeList_Dictionaries#CI_RoleCode",
        )
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # bad value type
        ds.setncattr("contributor_role", 21)
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        ds.setncattr("contributor_role", "editor,coAuthor")
        ds.setncattr("contributor_role_vocabulary", 64)
        results = self.ioos.check_contributor_role_and_vocabulary(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)
Пример #8
0
    def test_check_instrument_make_model_calib_date(self):
        """
        Per the IOOS-1.2 spec, instrument variables should have
        make_model and calibration_date attributes.
        """
        ds = MockTimeSeries()  # time, lat, lon, depth

        results = self.ioos.check_instrument_make_model_calib_date(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # make an instrument variable
        temp = ds.createVariable("temperature", "d", dimensions=("time", ))
        temp.setncattr("instrument", "inst")
        inst = ds.createVariable(
            "inst", "d", dimensions=())  # no make_model or calibration_date
        results = self.ioos.check_instrument_make_model_calib_date(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # add make_model
        inst.setncattr("make_model", "yessir")
        results = self.ioos.check_instrument_make_model_calib_date(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        # add calibration_date
        inst.setncattr("calibration_date", "2020-08-19")  # not ISO, fail
        results = self.ioos.check_instrument_make_model_calib_date(ds)
        scored, out_of, messages = get_results(results)
        self.assertLess(scored, out_of)

        inst.setncattr("calibration_date", "2020-08-19T00:00:00")  # ISO, pass
        results = self.ioos.check_instrument_make_model_calib_date(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)
    def test_check_qartod_variables_flags(self):
        ds = MockTimeSeries()  # time, lat, lon, depth

        # no QARTOD variables
        results = self.ioos.check_qartod_variables_flags(ds)
        scored, out_of, messages = get_results(results)
        self.assertEqual(scored, out_of)

        # QARTOD variable without flag_values, flag_meanings (fail)
        qr = ds.createVariable("depth_qc", np.byte)
        qr.setncattr("standard_name", "spike_test_quality_flag")
        results = self.ioos.check_qartod_variables_flags(ds)
        self.assertTrue(not any(r.value for r in results))  # all False

        # QARTOD variable with flag meanings, without flag_meanings
        qr.setncattr("flag_values", np.array([0, 1, 2], dtype=np.byte))
        results = self.ioos.check_qartod_variables_flags(ds)
        self.assertEqual(results[0].value[0],
                         results[0].value[1])  # should pass
        self.assertFalse(results[1].value)  # still fail

        # QARTOD variable with flag meanings, flag_values
        qr.setncattr("flag_meanings", "x y z")  # alphanumeric, space-separated
        results = self.ioos.check_qartod_variables_flags(ds)
        self.assertEqual(results[0].value[0], results[0].value[1])  # pass
        self.assertEqual(results[1].value[0], results[1].value[1])  # pass

        # flag_values array not equal to length of flag_meanings
        qr.setncattr("flag_values", np.array([0, 1], dtype=np.byte))
        results = self.ioos.check_qartod_variables_flags(ds)
        self.assertLess(results[0].value[0],
                        results[0].value[1])  # should fail
        self.assertEqual(results[1].value[0], results[1].value[1])  # pass

        # flag_values right length, wrong type
        qr.setncattr("flag_values", np.array([0, 1, 2], dtype=np.float64))
        results = self.ioos.check_qartod_variables_flags(ds)
        self.assertLess(results[0].value[0],
                        results[0].value[1])  # should fail
        self.assertEqual(results[1].value[0], results[1].value[1])  # pass