Skip to content

Commit

Permalink
fix: dependency issues (#387)
Browse files Browse the repository at this point in the history
* remove `pkg_resources`

* fix: `rasterio==1.4` issue

* update `cdsapi` pin

* fix cds api

* add version
  • Loading branch information
lkstrp authored Oct 25, 2024
1 parent e6d886e commit c8ac80f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
key: retrieved-cutouts-${{ env.today }}
enableCrossOsArchive: true
id: cache-env

- name: Download package
uses: actions/download-artifact@v4
with:
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +24,6 @@ paper
.coverage*
!.coveragerc

# Ignore PyCharm / JetBrains IDE project files
# Ignore IDE project files
.idea/
examples/Helsinki-Vantaa_2012.ipynb
.vscode
12 changes: 11 additions & 1 deletion atlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), "
Expand All @@ -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."
12 changes: 10 additions & 2 deletions atlite/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(_)
Expand All @@ -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)

Expand Down Expand Up @@ -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}
Expand Down
3 changes: 1 addition & 2 deletions atlite/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import numpy as np
import pandas as pd
import pkg_resources
import requests
import yaml
from dask.array import radians
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit c8ac80f

Please sign in to comment.