Commit 1237594e authored by Jessica Palka's avatar Jessica Palka
Browse files

Commiting a BadDataMask for the tested *.tif-Image.

Extending the test-functions "test_NoDataValueOfTiff" and "test_MaskBaddataOffTiff" (before: "test_MaskBaddataIsNone").
parent 22c306d3
Pipeline #895 passed with stages
in 45 seconds
......@@ -37,10 +37,7 @@ import geopandas
import numpy as np
import os
from os import path
try:
from osgeo import osr
except ImportError:
import osr
import osgeo.osr
import shapely
from shapely.geometry import Polygon
import time
......@@ -87,6 +84,7 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
given_pszProj4_string = '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs'
expected_epsg = 32633
given_nodata = -9999.0
given_bandnames = ['B1', 'B2']
# Variable for the parametrization of the test case.
k = 0
......@@ -117,13 +115,14 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
cls.L8_2bands_extract10x11 = np.loadtxt(array_path, 'float32').reshape(10, 11, 2)
# Change the pszProj4-string in a WKT-string.
srs = osr.SpatialReference()
srs = osgeo.osr.SpatialReference()
srs.ImportFromProj4(cls.given_pszProj4_string)
cls.given_projection = srs.ExportToWkt()
# Creating the "GeoArray"-instance with a NUMPY ARRAY.
# The notdata-value will be set in the test "test_NoDataValueOfTiff".
cls.testtiff = GeoArray(cls.L8_2bands_extract10x11, geotransform=cls.given_geotransform,
projection=cls.given_projection, nodata=cls.given_nodata)
projection=cls.given_projection, bandnames=cls.given_bandnames)
# Serialize the "GeoArray"-class to the "data"-directory
with open("".join((tests_path,"/tests/data/testtiff_array.tmp")),"wb") as f:
......@@ -202,7 +201,6 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
Testing the function: bandnames.
Test, if the default band names were correctly assigned.
"""
self.assertEqual(self.testtiff.bandnames, self.expected_bandnames,
msg="The bandnames of the Tiff-file are different than ['B1', 'B2'] (format: OrderedDict)")
......@@ -293,7 +291,7 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
# mgleahy, 21 November 2010, "SpatialNotes". [Online].
# URL: http://spatialnotes.blogspot.de/2010/11/converting-wkt-projection-info-to-proj4.html
# [Accessed 23 Mai 2017].
srs = osr.SpatialReference()
srs = osgeo.osr.SpatialReference()
srs.ImportFromWkt(self.testtiff.projection)
testtiff_pszProj4_string = srs.ExportToProj4()
......@@ -312,15 +310,20 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
def test_NoDataValueOfTiff(self):
"""
Testing the function: nodata,
indirect testing of the function: set_gdalDataset_meta(!).
Test, if the nodata value of the image was correctly assigned.
indirect testing of the functions: find_noDataVal(), set_gdalDataset_meta(!).
Test, if the nodata value of the GeoArray-instance was correctly assigned.
"""
if self.k == 1:
if self.testtiff.nodata == None:
self.testtiff.nodata = self.given_nodata
else:
self.skipTest("The nodata-value of the 'GeoArray'-object instanced with a numpy.array and without "
"declaring a nodata-value is not automatically set to 'None'! "
"The test 'test_NoDataValueOfTiff' will be skipped.")
self.assertEqual(self.testtiff.nodata, self.given_nodata,
msg="The nodata-value of the tested Tiff-file (%s) is not as expected (%s)!"
%(self.testtiff.nodata, self.given_nodata))
%(self.testtiff.nodata, self.given_nodata))
......@@ -413,15 +416,23 @@ class Test_GeoarrayFunctions(unittest.TestCase):
def test_MaskBaddataIsNone(self):
# TODO: Setting a baddata mask and testing, if mask_baddata is an instance of the BadDataMask-class (masks.py).
def test_MaskBaddataOffTiff(self):
"""
Testing the function: mask_baddata.
Test, if the output of the mask_baddata-function is "None" since a baddata-mask is not set within the used
TIFF-image.
Test,
a) if the output of the mask_baddata-function is "None", when the baddata-mask is not set and
b) if the output of the mask_baddata-function is an instance of "BadDataMask"(class, defined in masks.py).
"""
self.assertIsNone(self.testtiff.mask_baddata)
L8_BadDataMask10x11 = "".join((tests_path, "/tests/data/L8_BadDataMask10x11.tif"))
bdm = masks.BadDataMask(L8_BadDataMask10x11)
for i in range(0, 2, 1):
with self.subTest(i=1):
if i == 0:
self.assertIsNone(self.testtiff.mask_baddata)
if i == 1:
self.testtiff.mask_baddata = bdm
self.assertIsInstance(self.testtiff.mask_baddata, masks.BadDataMask)
......
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