From c8ac80f3cf99869162f53c1124031c862954f52a Mon Sep 17 00:00:00 2001 From: Lukas Trippe Date: Fri, 25 Oct 2024 16:30:57 +0200 Subject: [PATCH] fix: dependency issues (#387) * remove `pkg_resources` * fix: `rasterio==1.4` issue * update `cdsapi` pin * fix cds api * add version --- .github/workflows/test.yaml | 2 +- .gitignore | 7 +++---- atlite/__init__.py | 12 +++++++++++- atlite/gis.py | 12 ++++++++++-- atlite/resource.py | 3 +-- doc/conf.py | 6 +++--- setup.py | 4 ++-- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8f8dc926..fcd36628 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -80,7 +80,7 @@ jobs: key: retrieved-cutouts-${{ env.today }} enableCrossOsArchive: true id: cache-env - + - name: Download package uses: actions/download-artifact@v4 with: diff --git a/.gitignore b/.gitignore index 4e7e88e1..06e44417 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,9 @@ build/ dist/ .eggs atlite.egg-info/ -doc/.vscode/settings.json -.vscode/settings.json test/*.nc dev-scripts/ +dev/ examples/*.nc examples/*.csv examples/*.zip @@ -25,6 +24,6 @@ paper .coverage* !.coveragerc -# Ignore PyCharm / JetBrains IDE project files +# Ignore IDE project files .idea/ -examples/Helsinki-Vantaa_2012.ipynb +.vscode diff --git a/atlite/__init__.py b/atlite/__init__.py index 2aa1e7f0..c9a1635e 100644 --- a/atlite/__init__.py +++ b/atlite/__init__.py @@ -12,10 +12,12 @@ resource requirements especially on CPU and RAM resources low. """ +from importlib.metadata import version +import re + from atlite.cutout import Cutout from atlite.gis import ExclusionContainer, compute_indicatormatrix, regrid from atlite.resource import cspinstallations, solarpanels, windturbines -from atlite.version import version as __version__ __author__ = ( "The Atlite Authors: Gorm Andresen (Aarhus University), " @@ -27,3 +29,11 @@ "David Schlachtberger (FIAS), " ) __copyright__ = "Copyright 2016 - 2021 The Atlite Authors" + +# e.g. "0.17.1" or "0.17.1.dev4+ga3890dc0" (if installed from git) +__version__ = version("atlite") +# e.g. "0.17.0" # TODO, in the network structure it should use the dev version +match = re.match(r"(\d+\.\d+(\.\d+)?)", __version__) +assert match, f"Could not determine release_version of pypsa: {__version__}" +release_version = match.group(0) +assert not __version__.startswith("0.0"), "Could not determine version of atlite." diff --git a/atlite/gis.py b/atlite/gis.py index e8e629b9..37cd6457 100644 --- a/atlite/gis.py +++ b/atlite/gis.py @@ -703,7 +703,6 @@ def compute_availabilitymatrix( Here we stick to the top down version which is why we use `cutout.transform_r` and flipping the y-axis in the end. """ - availability = [] shapes = shapes.geometry if isinstance(shapes, gpd.GeoDataFrame) else shapes shapes = shapes.to_crs(excluder.crs) @@ -722,6 +721,7 @@ def compute_availabilitymatrix( iterator = shapes.index with catch_warnings(): simplefilter("ignore") + availability = [] for i in iterator: _ = shape_availability_reprojected(shapes.loc[[i]], *args)[0] availability.append(_) @@ -744,6 +744,8 @@ def compute_availabilitymatrix( ) availability = np.stack(availability)[:, ::-1] # flip axis, see Notes + if availability.ndim == 4: + availability = availability.squeeze(axis=1) coords = [(shapes.index), ("y", cutout.data.y.data), ("x", cutout.data.x.data)] return xr.DataArray(availability, coords=coords) @@ -820,7 +822,13 @@ def _reproject(src, **kwargs): mode="edge", ) - return rio.warp.reproject(src, empty(shape), src_transform=trans, **kwargs)[0] + reprojected = rio.warp.reproject( + src, empty(shape), src_transform=trans, **kwargs + )[0] + + if reprojected.ndim != src.ndim: + reprojected = reprojected.squeeze(axis=0) + return reprojected data_vars = ds.data_vars.values() if isinstance(ds, xr.Dataset) else (ds,) dtypes = {da.dtype for da in data_vars} diff --git a/atlite/resource.py b/atlite/resource.py index 825b7358..6e0bffec 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -17,7 +17,6 @@ import numpy as np import pandas as pd -import pkg_resources import requests import yaml from dask.array import radians @@ -28,7 +27,7 @@ logger = logging.getLogger(name=__name__) -RESOURCE_DIRECTORY = Path(pkg_resources.resource_filename(__name__, "resources")) +RESOURCE_DIRECTORY = Path(__file__).parent / "resources" WINDTURBINE_DIRECTORY = RESOURCE_DIRECTORY / "windturbine" SOLARPANEL_DIRECTORY = RESOURCE_DIRECTORY / "solarpanel" CSPINSTALLATION_DIRECTORY = RESOURCE_DIRECTORY / "cspinstallation" diff --git a/doc/conf.py b/doc/conf.py index ccb9d451..77b4d386 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -17,10 +17,9 @@ # serve to show the default. import os -import shlex import sys +from importlib.metadata import version as get_version -import pkg_resources # part of setuptools # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -78,7 +77,8 @@ # built documents. # # The short X.Y version. -version = pkg_resources.get_distribution("atlite").version +release: str = get_version("pypsa") +version: str = ".".join(release.split(".")[:2]) # The full version, including alpha/beta/rc tags. release = version diff --git a/setup.py b/setup.py index e08993e9..17641d2d 100644 --- a/setup.py +++ b/setup.py @@ -35,13 +35,13 @@ "toolz", "requests", "pyyaml", - "rasterio!=1.2.10", + "rasterio", "shapely", "progressbar2", "tqdm", "pyproj>=2", "geopandas", - "cdsapi>=0.7,<0.7.3", + "cdsapi>=0.7.4", ], extras_require={ "docs": [