Ejemplo n.º 1
0
    def _bag_checks_v2_gdal_compatibility(self, grid_file: str) -> None:
        if self._gdal_compatibility is False:
            self._bc_report += "GDAL Compatibility [SKIP_SEC]"
            self._bc_report += "All GDAL-compatibility-related checks are deactivated. [SKIP_REP]"
            return

        self._bc_report += "GDAL Compatibility [SECTION]"

        self._bc_gdal_compatibility_errors = 0
        self._bc_gdal_compatibility_warnings = 0

        try:
            bf = bag.BAGFile(grid_file)

            # CHK: Too many refinement grids
            self._bc_report += "Check for 'Too many refinement grids' GDAL error [CHECK]"
            bf_rows, bf_cols = bf.elevation_shape()
            if self._is_vr and ((bf_rows * bf_cols) > 10000000):
                self._bc_gdal_compatibility_warnings += 1
                self._bc_report += "[WARNING] Too big super-grid: %d, %d" % (bf_rows, bf_cols)
                return
            else:
                self._bc_report += "OK"

        except Exception as e:
            traceback.print_exc()
            self._bc_report += "Other potential issues [CHECK]"
            self._bc_gdal_compatibility_errors += 1
            self._bc_report += "[ERROR] Unexpected issue: %s" % e
Ejemplo n.º 2
0
    def _bag_checks_v2_elevation(self, grid_file: str) -> None:
        if self._elevation is False:
            self._bc_report += "Elevation [SKIP_SEC]"
            self._bc_report += "All elevation-related checks are deactivated. [SKIP_REP]"
            return

        self._bc_report += "Elevation [SECTION]"

        self._bc_elevation_errors = 0
        self._bc_elevation_warnings = 0

        try:
            bf = bag.BAGFile(grid_file)

            # CHK: presence of elevation
            self._bc_report += "Check the presence of the Elevation dataset [CHECK]"
            if not bf.has_elevation():
                self._bc_elevation_errors += 1
                self._bc_report += "[ERROR] Missing the Elevation dataset"
                return
            else:
                self._bc_report += "OK"

            self._cur_min_depth, self._cur_max_depth = bf.depth_min_max()
            logger.debug('min/max depth: %.2f/%.2f' % (self._cur_min_depth, self._cur_max_depth))

            # CHK: all NaN
            self._bc_report += "Check that all the values are not NaN [CHECK]"
            if np.isnan(self._cur_min_depth):  # all NaN case
                self._bc_elevation_warnings += 1
                self._bc_report += "[WARNING] All elevation values are NaN"
            else:
                self._bc_report += "OK"

            if self._is_vr:
                # CHK: presence of VR Refinements
                self._bc_report += "Check the presence of the VR Refinements dataset [CHECK]"
                if not bf.has_varres_refinements():
                    self._bc_elevation_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Refinements dataset"
                else:
                    self._bc_report += "OK"

                self._cur_vr_min_depth, self._cur_vr_max_depth = bf.vr_depth_min_max()
                logger.debug('VR min/max depth: %.2f/%.2f' % (self._cur_vr_min_depth, self._cur_vr_max_depth))

                # CHK: VR depth all NaN
                self._bc_report += "Check that all the VR depth values are not NaN [CHECK]"
                if np.isnan(self._cur_vr_min_depth):  # all NaN case
                    self._bc_elevation_warnings += 1
                    self._bc_report += "[WARNING] All VR elevation values are NaN"
                else:
                    self._bc_report += "OK"

        except Exception as e:
            traceback.print_exc()
            self._bc_report += "Other potential issues [CHECK]"
            self._bc_elevation_errors += 1
            self._bc_report += "[ERROR] Unknown issue: %s" % e
