def test_boundaries(self):
        '''
        Ensures that boundary variables are not listed as geophysical variables
        '''
        with Dataset(resources.STATIC_FILES['grid-boundaries']) as nc:
            assert 'lat_bnds' not in util.get_geophysical_variables(nc)
            assert 'lon_bnds' not in util.get_geophysical_variables(nc)
            assert 'lat_bnds' in util.get_cell_boundary_variables(nc)
            assert 'lon_bnds' in util.get_cell_boundary_variables(nc)

            boundary_map = util.get_cell_boundary_map(nc)
            assert boundary_map['lat'] == 'lat_bnds'
            assert boundary_map['lon'] == 'lon_bnds'
    def test_boundaries(self):
        '''
        Ensures that boundary variables are not listed as geophysical variables
        '''
        with Dataset(resources.STATIC_FILES['grid-boundaries']) as nc:
            assert 'lat_bnds' not in util.get_geophysical_variables(nc)
            assert 'lon_bnds' not in util.get_geophysical_variables(nc)
            assert 'lat_bnds' in util.get_cell_boundary_variables(nc)
            assert 'lon_bnds' in util.get_cell_boundary_variables(nc)

            boundary_map = util.get_cell_boundary_map(nc)
            assert boundary_map['lat'] == 'lat_bnds'
            assert boundary_map['lon'] == 'lon_bnds'
    def test_boundaries(self):
        """
        Ensures that boundary variables are not listed as geophysical variables
        """
        with Dataset(resources.STATIC_FILES["grid-boundaries"]) as nc:
            assert "lat_bnds" not in util.get_geophysical_variables(nc)
            assert "lon_bnds" not in util.get_geophysical_variables(nc)
            assert "lat_bnds" in util.get_cell_boundary_variables(nc)
            assert "lon_bnds" in util.get_cell_boundary_variables(nc)

            boundary_map = util.get_cell_boundary_map(nc)
            assert boundary_map["lat"] == "lat_bnds"
            assert boundary_map["lon"] == "lon_bnds"
 def test_3d_static_grid(self):
     '''
     Ensures 3D Static Grid detection works
     '''
     with Dataset(resources.STATIC_FILES['3d-static-grid']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_3d_static_grid(nc, variable), "{} is a 3D static grid".format(variable)
 def test_trajectory_single(self):
     '''
     Ensures trajectory-single detection works
     '''
     with Dataset(resources.STATIC_FILES['trajectory-single']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_single_trajectory(nc, variable), "{} is trajectory-single".format(variable)
Ejemplo n.º 6
0
    def get_applicable_variables(self, ds):
        """
        Returns a list of variable names that are applicable to ACDD Metadata
        Checks for variables. This includes geophysical and coordinate
        variables only.

        :param netCDF4.Dataset ds: An open netCDF dataset
        """
        if self._applicable_variables is None:
            self.applicable_variables = cfutil.get_geophysical_variables(ds)
            varname = cfutil.get_time_variable(ds)
            # avoid duplicates by checking if already present
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)
            varname = cfutil.get_lon_variable(ds)
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)
            varname = cfutil.get_lat_variable(ds)
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)
            varname = cfutil.get_z_variable(ds)
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)

        return self.applicable_variables
 def test_point(self):
     '''
     Ensures point detection works
     '''
     with Dataset(resources.STATIC_FILES['point']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_point(nc, variable), "{} is point".format(variable)
 def test_timeseries_profile_multi_station(self):
     '''
     Ensures timeseries profile multi station detection works
     '''
     with Dataset(resources.STATIC_FILES['timeseries-profile-multi-station']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries_profile_multi_station(nc, variable), "{} is timeseries-profile-multi-station".format(variable)
 def test_point(self):
     """
     Ensures point detection works
     """
     with Dataset(resources.STATIC_FILES["point"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_point(nc, variable), "{} is point".format(variable)
 def test_3d_regular_grid(self):
     '''
     Ensures 2U Regular Grid detection works
     '''
     with Dataset(resources.STATIC_FILES['3d-regular-grid']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_3d_regular_grid(nc, variable), "{} is 3d regular grid".format(variable)
 def test_multi_timeseries_incomplete(self):
     '''
     Ensures multi-timeseries-incomplete detection works
     '''
     with Dataset(resources.STATIC_FILES['multi-timeseries-incomplete']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_multi_timeseries_incomplete(nc, variable), "{} is multi-timeseries incomplete".format(variable)
 def test_timeseries_profile_ortho_depth(self):
     '''
     Ensures timeseries profile ortho depth detection works
     '''
     with Dataset(resources.STATIC_FILES['timeseries-profile-ortho-depth']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries_profile_ortho_depth(nc, variable), "{} is timeseries-profile-ortho-depth".format(variable)
 def test_profile_incomplete(self):
     '''
     Ensures profile-incomplete detection works
     '''
     with Dataset(resources.STATIC_FILES['profile-incomplete']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_profile_incomplete(nc, variable), "{} is profile-incomplete".format(variable)
 def test_profile_orthogonal(self):
     '''
     Ensures profile-orthogonal detection works
     '''
     with Dataset(resources.STATIC_FILES['profile-orthogonal']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_profile_orthogonal(nc, variable), "{} is profile-orthogonal".format(variable)
Ejemplo n.º 15
0
    def get_applicable_variables(self, ds):
        '''
        Returns a list of variable names that are applicable to ACDD Metadata
        Checks for variables. This includes geophysical and coordinate
        variables only.

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        if self._applicable_variables is None:
            self.applicable_variables = cfutil.get_geophysical_variables(ds)
            varname = cfutil.get_time_variable(ds)
            # avoid duplicates by checking if already present
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)
            varname = cfutil.get_lon_variable(ds)
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)
            varname = cfutil.get_lat_variable(ds)
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)
            varname = cfutil.get_z_variable(ds)
            if varname and (varname not in self.applicable_variables):
                self.applicable_variables.append(varname)

        return self.applicable_variables
Ejemplo n.º 16
0
    def check_var_coverage_content_type(self, ds):
        '''
        Check coverage content type against valid ISO-19115-1 codes

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        results = []
        for variable in cfutil.get_geophysical_variables(ds):
            msgs = []
            ctype = getattr(ds.variables[variable], 'coverage_content_type',
                            None)
            check = ctype is not None
            if not check:
                msgs.append("Var %s missing attr coverage_content_type" %
                            variable)
                results.append(
                    Result(BaseCheck.HIGH, check,
                           (variable, "coverage_content_type"), msgs))
                continue

            # ISO 19115-1 codes
            valid_ctypes = {
                'image', 'thematicClassification', 'physicalMeasurement',
                'auxiliaryInformation', 'qualityInformation',
                'referenceInformation', 'modelResult', 'coordinate'
            }
            if ctype not in valid_ctypes:
                msgs.append(
                    "Var %s does not have a coverage_content_type in %s" %
                    (variable, sorted(valid_ctypes)))

        return results
 def test_timeseries_profile_single_ortho_time(self):
     '''
     Ensures timeseries profile single station ortho time detection works
     '''
     with Dataset(resources.STATIC_FILES['timeseries-profile-single-ortho-time']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries_profile_single_ortho_time(nc, variable), "{} is timeseries-profile-single-ortho-time".format(variable)
 def test_multi_timeseries_orthogonal(self):
     '''
     Ensures multi-timeseries-orthogonal detection works
     '''
     with Dataset(resources.STATIC_FILES['multi-timeseries-orthogonal']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_multi_timeseries_orthogonal(nc, variable), "{} is multi-timeseries orthogonal".format(variable)
 def test_timeseries(self):
     '''
     Ensures timeseries detection works
     '''
     with Dataset(resources.STATIC_FILES['timeseries']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries(nc, variable), "{} is timeseries".format(variable)
 def test_3d_static_grid(self):
     '''
     Ensures 3D Static Grid detection works
     '''
     with Dataset(resources.STATIC_FILES['3d-static-grid']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_3d_static_grid(
                 nc, variable), "{} is a 3D static grid".format(variable)
 def test_3d_regular_grid(self):
     '''
     Ensures 2U Regular Grid detection works
     '''
     with Dataset(resources.STATIC_FILES['3d-regular-grid']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_3d_regular_grid(
                 nc, variable), "{} is 3d regular grid".format(variable)
 def test_trajectory_single(self):
     '''
     Ensures trajectory-single detection works
     '''
     with Dataset(resources.STATIC_FILES['trajectory-single']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_single_trajectory(
                 nc, variable), "{} is trajectory-single".format(variable)
 def test_timeseries(self):
     '''
     Ensures timeseries detection works
     '''
     with Dataset(resources.STATIC_FILES['timeseries']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries(
                 nc, variable), "{} is timeseries".format(variable)
 def test_profile_incomplete(self):
     '''
     Ensures profile-incomplete detection works
     '''
     with Dataset(resources.STATIC_FILES['profile-incomplete']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_profile_incomplete(
                 nc, variable), "{} is profile-incomplete".format(variable)
 def test_profile_orthogonal(self):
     '''
     Ensures profile-orthogonal detection works
     '''
     with Dataset(resources.STATIC_FILES['profile-orthogonal']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_profile_orthogonal(
                 nc, variable), "{} is profile-orthogonal".format(variable)
 def test_2d_static_grid(self):
     """
     Ensures 2D Static Grid detection works
     """
     with Dataset(resources.STATIC_FILES["2d-static-grid"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_2d_static_grid(
                 nc, variable
             ), "{} is a 2D static grid".format(variable)
 def test_timeseries_profile_ortho_depth(self):
     """
     Ensures timeseries profile ortho depth detection works
     """
     with Dataset(resources.STATIC_FILES["timeseries-profile-ortho-depth"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries_profile_ortho_depth(
                 nc, variable
             ), "{} is timeseries-profile-ortho-depth".format(variable)
 def test_2d_regular_grid(self):
     """
     Ensures 2D Regular Grid detection works
     """
     with Dataset(resources.STATIC_FILES["2d-regular-grid"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_2d_regular_grid(
                 nc, variable
             ), "{} is 2D regular grid".format(variable)
 def test_multi_timeseries_incomplete(self):
     """
     Ensures multi-timeseries-incomplete detection works
     """
     with Dataset(resources.STATIC_FILES["multi-timeseries-incomplete"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_multi_timeseries_incomplete(
                 nc, variable
             ), "{} is multi-timeseries incomplete".format(variable)
 def test_trajectory(self):
     """
     Ensures trajectory detection works
     """
     with Dataset(resources.STATIC_FILES["trajectory"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_cf_trajectory(nc, variable), "{} is trajectory".format(
                 variable
             )
 def test_timeseries_profile_single_station(self):
     """
     Ensures timeseries profile single station detection works
     """
     with Dataset(resources.STATIC_FILES["timeseries-profile-single-station"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries_profile_single_station(
                 nc, variable
             ), "{} is timeseries-profile-single-station".format(variable)
 def test_trajectory_profile_incomplete(self):
     """
     Ensures trajectory profile incomplete detection works
     """
     with Dataset(resources.STATIC_FILES["trajectory-profile-incomplete"]) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_trajectory_profile_incomplete(
                 nc, variable
             ), "{} is trajectory profile incomplete".format(variable)
 def test_climatology(self):
     """
     Ensures that climatology variables are identified as climatology variables and not geophysical variables
     """
     with Dataset(resources.STATIC_FILES["climatology"]) as nc:
         geophysical_variables = util.get_geophysical_variables(nc)
         climatology_variable = util.get_climatology_variable(nc)
         assert "temperature" in geophysical_variables
         assert "climatology_bounds" not in geophysical_variables
         assert "climatology_bounds" == climatology_variable
 def test_multi_timeseries_orthogonal(self):
     '''
     Ensures multi-timeseries-orthogonal detection works
     '''
     with Dataset(
             resources.STATIC_FILES['multi-timeseries-orthogonal']) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_multi_timeseries_orthogonal(
                 nc, variable), "{} is multi-timeseries orthogonal".format(
                     variable)
 def test_climatology(self):
     '''
     Ensures that climatology variables are identified as climatology variables and not geophysical variables
     '''
     with Dataset(resources.STATIC_FILES['climatology']) as nc:
         geophysical_variables = util.get_geophysical_variables(nc)
         climatology_variable = util.get_climatology_variable(nc)
         assert 'temperature' in geophysical_variables
         assert 'climatology_bounds' not in geophysical_variables
         assert 'climatology_bounds' == climatology_variable
 def test_climatology(self):
     '''
     Ensures that climatology variables are identified as climatology variables and not geophysical variables
     '''
     with Dataset(resources.STATIC_FILES['climatology']) as nc:
         geophysical_variables = util.get_geophysical_variables(nc)
         climatology_variable = util.get_climatology_variable(nc)
         assert 'temperature' in geophysical_variables
         assert 'climatology_bounds' not in geophysical_variables
         assert 'climatology_bounds' == climatology_variable
 def test_timeseries_profile_multi_ortho_time(self):
     '''
     Ensures timeseries profile multi station ortho time detection works
     '''
     with Dataset(
             resources.STATIC_FILES['timeseries-profile-multi-ortho-time']
     ) as nc:
         for variable in util.get_geophysical_variables(nc):
             assert util.is_timeseries_profile_multi_ortho_time(
                 nc, variable
             ), "{} is timeseries-profile-multi-ortho-time".format(variable)
Ejemplo n.º 38
0
    def check_geophysical_vars_standard_name(self, ds):
        '''
        Check that geophysical variables contain standard names.

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        results = []
        for geo_var in get_geophysical_variables(ds):
            results.append(
                self._has_var_attr(ds, geo_var, 'standard_name',
                                   'geophysical variables standard_name'), )
        return results
Ejemplo n.º 39
0
    def check_geophysical_vars_fill_value(self, ds):
        '''
        Check that geophysical variables contain fill values.

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        results = []
        for geo_var in get_geophysical_variables(ds):
            results.append(
                self._has_var_attr(ds, geo_var, '_FillValue', '_FillValue',
                                   BaseCheck.MEDIUM), )
        return results
Ejemplo n.º 40
0
    def check_geophysical_vars_fill_value(self, ds):
        '''
        Check that geophysical variables contain fill values.

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        results = []
        for geo_var in get_geophysical_variables(ds):
            results.append(
                self._has_var_attr(ds, geo_var, '_FillValue', '_FillValue', BaseCheck.MEDIUM),
            )
        return results
Ejemplo n.º 41
0
    def check_geophysical_vars_standard_name(self, ds):
        '''
        Check that geophysical variables contain standard names.

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        results = []
        for geo_var in get_geophysical_variables(ds):
            results.append(
                self._has_var_attr(ds, geo_var, 'standard_name', 'geophysical variables standard_name'),
            )
        return results
    def test_forecast_reference_metadata(self):
        """
        Tests variables used for forecast reference metadata to ensure they are
        not misclassified as geophysical variables.
        """
        with Dataset(resources.STATIC_FILES["forecast_reference"]) as nc:
            self.assertFalse(util.is_geophysical(nc, "forecast_reference_time"))
            self.assertFalse(util.is_geophysical(nc, "forecast_hour"))
            self.assertTrue(util.is_geophysical(nc, "air_temp"))
            self.assertFalse(util.is_geophysical(nc, "time"))

            assert len(util.get_coordinate_variables(nc)) == 3
            assert len(util.get_geophysical_variables(nc)) == 1
Ejemplo n.º 43
0
    def check_var_coverage_content_type(self, ds):
        """
        Check coverage content type against valid ISO-19115-1 codes

        :param netCDF4.Dataset ds: An open netCDF dataset
        """
        results = []
        for variable in cfutil.get_geophysical_variables(ds):
            msgs = []
            ctype = getattr(ds.variables[variable], "coverage_content_type", None)
            check = ctype is not None
            if not check:
                msgs.append("coverage_content_type")
                results.append(
                    Result(
                        BaseCheck.HIGH, check, self._var_header.format(variable), msgs
                    )
                )
                continue

            # ISO 19115-1 codes
            valid_ctypes = {
                "image",
                "thematicClassification",
                "physicalMeasurement",
                "auxiliaryInformation",
                "qualityInformation",
                "referenceInformation",
                "modelResult",
                "coordinate",
            }
            if ctype not in valid_ctypes:
                msgs.append(
                    'coverage_content_type in "%s"' % (variable, sorted(valid_ctypes))
                )
                results.append(
                    Result(
                        BaseCheck.HIGH,
                        check,  # append to list
                        self._var_header.format(variable),
                        msgs,
                    )
                )

        return results
Ejemplo n.º 44
0
    def get_applicable_variables(self, ds):
        '''
        Returns a list of variable names that are applicable to ACDD Metadata
        Checks for variables. This includes geophysical and coordinate
        variables only.

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        if self._applicable_variables is None:
            self.applicable_variables = cfutil.get_geophysical_variables(ds)
            varname = cfutil.get_time_variable(ds)
            if varname:
                self.applicable_variables.append(varname)
            varname = cfutil.get_lon_variable(ds)
            if varname:
                self.applicable_variables.append(varname)
            varname = cfutil.get_lat_variable(ds)
            if varname:
                self.applicable_variables.append(varname)
            varname = cfutil.get_z_variable(ds)
            if varname:
                self.applicable_variables.append(varname)
        return self.applicable_variables
Ejemplo n.º 45
0
    def check_var_coverage_content_type(self, ds):
        '''
        Check coverage content type against valid ISO-19115-1 codes

        :param netCDF4.Dataset ds: An open netCDF dataset
        '''
        results = []
        for variable in cfutil.get_geophysical_variables(ds):
            msgs = []
            ctype = getattr(ds.variables[variable],
                            'coverage_content_type', None)
            check = ctype is not None
            if not check:
                msgs.append("coverage_content_type")
                results.append(Result(BaseCheck.HIGH, check,
                                      self._var_header.format(variable), msgs))
                continue

            # ISO 19115-1 codes
            valid_ctypes = {
                'image',
                'thematicClassification',
                'physicalMeasurement',
                'auxiliaryInformation',
                'qualityInformation',
                'referenceInformation',
                'modelResult',
                'coordinate'
            }
            if ctype not in valid_ctypes:
                msgs.append("coverage_content_type in \"%s\""
                            % (variable, sorted(valid_ctypes)))
                results.append(Result(BaseCheck.HIGH, check, # append to list
                                      self._var_header.format(variable), msgs))

        return results