Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional unit tests #406

Merged
merged 16 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions atlite/cutout.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-FileCopyrightText: Contributors to atlite <https://github.com/pypsa/atlite>
# SPDX-FileCopyrightText: 2016 - 2023 The Atlite Authors
lkstrp marked this conversation as resolved.
Show resolved Hide resolved
#
# SPDX-License-Identifier: MIT
"""
Base class for atlite.
Base class for Atlite.
lkstrp marked this conversation as resolved.
Show resolved Hide resolved
"""

# There is a binary incompatibility between the pip wheels of netCDF4 and
Expand Down Expand Up @@ -68,7 +68,7 @@ class Cutout:

def __init__(self, path, **cutoutparams):
"""
Provide an atlite cutout object.
Provide an Atlite cutout object.
lkstrp marked this conversation as resolved.
Show resolved Hide resolved

Create a cutout object to use atlite operations on it. Based on the
provided parameters, atlite first checks whether this cutout already
Expand Down Expand Up @@ -576,6 +576,15 @@ def uniform_density_layout(self, capacity_density, crs=None):
"""
return capacity_density * self.area(crs)

def equals(self, other):
"""
It overrides xarray.Dataset.equals and ignores the path attribute in the comparison
"""
if not isinstance(other, Cutout):
return NotImplemented
# Compare cutouts data attributes
return self.data.equals(other.data)

def layout_from_capacity_list(self, data, col="Capacity"):
"""
Get a capacity layout aligned to the cutout based on a capacity list.
Expand Down
48 changes: 48 additions & 0 deletions test/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import numpy as np
import pytest
import rasterio as rio
from xarray.testing import assert_equal

from atlite import Cutout
Expand All @@ -31,6 +32,53 @@ def ref():
)


def test_name(ref):
assert ref.name == "creation_ref"


def test_module(ref):
assert ref.module == "era5"


def test_crs(ref):
assert ref.crs == "EPSG:4326"


def test_shape(ref):
assert ref.shape == (21, 23)


def test_extent(ref):
reference_extent = [-4.125, 1.625, 55.875, 61.125]
assert all([x == y for x, y in zip(ref.extent, reference_extent)])


def test_bounds(ref):
reference_extent = [-4.125, 55.875, 1.625, 61.125]
assert all([x == y for x, y in zip(ref.bounds, reference_extent)])


def test_transform(ref):
reference_affine = rio.Affine(
0.25, 0.00, -4.125, 0.00, 0.25, 55.875, 0.00, 0.00, 1.00
)
assert reference_affine == ref.transform


def test_equals(ref):
test_cutout = Cutout(
path="creation_ref", module="era5", bounds=(X0, Y0, X1, Y1), time=TIME
)
assert ref.equals(test_cutout)


def test_transform_r(ref):
reference_affine = rio.Affine(
0.25, 0.00, -4.125, 0.00, -0.25, 61.125, 0.00, 0.00, 1.00
)
assert reference_affine == ref.transform_r


def test_odd_bounds_coords(ref):
cutout = Cutout(
path="odd_bounds",
Expand Down