def test_is_vertical_coordinate(self):
        '''
        Section 4.3 Qualifiers for Vertical Coordinate

        NOTE: The standard doesn't explicitly say that vertical coordinates must be a
        coordinate type.
        '''
        # Make something that I can attach attrs to
        mock_variable = MockVariable

        # Proper name/standard_name
        known_name = mock_variable()
        known_name.standard_name = 'depth'
        self.assertTrue(is_vertical_coordinate('not_known', known_name))

        # Proper Axis
        axis_set = mock_variable()
        axis_set.axis = 'Z'
        self.assertTrue(is_vertical_coordinate('not_known', axis_set))

        # Proper units
        units_set = mock_variable()
        units_set.units = 'dbar'
        self.assertTrue(is_vertical_coordinate('not_known', units_set))

        # Proper units/positive
        positive = mock_variable()
        positive.units = 'm'
        positive.positive = 'up'
        self.assertTrue(is_vertical_coordinate('not_known', positive))
Beispiel #2
0
    def test_is_vertical_coordinate(self):
        '''
        Section 4.3 Qualifiers for Vertical Coordinate

        NOTE: The standard doesn't explicitly say that vertical coordinates must be a
        coordinate type.
        '''
        # Make something that I can attach attrs to
        mock_variable = MockVariable

        # Proper name/standard_name
        known_name = mock_variable()
        known_name.standard_name = 'depth'
        self.assertTrue(is_vertical_coordinate('not_known', known_name))

        # Proper Axis
        axis_set = mock_variable()
        axis_set.axis = 'Z'
        self.assertTrue(is_vertical_coordinate('not_known', axis_set))

        # Proper units
        units_set = mock_variable()
        units_set.units = 'dbar'
        self.assertTrue(is_vertical_coordinate('not_known', units_set))

        # Proper units/positive
        positive = mock_variable()
        positive.units = 'm'
        positive.positive = 'up'
        self.assertTrue(is_vertical_coordinate('not_known', positive))
Beispiel #3
0
    def test_is_vertical_coordinate(self):
        """
        Section 4.3 Qualifiers for Vertical Coordinate

        NOTE: The standard doesn't explicitly say that vertical coordinates must be a 
        coordinate type.
        """
        # Make something that I can attach attrs to
        mock_variable = MockVariable

        # Proper name/standard_name
        known_name = mock_variable()
        known_name.standard_name = "depth"
        self.assertTrue(is_vertical_coordinate("not_known", known_name))

        # Proper Axis
        axis_set = mock_variable()
        axis_set.axis = "Z"
        self.assertTrue(is_vertical_coordinate("not_known", axis_set))

        # Proper units
        units_set = mock_variable()
        units_set.units = "dbar"
        self.assertTrue(is_vertical_coordinate("not_known", units_set))

        # Proper units/positive
        positive = mock_variable()
        positive.units = "m"
        positive.positive = "up"
        self.assertTrue(is_vertical_coordinate("not_known", positive))
Beispiel #4
0
    def check_vertical_extents(self, ds):
        """
        Check that the values of geospatial_vertical_min/geospatial_vertical_max approximately match the data.
        """
        if not (hasattr(ds, 'geospatial_vertical_min')
                and hasattr(ds, 'geospatial_vertical_max')):
            return

        vert_min = ds.geospatial_vertical_min
        vert_max = ds.geospatial_vertical_max

        # identify vertical vars as per CF 4.3
        v_vars = [
            var for name, var in ds.variables.items()
            if is_vertical_coordinate(name, var)
        ]

        if len(v_vars) == 0:
            return Result(
                BaseCheck.MEDIUM, False, 'geospatial_vertical_extents_match', [
                    'Could not find vertical variable to test extent of geospatial_vertical_min/geospatial_vertical_max, see CF-1.6 spec chapter 4.3'
                ])

        obs_mins = {
            var._name: np.nanmin(var)
            for var in v_vars if not np.isnan(var).all()
        }
        obs_maxs = {
            var._name: np.nanmax(var)
            for var in v_vars if not np.isnan(var).all()
        }

        min_pass = any(
            (np.isclose(vert_min, min_val) for min_val in obs_mins.values()))
        max_pass = any(
            (np.isclose(vert_max, max_val) for max_val in obs_maxs.values()))

        allpass = sum((min_pass, max_pass))

        msgs = []
        if not min_pass:
            msgs.append(
                "Data for possible vertical variables (%s) did not match geospatial_vertical_min value (%s)"
                % (obs_mins, vert_min))
        if not max_pass:
            msgs.append(
                "Data for possible vertical variables (%s) did not match geospatial_vertical_max value (%s)"
                % (obs_maxs, vert_max))

        return Result(BaseCheck.MEDIUM, (allpass, 2),
                      'geospatial_vertical_extents_match', msgs)
Beispiel #5
0
    def check_vertical_extents(self, ds):
        """
        Check that the values of geospatial_vertical_min/geospatial_vertical_max approximately match the data.
        """
        if not (hasattr(ds, "geospatial_vertical_min") and hasattr(ds, "geospatial_vertical_max")):
            return

        vert_min = ds.geospatial_vertical_min
        vert_max = ds.geospatial_vertical_max

        # identify vertical vars as per CF 4.3
        v_vars = [var for name, var in ds.variables.items() if is_vertical_coordinate(name, var)]

        if len(v_vars) == 0:
            return Result(
                BaseCheck.MEDIUM,
                False,
                "geospatial_vertical_extents_match",
                [
                    "Could not find vertical variable to test extent of geospatial_vertical_min/geospatial_vertical_max, see CF-1.6 spec chapter 4.3"
                ],
            )

        obs_mins = {var._name: np.nanmin(var) for var in v_vars if not np.isnan(var).all()}
        obs_maxs = {var._name: np.nanmax(var) for var in v_vars if not np.isnan(var).all()}

        min_pass = any((np.isclose(vert_min, min_val) for min_val in obs_mins.values()))
        max_pass = any((np.isclose(vert_max, max_val) for max_val in obs_maxs.values()))

        allpass = sum((min_pass, max_pass))

        msgs = []
        if not min_pass:
            msgs.append(
                "Data for possible vertical variables (%s) did not match geospatial_vertical_min value (%s)"
                % (obs_mins, vert_min)
            )
        if not max_pass:
            msgs.append(
                "Data for possible vertical variables (%s) did not match geospatial_vertical_max value (%s)"
                % (obs_maxs, vert_max)
            )

        return Result(BaseCheck.MEDIUM, (allpass, 2), "geospatial_vertical_extents_match", msgs)