Commit 7d8b5af1 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added two tests that validate the metadata written by GeoArray.save() for ENVI...


Added two tests that validate the metadata written by GeoArray.save() for ENVI and GTiff format. Track tif and bsq files with git-lfs.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 873aa965
*.zip filter=lfs diff=lfs merge=lfs -text
*.bsq filter=lfs diff=lfs merge=lfs -text
*.tif filter=lfs diff=lfs merge=lfs -text
......@@ -12,6 +12,8 @@ History
* *Warning 2*: The IFD has been rewritten at the end of the file, which breaks COG layout.
* Fixed unsupported band-specific nodata values in case of ENVI output format.
* Added two tests that validate the metadata written by GeoArray.save() for ENVI and GTiff format.
* Track tif and bsq files with git-lfs.
0.14.0 (2021-07-26)
......
No preview for this file type
ENVI
description = {
File Resize Result, x resize factor: 1.000000, y resize factor: 1.000000.
[Wed Aug 08 13:35:48 2018]}
File Resize Result, x resize factor: 1.000000, y resize factor: 1.000000. [Wed Aug 08 13:35:48 2018]}
samples = 5
lines = 5
bands = 10
......@@ -9,32 +8,65 @@ header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
sensor type = Unknown
byte order = 0
x start = 350
y start = 10500
map info = {UTM, 1.000, 1.000, 287232.433, 4080098.314, 1.4200000000e+001, 1.4200000000e+001, 11, North, WGS-84, units=Meters, rotation=-12.00000000}
map info = {UTM, 1, 1, 287232.433, 4080098.314, 14.2, 14.2, 11, North,WGS-84, rotation=-12}
coordinate system string = {PROJCS["UTM_Zone_11N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-117.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]}
wavelength units = Nanometers
band names = {
Resize (Band 5:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 6:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 7:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 8:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 9:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 10:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 11:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 12:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 13:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 14:f141006t01p00r16_refl_BSQ.bsq)}
wavelength = {
404.596649, 414.278656, 423.964661, 433.654663, 443.349670, 453.049652,
462.752655, 472.460663, 482.173645, 491.890656}
fwhm = {
9.645100, 9.599000, 9.555200, 9.513600, 9.474300, 9.437300, 9.402500,
9.370000, 9.339700, 9.311700}
bbl = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
correction factors = {
1.10059, 1.08712, 1.0534, 0.99914, 0.98411, 0.99055, 0.96899, 0.98119,
0.9779, 0.97234}
Resize (Band 5:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 6:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 7:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 8:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 9:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 10:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 11:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 12:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 13:f141006t01p00r16_refl_BSQ.bsq),
Resize (Band 14:f141006t01p00r16_refl_BSQ.bsq)}
bbl = { 1,
1,
1,
1,
1,
1,
1,
1,
1,
1 }
corner coordinates lonlat = [[72.45254791675194, 40.30295607534694], [72.74642602223325, 40.30905731897239], [72.46095641250194, 40.07798579894774], [72.75386662265068, 40.08403894986721]]
correction factors = { 1.100590,
1.087120,
1.053400,
0.999140,
0.984110,
0.990550,
0.968990,
0.981190,
0.977900,
0.972340 }
data gain values = 0.010000, 0.010000
data offset values = 0, 0
EarthSunDist = 1.005349
fwhm = { 9.645100,
9.599000,
9.555200,
9.513600,
9.474300,
9.437300,
9.402500,
9.370000,
9.339700,
9.311700 }
sensor type = Unknown
wavelength = { 404.596649,
414.278656,
423.964661,
433.654663,
443.349670,
453.049652,
462.752655,
472.460663,
482.173645,
491.890656 }
wavelength units = Nanometers
x start = 350
y start = 10500
......@@ -34,6 +34,9 @@ import tempfile
import os
from collections import OrderedDict
from typing import Iterable
from tempfile import TemporaryDirectory
from difflib import unified_diff
from subprocess import getoutput
import numpy as np
from shapely.geometry import Polygon
......@@ -52,18 +55,21 @@ __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")
path_data_tif = os.path.join(tests_path, "tests", "data", "L8_2bands_extract10x11.tif")
path_subset_bsq = os.path.join(tests_path, "tests", "data", "subset_metadata.bsq")
path_subset_hdr = os.path.join(tests_path, "tests", "data", "subset_metadata.hdr")
path_subset_tif = os.path.join(tests_path, "tests", "data", "subset_metadata.tif")
# disable matplotlib figure popups
matplotlib.use('Template') # disables matplotlib figure popups
def _get_gA_inMem_notInMem():
gA_inMem = GeoArray(path_data)
def _get_gA_inMem_notInMem(path_file=path_data_tif):
gA_inMem = GeoArray(path_file)
gA_inMem.to_mem()
gA_inMem.filePath = ""
gA_notInMem = GeoArray(path_data)
gA_notInMem = GeoArray(path_file)
params_inMem_NotInMem = [("inMem", gA_inMem),
("notInMem", gA_notInMem)]
......@@ -84,10 +90,10 @@ class Test_GeoArray(TestCase):
with tempfile.TemporaryDirectory() as td:
path_zip = os.path.join(td, 'temp_archive.zip')
file_basename = os.path.basename(path_data)
file_basename = os.path.basename(path_data_tif)
with zipfile.ZipFile(path_zip, 'w') as zf:
zf.write(path_data, file_basename)
zf.write(path_data_tif, file_basename)
gA = GeoArray(f'/vsizip/{path_zip}/{file_basename}')
self.assertIsInstance(gA[:], np.ndarray)
......@@ -482,6 +488,45 @@ class Test_GeoArray(TestCase):
# TODO validate written metadata (inMem, notInMem, in case a notInMem dataset already has custom metadata)
@parameterized.expand(_get_gA_inMem_notInMem(path_subset_bsq))
def test_save_meta_ENVI(self, _, gA):
with TemporaryDirectory(prefix='geoarray__') as td:
p_out = os.path.join(td, 'outfile.bsq')
gA.save(p_out, fmt='ENVI')
# compare gdalinfo output
gdalinfo_out = [i + '\n' for i in getoutput(f'gdalinfo -mdd ENVI {p_out}').split('\n')]
gdalinfo_orig = [i + '\n' for i in getoutput(f'gdalinfo -mdd ENVI {path_subset_bsq}').split('\n')]
diff = ''.join(list(unified_diff(gdalinfo_orig[3:], gdalinfo_out[3:])))
self.assertFalse(diff)
# compare header files
with open(p_out[:-4] + '.hdr', 'r') as inF:
new = inF.readlines()
with open(path_subset_hdr, 'r') as inF:
old = inF.readlines()
diff = ''.join(list(unified_diff(old[3:], new[3:])))
self.assertFalse(diff)
# os.system(f'gdalinfo {p_out}')
@parameterized.expand(_get_gA_inMem_notInMem(path_subset_tif))
def test_save_meta_GTiff(self, _, gA):
with TemporaryDirectory(prefix='geoarray__') as td:
p_out = os.path.join(td, 'outfile.tif')
gA.save(p_out, fmt='GTiff')
# compare gdalinfo output
gdalinfo_out = [i + '\n' for i in getoutput(f'gdalinfo {p_out}').split('\n')]
gdalinfo_orig = [i + '\n' for i in getoutput(f'gdalinfo {path_subset_tif}').split('\n')]
diff = ''.join(list(unified_diff(gdalinfo_orig[2:], gdalinfo_out[2:])))
self.assertFalse(diff)
# os.system(f'gdalinfo {p_out}')
def test_show(self):
# test 3D case
self.gA.show()
......
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