How to use the mapchete.errors.MapcheteDriverError function in mapchete

To help you get started, we’ve selected a few mapchete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ungarj / mapchete / test / test_formats_tiledir_input.py View on Github external
with pytest.raises(MapcheteDriverError):
        mapchete.open(vector_type)
    # without type
    vector_type = deepcopy(geojson_tiledir.dict)
    vector_type["input"]["file1"].pop("grid")
    with pytest.raises(MapcheteDriverError):
        mapchete.open(vector_type)
    # wrong type
    vector_type = deepcopy(geojson_tiledir.dict)
    vector_type["input"]["file1"]["grid"] = "invalid"
    with pytest.raises(MapcheteDriverError):
        mapchete.open(vector_type)
    # without extension
    vector_type = deepcopy(geojson_tiledir.dict)
    vector_type["input"]["file1"].pop("extension")
    with pytest.raises(MapcheteDriverError):
        mapchete.open(vector_type)
    # without invalid extension
    vector_type = deepcopy(geojson_tiledir.dict)
    vector_type["input"]["file1"]["extension"] = "invalid"
    with pytest.raises(MapcheteDriverError):
        mapchete.open(vector_type)

    # raster type specific
    ######################
    # without count
    raster_type = deepcopy(cleantopo_br_tiledir.dict)
    raster_type["input"]["file1"].pop("count")
    with pytest.raises(MapcheteDriverError):
        mapchete.open(raster_type)
    # without dtype
    raster_type = deepcopy(cleantopo_br_tiledir.dict)
github ungarj / mapchete / test / test_formats_tiledir_input.py View on Github external
def test_no_metadata_json(mp_tmpdir, cleantopo_br_tiledir):
    """Read raster data."""
    # prepare data
    with pytest.raises(MapcheteDriverError):
        mapchete.open(
            dict(cleantopo_br_tiledir.dict, input=dict(file1="tmp/cleantopo_br"))
        )
github ungarj / mapchete / test / test_config.py View on Github external
def test_abstract_input(abstract_input):
    """Read abstract input definitions."""
    with pytest.raises(MapcheteDriverError):
        MapcheteConfig(abstract_input.path)
github ungarj / mapchete / test / test_formats.py View on Github external
def test_input_reader_errors():
    """Test errors when loading input readers."""
    with pytest.raises(TypeError):
        load_input_reader("not_a_dictionary")
    with pytest.raises(errors.MapcheteDriverError):
        load_input_reader({})
    with pytest.raises(errors.MapcheteDriverError):
        load_input_reader({"abstract": {"format": "invalid_format"}})
github ungarj / mapchete / mapchete / formats / __init__.py View on Github external
driver : string
        driver name
    """
    file_ext = os.path.splitext(input_file)[1].split(".")[1]
    if file_ext == "mapchete":
        return "Mapchete"
    try:
        with rasterio.open(input_file):
            return "raster_file"
    except:
        try:
            with fiona.open(input_file):
                return "vector_file"
        except:
            if path_exists(input_file):
                raise MapcheteDriverError(
                    "%s has an unknown file extension or could not be opened by neither "
                    "rasterio nor fiona." % input_file
                )
            else:
                raise FileNotFoundError("%s does not exist" % input_file)
github ungarj / mapchete / mapchete / config / _parse_input.py View on Github external
)
                LOGGER.debug(
                    "input reader for abstract input %s is %s", input_obj,
                    _input_reader
                )
            else:
                raise MapcheteConfigError(
                    "invalid input type %s", type(input_obj))
            # trigger input bounding box caches
            _input_reader.bbox(out_crs=pyramid.crs)
            return key, (input_obj, _input_reader)
        else:
            return key, (None, None)
    except Exception as e:
        LOGGER.exception("input driver error")
        raise MapcheteDriverError("%s could not be read: %s" % (key, e))
github ungarj / mapchete / mapchete / config.py View on Github external
elif isinstance(v, dict):
                    logger.debug("load input reader for abstract input %s", v)
                    try:
                        reader = load_input_reader(
                            dict(
                                abstract=deepcopy(v),
                                pyramid=self.process_pyramid,
                                pixelbuffer=self.process_pyramid.pixelbuffer,
                                delimiters=self._delimiters,
                                conf_dir=self.config_dir
                            ),
                            readonly=self.mode == "readonly"
                        )
                    except Exception as e:
                        logger.exception(e)
                        raise MapcheteDriverError(
                            "error when loading input %s: %s" % (v, e)
                        )
                    logger.debug("input reader for abstract input %s is %s", v, reader)
                else:
                    raise MapcheteConfigError("invalid input type %s", type(v))
                # trigger bbox creation
                reader.bbox(out_crs=self.process_pyramid.crs)
                initalized_inputs[k] = reader

        else:
            for k in raw_inputs.keys():
                initalized_inputs[k] = None

        return initalized_inputs
github ungarj / mapchete / mapchete / formats / __init__.py View on Github external
-------
    output : ``OutputDataReader``
        output reader object
    """
    if not isinstance(output_params, dict):
        raise TypeError("output_params must be a dictionary")
    driver_name = output_params["format"]
    for v in drivers:
        _driver = v.load()
        if all(
            [hasattr(_driver, attr) for attr in ["OutputDataReader", "METADATA"]]
            ) and (
            _driver.METADATA["driver_name"] == driver_name
        ):
            return _driver.OutputDataReader(output_params, readonly=True)
    raise MapcheteDriverError("no loader for driver '%s' could be found." % driver_name)
github ungarj / mapchete / mapchete / config.py View on Github external
if isinstance(v, six.string_types):
                # get absolute paths if not remote
                path = v if v.startswith(
                    ("s3://", "https://", "http://")) else os.path.normpath(
                    os.path.join(self.config_dir, v))
                logger.debug("load input reader for file %s",  v)
                try:
                    reader = load_input_reader(
                        dict(
                            path=deepcopy(path), pyramid=self.process_pyramid,
                            pixelbuffer=self.process_pyramid.pixelbuffer,
                            delimiters=delimiters
                        ), self.mode == "readonly")
                except Exception as e:
                    logger.exception(e)
                    raise MapcheteDriverError(e)
                logger.debug(
                    "input reader for file %s is %s", v, reader)
            # for abstract inputs
            elif isinstance(v, dict):
                logger.debug(
                    "load input reader for abstract input %s", v)
                try:
                    reader = load_input_reader(
                        dict(
                            abstract=deepcopy(v), pyramid=self.process_pyramid,
                            pixelbuffer=self.process_pyramid.pixelbuffer,
                            delimiters=delimiters, conf_dir=self.config_dir
                        ), self.mode == "readonly")
                except Exception as e:
                    logger.exception(e)
                    raise MapcheteDriverError(e)