Commit f45f5867 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed issue that tested GeoArray is altered by test methods and thus not...


Fixed issue that tested GeoArray is altered by test methods and thus not passed as a newly created instance to some tests.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent dbfa7b28
Pipeline #19581 passed with stages
in 14 minutes and 40 seconds
......@@ -2,6 +2,13 @@
History
=======
0.10.10 (2021-02-19)
--------------------
* Fixed issue that tested GeoArray is altered by test methods and
thus not passed as a newly created instance to some tests.
0.10.9 (2021-02-19)
-------------------
......
......@@ -38,13 +38,13 @@ from typing import Iterable
import numpy as np
from shapely.geometry import Polygon
from osgeo.osr import SpatialReference
from osgeo.osr import SpatialReference # noqa
import matplotlib
from parameterized import parameterized
from parameterized import parameterized # noqa
from py_tools_ds.geo.vector import geometry
from py_tools_ds.geo.coord_trafo import transform_any_prj
from geoarray import GeoArray, masks, __file__ as geoarray_root
from geoarray import GeoArray, masks, __file__ as geoarray_root # noqa
from geoarray.metadata import GDAL_Metadata
......@@ -53,19 +53,23 @@ __author__ = ["Daniel Scheffler", "Jessica Palka"]
# Path of the tests-directory in the geoarray-package.
tests_path = os.path.abspath(os.path.join(geoarray_root, "..", ".."))
path_data = os.path.join(tests_path, "tests", "data", "L8_2bands_extract10x11.tif")
# disable matplotlib figure popups
matplotlib.use('Template') # disables matplotlib figure popups
path_data = os.path.join(tests_path, "tests", "data", "L8_2bands_extract10x11.tif")
gA_inMem = GeoArray(path_data)
gA_inMem.to_mem()
gA_inMem.filePath = ""
def _get_gA_inMem_notInMem():
gA_inMem = GeoArray(path_data)
gA_inMem.to_mem()
gA_inMem.filePath = ""
gA_notInMem = GeoArray(path_data)
params_inMem_NotInMem = [("inMem", gA_inMem),
("notInMem", gA_notInMem)]
gA_notInMem = GeoArray(path_data)
params_inMem_NotInMem = [("inMem", gA_inMem),
("notInMem", gA_notInMem)]
return params_inMem_NotInMem
class Test_GeoArray(TestCase):
......@@ -74,14 +78,14 @@ class Test_GeoArray(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.gA = gA_inMem
cls.gA = _get_gA_inMem_notInMem()[0][1]
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_bandnames(self, _, gA):
"""Test GeoArray.bandnames."""
self.assertEqual(gA.bandnames, OrderedDict([('B1', 0), ('B2', 1)]))
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_shape(self, _, gA):
"""Test GeoArray.shape, .ndim, .rows, .columns, and .bands"""
shape_attrs = (gA.ndim, gA.rows, gA.columns, gA.bands)
......@@ -97,12 +101,12 @@ class Test_GeoArray(TestCase):
msg='The number of {i} is different from the expected result!'.format(
i=shape_property[i]))
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_dtype(self, _, gA):
"""Test GeoArray.dtype."""
self.assertEqual(gA.dtype, np.dtype('float32'))
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_geotransform_gsd_grid(self, _, gA):
"""Test GeoArray.geotransform, .xgsd, .ygsd, and .xygrid_specs."""
self.assertEqual(gA.geotransform, [365985.0, 30.0, 0.0, 5916615.0, 0.0, -30.0])
......@@ -110,7 +114,7 @@ class Test_GeoArray(TestCase):
self.assertEqual(gA.xygrid_specs, [[365985.0, 366015.0], [5916615.0, 5916585.0]],
msg='The [[xOrigin, xGSD], [yOrigin, yGSD]]-grid is not as expected!')
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_projection_epsg(self, _, gA):
"""Test GeoArray.projection and .epsg."""
......@@ -133,7 +137,7 @@ class Test_GeoArray(TestCase):
gA = GeoArray(np.array([1, 2]), nodata=-9999)
self.assertEqual(gA.nodata, -9999.0)
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_calc_mask_nodata(self, _, gA):
def test_with_flag_all(_gA):
"""Test mask output with flag='all' (flag when nodata in ALL bands)."""
......@@ -168,7 +172,7 @@ class Test_GeoArray(TestCase):
with self.assertRaises(ValueError):
gA.calc_mask_nodata(overwrite=True, flag='bad_string')
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test___getitem__(self, _, gA):
def validate(array, exp_shape):
self.assertIsInstance(array, np.ndarray)
......@@ -292,7 +296,7 @@ class Test_GeoArray(TestCase):
self.assertIsInstance(tiles, Iterable)
for ((rS, rE), (cS, cE)), tile in tiles:
self.assertTrue(np.array_equal(tile, gA[rS: rE + 1, cS: cE + 1], equal_nan=True))
self.assertTrue(np.array_equal(tile, gA[rS: rE + 1, cS: cE + 1]))
def test_get_subset_3D_geoarray(self):
# test without resetting band names
......@@ -328,7 +332,7 @@ class Test_GeoArray(TestCase):
# test arrays are equal
sub_gA = self.gA.get_subset(xslice=slice(2, 5), yslice=slice(None, 3), zslice=slice(1, 2))
sub_arr = self.gA[:3, 2:5, 1:2]
self.assertTrue(np.array_equal(sub_gA[:], sub_arr, equal_nan=True))
self.assertTrue(np.array_equal(sub_gA[:], sub_arr))
# test deepcopied arrays (modification of sub_gA.arr must not affect self.gA.arr)
sub_gA[:2, :2] = 99
......@@ -414,7 +418,7 @@ class Test_GeoArray(TestCase):
self.assertIsInstance(out[1], tuple)
self.assertIsInstance(out[2], str)
@parameterized.expand(params_inMem_NotInMem)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_save(self, _, gA):
"""Test GeoArray.save."""
# Save as temporary GTiff
......@@ -425,7 +429,7 @@ class Test_GeoArray(TestCase):
self.assertTrue(os.path.exists(L8_2bands_extract10x11_copy))
self.assertIsInstance(gA_copy, GeoArray)
self.assertTrue(np.array_equal(gA[:], gA_copy[:], equal_nan=True))
self.assertTrue(np.array_equal(gA[:], gA_copy[:]))
def test_show(self):
# test 3D case
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment