pypsa-eur/scripts/build_ship_raster.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2022-07-29 12:56:00 +00:00
# SPDX-FileCopyrightText: : 2022 The PyPSA-Eur Authors
2022-07-28 08:38:24 +00:00
#
# SPDX-License-Identifier: MIT
"""
2023-02-16 10:50:55 +00:00
Transforms the global ship density data from the `World Bank Data Catalogue.
<https://datacatalog.worldbank.org/search/dataset/0037580/Global-Shipping-Traffic-Density>`_
to the size of the considered cutout. The global ship density raster is later
used for the exclusion when calculating the offshore potentials.
2022-07-28 08:38:24 +00:00
Relevant Settings
-----------------
.. code:: yaml
renewable:
{technology}:
cutout:
.. seealso::
Documentation of the configuration file ``config/config.yaml`` at
2022-07-28 08:38:24 +00:00
:ref:`renewable_cf`
Inputs
------
2023-02-16 11:37:30 +00:00
- ``data/bundle/shipdensity/shipdensity_global.zip``: Global shipping traffic
density from `World Bank Data Catalogue
<https://datacatalog.worldbank.org/search/dataset/0037580/>`_.
2022-07-28 08:38:24 +00:00
Outputs
-------
2023-02-16 11:37:30 +00:00
- ``resources/europe_shipdensity_raster.nc``: Reduced version of global shipping
traffic density from `World Bank Data Catalogue
<https://datacatalog.worldbank.org/search/dataset/0037580/>`_ to reduce
computation time.
2022-07-28 08:38:24 +00:00
Description
-----------
"""
import logging
import zipfile
2023-08-15 13:02:41 +00:00
from pathlib import Path
import rioxarray
2023-08-15 13:02:41 +00:00
from _helpers import configure_logging, set_scenario_config
2022-07-28 08:38:24 +00:00
from build_natura_raster import determine_cutout_xXyY
logger = logging.getLogger(__name__)
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
2022-07-28 08:38:24 +00:00
snakemake = mock_snakemake("build_ship_raster")
configure_logging(snakemake)
2023-08-15 13:02:41 +00:00
set_scenario_config(snakemake)
2022-07-28 08:38:24 +00:00
cutouts = snakemake.input.cutouts
xs, Xs, ys, Ys = zip(*(determine_cutout_xXyY(cutout) for cutout in cutouts))
2022-07-28 13:21:21 +00:00
2022-07-28 08:38:24 +00:00
with zipfile.ZipFile(snakemake.input.ship_density) as zip_f:
2023-08-15 13:02:41 +00:00
resources = Path(snakemake.output[0]).parent
fn = "shipdensity_global.tif"
zip_f.extract(fn, resources)
with rioxarray.open_rasterio(resources / fn) as ship_density:
ship_density = ship_density.drop_vars(["band"]).sel(
2023-08-15 13:02:41 +00:00
x=slice(min(xs), max(Xs)), y=slice(max(Ys), min(ys))
)
ship_density.rio.to_raster(snakemake.output[0])
(resources / fn).unlink()