Skip to content

Commit

Permalink
Merge branch 'master' into fix-era5t
Browse files Browse the repository at this point in the history
  • Loading branch information
lkstrp authored Oct 25, 2024
2 parents 7888fa1 + c8ac80f commit e74a77e
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 206 deletions.
48 changes: 30 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,27 @@ jobs:
- windows-latest
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434

steps:
- name: Setup cache and secrets (Linux & MacOS)
if: runner.os != 'Windows'
run: |
echo "CACHE_PATH=$HOME/.atlite_cache" >> $GITHUB_ENV
echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo -ne "url: ${{ vars.CDSAPI_URL }}\nkey: ${{ secrets.CDSAPI_TOKEN }}\n" > ~/.cdsapirc
shell: bash

- name: Setup cache and secrets (Windows)
if: runner.os == 'Windows'
run: |
echo CACHE_PATH=%USERPROFILE%\.atlite_cache >> %GITHUB_ENV%
echo url: ${{ vars.CDSAPI_URL }} > %USERPROFILE%\.cdsapirc
echo key: ${{ secrets.CDSAPI_TOKEN }} >> %USERPROFILE%\.cdsapirc
for /f "tokens=2 delims==" %%a in ('"wmic os get localdatetime /value"') do set "today=%%a"
set mydate=%today:~0,4%-%today:~4,2%-%today:~6,2%
echo today=%mydate% >> %GITHUB_ENV%
shell: cmd

- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for setuptools_scm
Expand All @@ -53,17 +73,14 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install macos dependencies
if: matrix.os == 'macos-latest'
run: |
brew install hdf5
- name: Setup CDS API
run: |
echo -ne "url: https://cds-beta.climate.copernicus.eu/api \nkey: ${{secrets.CDSAPI_TOKEN_BETA}}\n" > ~/.cdsapirc
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Cache retrieved cutouts
uses: actions/cache@v4
with:
path: ${{ env.CACHE_PATH }}
key: retrieved-cutouts-${{ env.today }}
enableCrossOsArchive: true
id: cache-env

- name: Download package
uses: actions/download-artifact@v4
with:
Expand All @@ -74,17 +91,12 @@ jobs:
run: |
python -m pip install uv
uv pip install --compile --system "$(ls dist/*.whl)[dev]"
# Use --compile to get pip's behavior. Otherwise the pandapower installation
# will be broken on python<3.12
# See https://github.com/astral-sh/uv/issues/1928#issuecomment-1968857514
- name: Test with pytest
run: |
coverage run -m pytest
coverage run -m pytest . --cache-path=${{ env.CACHE_PATH }} --verbose
coverage xml
cat coverage.xml
- name: Upload code coverage report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
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
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
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
Loading

0 comments on commit e74a77e

Please sign in to comment.