Ejemplo n.º 3
0
    def _bag_checks_v1_tracking_list(self, grid_file: str) -> None:
        if self._tracking_list is False:
            self._bc_report += "Tracking List [SKIP_SEC]"
            self._bc_report += "All tracking-list-related checks are deactivated. [SKIP_REP]"
            return

        self._bc_report += "Tracking List [SECTION]"

        self._bc_tracking_list_errors = 0
        self._bc_tracking_list_warnings = 0

        try:
            bf = bag.BAGFile(grid_file)

            # CHK: presence of tracking list
            self._bc_report += "Check the presence of the Tracking List dataset [CHECK]"
            if not bf.has_tracking_list():
                self._bc_tracking_list_errors += 1
                self._bc_report += "[ERROR] Missing the Tracking List dataset"
                return
            else:
                self._bc_report += "OK"

            # CHK validity of row columns
            self._bc_report += "Check the validity of 'row' columns [CHECK]"
            if not bf.has_valid_row_in_tracking_list():
                self._bc_tracking_list_errors += 1
                self._bc_report += "[ERROR] At least 1 invalid value in 'row' columns"
            else:
                self._bc_report += "OK"

            # CHK validity of col columns
            self._bc_report += "Check the validity of 'col' columns [CHECK]"
            if not bf.has_valid_col_in_tracking_list():
                self._bc_tracking_list_errors += 1
                self._bc_report += "[ERROR] At least 1 invalid value in 'col' columns"
            else:
                self._bc_report += "OK"

            if self._is_vr:
                # CHK: presence of VR Tracking List
                self._bc_report += "Check the presence of the VR Tracking List dataset [CHECK]"
                if not bf.has_varres_tracking_list():
                    self._bc_tracking_list_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Tracking List dataset"
                else:
                    self._bc_report += "OK"

        except Exception as e:
            traceback.print_exc()
            self._bc_report += "Other potential issues [CHECK]"
            self._bc_tracking_list_errors += 1
            self._bc_report += "[ERROR] Unexpected issue: %s" % e
