Skip to content

Commit

Permalink
extending test cases to provide a higher coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas committed Nov 12, 2023
1 parent d705eee commit ed5aede
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 46 additions & 0 deletions tests/core/test_landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'''

import geopandas as gpd
import numpy as np
import pytest

from datetime import datetime
Expand Down Expand Up @@ -52,3 +53,48 @@ def test_landsat_from_usgs():
for band_name in landsat.band_names[:-1]:
assert 0 < landsat[band_name].values.min() <= 1, 'wrong value'
assert 0 < landsat[band_name].values.max() <= 1, 'wrong value'

# get the cloud mask -> this should fail because we didn't
# read the qa bands
with pytest.raises(KeyError):
cloud_mask = landsat.get_cloud_and_shadow_mask()

# repeat the reading of the scene WITH the qa bands
band_selection = ['blue', 'green', 'red', 'nir08', 'swir12']
landsat = Landsat.from_usgs(
in_dir=landsat_scene_item['assets'],
vector_features=gdf,
read_qa=True,
read_atcor=False,
band_selection=band_selection
)
assert 'qa_pixel' in landsat.band_names, 'missing quality band'

# now the generation of a binary cloud mask should work
cloud_mask = landsat.get_cloud_and_shadow_mask()
assert cloud_mask.values.dtype == bool, 'expected boolean'

water_mask = landsat.get_water_mask()
assert water_mask.values.dtype == 'bool', 'expected boolean'

# mask clouds and shadows -> check if the mask has an effect
landsat.mask_clouds_and_shadows(inplace=True)
assert landsat['blue'].is_masked_array, 'expected as masked array'

# calculate the NDVI
landsat.calc_si(si_name='NDVI', inplace=True)
assert 'NDVI' in landsat.band_names
assert -1 <= landsat['NDVI'].values.min() <= 1
assert -1 <= landsat['NDVI'].values.max() <= 1
assert np.isnan(landsat['NDVI'].nodata)

# repeat the reading of the scene WITH the atcor bands
band_selection = ['blue', 'green', 'red', 'nir08', 'swir12']
landsat = Landsat.from_usgs(
in_dir=landsat_scene_item['assets'],
vector_features=gdf,
read_qa=True,
read_atcor=True,
band_selection=band_selection
)
assert 'lwir' in landsat.band_names
6 changes: 5 additions & 1 deletion tests/core/test_sentinel2.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def test_read_from_safe_with_mask_l2a(datadir, get_s2_safe_l2a, get_polygons, ge
# make sure meta information was saved correctly
assert handler['scl'].meta['dtype'] == 'uint8', 'wrong data type for SCL in meta'

# get a binary cloud mask
cloud_mask = handler.get_cloud_and_shadow_mask()
assert cloud_mask.values.dtype == bool, 'expected boolean'

# to_xarray should fail because of different spatial resolutions
with pytest.raises(ValueError):
handler.to_xarray()
Expand Down Expand Up @@ -413,7 +417,7 @@ def test_read_from_safe_l2a(datadir, get_s2_safe_l2a):
inplace=True
)

assert reader.is_bandstack(), 'data should fulfill bandstack criteria but doesnot'
assert reader.is_bandstack(), 'data should fulfill bandstack criteria but does not'
assert reader['blue'].crs == 32633, 'projection was not updated'

# try writing bands to output file
Expand Down

0 comments on commit ed5aede

Please sign in to comment.