From f1fd74d935074bbfc507193282ea7147077699cd Mon Sep 17 00:00:00 2001 From: AleksMat Date: Mon, 17 Jun 2019 15:08:51 +0200 Subject: [PATCH] removed module for testing, moved TestInputs outside the package, updated readme --- README.md | 18 ----- requirements.txt | 2 - s2cloudless/__init__.py | 3 +- s2cloudless/test_cloud_detector.py | 74 ------------------ setup.py | 4 +- .../TestInputs/input_arrays.npz | Bin tests/test_all.py | 3 +- 7 files changed, 3 insertions(+), 101 deletions(-) delete mode 100644 s2cloudless/test_cloud_detector.py rename {s2cloudless => tests}/TestInputs/input_arrays.npz (100%) diff --git a/README.md b/README.md index 08da781..bfbd8fd 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ check [LightGBM installation guide](https://lightgbm.readthedocs.io/en/latest/In Before installing `s2cloudless` on **Windows** it is recommended to install package `shapely` from [Unofficial Windows wheels repository](https://www.lfd.uci.edu/~gohlke/pythonlibs/) - ## Input: Sentinel-2 scenes The input to cloud detector are Sentinel-2 images. In particular, the cloud detector requires the following 10 @@ -42,23 +41,6 @@ reflectance value in the following way: `B_i/10000`. You don't need to worry about any of this, if you're doing classification of scenes obtained using Sentinel Hub's WMS or WCS services (i.e. using ours Python library [sentinelhub-py](https://github.com/sentinel-hub/sentinelhub-py)). -## Test - -Please test the cloud detector after the installation by performing a classification on a test scene provided with -this package. To execute it do the following: - -```Python ->>> import s2cloudless ->>> s2cloudless.test_sentinelhub_cloud_detector() -``` - -In case your installation is fine and cloud detector works properly you should get the following output: - -``` -INFO:s2cloudless.test_cloud_detector:Test OK. -Cloud probabilities and cloud masks match templates. -``` - ## Examples Jupyter notebook on how to use the cloud detector to produce cloud mask or cloud probability map diff --git a/requirements.txt b/requirements.txt index b6f67b6..5feabb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,5 @@ numpy>=1.13.3 scipy>=0.19.1 scikit-learn>=0.19.0 scikit-image>=0.13.0 -matplotlib>=2.1.0; python_version < '3.7' -matplotlib>=3.0.2; python_version >= '3.7' lightgbm>=2.0.11 sentinelhub>=2.4.6 diff --git a/s2cloudless/__init__.py b/s2cloudless/__init__.py index 2804a92..4c4ec5a 100644 --- a/s2cloudless/__init__.py +++ b/s2cloudless/__init__.py @@ -4,7 +4,6 @@ from .S2PixelCloudDetector import S2PixelCloudDetector, CloudMaskRequest, MODEL_EVALSCRIPT, S2_BANDS_EVALSCRIPT from .PixelClassifier import PixelClassifier -from .test_cloud_detector import test_sentinelhub_cloud_detector -__version__ = '1.2.2' +__version__ = '1.3.0' diff --git a/s2cloudless/test_cloud_detector.py b/s2cloudless/test_cloud_detector.py deleted file mode 100644 index 594673b..0000000 --- a/s2cloudless/test_cloud_detector.py +++ /dev/null @@ -1,74 +0,0 @@ -""" -Python script to test cloud detector -""" - -import logging -import os -import numpy as np - -try: - import matplotlib.pyplot as plt -except ImportError: - import matplotlib - matplotlib.use('agg') - import matplotlib.pyplot as plt - -from s2cloudless import S2PixelCloudDetector - -LOGGER = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) - - -def test_sentinelhub_cloud_detector(display=False): - """ - Runs the classification on the test scene and compares the results with the provided - cloud probability map and probability mask. Used to verify the installation of the - package. - - :param display: flag to turn on or off the display of results. - :type display: bool, default is False - """ - # Load arrays - templates_filename = os.path.join(os.path.dirname(__file__), './TestInputs/input_arrays.npz') - templates = np.load(templates_filename) - - # Classifier instance, image has all bands - cloud_detector = S2PixelCloudDetector(all_bands=True) - - # Compute cloud probabilities - cloud_probs = cloud_detector.get_cloud_probability_maps(templates['s2_im']) - - # Compute cloud mask - cloud_mask = cloud_detector.get_cloud_masks(templates['s2_im']) - - # Check predicted results match templates - probs_ok = np.isclose(cloud_probs, templates['cl_probs']).all() - mask_ok = np.array_equal(cloud_mask, templates['cl_mask']) - - if not probs_ok: - LOGGER.info('Test FAILED.\nCloud probabilities DO NOT match templates.') - - if not mask_ok: - LOGGER.info('Test FAILED.\nCloud masks DO NOT match templates.') - - if mask_ok and probs_ok: - LOGGER.info('Test OK.\nCloud probabilities and cloud masks match templates.') - - # Display results - if display: - _ = plt.figure(figsize=(20, 10)) - plt.subplot(131) - plt.imshow(np.squeeze(templates['s2_im'])[:, :, [3, 2, 1]]) - plt.title('RGB image') - plt.axis('off') - plt.subplot(132) - plt.imshow(np.squeeze(templates['s2_im'])[:, :, [3, 2, 1]]) - plt.imshow(np.squeeze(templates['cl_mask']), vmin=0, vmax=1, alpha=.4) - plt.title('RGB image with template mask overlay') - plt.axis('off') - plt.subplot(133) - plt.imshow(np.squeeze(templates['s2_im'])[:, :, [3, 2, 1]]) - plt.imshow(np.squeeze(cloud_mask), vmin=0, vmax=1, alpha=.4) - plt.title('RGB image with predicted mask overlay') - plt.axis('off') - plt.show() diff --git a/setup.py b/setup.py index 30ba46d..8d1eeba 100644 --- a/setup.py +++ b/setup.py @@ -34,9 +34,7 @@ def parse_requirements(file): packages=find_packages(), package_dir={'': '.'}, include_package_data=True, - package_data={'s2cloudless': ['models/pixel_s2_cloud_detector_lightGBM_v0.1.joblib.dat', - 'TestInputs/input_arrays.npz'] - }, + package_data={'s2cloudless': ['models/pixel_s2_cloud_detector_lightGBM_v0.1.joblib.dat']}, install_requires=parse_requirements('requirements.txt'), extras_require={'DEV': parse_requirements('requirements-dev.txt')}, zip_safe=False, diff --git a/s2cloudless/TestInputs/input_arrays.npz b/tests/TestInputs/input_arrays.npz similarity index 100% rename from s2cloudless/TestInputs/input_arrays.npz rename to tests/TestInputs/input_arrays.npz diff --git a/tests/test_all.py b/tests/test_all.py index bfb580e..c5c98c3 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -6,8 +6,7 @@ class TestS2Cloudless(TestSentinelHub): - INPUT_DATA_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 's2cloudless', - 'TestInputs', 'input_arrays.npz') + INPUT_DATA_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'TestInputs', 'input_arrays.npz') if __name__ == '__main__':