Ejemplo n.º 4
0
    def _bag_checks_v1_uncertainty(self, grid_file: str) -> None:
        if self._uncertainty is False:
            self._bc_report += "Uncertainty [SKIP_SEC]"
            self._bc_report += "All uncertainty-related checks are deactivated. [SKIP_REP]"
            return

        self._bc_report += "Uncertainty [SECTION]"

        self._bc_uncertainty_errors = 0
        self._bc_uncertainty_warnings = 0

        try:
            bf = bag.BAGFile(grid_file)

            # CHK: presence of uncertainty
            self._bc_report += "Check the presence of the Uncertainty dataset [CHECK]"
            if not bf.has_uncertainty():
                self._bc_uncertainty_errors += 1
                self._bc_report += "[ERROR] Missing the Uncertainty dataset"
                return
            else:
                self._bc_report += "OK"

            if self._cur_max_depth is None:
                self._cur_min_depth, self._cur_max_depth = bf.depth_min_max()
            logger.debug('min/max depth: %.2f/%.2f' %
                         (self._cur_min_depth, self._cur_max_depth))
            if np.isnan(self._cur_max_depth) or (self._cur_max_depth < 0.0):
                high_unc_threshold = 2.0
            else:
                high_unc_threshold = 2.0 + 0.05 * self._cur_max_depth
            logger.debug('max uncertainty threshold: %.2f' %
                         (high_unc_threshold, ))

            # logger.debug('min/max elevation: %s/%s' % (min_elevation, max_elevation))
            min_uncertainty, max_uncertainty = bf.uncertainty_min_max()
            logger.debug('min/max uncertainty: %.2f/%.2f' %
                         (min_uncertainty, max_uncertainty))

            if self._noaa_nbs_profile:
                # CHK: all NaN
                self._bc_report += "Check that all the values are not NaN [CHECK]"
                if np.isnan(min_uncertainty):  # all NaN case
                    self._bc_uncertainty_warnings += 1
                    self._bc_report += "[WARNING] All uncertainty values are NaN"
                    return
                else:
                    self._bc_report += "OK"

            # CHK: negative uncertainty
            self._bc_report += "Check that uncertainty values are only positive [CHECK]"
            if min_uncertainty <= 0.0:
                self._bc_uncertainty_errors += 1
                self._bc_report += "[ERROR] At least one negative or zero value of uncertainty is present (%.3f)" \
                                   % min_uncertainty
            else:
                self._bc_report += "OK"

            if self._noaa_nbs_profile:
                # CHK: negative uncertainty
                self._bc_report += "Check that uncertainty values are not too high (<%.2fm) [CHECK]" \
                                   % high_unc_threshold
                if max_uncertainty >= high_unc_threshold:
                    self._bc_uncertainty_warnings += 1
                    self._bc_report += "[WARNING] Too high value for maximum uncertainty: %.2f" % max_uncertainty
                else:
                    self._bc_report += "OK"

            if self._is_vr:
                # CHK: presence of VR Refinements
                self._bc_report += "Check the presence of the VR Refinements dataset [CHECK]"
                if not bf.has_varres_refinements():
                    self._bc_uncertainty_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Refinements dataset"
                else:
                    self._bc_report += "OK"

                if self._cur_vr_max_depth is None:
                    self._cur_vr_min_depth, self._cur_vr_max_depth = bf.vr_depth_min_max(
                    )
                logger.debug('min/max elevation: %.2f/%.2f' %
                             (self._cur_vr_min_depth, self._cur_vr_max_depth))
                if np.isnan(self._cur_vr_max_depth) or (self._cur_vr_max_depth
                                                        < 0.0):
                    vr_high_unc_threshold = 2.0
                else:
                    vr_high_unc_threshold = 2.0 + 0.05 * self._cur_vr_max_depth
                logger.debug('VR uncertainty threshold: %.2f' %
                             (vr_high_unc_threshold, ))

                vr_min_uncertainty, vr_max_uncertainty = bf.vr_uncertainty_min_max(
                )
                logger.debug('VR min/max uncertainty: %.2f/%.2f' %
                             (vr_min_uncertainty, vr_max_uncertainty))

                if self._noaa_nbs_profile:
                    # CHK: all NaN
                    self._bc_report += "Check that all the VR values are not NaN [CHECK]"
                    if np.isnan(vr_min_uncertainty):  # all NaN case
                        self._bc_uncertainty_warnings += 1
                        self._bc_report += "[WARNING] All uncertainty values are NaN"
                        return
                    else:
                        self._bc_report += "OK"

                # CHK: negative uncertainty
                self._bc_report += "Check that VR uncertainty values are only positive [CHECK]"
                if vr_min_uncertainty <= 0.0:
                    self._bc_uncertainty_errors += 1
                    self._bc_report += "[ERROR] At least one negative or zero value of uncertainty is present (%.3f)" \
                                       % min_uncertainty
                else:
                    self._bc_report += "OK"

                if self._noaa_nbs_profile:
                    # CHK: negative uncertainty
                    self._bc_report += "Check that VR uncertainty values are not too high (<%.2fm) [CHECK]" \
                                       % vr_high_unc_threshold
                    if vr_max_uncertainty >= vr_high_unc_threshold:
                        self._bc_uncertainty_warnings += 1
                        self._bc_report += "[WARNING] Too high value for maximum uncertainty: %.2f" % vr_max_uncertainty
                    else:
                        self._bc_report += "OK"

        except Exception as e:
            traceback.print_exc()
            self._bc_report += "Other potential issues [CHECK]"
            self._bc_uncertainty_errors += 1
            self._bc_report += "[ERROR] Unuspected issue: %s" % e
Ejemplo n.º 5
0
    def _bag_checks_v1_metadata(self, grid_file: str) -> None:
        if self._metadata is False:
            self._bc_report += "Metadata [SKIP_SEC]"
            self._bc_report += "All metadata-related checks are deactivated. [SKIP_REP]"
            return

        self._bc_report += "Metadata [SECTION]"

        self._bc_metadata_errors = 0
        self._bc_metadata_warnings = 0

        try:
            bf = bag.BAGFile(grid_file)

            # CHK: presence of metadata
            self._bc_report += "Check the presence of the Metadata dataset [CHECK]"
            if not bf.has_metadata():
                self._bc_metadata_errors += 1
                self._bc_report += "[ERROR] Missing the Metadata dataset"
                return
            else:
                self._bc_report += "OK"

            bf.populate_metadata()
            # bf.extract_metadata('test.xml')

            if self._noaa_nbs_profile:

                # CHK: use of projected spatial reference system
                self._bc_report += "Check that the spatial reference system is projected [CHECK]"
                if bf.meta.wkt_srs is None:
                    if b"UTM" not in bf.meta.xml_srs:
                        self._bc_report += "[WARNING] The spatial reference system might be NOT projected [%s...]" \
                                           % bf.meta.xml_srs[:20]
                        self._bc_metadata_warnings += 1
                    else:
                        self._bc_report += "OK"
                else:
                    srs = osr.SpatialReference()
                    srs.ImportFromWkt(bf.meta.wkt_srs)
                    # check if projected coordinates
                    if not srs.IsProjected:
                        self._bc_report += "[WARNING] The spatial reference system does is NOT projected [%s...]" \
                                           % bf.meta.wkt_srs[:20]
                        self._bc_metadata_warnings += 1
                    else:
                        self._bc_report += "OK"

            # TODO: additional checks on SRS

            if self._noaa_nbs_profile:

                # CHK: definition of vertical datum
                self._bc_report += "Check that the vertical datum is defined [CHECK]"
                if bf.meta.wkt_vertical_datum is None:
                    if b"Unknown" in bf.meta.xml_vertical_datum:
                        self._bc_report += "[WARNING] The vertical datum might be unknown [%s...]" \
                                           % bf.meta.xml_vertical_datum[:20]
                        self._bc_metadata_warnings += 1
                    else:
                        self._bc_report += "OK"
                else:
                    if "unknown" in bf.meta.wkt_vertical_datum.lower():
                        self._bc_report += "[WARNING] The vertical datum is unknown [%s...]" \
                                           % bf.meta.wkt_vertical_datum[:20]
                        self._bc_metadata_warnings += 1
                    else:
                        self._bc_report += "OK"

            if self._noaa_nbs_profile:
                # CHK: presence of creation date
                self._bc_report += "Check the presence of the creation date [CHECK]"
                if bf.meta.date is None:
                    self._bc_report += "[WARNING] Unable to retrieve the creation date."
                    self._bc_metadata_warnings += 1
                else:
                    self._bc_report += "OK"

                # CHK: presence of survey start date
                self._bc_report += "Check the presence of the survey start date [CHECK]"
                if bf.meta.survey_start_date is None:
                    self._bc_report += "[WARNING] Unable to retrieve the survey start date."
                    self._bc_metadata_warnings += 1
                else:
                    self._bc_report += "OK"

                # CHK: presence of survey end date
                self._bc_report += "Check the presence of the survey end date [CHECK]"
                if bf.meta.survey_end_date is None:
                    self._bc_report += "[WARNING] Unable to retrieve the survey end date."
                    self._bc_metadata_warnings += 1
                else:
                    self._bc_report += "OK"

            if self._noaa_nbs_profile:
                # CHK: use of product uncertainty
                self._bc_report += "Check the selection of Product Uncertainty [CHECK]"
                if not bf.has_product_uncertainty():
                    self._bc_metadata_warnings += 1
                    self._bc_report += "[WARNING] The Uncertainty layer does not contain Product Uncertainty: %s" \
                                       % bf.meta.unc_type
                else:
                    self._bc_report += "OK"

            if self._is_vr:
                # CHK: presence of VR Metadata
                self._bc_report += "Check the presence of the VR Metadata dataset [CHECK]"
                if not bf.has_varres_metadata():
                    self._bc_metadata_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Metadata dataset"
                else:
                    self._bc_report += "OK"

        except Exception as e:
            traceback.print_exc()
            self._bc_report += "Other potential issues [CHECK]"
            self._bc_metadata_errors += 1
            self._bc_report += "[ERROR] Unexpected issue: %s" % e
Ejemplo n.º 6
0
    def _bag_checks_v1_structure(self, grid_file: str) -> None:
        if self._structure is False:
            self._bc_report += "Structure [SKIP_SEC]"
            self._bc_report += "All structure-related checks are deactivated. [SKIP_REP]"
            return

        self._bc_report += "Structure [SECTION]"

        self._bc_structure_errors = 0
        self._bc_structure_warnings = 0

        try:
            bf = bag.BAGFile(grid_file)
            # logger.debug('BAG version: %s' % bf.bag_version())

            # CHK: presence of root
            self._bc_report += "Check the presence of the BAG Root group [CHECK]"
            if not bf.has_bag_root():
                self._bc_structure_errors += 1
                self._bc_report += "[ERROR] Missing the BAG Root group"
            else:
                self._bc_report += "OK"

            # CHK: presence of version
            self._bc_report += "Check the presence of the BAG Version attribute [CHECK]"
            if not bf.has_bag_version():
                self._bc_structure_errors += 1
                self._bc_report += "[ERROR] Missing the BAG Version attribute"
            else:
                self._bc_report += "OK"

            # CHK: presence of metadata
            self._bc_report += "Check the presence of the Metadata dataset [CHECK]"
            if not bf.has_metadata():
                self._bc_structure_errors += 1
                self._bc_report += "[ERROR] Missing the Metadata dataset"
            else:
                self._bc_report += "OK"

            # CHK: presence of elevation
            self._bc_report += "Check the presence of the Elevation dataset [CHECK]"
            if not bf.has_elevation():
                self._bc_structure_errors += 1
                self._bc_report += "[ERROR] Missing the Elevation dataset"
            else:
                self._bc_report += "OK"

            # CHK: presence of uncertainty
            self._bc_report += "Check the presence of the Uncertainty dataset [CHECK]"
            if not bf.has_uncertainty():
                self._bc_structure_errors += 1
                self._bc_report += "[ERROR] Missing the Uncertainty dataset"
            else:
                self._bc_report += "OK"

            # CHK: presence of tracking list
            self._bc_report += "Check the presence of the Tracking List dataset [CHECK]"
            if not bf.has_tracking_list():
                self._bc_structure_errors += 1
                self._bc_report += "[ERROR] Missing the Tracking List dataset"
            else:
                self._bc_report += "OK"

            if self._is_vr:
                # CHK: presence of VR Metadata
                self._bc_report += "Check the presence of the VR Metadata dataset [CHECK]"
                if not bf.has_varres_metadata():
                    self._bc_structure_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Metadata dataset"
                else:
                    self._bc_report += "OK"

                # CHK: presence of VR Refinements
                self._bc_report += "Check the presence of the VR Refinements dataset [CHECK]"
                if not bf.has_varres_refinements():
                    self._bc_structure_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Refinements dataset"
                else:
                    self._bc_report += "OK"

                # CHK: presence of VR Tracking List
                self._bc_report += "Check the presence of the VR Tracking List dataset [CHECK]"
                if not bf.has_varres_tracking_list():
                    self._bc_structure_errors += 1
                    self._bc_report += "[ERROR] Missing the VR Tracking List dataset"
                else:
                    self._bc_report += "OK"

        except Exception as e:
            traceback.print_exc()
            self._bc_report += "Other potential issues [CHECK]"
            self._bc_structure_errors += 1
            self._bc_report += "[ERROR] %s" % e