├── .gitignore ├── CMakeLists.txt ├── COPYRIGHT ├── Common ├── CMakeLists.txt ├── include │ ├── BaseImageTypes.h │ ├── GlobalDefs.h │ ├── ImageResampler.h │ ├── MetadataAngles.h │ ├── MetadataBands.h │ ├── MetadataHelper.h │ ├── MetadataHelperFactory.h │ ├── MuscateMetadataHelper.h │ ├── ResamplingBandExtractor.h │ └── TestImageCreator.h ├── src │ ├── GlobalDefs.cpp │ ├── MetadataBands.cpp │ ├── MetadataHelper.cpp │ ├── MetadataHelperFactory.cpp │ └── MuscateMetadataHelper.cpp └── test │ ├── CMakeLists.txt │ ├── test_ImageResampler.cpp │ ├── test_MetadataBands.cpp │ ├── test_MuscateMetadataHelper.cpp │ └── test_MuscateMetadataHelperVenus.cpp ├── CompositePreprocessing ├── CMakeLists.txt ├── include │ ├── ComputeNDVI.h │ ├── CreateS2AnglesRaster.h │ ├── DirectionalCorrection.h │ ├── DirectionalCorrectionFilter.h │ ├── DirectionalCorrectionFunctor.h │ ├── DirectionalModel.h │ ├── MaskExtractorFilter.h │ ├── MaskExtractorFunctor.h │ ├── PreprocessingAdapter.h │ ├── PreprocessingSentinel.h │ └── PreprocessingVenus.h ├── scattering_coeffs_10m.txt ├── scattering_coeffs_20m.txt ├── src │ ├── CompositePreprocessing.cpp │ ├── ComputeNDVI.cpp │ ├── CreateS2AnglesRaster.cpp │ ├── DirectionalCorrection.cpp │ ├── DirectionalCorrectionFunctor.txx │ ├── DirectionalModel.cpp │ ├── MaskExtractorFilter.txx │ ├── PreprocessingAdapter.cpp │ ├── PreprocessingSentinel.cpp │ └── PreprocessingVenus.cpp └── test │ ├── CMakeLists.txt │ ├── test_ComputeNDVI.cpp │ ├── test_CreateS2AnglesRaster.cpp │ ├── test_DirectionalCorrection.cpp │ └── test_MaskExtractorFilter.cpp ├── Doxyfile.in ├── LICENSE.md ├── MuscateMetadata ├── CMakeLists.txt ├── include │ ├── FluentXML.hpp │ ├── MetadataUtil.hpp │ ├── MuscateMetadata.hpp │ ├── MuscateMetadataReader.hpp │ ├── MuscateMetadataWriter.hpp │ ├── ViewingAngles.hpp │ ├── string_utils.hpp │ └── tinyxml_utils.hpp ├── src │ ├── FluentXML.cpp │ ├── MetadataUtil.cpp │ ├── MuscateMetadataReader.cpp │ ├── MuscateMetadataWriter.cpp │ ├── ViewingAngles.cpp │ ├── string_utils.cpp │ └── tinyxml_utils.cpp └── test │ ├── CMakeLists.txt │ ├── test_MuscateMetadataReadWrite.cpp │ ├── test_MuscateMetadataReader.cpp │ └── test_MuscateMetadataWriteRead.cpp ├── ProductFormatter ├── CMakeLists.txt ├── include │ ├── ProductCreatorAdapter.h │ ├── ProductCreatorSentinelMuscate.h │ ├── ProductCreatorVenusMuscate.h │ └── ProductDefinitions.h ├── src │ ├── ProductCreatorAdapter.cpp │ ├── ProductCreatorSentinelMuscate.cpp │ ├── ProductCreatorVenusMuscate.cpp │ └── ProductFormatter.cpp └── test │ └── CMakeLists.txt ├── PythonScripts ├── CMakeLists.txt ├── CompareL3AProducts.py ├── WASP.py ├── __init__.py ├── base_comparison.py ├── test_S2A_T33UUU_8_20150727.py ├── test_S2B_T31TCH_1_20171008.py ├── test_S2B_T31TGL_1_20180321.py ├── test_S2X_T31TCJ_11_20180511.py └── test_VNS_FR-LUS_4_20180207.py ├── README.md ├── Scripts └── WASP ├── UpdateSynthesis ├── CMakeLists.txt ├── include │ ├── BandsDefs.h │ └── UpdateSynthesisFunctor.h ├── src │ ├── UpdateSynthesis.cpp │ └── UpdateSynthesisFunctor.txx └── test │ └── CMakeLists.txt └── WeightCalculation ├── CMakeLists.txt ├── TotalWeight ├── CMakeLists.txt ├── include │ └── TotalWeightComputation.h ├── src │ ├── TotalWeight.cpp │ └── TotalWeightComputation.cpp └── test │ └── CMakeLists.txt ├── WeightAOT ├── CMakeLists.txt ├── include │ └── WeightAOTComputation.h ├── src │ ├── WeightAOT.cpp │ └── WeightAOTComputation.cpp └── test │ └── CMakeLists.txt └── WeightOnClouds ├── CMakeLists.txt ├── include ├── CloudMaskBinarization.h ├── CloudWeightComputation.h ├── CloudsInterpolation.h ├── CuttingImageFilter.h ├── GaussianFilter.h ├── PaddingImageHandler.h └── ROIImageFilter.h ├── src └── WeightOnClouds.cpp └── test └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Install build folders 2 | install*/ 3 | build*/ 4 | 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | .idea/ 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | .hypothesis/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | .static_storage/ 60 | .media/ 61 | local_settings.py 62 | 63 | # Flask stuff: 64 | instance/ 65 | .webassets-cache 66 | 67 | # Scrapy stuff: 68 | .scrapy 69 | 70 | # Sphinx documentation 71 | docs/_build/ 72 | 73 | # PyBuilder 74 | target/ 75 | 76 | # Jupyter Notebook 77 | .ipynb_checkpoints 78 | 79 | # pyenv 80 | .python-version 81 | 82 | # celery beat schedule file 83 | celerybeat-schedule 84 | 85 | # SageMath parsed files 86 | *.sage.py 87 | 88 | # Environments 89 | .env 90 | .venv 91 | env/ 92 | venv/ 93 | ENV/ 94 | env.bak/ 95 | venv.bak/ 96 | # Eclipse project settings 97 | .settings 98 | .cproject 99 | .project 100 | 101 | # Spyder project settings 102 | .spyderproject 103 | .spyproject 104 | 105 | # Rope project settings 106 | .ropeproject 107 | 108 | # mkdocs documentation 109 | /site 110 | 111 | # mypy 112 | .mypy_cache/ 113 | 114 | # SonarQube 115 | .scannerwork/ 116 | 117 | # Project specific 118 | OUTPUTS/ 119 | 120 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(NewTemporalSynthesis) 2 | 3 | cmake_minimum_required(VERSION 2.8) 4 | 5 | include(CTest) 6 | 7 | find_package(OTB REQUIRED) 8 | find_program(BASH_Program bash) 9 | 10 | include(${OTB_USE_FILE}) 11 | include(FindPythonInterp) 12 | 13 | # Set a default build type if none was specified 14 | set(default_build_type "Release") 15 | 16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 17 | message(STATUS "Setting build type to '${default_build_type}' as none was specified.") 18 | set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE 19 | STRING "Choose the type of build." FORCE) 20 | # Set the possible values of build type for cmake-gui 21 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 22 | "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 23 | endif() 24 | 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wno-missing-field-initializers") 26 | 27 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) 28 | 29 | find_package(Boost REQUIRED COMPONENTS unit_test_framework filesystem) 30 | add_definitions(-DBOOST_TEST_DYN_LINK) 31 | 32 | message("Project binary folder:" ${PROJECT_BINARY_DIR}) 33 | add_definitions(-DVCL_CAN_STATIC_CONST_INIT_FLOAT=0) 34 | 35 | add_subdirectory(Common) 36 | add_subdirectory(MuscateMetadata) 37 | add_subdirectory(CompositePreprocessing) 38 | add_subdirectory(WeightCalculation) 39 | add_subdirectory(UpdateSynthesis) 40 | add_subdirectory(ProductFormatter) 41 | add_subdirectory(PythonScripts) 42 | 43 | install(FILES ./Scripts/WASP PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) 44 | # first we can indicate the documentation build as an option and set it to ON by default 45 | option(BUILD_DOC "Build documentation" ON) 46 | 47 | # add a target to generate API documentation with Doxygen 48 | find_package(Doxygen) 49 | if(DOXYGEN_FOUND) 50 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 51 | add_custom_target(doc 52 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 53 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 54 | COMMENT "Generating API documentation with Doxygen" VERBATIM 55 | ) 56 | endif(DOXYGEN_FOUND) 57 | 58 | message("Installing WASP to: " ${CMAKE_INSTALL_PREFIX}) 59 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: Weighted Average Synthesis Processor (WASP) 3 | Upstream-Contact: CNES , CESBIO 4 | 5 | Files: * 6 | Copyright: <2018-2019> Centre national d'études spatiales (CNES), France 7 | Comment: WASP project, initialy named TemporalSynthesis, for MUSCATE/THEIA 8 | License: GPL-3+ 9 | 10 | Files: Common/include/GlobalDefs.h 11 | Common/include/ImageResampler.h 12 | Common/include/MetadataAngles.h 13 | Common/include/MetadataHelperFactory.h 14 | Common/include/MetadataHelper.h 15 | Common/include/ResamplingBandExtractor.h 16 | Common/src/MetadataHelper.cpp 17 | Common/src/MetadataHelperFactory.cpp 18 | CompositePreprocessing/include/ComputeNDVI.h 19 | CompositePreprocessing/include/CreateS2AnglesRaster.h 20 | CompositePreprocessing/include/DirectionalCorrectionFilter.h 21 | CompositePreprocessing/include/DirectionalCorrectionFunctor.h 22 | CompositePreprocessing/include/DirectionalCorrection.h 23 | CompositePreprocessing/include/DirectionalModel.h 24 | CompositePreprocessing/include/MaskExtractorFilter.h 25 | CompositePreprocessing/src/ComputeNDVI.cpp 26 | CompositePreprocessing/src/CreateS2AnglesRaster.cpp 27 | CompositePreprocessing/src/DirectionalCorrection.cpp 28 | CompositePreprocessing/src/DirectionalCorrectionFunctor.txx 29 | CompositePreprocessing/src/DirectionalModel.cpp 30 | CompositePreprocessing/src/MaskExtractorFilter.txx 31 | MuscateMetadata/include/FluentXML.hpp 32 | MuscateMetadata/include/MetadataUtil.hpp 33 | MuscateMetadata/include/string_utils.hpp 34 | MuscateMetadata/include/tinyxml_utils.hpp 35 | MuscateMetadata/include/ViewingAngles.hpp 36 | MuscateMetadata/src/FluentXML.cpp 37 | MuscateMetadata/src/MetadataUtil.cpp 38 | MuscateMetadata/src/string_utils.cpp 39 | MuscateMetadata/src/tinyxml_utils.cpp 40 | MuscateMetadata/src/ViewingAngles.cpp 41 | ProductFormatter/src/ProductFormatter.cpp 42 | UpdateSynthesis/include/BandsDefs.h 43 | UpdateSynthesis/include/UpdateSynthesisFunctor.h 44 | UpdateSynthesis/src/UpdateSynthesis.cpp 45 | UpdateSynthesis/src/UpdateSynthesisFunctor.txx 46 | WeightCalculation/TotalWeight/include/TotalWeightComputation.h 47 | WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp 48 | WeightCalculation/TotalWeight/src/TotalWeight.cpp 49 | WeightCalculation/WeightAOT/include/WeightAOTComputation.h 50 | WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp 51 | WeightCalculation/WeightAOT/src/WeightAOT.cpp 52 | WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h 53 | WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h 54 | WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h 55 | WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h 56 | WeightCalculation/WeightOnClouds/include/GaussianFilter.h 57 | WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h 58 | WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp 59 | Copyright: <2014-2018> CS-Romania SA, Romania 60 | <2018-2019> Centre national d'études spatiales (CNES), France 61 | Comment: Initial work funded by ESA during the ESA DUE Sentinel-2 For 62 | Agriculture Project. Modified for WASP project 63 | License: GPL-3+ 64 | 65 | This program is free software: you can redistribute it and/or modify 66 | it under the terms of the GNU General Public License as published by 67 | the Free Software Foundation, either version 3 of the License, or 68 | (at your option) any later version. 69 | 70 | This program is distributed in the hope that it will be useful, 71 | but WITHOUT ANY WARRANTY; without even the implied warranty of 72 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 73 | GNU General Public License for more details. 74 | 75 | You should have received a copy of the GNU General Public License 76 | along with this program. If not, see . 77 | -------------------------------------------------------------------------------- /Common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MetadataHelper_HEADERS 2 | include/MuscateMetadataHelper.h 3 | include/MetadataHelperFactory.h 4 | include/MetadataHelper.h 5 | include/MetadataBands.h 6 | include/MetadataAngles.h 7 | include/GlobalDefs.h 8 | include/ResamplingBandExtractor.h 9 | include/ImageResampler.h 10 | include/TestImageCreator.h 11 | ) 12 | 13 | set(MetadataHelper_SOURCES 14 | src/MuscateMetadataHelper.cpp 15 | src/GlobalDefs.cpp 16 | src/MetadataHelper.cpp 17 | src/MetadataBands.cpp 18 | src/MetadataHelperFactory.cpp 19 | ) 20 | 21 | add_library(MetadataHelper SHARED ${MetadataHelper_HEADERS} ${MetadataHelper_SOURCES}) 22 | target_link_libraries(MetadataHelper MuscateMetadata 23 | "${Boost_LIBRARIES}" 24 | "${OTBCommon_LIBRARIES}" 25 | "${OTBITK_LIBRARIES}") 26 | 27 | target_include_directories(MetadataHelper PUBLIC include) 28 | install(TARGETS MetadataHelper DESTINATION lib/) 29 | 30 | if(BUILD_TESTING) 31 | add_subdirectory(test) 32 | endif() 33 | -------------------------------------------------------------------------------- /Common/include/BaseImageTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef COMMON_INCLUDE_BASEIMAGETYPES_H_ 29 | #define COMMON_INCLUDE_BASEIMAGETYPES_H_ 30 | 31 | 32 | #include "itkLightObject.h" 33 | #include "otbImage.h" 34 | #include "otbVectorImage.h" 35 | #include "otbImageFileReader.h" 36 | #include "otbObjectList.h" 37 | #include "otbImageList.h" 38 | #include "otbWrapperApplication.h" 39 | 40 | /** 41 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 42 | */ 43 | namespace ts { 44 | /** 45 | * @brief Stores all base typedefs used in the processing chain 46 | */ 47 | class BaseImageTypes{ 48 | public: 49 | typedef unsigned char BytePixelType; 50 | typedef otb::Image ByteImageType; 51 | typedef otb::ImageFileReader ByteImageReaderType; 52 | typedef otb::ObjectList ByteImageReaderListType; 53 | typedef otb::ImageList ByteImageListType; 54 | 55 | typedef short ShortPixelType; 56 | typedef otb::Image ShortImageType; 57 | typedef otb::ImageFileReader ShortImageReaderType; 58 | typedef otb::ObjectList ShortImageReaderListType; 59 | typedef otb::ImageList ShortImageListType; 60 | 61 | typedef otb::Wrapper::Int16VectorImageType ShortVectorImageType; 62 | typedef otb::ImageFileReader ShortVectorImageReaderType; 63 | typedef otb::ObjectList ShortVectorImageReaderListType; 64 | typedef otb::ImageList ShortVectorImageListType; 65 | 66 | typedef float FloatPixelType; 67 | typedef otb::Image FloatImageType; 68 | typedef otb::ImageFileReader FloatImageReaderType; 69 | typedef otb::ObjectList FloatImageReaderListType; 70 | typedef otb::ImageList FloatImageListType; 71 | 72 | typedef otb::Wrapper::FloatVectorImageType FloatVectorImageType; 73 | typedef otb::ImageFileReader FloatVectorImageReaderType; 74 | typedef otb::ObjectList FloatVectorImageReaderListType; 75 | typedef otb::ImageList FloatVectorImageListType; 76 | 77 | }; 78 | } // namespace ts 79 | 80 | 81 | #endif /* COMMON_INCLUDE_BASEIMAGETYPES_H_ */ 82 | -------------------------------------------------------------------------------- /Common/include/GlobalDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef GLOBALDEFS_H 27 | #define GLOBALDEFS_H 28 | 29 | #include 30 | #include 31 | /** 32 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 33 | */ 34 | namespace ts { 35 | 36 | 37 | /* The product return Type used for all products */ 38 | using productReturnType = std::vector; 39 | 40 | #define DEFAULT_QUANTIFICATION_VALUE 1000 41 | #define NO_DATA_VALUE -10000 42 | 43 | #define WEIGHT_NO_DATA_VALUE -10000 44 | 45 | #define EPSILON 0.0001f 46 | 47 | #define TIF_EXTENSION ".tif" 48 | #define JPEG_EXTENSION ".jpg" 49 | #define XML_EXTENSION ".xml" 50 | 51 | #define COMPOSITE_REFLECTANCE_SUFFIX "FRC" 52 | #define REFLECTANCE_SUFFIX "SRE" 53 | #define FLAT_REFLECTANCE_SUFFIX "FRE" 54 | #define QUICKLOOK_SUFFIX "QKL_ALL" 55 | #define COMPOSITE_WEIGHTS_SUFFIX "WGT" 56 | #define COMPOSITE_DATES_SUFFIX "DTS" 57 | #define COMPOSITE_FLAGS_SUFFIX "FLG" 58 | #define METADATA_CATEG "MTD_ALL" 59 | #define IPP_DATA_SUFFIX "IPP_ALL" 60 | 61 | #define NO_DATA_VALUE_STR "-10000" 62 | 63 | #define DATA_FOLDER_NAME "DATA" 64 | #define MASKS_FOLDER_NAME "MASKS" 65 | 66 | 67 | #define SENTINEL_MISSION_STR "SENTINEL" 68 | #define VENUS_MISSION_STR "VENUS" 69 | 70 | #define LANDSAT8 "LANDSAT8" 71 | #define SENTINEL2X "SENTINEL2X" 72 | #define SENTINEL2A "SENTINEL2A" 73 | #define SENTINEL2B "SENTINEL2B" 74 | #define MULTISAT "S2AS2BL8" 75 | #define VENUS VENUS_MISSION_STR 76 | 77 | #define NONE_STRING "None" 78 | 79 | #define MAIN_RESOLUTION_INDEX 0 80 | #define N_RESOLUTIONS_SENTINEL 2 81 | /** 82 | * @brief Output Flag-mask definitions 83 | */ 84 | typedef enum { 85 | IMG_FLG_NO_DATA=0, //!< IMG_FLG_NO_DATA 86 | IMG_FLG_CLOUD=1, //!< IMG_FLG_CLOUD 87 | IMG_FLG_SNOW=2, //!< IMG_FLG_SNOW 88 | IMG_FLG_WATER=3, //!< IMG_FLG_WATER 89 | IMG_FLG_LAND=4, //!< IMG_FLG_LAND 90 | IMG_FLG_CLOUD_SHADOW=5,//!< IMG_FLG_CLOUD_SHADOW 91 | IMG_FLG_SATURATION=6 //!< IMG_FLG_SATURATION 92 | } FlagType; 93 | 94 | 95 | /** 96 | * @brief Interpolator types 97 | */ 98 | typedef enum 99 | { 100 | Interpolator_NNeighbor,//!< Interpolator_NNeighbor 101 | Interpolator_Linear, //!< Interpolator_Linear 102 | Interpolator_BCO //!< Interpolator_BCO 103 | } Interpolator_Type; 104 | 105 | /** 106 | * @brief Used to determine whether the underlying structure has a size()-method or not. 107 | * @note Used in the ShortToFloat- and FloatToShort-TranslationFunctors 108 | */ 109 | template 110 | struct HasSizeMethod 111 | { 112 | template struct SFINAE {}; 113 | template static char Test(SFINAE*); 114 | template static int Test(...); 115 | static const bool Has = sizeof(Test(0)) == sizeof(char); 116 | }; 117 | 118 | ///////////////////////// 119 | /// GLOBAL FUNCTIONS /// 120 | /////////////////////// 121 | 122 | /** 123 | * @brief Returns the base name in a string 124 | * @param path Reference to the input string 125 | * @return string containing the base name 126 | */ 127 | std::string getDirname(const std::string &path); 128 | 129 | /** 130 | *@brief Returns the directory name in a string 131 | *@param path Reference to the input string 132 | *@return string containing the directory name 133 | */ 134 | std::string getBasename(const std::string &path); 135 | 136 | /** 137 | * @brief get Environment Variable by key name 138 | * @param key The name of the key, e.g. PATH 139 | * @return The value of the variable, if existing 140 | */ 141 | std::string getEnvVar( std::string const & key ); 142 | 143 | } // namespace ts 144 | 145 | #endif //GLOBALDEFS_H 146 | -------------------------------------------------------------------------------- /Common/include/MetadataAngles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef COMMON_METADATAANGLES_H_ 27 | #define COMMON_METADATAANGLES_H_ 28 | 29 | #include 30 | 31 | /** 32 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 33 | */ 34 | namespace ts { 35 | 36 | typedef struct { 37 | double zenith; 38 | double azimuth; 39 | } MeanAngles_Type; 40 | 41 | struct MetadataHelperAngleList 42 | { 43 | std::string ColumnUnit; 44 | std::string ColumnStep; 45 | std::string RowUnit; 46 | std::string RowStep; 47 | std::vector > Values; 48 | }; 49 | 50 | struct MetadataHelperAngles 51 | { 52 | MetadataHelperAngleList Zenith; 53 | MetadataHelperAngleList Azimuth; 54 | }; 55 | 56 | struct MetadataHelperViewingAnglesGrid 57 | { 58 | std::string BandId; 59 | std::string DetectorId; 60 | MetadataHelperAngles Angles; 61 | }; 62 | 63 | typedef enum {MSK_CLOUD=1, MSK_SNOW=2, MSK_WATER=4, MSK_SAT=8, MSK_VALID=16, ALL=0x1F} MasksFlagType; 64 | 65 | } // namespace ts 66 | #endif /* COMMON_METADATAANGLES_H_ */ 67 | -------------------------------------------------------------------------------- /Common/include/MetadataHelperFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef COMPOSITENAMINGHELPERFACTORY_H 27 | #define COMPOSITENAMINGHELPERFACTORY_H 28 | 29 | #include "itkLightObject.h" 30 | #include "itkObjectFactory.h" 31 | 32 | #include "MetadataHelper.h" 33 | #include 34 | #include 35 | 36 | /** 37 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 38 | */ 39 | namespace ts { 40 | 41 | /** 42 | * @brief Factory to load a metadata-helper 43 | */ 44 | class MetadataHelperFactory : public itk::LightObject 45 | { 46 | public: 47 | typedef MetadataHelperFactory Self; 48 | typedef itk::LightObject Superclass; 49 | typedef itk::SmartPointer Pointer; 50 | typedef itk::SmartPointer ConstPointer; 51 | 52 | itkNewMacro(Self) 53 | 54 | itkTypeMacro(MetadataHelperFactory, itk::LightObject) 55 | 56 | std::unique_ptr GetMetadataHelper(const std::string& metadataFileName); 57 | }; 58 | } // namespace ts 59 | 60 | #endif // COMPOSITENAMINGHELPERFACTORY_H 61 | -------------------------------------------------------------------------------- /Common/include/MuscateMetadataHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef MUSCATEMETADATAHELPER_H 29 | #define MUSCATEMETADATAHELPER_H 30 | 31 | #include "MetadataHelper.h" 32 | #include "../../MuscateMetadata/include/MuscateMetadataReader.hpp" 33 | #include 34 | #include "GlobalDefs.h" 35 | 36 | /** 37 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 38 | */ 39 | namespace ts { 40 | 41 | /** 42 | * @brief Class to load a MuscateMetadata-file 43 | */ 44 | class MuscateMetadataHelper : public MetadataHelper 45 | { 46 | public: 47 | MuscateMetadataHelper(); 48 | const char * GetNameOfClass() { return "MuscateMetadataHelper"; } 49 | 50 | /** 51 | * @brief Return Filename by given string 52 | * @param filenames The vector of filenames to be searched for 53 | * @param toFind The string to be found. 54 | * @return The filename containing a string. If multiple results are given, it returns the first element. 55 | * If none are found, an empty string is returned 56 | */ 57 | std::string getFileNameByString(const productReturnType &filenames, const std::string &toFind); 58 | 59 | /** 60 | * @brief Get a pointer to the full metadata Struct 61 | * @return Shared Ptr to the internal MuscateFileMetadata 62 | */ 63 | std::shared_ptr getFullMetadata(); 64 | 65 | protected: 66 | 67 | typedef ts::muscate::MuscateMetadataReader MuscateMetadataReaderType; 68 | 69 | /** 70 | * @brief The main Metadata-reader function. Sets all variables and has to be called prior to using them 71 | * @return True, if the reading suceeded, false if not 72 | */ 73 | bool DoLoadMetadata(); 74 | 75 | productReturnType getAllImageFileNames(const std::string &name); 76 | productReturnType getAllMaskFileNames(const std::string &name); 77 | productReturnType getImageFilenamesByResolution(const std::string &trigram, const size_t &res); 78 | productReturnType getImageFileName(); 79 | productReturnType getAotFileName(); 80 | productReturnType getCloudFileName(); 81 | productReturnType getWaterFileName(); 82 | productReturnType getSnowFileName(); 83 | productReturnType getQualityFileName(); 84 | 85 | private: 86 | 87 | /** 88 | * @brief Checks if mission string is known 89 | * @param mission The mission string found 90 | * @return True, if mission is VENUS/Sentinel, false otherwise 91 | */ 92 | bool IsMissionKnown(const std::string &mission); 93 | 94 | /** 95 | * @brief Updates all values for Venus products 96 | */ 97 | void UpdateValuesForVenus(); 98 | 99 | /** 100 | * @brief Updates all values for the Sentinel-L2A products 101 | */ 102 | void UpdateValuesForSentinel(); 103 | 104 | /** 105 | * @brief Reads all Angles values 106 | * @note Mostly found in the Geometric_Informations section of the Metadata 107 | */ 108 | void UpdateAngles(); 109 | 110 | /** 111 | * @brief Remove duplicate elements inside the given vector 112 | * @param vec The vector containing multiple filenames, some can be duplicates. 113 | * @note Return by reference 114 | */ 115 | void removeDuplicateElements(productReturnType &vec); 116 | /** 117 | * @brief MuscateMetadataHelper::CheckFileExistence 118 | * Checks if the file exists and if not, it tries to change the extension to small capitals letters. 119 | * If the file with the changed extension exists, it is returned instead otherwise it is not modified 120 | * @param fileName - in/out parameter 121 | * @return 122 | */ 123 | bool CheckFileExistence(std::string &fileName); 124 | 125 | std::shared_ptr m_metadata; 126 | }; 127 | } // namespace ts 128 | #endif // MUSCATEMETADATAHELPER_H 129 | -------------------------------------------------------------------------------- /Common/include/TestImageCreator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef COMMON_INCLUDE_TESTIMAGECREATOR_H_ 29 | #define COMMON_INCLUDE_TESTIMAGECREATOR_H_ 30 | 31 | #include "BaseImageTypes.h" 32 | 33 | /** 34 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 35 | */ 36 | namespace ts { 37 | 38 | class TestImageCreator : public BaseImageTypes{ 39 | public: 40 | 41 | /** 42 | * @brief Create test image of size height * width with values 0...height*width 43 | * @param height 44 | * @param width 45 | * @return 46 | */ 47 | template 48 | typename TImage::Pointer createTestImage(const size_t &height, const size_t &width){ 49 | itk::Size<2> size({width, height}); 50 | 51 | itk::Index<2> index; 52 | index.Fill(0); 53 | 54 | itk::ImageRegion<2> region(index, size); 55 | 56 | typename TImage::Pointer testImg = TImage::New(); 57 | testImg->SetRegions(region); 58 | testImg->Allocate(); 59 | testImg->FillBuffer(0); 60 | size_t i = 0; 61 | for(unsigned int c = 0; c < height; c++) 62 | { 63 | for(unsigned int r = 0; r < width; r++) 64 | { 65 | typename TImage::IndexType pixelIndex; 66 | pixelIndex[0] = r; 67 | pixelIndex[1] = c; 68 | testImg->SetPixel(pixelIndex, i++); 69 | } 70 | } 71 | return testImg.GetPointer(); 72 | } 73 | }; 74 | 75 | } //namespace ts 76 | 77 | 78 | #endif /* COMMON_INCLUDE_TESTIMAGECREATOR_H_ */ 79 | -------------------------------------------------------------------------------- /Common/src/GlobalDefs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #include "GlobalDefs.h" 29 | #include 30 | #include 31 | 32 | std::string ts::getDirname(const std::string &path) { 33 | boost::filesystem::path p(path); 34 | p.remove_filename(); 35 | return p.native(); 36 | } 37 | 38 | std::string ts::getBasename(const std::string &path) { 39 | boost::filesystem::path p(path); 40 | return p.filename().native(); 41 | } 42 | 43 | std::string ts::getEnvVar( std::string const & key ) { 44 | char * val = getenv( key.c_str() ); 45 | return val == NULL ? std::string("") : std::string(val); 46 | } 47 | -------------------------------------------------------------------------------- /Common/src/MetadataBands.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #include "MetadataBands.h" 29 | 30 | using namespace ts; 31 | 32 | int Resolution::getBandIndexByType(const std::string &type){ 33 | for(size_t band = 0; band < m_bands.size(); band++){ 34 | if(m_bands[band].getType() == type) return (int)band; 35 | } 36 | return -1; 37 | } 38 | 39 | bool Resolution::doesBandTypeExist(const std::string &type){ 40 | if(getBandIndexByType(type) >= 0) return true; 41 | return false; 42 | } 43 | 44 | 45 | MultiResolution::MultiResolution(){ 46 | m_resolutions = {}; 47 | } 48 | 49 | void MultiResolution::addResolution(const Resolution &res){ 50 | m_resolutions.emplace_back(res); 51 | } 52 | 53 | size_t MultiResolution::getNumberOfResolutions(){ 54 | return m_resolutions.size(); 55 | } 56 | 57 | size_t MultiResolution::getTotalNumberOfBands(){ 58 | size_t total = 0; 59 | for(auto resolution : m_resolutions){ 60 | total += resolution.getBands().size(); 61 | } 62 | return total; 63 | } 64 | 65 | productReturnType MultiResolution::getNthResolutionFilenames(const size_t &n = 0){ 66 | if(n > m_resolutions.size()){ 67 | return {}; 68 | } 69 | productReturnType filenames; 70 | for(auto band : m_resolutions[n].getBands()){ 71 | filenames.emplace_back(band.getPath()); 72 | } 73 | return filenames; 74 | } 75 | 76 | bool MultiResolution::doesBandTypeExist(const std::string &type) const{ 77 | for(auto resolution : m_resolutions){ 78 | for(auto band : resolution.getBands()){ 79 | if(band.getType() == type) return true; 80 | } 81 | } 82 | return false; 83 | } 84 | 85 | std::string MultiResolution::getSpecificBandTypeFilename(const std::string &type){ 86 | for(auto resolution : m_resolutions){ 87 | for(auto band : resolution.getBands()){ 88 | if(band.getType() == type) return band.getPath(); 89 | } 90 | } 91 | return ""; 92 | } 93 | -------------------------------------------------------------------------------- /Common/src/MetadataHelper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "MetadataHelper.h" 27 | #include 28 | #include 29 | #include 30 | #include "libgen.h" 31 | #include 32 | #include 33 | 34 | using namespace ts; 35 | 36 | MetadataHelper::MetadataHelper() 37 | { 38 | m_detailedAnglesGridSize = 0; 39 | m_Resolutions = {}; 40 | } 41 | 42 | MetadataHelper::~MetadataHelper() 43 | { 44 | 45 | } 46 | 47 | bool MetadataHelper::LoadMetadataFile(const std::string& file) 48 | { 49 | Reset(); 50 | m_inputMetadataFileName = file; 51 | m_DirName = getDirname(m_inputMetadataFileName); 52 | m_basename = getBasename(m_inputMetadataFileName); 53 | return DoLoadMetadata(); 54 | } 55 | 56 | void MetadataHelper::Reset() 57 | { 58 | m_Mission = ""; 59 | m_productLevel = ""; 60 | 61 | m_AotFileName = {""}; 62 | m_CloudFileName = {""}; 63 | m_WaterFileName = {""}; 64 | m_SnowFileName = {""}; 65 | m_ImageFileName = {""}; 66 | 67 | m_AcquisitionDate = ""; 68 | 69 | m_ReflQuantifVal = 1.0; 70 | 71 | m_fAotQuantificationValue = 0.0; 72 | m_fAotNoDataVal = 0; 73 | 74 | m_solarMeanAngles.azimuth = m_solarMeanAngles.zenith = 0.0; 75 | m_bHasDetailedAngles = false; 76 | m_Resolutions = {}; 77 | } 78 | 79 | std::string MetadataHelper::GetAcquisitionDate(){ 80 | std::string acqDateShort = m_AcquisitionDate.substr(0, m_AcquisitionDate.find("T", 0)); //Cut After "T" 81 | acqDateShort.erase(std::remove(acqDateShort.begin(), acqDateShort.end(), '-'), acqDateShort.end()); //Remove the two "-" separators 82 | 83 | return acqDateShort; 84 | } 85 | 86 | int MetadataHelper::GetAcquisitionDateAsDoy() 87 | { 88 | struct tm tmDate = {}; 89 | if (strptime(GetAcquisitionDate().c_str(), "%Y%m%d", &tmDate) == NULL) { 90 | return -1; 91 | } 92 | auto curTime = std::mktime(&tmDate); 93 | 94 | std::tm tmYearStart = {}; 95 | tmYearStart.tm_year = tmDate.tm_year; 96 | tmYearStart.tm_mon = 0; 97 | tmYearStart.tm_mday = 1; 98 | 99 | auto yearStart = std::mktime(&tmYearStart); 100 | auto diff = curTime - yearStart; 101 | 102 | return lrintf(diff / 86400 /* 60*60*24*/); 103 | } 104 | 105 | MeanAngles_Type MetadataHelper::GetSensorMeanAngles() { 106 | MeanAngles_Type angles = {0,0}; 107 | 108 | if(HasBandMeanAngles()) { 109 | size_t nBandsCnt = m_sensorBandsMeanAngles.size(); 110 | int nValidAzimuths = 0; 111 | int nValidZeniths = 0; 112 | for(size_t i = 0; i < nBandsCnt; i++) { 113 | MeanAngles_Type bandAngles = m_sensorBandsMeanAngles[i]; 114 | if(!std::isnan(bandAngles.azimuth)) { 115 | angles.azimuth += bandAngles.azimuth; 116 | nValidAzimuths++; 117 | } 118 | if(!std::isnan(bandAngles.zenith)) { 119 | angles.zenith += bandAngles.zenith; 120 | nValidZeniths++; 121 | } 122 | } 123 | if(nValidAzimuths > 0) { 124 | angles.azimuth = angles.azimuth / nValidAzimuths; 125 | } else { 126 | angles.azimuth = 0; 127 | } 128 | if(nValidZeniths > 0) { 129 | angles.zenith = angles.zenith / nValidZeniths; 130 | } else { 131 | angles.zenith = 0; 132 | } 133 | } else { 134 | angles = GetSensorMeanAngles(0); 135 | } 136 | 137 | return angles; 138 | } 139 | 140 | MeanAngles_Type MetadataHelper::GetSensorMeanAngles(int nBand) { 141 | MeanAngles_Type angles = {0,0}; 142 | if(nBand >= 0 && nBand < (int)m_sensorBandsMeanAngles.size()) { 143 | angles = m_sensorBandsMeanAngles[nBand]; 144 | } else if(m_sensorBandsMeanAngles.size() > 0) { 145 | angles = m_sensorBandsMeanAngles[0]; 146 | } 147 | return angles; 148 | } 149 | 150 | double MetadataHelper::GetRelativeAzimuthAngle() 151 | { 152 | MeanAngles_Type solarAngle = GetSolarMeanAngles(); 153 | MeanAngles_Type sensorAngle = GetSensorMeanAngles(); 154 | 155 | double relAzimuth = solarAngle.azimuth - sensorAngle.azimuth/* - 180.0 */; 156 | /* 157 | if (relAzimuth < -180.0) { 158 | relAzimuth = relAzimuth + 360.0; 159 | } 160 | if (relAzimuth > 180.0) { 161 | relAzimuth = relAzimuth - 360.0; 162 | } 163 | */ 164 | return relAzimuth; 165 | } 166 | 167 | std::string MetadataHelper::buildFullPath(const std::string& fileName) 168 | { 169 | boost::filesystem::path p(m_DirName); 170 | p /= fileName; 171 | return p.string(); 172 | } 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /Common/src/MetadataHelperFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "MetadataHelperFactory.h" 27 | #include "MuscateMetadataHelper.h" 28 | 29 | using namespace ts; 30 | 31 | std::unique_ptr MetadataHelperFactory::GetMetadataHelper(const std::string& metadataFileName) 32 | { 33 | 34 | //Only Muscate existing so far here. 35 | std::unique_ptr muscateMetadataHelper(new MuscateMetadataHelper); 36 | if (muscateMetadataHelper->LoadMetadataFile(metadataFileName)){ 37 | return muscateMetadataHelper; 38 | } 39 | itkExceptionMacro("Unable to read metadata from " << metadataFileName); 40 | return NULL; 41 | } 42 | -------------------------------------------------------------------------------- /Common/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(test_MetadataBands test_MetadataBands.cpp) 2 | target_link_libraries(test_MetadataBands 3 | MuscateMetadata 4 | MetadataHelper 5 | "${Boost_LIBRARIES}" 6 | "${OTBCommon_LIBRARIES}" 7 | "${OTBITK_LIBRARIES}" 8 | ) 9 | 10 | add_executable(test_MuscateMetadataHelper test_MuscateMetadataHelper.cpp) 11 | target_link_libraries(test_MuscateMetadataHelper 12 | MuscateMetadata 13 | MetadataHelper 14 | "${Boost_LIBRARIES}" 15 | "${OTBCommon_LIBRARIES}" 16 | "${OTBITK_LIBRARIES}" 17 | ) 18 | 19 | 20 | add_executable(test_MuscateMetadataHelperVenus test_MuscateMetadataHelperVenus.cpp) 21 | target_link_libraries(test_MuscateMetadataHelperVenus 22 | MuscateMetadata 23 | MetadataHelper 24 | "${Boost_LIBRARIES}" 25 | "${OTBCommon_LIBRARIES}" 26 | "${OTBITK_LIBRARIES}" 27 | ) 28 | 29 | add_executable(test_ImageResampler test_ImageResampler.cpp ../include/ImageResampler.h) 30 | target_link_libraries(test_ImageResampler 31 | MuscateMetadata 32 | MetadataHelper 33 | ${Boost_LIBRARIES} 34 | ${OTB_LIBRARIES} 35 | ) 36 | 37 | target_include_directories(test_MuscateMetadataHelper PUBLIC ../include) 38 | add_test(test_MuscateMetadataHelper test_MuscateMetadataHelper) 39 | 40 | target_include_directories(test_MetadataBands PUBLIC ../include) 41 | add_test(test_MetadataBands test_MetadataBands) 42 | 43 | target_include_directories(test_MuscateMetadataHelperVenus PUBLIC ../include) 44 | add_test(test_MuscateMetadataHelperVenus test_MuscateMetadataHelperVenus) 45 | 46 | target_include_directories(test_ImageResampler PUBLIC ../include) 47 | add_test(test_ImageResampler test_ImageResampler) 48 | -------------------------------------------------------------------------------- /Common/test/test_ImageResampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #define BOOST_TEST_MODULE ImageResampler 29 | #include 30 | #include "../include/ImageResampler.h" 31 | #include "TestImageCreator.h" 32 | #include 33 | 34 | using namespace ts; 35 | 36 | typedef short InputPixelType; 37 | typedef float OutputPixelType; 38 | 39 | typedef otb::Image OutputImageType; 40 | typedef otb::Image InputImageType; 41 | 42 | 43 | BOOST_AUTO_TEST_CASE( testResamplingFloat ){ 44 | 45 | ts::TestImageCreator t; 46 | OutputImageType::Pointer testImg = t.createTestImage(5,5); 47 | ImageResampler resampler; 48 | 49 | OutputImageType::Pointer output = resampler.getResamplerWantedSize(testImg.GetPointer(), 2, 2)->GetOutput(); 50 | output->Update(); 51 | itk::ImageRegionIterator imageIterator(output,output->GetLargestPossibleRegion()); 52 | 53 | std::vector ref = {6,9,21,24}; 54 | size_t i = 0; 55 | while(!imageIterator.IsAtEnd()) 56 | { 57 | BOOST_CHECK_EQUAL(imageIterator.Get(), ref[i++]); 58 | ++imageIterator; 59 | } 60 | } 61 | 62 | BOOST_AUTO_TEST_CASE( testResamplingShort ){ 63 | 64 | ts::TestImageCreator t; 65 | InputImageType::Pointer testImg = t.createTestImage(5,5); 66 | ImageResampler resampler; 67 | 68 | InputImageType::Pointer output = resampler.getResamplerWantedSize(testImg.GetPointer(), 2, 2)->GetOutput(); 69 | output->Update(); 70 | itk::ImageRegionIterator imageIterator(output,output->GetLargestPossibleRegion()); 71 | 72 | std::vector ref = {6,9,21,24}; 73 | size_t i = 0; 74 | while(!imageIterator.IsAtEnd()) 75 | { 76 | BOOST_CHECK_EQUAL(imageIterator.Get(), ref[i++]); 77 | ++imageIterator; 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /Common/test/test_MetadataBands.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #define BOOST_TEST_MODULE MetadataBands 29 | #include 30 | #include "MetadataBands.h" 31 | #include 32 | 33 | using namespace ts; 34 | 35 | const std::string SREtype = std::string(FLAT_REFLECTANCE_SUFFIX); 36 | const std::vector SREendings = {"B2", "B3", "B4", "B5", "B6", "B7", "B8", "B8A", "B11", "B12"}; 37 | const std::vector SREresolutions = {10, 10, 10, 20, 20, 20, 10, 20, 20, 20}; 38 | 39 | 40 | Resolution initR1(){ 41 | Resolution R1("R1"); 42 | for(size_t i = 0; i < SREendings.size(); i++){ 43 | Band B(std::string(SREtype + "_" + SREendings[i] + TIF_EXTENSION), SREendings[i], SREresolutions[i]); 44 | if(SREresolutions[i] == 10){ 45 | R1.addBand(B); 46 | } 47 | } 48 | 49 | return R1; 50 | } 51 | 52 | Resolution initR2(){ 53 | Resolution R2("R2"); 54 | for(size_t i = 0; i < SREendings.size(); i++){ 55 | Band B(std::string(SREtype + "_" + SREendings[i] + TIF_EXTENSION), SREendings[i], SREresolutions[i]); 56 | if(SREresolutions[i] == 20){ 57 | R2.addBand(B); 58 | } 59 | } 60 | 61 | return R2; 62 | } 63 | 64 | BOOST_AUTO_TEST_CASE( testBandPresence ){ 65 | Resolution R1 = initR1(); Resolution R2 = initR2(); 66 | MultiResolution res; 67 | BOOST_CHECK_EQUAL(res.getNumberOfResolutions(), size_t(0)); 68 | BOOST_CHECK_EQUAL(res.getTotalNumberOfBands(), size_t(0)); 69 | res.addResolution(R1); //Main resolution, therefore has to be added first 70 | BOOST_CHECK_EQUAL(res.getNumberOfResolutions(), size_t(1)); 71 | BOOST_CHECK_EQUAL(res.getTotalNumberOfBands(), size_t(4)); 72 | res.addResolution(R2); 73 | BOOST_CHECK_EQUAL(res.getNumberOfResolutions(), size_t(2)); 74 | BOOST_CHECK_EQUAL(res.getTotalNumberOfBands(), size_t(10)); 75 | 76 | size_t totalNumber = res.getTotalNumberOfBands(); 77 | 78 | for(size_t i = 0; i < totalNumber; i++){ 79 | BOOST_CHECK(res.doesBandTypeExist(SREendings[i])); 80 | } 81 | } 82 | 83 | BOOST_AUTO_TEST_CASE( testBandFilenames ){ 84 | Resolution R1 = initR1(); Resolution R2 = initR2(); 85 | MultiResolution res; 86 | res.addResolution(R1); //Main resolution, therefore has to be added first 87 | res.addResolution(R2); 88 | 89 | BOOST_CHECK_EQUAL(res.getSpecificBandTypeFilename(SREendings[0]), "FRE_B2.tif"); 90 | BOOST_CHECK_EQUAL(res.getSpecificBandTypeFilename(SREendings[9]), "FRE_B12.tif"); 91 | 92 | productReturnType filenames = res.getNthResolutionFilenames(0); //Main 93 | BOOST_CHECK_EQUAL(filenames.size(), size_t(4)); 94 | BOOST_CHECK_EQUAL(filenames[0], "FRE_B2.tif"); 95 | BOOST_CHECK_EQUAL(filenames[1], "FRE_B3.tif"); 96 | BOOST_CHECK_EQUAL(filenames[2], "FRE_B4.tif"); 97 | BOOST_CHECK_EQUAL(filenames[3], "FRE_B8.tif"); 98 | 99 | } 100 | -------------------------------------------------------------------------------- /Common/test/test_MuscateMetadataHelperVenus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #define BOOST_TEST_MODULE MuscateWriter 29 | #include 30 | #include "../include/MuscateMetadataHelper.h" 31 | #include "../include/GlobalDefs.h" 32 | #include 33 | 34 | using namespace ts; 35 | 36 | #define TEST_NAME "test_MuscateMetadata" 37 | #define TEST_SRC getEnvVar("WASP_TEST") 38 | #define INPUT_XML1 "VENUS-XS_20180202-105554-000_L2A_FR-LUS_C_V1-0_MTD_ALL.xml" 39 | 40 | const std::vector FRE_endings = {"FRE_B1", "FRE_B2", "FRE_B3", "FRE_B4", "FRE_B5", "FRE_B6", "FRE_B7", "FRE_B8", "FRE_B9", "FRE_B10", "FRE_B11", "FRE_B12"}; 41 | const std::vector CLDendings = {"CLM_XS"}; 42 | const std::vector MG2endings = {"MG2_XS"}; 43 | const std::vector ATBendings = {"ATB_XS"}; 44 | 45 | /** 46 | * @brief Find if string ends with certain ending. 47 | * @param value The string to be tested 48 | * @param ending The ending to be searched for 49 | * @param Append filename ".tif" to every ending, if true 50 | * @return True, if value ends in ending, False if not 51 | */ 52 | inline bool ends_with(std::string const & value, std::vector const & endings, const bool &withFilename = true) 53 | { 54 | for(auto ending : endings){ 55 | std::string endingFilename = withFilename? ending + ".tif" : ending; 56 | if (endingFilename.size() > value.size()) return false; 57 | if(std::equal(endingFilename.rbegin(), endingFilename.rend(), value.rbegin())){ 58 | return true; 59 | } 60 | } 61 | std::cout << "Cannot find ending for " << value << std::endl; 62 | return false; 63 | 64 | } 65 | 66 | BOOST_AUTO_TEST_CASE(TestGetFilenameByString){ 67 | MuscateMetadataHelper helper; 68 | if(TEST_SRC == ""){ 69 | BOOST_FAIL("Did not set env-var WASP_TEST!"); 70 | } 71 | std::cout << std::string(TEST_SRC + "/" + TEST_NAME + "/" + INPUT_XML1) << std::endl; 72 | if(helper.LoadMetadataFile(std::string(TEST_SRC + "/" + TEST_NAME + "/" + INPUT_XML1))){ 73 | std::string b12 = helper.getFileNameByString(helper.GetImageFileNames(), "B10"); 74 | BOOST_CHECK_EQUAL(b12, helper.GetImageFileNames()[1]); //B12 is the first in the list 75 | std::string b8 = helper.getFileNameByString(helper.GetImageFileNames(), "B6"); 76 | BOOST_CHECK_EQUAL(b8, helper.GetImageFileNames()[8]); 77 | std::string b8a = helper.getFileNameByString(helper.GetImageFileNames(), "B7"); 78 | BOOST_CHECK_EQUAL(b8a, helper.GetImageFileNames()[9]); 79 | }else{ 80 | BOOST_FAIL("Cannot read metadata from" << std::string(TEST_SRC + "/" + TEST_NAME + "/" + INPUT_XML1)); 81 | } 82 | } 83 | 84 | BOOST_AUTO_TEST_CASE(TestLoadMetadata_Venus_FR_LUS){ 85 | MuscateMetadataHelper helper; 86 | if(TEST_SRC == ""){ 87 | BOOST_FAIL("Did not set env-var WASP_TEST!"); 88 | } 89 | std::cout << std::string(TEST_SRC + "/" + TEST_NAME + "/" + INPUT_XML1) << std::endl; 90 | if(helper.LoadMetadataFile(std::string(TEST_SRC + "/" + TEST_NAME + "/" + INPUT_XML1))){ 91 | BOOST_CHECK_EQUAL(helper.GetMissionName(), "VENUS"); 92 | BOOST_CHECK_EQUAL(helper.getProductLevel(), "L2A"); 93 | BOOST_CHECK_EQUAL(helper.GetReflectanceQuantificationValue(), 1000); 94 | BOOST_CHECK_EQUAL(helper.GetAotQuantificationValue(), 200); 95 | BOOST_CHECK_EQUAL(helper.GetNoDataValue(), "-10000"); 96 | BOOST_CHECK_EQUAL(helper.GetAcquisitionDate(), "20180202"); 97 | BOOST_CHECK_EQUAL(helper.GetAcquisitionDateLong(), "2018-02-02T10:55:54.000"); 98 | BOOST_CHECK_EQUAL(helper.GetAcquisitionDateAsDoy(), 32); 99 | for(auto filename : helper.GetImageFileNames()){ 100 | BOOST_CHECK(ends_with(filename, FRE_endings)); 101 | } 102 | for(auto filename : helper.GetCloudImageFileNames()){ 103 | BOOST_CHECK(ends_with(filename, CLDendings)); 104 | } 105 | for(auto filename : helper.GetAotImageFileNames()){ 106 | BOOST_CHECK(ends_with(filename, ATBendings)); 107 | } 108 | for(auto filename : helper.GetSnowImageFileNames()){ 109 | BOOST_CHECK(ends_with(filename, MG2endings)); 110 | } 111 | BOOST_CHECK_EQUAL(helper.getResolutions().getNumberOfResolutions(), size_t(1)); 112 | std::vector xs = helper.getResolutions().getNthResolutionFilenames(0); 113 | for(size_t i = 0; i < xs.size(); i++){ 114 | BOOST_CHECK(ends_with(xs[i], FRE_endings)); 115 | } 116 | }else{ 117 | BOOST_FAIL("Cannot read metadata from" << std::string(TEST_SRC + "/" + TEST_NAME + "/" + INPUT_XML1)); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /CompositePreprocessing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | otb_create_application( 2 | NAME CompositePreprocessing 3 | SOURCES src/CompositePreprocessing.cpp 4 | include/ComputeNDVI.h 5 | src/ComputeNDVI.cpp 6 | include/MaskExtractorFilter.h 7 | include/MaskExtractorFunctor.h 8 | src/MaskExtractorFilter.txx 9 | include/DirectionalCorrectionFunctor.h 10 | src/DirectionalCorrectionFunctor.txx 11 | src/DirectionalCorrection.cpp 12 | include/DirectionalModel.h 13 | src/DirectionalModel.cpp 14 | include/DirectionalCorrection.h 15 | include/DirectionalCorrectionFilter.h 16 | include/CreateS2AnglesRaster.h 17 | src/CreateS2AnglesRaster.cpp 18 | src/PreprocessingAdapter.cpp 19 | src/PreprocessingSentinel.cpp 20 | src/PreprocessingVenus.cpp 21 | LINK_LIBRARIES ${OTB_LIBRARIES} MuscateMetadata MetadataHelper) 22 | 23 | target_include_directories(otbapp_CompositePreprocessing PUBLIC include) 24 | 25 | install(TARGETS otbapp_CompositePreprocessing DESTINATION lib/otb/applications/) 26 | 27 | if(BUILD_TESTING) 28 | add_subdirectory(test) 29 | endif() 30 | 31 | install(FILES scattering_coeffs_10m.txt scattering_coeffs_20m.txt DESTINATION share/) 32 | 33 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/ComputeNDVI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef COMPOSITEPREPROCESSING_COMPUTENDVI_NEW_H_ 27 | #define COMPOSITEPREPROCESSING_COMPUTENDVI_NEW_H_ 28 | 29 | 30 | 31 | #include "otbImage.h" 32 | #include "otbWrapperTypes.h" 33 | #include "otbVectorImage.h" 34 | #include "otbImageFileReader.h" 35 | #include "otbImageFileWriter.h" 36 | #include "itkUnaryFunctorImageFilter.h" 37 | #include "itkBinaryFunctorImageFilter.h" 38 | #include "GlobalDefs.h" 39 | #include "ImageResampler.h" 40 | #include "BaseImageTypes.h" 41 | 42 | /** 43 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 44 | */ 45 | namespace ts { 46 | 47 | /** 48 | * @brief Namespace around Functors to be used in the filters defined below 49 | */ 50 | namespace Functor 51 | { 52 | 53 | /** 54 | * @brief Functor to Compute the NDVI of two images 55 | */ 56 | template< class TInput, class TOutput> 57 | class NDVIFunctor 58 | { 59 | public: 60 | NDVIFunctor() {} 61 | ~NDVIFunctor() {} 62 | bool operator!=(const NDVIFunctor &) const { 63 | return false; 64 | } 65 | bool operator==(const NDVIFunctor & other) const { 66 | return !( *this != other ); 67 | } 68 | 69 | inline TOutput operator()(const TInput & A, const TInput & B) const { 70 | const double redVal = static_cast< double >( A ); 71 | const double nirVal = static_cast< double >( B ); 72 | TOutput ret; 73 | if((fabs(redVal - NO_DATA_VALUE) < 0.000001) || (fabs(nirVal - NO_DATA_VALUE) < 0.000001)) { 74 | ret = 0; 75 | } else { 76 | if(fabs(redVal + nirVal) < 0.000001) { 77 | ret = 0; 78 | } else { 79 | ret = (nirVal - redVal)/(nirVal+redVal); 80 | } 81 | } 82 | return ret; 83 | } 84 | }; 85 | } //namespace Functor 86 | 87 | /** 88 | * @brief Class to compute the NDVI from two images 89 | * @note Used to compute the Directional correction in the pre-processing step. 90 | */ 91 | class ComputeNDVI : public BaseImageTypes { 92 | public: 93 | typedef itk::BinaryFunctorImageFilter > NDVIFilterType; 95 | 96 | /** 97 | * @brief Constructor 98 | */ 99 | ComputeNDVI(); 100 | 101 | /** 102 | * @brief Init the NDVI calculation 103 | * @param xml Metadata-filename 104 | */ 105 | void DoInit(const std::string &xml); 106 | 107 | /** 108 | * @brief Execute the application 109 | * @return FloatImage Containing the NDVI 110 | */ 111 | FloatImageType::Pointer DoExecute(); 112 | 113 | /** 114 | * @brief Return the name of the class 115 | * @return 116 | */ 117 | const char * GetNameOfClass(){ return "ComputeNDVI";}; 118 | 119 | private: 120 | std::string m_inXml; 121 | ShortImageReaderType::Pointer m_InputImageReaderRed; 122 | ShortImageReaderType::Pointer m_InputImageReaderNIR; 123 | NDVIFilterType::Pointer m_NDVI; 124 | ImageResampler m_Resampler; 125 | }; 126 | 127 | } // namespace ts 128 | 129 | 130 | 131 | #endif /* COMPOSITEPREPROCESSING_COMPUTENDVI_NEW_H_ */ 132 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/CreateS2AnglesRaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef CREATE_S2_ANGLES_RASTER_H 27 | #define CREATE_S2_ANGLES_RASTER_H 28 | 29 | #include "itkLightObject.h" 30 | #include "ViewingAngles.hpp" 31 | 32 | #include "ImageResampler.h" 33 | #include "BaseImageTypes.h" 34 | 35 | /** 36 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 37 | */ 38 | namespace ts { 39 | 40 | /** 41 | * @brief Creates the Sentinel-2 angle rasters to perform the directional correction 42 | */ 43 | class CreateS2AnglesRaster: public BaseImageTypes { 44 | public: 45 | /** 46 | * @brief Constructor 47 | */ 48 | CreateS2AnglesRaster(); 49 | 50 | /** 51 | * @brief Init the angles raster creation 52 | * @param res Current resolution 53 | * @param xml Metadata-file 54 | */ 55 | void DoInit(int res, const std::string &xml); 56 | 57 | /** 58 | * @brief Execute the application 59 | * @return FloatVectorImage containing the angle rasters for S2 60 | */ 61 | FloatVectorImageType::Pointer DoExecute(); 62 | 63 | /** 64 | * @brief Return the name of the class 65 | * @return 66 | */ 67 | const char * GetNameOfClass(){ return "CreateS2AnglesRaster";}; 68 | private: 69 | FloatVectorImageType::Pointer m_AnglesRaster; 70 | std::string m_inXml; 71 | size_t m_resolutionIndex; 72 | ImageResampler m_ResampledBandsExtractor; 73 | }; 74 | 75 | } //namespace ts 76 | 77 | #endif // CREATE_S2_ANGLES_RASTER_H 78 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/DirectionalCorrectionFunctor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef DIRECTIONALCORRECTIONFUNCTOR_H 27 | #define DIRECTIONALCORRECTIONFUNCTOR_H 28 | 29 | /** 30 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 31 | */ 32 | namespace ts { 33 | 34 | /** 35 | * @brief Namespace around Functors to be used in the filters defined below 36 | */ 37 | namespace Functor 38 | { 39 | 40 | /** 41 | * @brief Contains scattering coefficients used for the directional correction 42 | */ 43 | class ScatteringFunctionCoefficients { 44 | public: 45 | float V0; 46 | float V1; 47 | float R0; 48 | float R1; 49 | }; 50 | 51 | /** 52 | * @brief Functor to perform the directional correction 53 | */ 54 | template< class TInput, class TOutput> 55 | class DirectionalCorrectionFunctor 56 | { 57 | public: 58 | DirectionalCorrectionFunctor(); 59 | DirectionalCorrectionFunctor& operator =(const DirectionalCorrectionFunctor& copy); 60 | bool operator!=( const DirectionalCorrectionFunctor & other) const; 61 | bool operator==( const DirectionalCorrectionFunctor & other ) const; 62 | TOutput operator()( const TInput & A ); 63 | void Initialize(const std::vector &coeffs); 64 | 65 | const char * GetNameOfClass() { return "DirectionalCorrectionFunctor"; } 66 | 67 | bool IsSnowPixel(const TInput & A); 68 | bool IsWaterPixel(const TInput & A); 69 | bool IsCloudPixel(const TInput & A); 70 | bool IsLandPixel(const TInput & A); 71 | float GetCurrentL2AWeightValue(const TInput & A); 72 | bool IsNoDataValue(float fValue, float fNoDataValue); 73 | 74 | private: 75 | std::vector m_ScatteringCoeffs; 76 | 77 | int m_nReflBandsCount; 78 | 79 | int m_nCloudMaskBandIndex; 80 | int m_nSnowMaskBandIndex; 81 | int m_nWaterMaskBandIndex; 82 | int m_nNdviBandIdx; 83 | int m_nSunAnglesBandStartIdx; 84 | int m_nSensoAnglesBandStartIdx; 85 | 86 | float m_fReflNoDataValue; 87 | 88 | }; 89 | } //namespace Functor 90 | } //namespace ts 91 | 92 | #include "../src/DirectionalCorrectionFunctor.txx" 93 | 94 | #endif // DIRECTIONALCORRECTIONFUNCTOR_H 95 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/DirectionalModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef DIRECTIONAL_MODEL_H 27 | #define DIRECTIONAL_MODEL_H 28 | 29 | /** 30 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 31 | */ 32 | namespace ts { 33 | 34 | /** 35 | * @brief Implementation of the directional model used 36 | */ 37 | class DirectionalModel { 38 | public: 39 | /** 40 | * @brief Constructor, initializing the four angles theta_(s,v) and phi_(s,v) 41 | * @param theta_s 42 | * @param phi_s 43 | * @param theta_v 44 | * @param phi_v 45 | */ 46 | DirectionalModel(double theta_s, double phi_s, double theta_v, double phi_v); 47 | double delta(); 48 | double masse(); 49 | double cos_xsi(); 50 | double sin_xsi(); 51 | double xsi(); 52 | double cos_t(); 53 | double sin_t(); 54 | double t(); 55 | double FV(); 56 | double FR(); 57 | double dir_mod(double kV,double kR); 58 | 59 | private: 60 | double m_theta_s; 61 | double m_theta_v; 62 | double m_phi; 63 | 64 | // These variables are for optimizing the calculations to avoid repetitive operations. 65 | double m_sin_phi; 66 | double m_cos_phi; 67 | 68 | double m_sin_theta_s; 69 | double m_cos_theta_s; 70 | double m_tan_theta_s; 71 | 72 | double m_sin_theta_v; 73 | double m_cos_theta_v; 74 | double m_tan_theta_v; 75 | 76 | double m_delta_Val; 77 | double m_masse_Val; 78 | double m_cos_xsi_Val; 79 | double m_sin_xsi_Val; 80 | double m_xsi_Val; 81 | double m_cos_t_Val; 82 | double m_sin_t_Val; 83 | double m_t_Val; 84 | double m_FV_Val; 85 | double m_FR_Val; 86 | }; 87 | } //namespace ts 88 | #endif // DIRECTIONAL_MODEL 89 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/MaskExtractorFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef MASKEXTRACTORFILTER_H 27 | #define MASKEXTRACTORFILTER_H 28 | 29 | #include "otbWrapperTypes.h" 30 | #include "otbMultiToMonoChannelExtractROI.h" 31 | #include "otbImageFileReader.h" 32 | #include "otbUnaryFunctorImageFilter.h" 33 | #include "MaskExtractorFunctor.h" 34 | 35 | #include "itkNumericTraits.h" 36 | #include "otbImage.h" 37 | 38 | /** 39 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 40 | */ 41 | namespace ts { 42 | 43 | /** 44 | * @brief Extract a certain bit from an image 45 | */ 46 | template 47 | class ITK_EXPORT MaskExtractorFilter : public itk::ImageToImageFilter { 48 | public: 49 | typedef MaskExtractorFilter Self; 50 | typedef itk::ImageToImageFilter Superclass; 51 | typedef itk::SmartPointer Pointer; 52 | typedef itk::SmartPointer ConstPointer; 53 | 54 | typedef typename TImageType::PixelType PixelType; 55 | typedef typename TOutputImageType::PixelType OutputPixelType; 56 | 57 | itkNewMacro(Self); 58 | itkTypeMacro(MaskExtractorFilter, itk::ImageToImageFilter); 59 | 60 | /** 61 | * @brief Set the bit to be extracted 62 | * @param bit The bit, starting at 0 63 | */ 64 | void SetBitMask(const int & bit); 65 | 66 | MaskExtractorFilter(); 67 | 68 | protected: 69 | typedef Functor::MaskExtractorFunctor MaskHandlerFunctorType; 70 | typedef itk::UnaryFunctorImageFilter< TImageType, TOutputImageType, MaskHandlerFunctorType > BitExtractorType; 71 | 72 | /** 73 | * @brief Run the extraction 74 | */ 75 | virtual void GenerateData() ITK_OVERRIDE; 76 | 77 | private: 78 | 79 | MaskExtractorFilter(Self &); // intentionally not implemented 80 | void operator =(const Self&); // intentionally not implemented 81 | 82 | typename BitExtractorType::Pointer m_BitExtractor; 83 | }; 84 | 85 | } /* namespace ts */ 86 | 87 | #include "../src/MaskExtractorFilter.txx" 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/MaskExtractorFunctor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef MASKEXTRACTORFUNCTOR_H 29 | #define MASKEXTRACTORFUNCTOR_H 30 | 31 | #include "GlobalDefs.h" 32 | 33 | /** 34 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 35 | */ 36 | namespace ts { 37 | 38 | /** 39 | * @brief Namespace around Functors to be used in the filters defined below 40 | */ 41 | namespace Functor 42 | { 43 | 44 | /** 45 | * @brief Functor to extract a bit from an image 46 | */ 47 | template< class TInput, class TOutput> 48 | class MaskExtractorFunctor { 49 | public: 50 | MaskExtractorFunctor() { 51 | m_bit = -1; 52 | } 53 | 54 | ~MaskExtractorFunctor() { 55 | 56 | } 57 | 58 | MaskExtractorFunctor& operator =(const MaskExtractorFunctor& copy) 59 | { 60 | return *this; 61 | } 62 | 63 | bool operator!=( const MaskExtractorFunctor & other) const { 64 | return true; 65 | } 66 | 67 | bool operator==( const MaskExtractorFunctor & other ) const { 68 | return false; 69 | } 70 | 71 | /** 72 | * @brief Operator to run on every pixel sequentially 73 | * @param A The pixel value 74 | * @return The new pixel value for the output image 75 | */ 76 | TOutput operator()( const TInput & A) { 77 | TOutput var(NO_DATA_VALUE); 78 | if(m_bit > -1 && m_bit < 8) //Min and Max borders - if not return NODATA 79 | var = static_cast((A & m_MasksArray[m_bit]) >> m_bit); 80 | return var; 81 | } 82 | 83 | /** 84 | * @brief Set bit to be extracted 85 | * @param bit Value between 0 to 7 86 | */ 87 | void SetBitMask(const int &bit) { 88 | m_bit = bit; 89 | } 90 | 91 | private: 92 | int m_MasksArray[8] = {0x01, 0x02, 0x04, 0x08, 0x16, 0x32, 0x64, 0x128}; 93 | int m_bit; 94 | }; 95 | 96 | } //namespace Functor 97 | } //namespace ts 98 | 99 | #endif // MASKEXTRACTORFUNCTOR_H 100 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/PreprocessingAdapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGADAPTER_H_ 29 | #define COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGADAPTER_H_ 30 | 31 | #include "itkLightObject.h" 32 | #include "otbImage.h" 33 | #include "otbVectorImage.h" 34 | #include "otbImageFileReader.h" 35 | #include "otbObjectList.h" 36 | 37 | #include "BaseImageTypes.h" 38 | #include "MaskExtractorFilter.h" 39 | 40 | /** 41 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 42 | */ 43 | namespace ts { 44 | 45 | /** 46 | * @brief Namespace for all preprocessing steps 47 | */ 48 | namespace preprocessing { 49 | 50 | class PreprocessingAdapter : public itk::LightObject, public BaseImageTypes{ 51 | public: 52 | typedef MaskExtractorFilter ExtractorFilterType; 53 | typedef otb::ObjectList ExtractorListType; 54 | 55 | void init(){ 56 | m_MaskList = ByteImageReaderListType::New(); 57 | m_ExtractorList = ExtractorListType::New(); 58 | } 59 | 60 | /** 61 | * @brief Extract the muscate cloud mask of the mission 62 | * @param filename The filename of the input file 63 | * @param bit The bit number 64 | * @return The cloud mask stored as float image 65 | */ 66 | virtual FloatImageType::Pointer getCloudMask(const std::string &filename, const unsigned char &bit = 0) = 0; 67 | 68 | /** 69 | * @brief Extract the muscate AOT mask of the mission 70 | * @param filename The filename of the input file 71 | * @param band The band number 72 | * @return The AOT mask stored as float image 73 | */ 74 | virtual FloatImageType::Pointer getAotMask(const std::string &filename, const unsigned char &band = 2) = 0; 75 | 76 | /** 77 | * @brief Extract the muscate snow mask of the mission 78 | * @param filename The filename of the input file 79 | * @param bit The bit number 80 | * @return The snow mask stored as float image 81 | */ 82 | virtual FloatImageType::Pointer getSnowMask(const std::string &filename, const unsigned char &bit = 2) = 0; 83 | 84 | /** 85 | * @brief Extract the muscate water mask of the mission 86 | * @param filename The filename of the input file 87 | * @param bit The bit number 88 | * @return The water mask stored as float image 89 | */ 90 | virtual FloatImageType::Pointer getWaterMask(const std::string &filename, const unsigned char &bit = 0) = 0; 91 | 92 | /** 93 | * @brief Set the scattering coefficient filenames 94 | * @param scatteringcoeffs The path to each scattering coefficient file 95 | */ 96 | void setScatteringCoefficients(const std::vector &scatteringcoeffs); 97 | 98 | virtual std::vector getCorrectedRasters( 99 | const std::string &filename, 100 | FloatImageType::Pointer cloudImage, FloatImageType::Pointer watImage, 101 | FloatImageType::Pointer snowImage) = 0; 102 | protected: 103 | /** 104 | * @brief Extract a float image 105 | * @param filename The filename of the input file 106 | * @param bit The bit number 107 | * @return The pointer to the image 108 | */ 109 | FloatImageType::Pointer getFloatMask(const std::string &filename, const unsigned char &bit); 110 | 111 | 112 | FloatVectorImageReaderType::Pointer m_aotReader; 113 | ByteImageReaderListType::Pointer m_MaskList; 114 | ExtractorListType::Pointer m_ExtractorList; 115 | std::vector m_scatteringCoeffs; 116 | }; 117 | 118 | } // namespace preprocessing 119 | } // namespace ts 120 | 121 | #endif /* COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGADAPTER_H_ */ 122 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/PreprocessingSentinel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGSENTINEL_H_ 29 | #define COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGSENTINEL_H_ 30 | 31 | 32 | #include "PreprocessingAdapter.h" 33 | #include "ComputeNDVI.h" 34 | #include "CreateS2AnglesRaster.h" 35 | #include "DirectionalCorrection.h" 36 | 37 | /** 38 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 39 | */ 40 | namespace ts { 41 | 42 | /** 43 | * @brief Namespace for all preprocessing steps 44 | */ 45 | namespace preprocessing { 46 | 47 | class PreprocessingSentinel : public PreprocessingAdapter { 48 | public: 49 | /** 50 | * @brief Extract the muscate cloud mask of Sentinel 51 | * @param filename The filename of the input file 52 | * @param bit The bit number 53 | * @return The cloud mask stored as float image 54 | */ 55 | virtual FloatImageType::Pointer getCloudMask(const std::string &filename, const unsigned char &bit = 0); 56 | 57 | /** 58 | * @brief Extract the muscate AOT mask of Sentinel 59 | * @param filename The filename of the input file 60 | * @param band The band number 61 | * @return The AOT mask stored as float image 62 | */ 63 | virtual FloatImageType::Pointer getAotMask(const std::string &filename, const unsigned char &band = 2); 64 | 65 | /** 66 | * @brief Extract the muscate snow mask of Sentinel 67 | * @param filename The filename of the input file 68 | * @param bit The bit number 69 | * @return The snow mask stored as float image 70 | */ 71 | virtual FloatImageType::Pointer getSnowMask(const std::string &filename, const unsigned char &bit = 2); 72 | 73 | /** 74 | * @brief Extract the muscate water mask of Sentinel 75 | * @param filename The filename of the input file 76 | * @param bit The bit number 77 | * @return The water mask stored as float image 78 | */ 79 | virtual FloatImageType::Pointer getWaterMask(const std::string &filename, const unsigned char &bit = 0); 80 | 81 | /** 82 | * @brief Extract the rasters of Sentinel, using a directional correction 83 | * @param xml The filename to the xml-file 84 | * @param cldImg Cloud Image file 85 | * @param watImg Water image file 86 | * @param snowImg Snow image file 87 | * @param angles Angles raster 88 | * @param ndvi NDVI image 89 | * @return The raster for each resolution type stored in a floatVector-Image 90 | */ 91 | virtual std::vector getCorrectedRasters( 92 | const std::string &filename, 93 | FloatImageType::Pointer cloudImage, FloatImageType::Pointer watImage, 94 | FloatImageType::Pointer snowImage); 95 | 96 | private: 97 | 98 | ComputeNDVI m_computeNdvi; 99 | ImageResampler m_Resampler; 100 | std::vector m_createAngles; 101 | std::vector m_dirCorr; 102 | ResamplingBandExtractor m_aotExtractor; 103 | 104 | }; 105 | 106 | } // namespace preprocessing 107 | } // namespace ts 108 | 109 | #endif /* COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGSENTINEL_H_ */ 110 | -------------------------------------------------------------------------------- /CompositePreprocessing/include/PreprocessingVenus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGVENUS_H_ 29 | #define COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGVENUS_H_ 30 | 31 | #include "PreprocessingAdapter.h" 32 | #include "ComputeNDVI.h" 33 | #include "ResamplingBandExtractor.h" 34 | #include "otbImageListToVectorImageFilter.h" 35 | 36 | /** 37 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 38 | */ 39 | namespace ts { 40 | 41 | /** 42 | * @brief Namespace for all preprocessing steps 43 | */ 44 | namespace preprocessing { 45 | 46 | class PreprocessingVenus : public PreprocessingAdapter { 47 | public: 48 | /** 49 | * @brief Extract the muscate cloud mask of Venus 50 | * @param filename The filename of the input file 51 | * @param bit The bit number 52 | * @return The cloud mask stored as float image 53 | */ 54 | virtual FloatImageType::Pointer getCloudMask(const std::string &filename, const unsigned char &bit = 0); 55 | 56 | /** 57 | * @brief Extract the muscate AOT mask of Venus 58 | * @param filename The filename of the input file 59 | * @param band The band number 60 | * @return The AOT mask stored as float image 61 | */ 62 | virtual FloatImageType::Pointer getAotMask(const std::string &filename, const unsigned char &band = 2); 63 | 64 | /** 65 | * @brief Extract the muscate snow mask of Venus 66 | * @param filename The filename of the input file 67 | * @param bit The bit number 68 | * @return The snow mask stored as float image 69 | */ 70 | virtual FloatImageType::Pointer getSnowMask(const std::string &filename, const unsigned char &bit = 2); 71 | 72 | /** 73 | * @brief Extract the muscate water mask of Venus 74 | * @param filename The filename of the input file 75 | * @param bit The bit number 76 | * @return The water mask stored as float image 77 | */ 78 | virtual FloatImageType::Pointer getWaterMask(const std::string &filename, const unsigned char &bit = 0); 79 | 80 | /** 81 | * @brief Extract the rasters of Venus 82 | * @param xml The filename to the xml-file 83 | * @param cldImg Cloud Image file 84 | * @param watImg Water image file 85 | * @param snowImg Snow image file 86 | * @param angles Angles raster 87 | * @param ndvi NDVI image 88 | * @return The raster for each resolution type stored in a floatVector-Image 89 | */ 90 | virtual std::vector getCorrectedRasters( 91 | const std::string &filename, 92 | FloatImageType::Pointer cloudImage, FloatImageType::Pointer watImage, 93 | FloatImageType::Pointer snowImage); 94 | 95 | private: 96 | typedef otb::ImageListToVectorImageFilter< 97 | ShortImageListType, ShortVectorImageType> ShortImageListToVectorImageType; 98 | 99 | ResamplingBandExtractor m_aotExtractor; 100 | ShortVectorImageReaderType::Pointer m_inputImageReader; 101 | ShortImageReaderListType::Pointer m_ReaderList; 102 | std::vector m_ImageList; 103 | std::vector m_RasterExtractorList; 104 | }; 105 | 106 | } // namespace preprocessing 107 | } // namespace ts 108 | 109 | #endif /* COMPOSITEPREPROCESSING_INCLUDE_PREPROCESSINGVENUS_H_ */ 110 | -------------------------------------------------------------------------------- /CompositePreprocessing/scattering_coeffs_10m.txt: -------------------------------------------------------------------------------- 1 | #band B2 2 | 0.481 0.0 0.102 0.0 3 | 4 | #band B3 5 | 0.440 0.0 0.136 0.0 6 | 7 | #band B4 8 | 0.340 0.0 0.134 0.0 9 | 10 | #band B8 11 | 0.496 0.0 0.107 0.0 12 | -------------------------------------------------------------------------------- /CompositePreprocessing/scattering_coeffs_20m.txt: -------------------------------------------------------------------------------- 1 | #band B5 2 | 0.340 0.0 0.134 0.0 3 | 4 | 5 | #band B6 6 | 0.418 0.0 0.121 0.0 7 | 8 | 9 | #band B7 10 | 0.496 0.0 0.107 0.0 11 | 12 | 13 | #band B8a 14 | 0.496 0.0 0.107 0.0 15 | 16 | 17 | #band B11 18 | 0.336 0.0 0.132 0.0 19 | 20 | #band B12 21 | 0.240 0.0 0.145 0.0 22 | -------------------------------------------------------------------------------- /CompositePreprocessing/src/ComputeNDVI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "ComputeNDVI.h" 27 | #include "MetadataHelperFactory.h" 28 | 29 | using namespace ts; 30 | 31 | ComputeNDVI::ComputeNDVI() { 32 | } 33 | 34 | void ComputeNDVI::DoInit(const std::string &xml) { 35 | m_inXml = xml; 36 | } 37 | 38 | ComputeNDVI::FloatImageType::Pointer ComputeNDVI::DoExecute() { 39 | auto factory = MetadataHelperFactory::New(); 40 | auto pHelper = factory->GetMetadataHelper(m_inXml); 41 | //Read all input parameters 42 | m_InputImageReaderRed = ShortImageReaderType::New(); 43 | m_InputImageReaderNIR = ShortImageReaderType::New(); 44 | std::string imgFileNameRed = pHelper->getFileNameByString(pHelper->GetImageFileNames(), "B4"); 45 | std::string imgFileNameNIR = pHelper->getFileNameByString(pHelper->GetImageFileNames(), "B8");//Approximation used. Normally B8A should be used here. 46 | 47 | std::cout << "ComputeNDVI Filenames found: \n" << imgFileNameRed << "\n" << imgFileNameNIR << std::endl; 48 | 49 | m_InputImageReaderRed->SetFileName(imgFileNameRed); 50 | m_InputImageReaderRed->UpdateOutputInformation(); 51 | ShortImageType::Pointer imgRed = m_InputImageReaderRed->GetOutput(); 52 | int curResRed = imgRed->GetSpacing()[0]; 53 | m_InputImageReaderNIR->SetFileName(imgFileNameNIR); 54 | m_InputImageReaderNIR->UpdateOutputInformation(); 55 | ShortImageType::Pointer imgNIR = m_InputImageReaderNIR->GetOutput(); 56 | int curResNIR = imgNIR->GetSpacing()[0]; 57 | m_NDVI = NDVIFilterType::New(); 58 | if(curResRed != curResNIR){ 59 | //Rescale image in this case 60 | ShortImageType::Pointer imgNIR_Resized = m_Resampler.getResampler(imgNIR.GetPointer(), double(curResNIR) / curResRed)->GetOutput(); 61 | m_NDVI->SetInput2(imgNIR_Resized); 62 | }else{ 63 | m_NDVI->SetInput2(imgNIR); 64 | } 65 | m_NDVI->SetInput1(imgRed); 66 | m_NDVI->UpdateOutputInformation(); 67 | return m_NDVI->GetOutput(); 68 | } 69 | -------------------------------------------------------------------------------- /CompositePreprocessing/src/DirectionalModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include 27 | #include // std::min, std::max 28 | #include "DirectionalModel.h" 29 | 30 | #define xsi_0 (1.5*M_PI/180.) 31 | 32 | using namespace ts; 33 | 34 | DirectionalModel::DirectionalModel(double theta_s, double phi_s, double theta_v, double phi_v) 35 | { 36 | m_theta_s = theta_s * M_PI / 180; 37 | m_theta_v = theta_v * M_PI / 180; 38 | m_phi = (phi_s - phi_v) * M_PI / 180; 39 | 40 | m_sin_theta_s = sin(m_theta_s); 41 | m_cos_theta_s = cos(m_theta_s); 42 | m_tan_theta_s = tan(m_theta_s); 43 | 44 | m_sin_theta_v = sin(m_theta_v); 45 | m_cos_theta_v = cos(m_theta_v); 46 | m_tan_theta_v = tan(m_theta_v); 47 | 48 | m_sin_phi = sin(m_phi); 49 | m_cos_phi = cos(m_phi); 50 | 51 | m_delta_Val = delta(); 52 | m_masse_Val = masse(); 53 | m_cos_xsi_Val = cos_xsi(); 54 | m_sin_xsi_Val = sin_xsi(); 55 | m_xsi_Val = xsi(); 56 | m_cos_t_Val = cos_t(); 57 | m_sin_t_Val = sin_t(); 58 | m_t_Val = t(); 59 | m_FV_Val = FV(); 60 | m_FR_Val = FR(); 61 | } 62 | 63 | double DirectionalModel::delta() { 64 | double delta = sqrt(m_tan_theta_s*m_tan_theta_s + m_tan_theta_v*m_tan_theta_v - 2*m_tan_theta_s*m_tan_theta_v*m_cos_phi); 65 | return delta; 66 | } 67 | 68 | // Air Mass 69 | double DirectionalModel::masse() { 70 | double masse=1/m_cos_theta_s+1/m_cos_theta_v; 71 | return masse; 72 | } 73 | 74 | double DirectionalModel::cos_xsi() { 75 | double cos_xsi=m_cos_theta_s*m_cos_theta_v + m_sin_theta_s*m_sin_theta_v*m_cos_phi; 76 | return cos_xsi; 77 | } 78 | 79 | double DirectionalModel::sin_xsi() { 80 | double x=m_cos_xsi_Val; 81 | double sin_xsi=sqrt(1 - x*x); 82 | return sin_xsi; 83 | } 84 | 85 | double DirectionalModel::xsi() { 86 | double xsi=acos(m_cos_xsi_Val); 87 | return xsi; 88 | } 89 | 90 | //#Function t 91 | double DirectionalModel::cos_t() { 92 | double trig=m_tan_theta_s*m_tan_theta_v*m_sin_phi; 93 | double coef=1; //#Coef=1 looks good, but Bréon et Vermote use Coef=2; 94 | double cos_t=std::min(std::max(coef/m_masse_Val*sqrt(m_delta_Val*m_delta_Val + trig*trig),(double)-1),(double)1); 95 | return cos_t; 96 | } 97 | 98 | double DirectionalModel::sin_t() { 99 | double x=m_cos_t_Val; 100 | double sin_t=sqrt(1 - x*x); 101 | return sin_t; 102 | } 103 | 104 | double DirectionalModel::t() { 105 | double t=acos(m_cos_t_Val); 106 | return t; 107 | } 108 | 109 | // #function FV Ross_Thick, V stands for Volume 110 | double DirectionalModel::FV() { 111 | 112 | double FV=m_masse_Val/M_PI*(m_t_Val - m_sin_t_Val*m_cos_t_Val - M_PI) + (1+m_cos_xsi_Val)/2/m_cos_theta_s/m_cos_theta_v; 113 | return FV; 114 | } 115 | 116 | // #function FR Li-Sparse, R stands for Roughness 117 | double DirectionalModel::FR() { 118 | double A=1/(m_cos_theta_s+m_cos_theta_v); 119 | 120 | double FR=4/3./M_PI*A*((M_PI/2-m_xsi_Val)*m_cos_xsi_Val+m_sin_xsi_Val)*(1+1/(1+m_xsi_Val/xsi_0))- 1./3; 121 | return FR; 122 | } 123 | 124 | double DirectionalModel::dir_mod(double kV,double kR) { 125 | double rho=1 +kV*m_FV_Val + kR*m_FR_Val; 126 | return rho; 127 | } 128 | -------------------------------------------------------------------------------- /CompositePreprocessing/src/MaskExtractorFilter.txx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #include "MaskExtractorFilter.h" 29 | 30 | namespace ts 31 | { 32 | 33 | template 34 | MaskExtractorFilter::MaskExtractorFilter() { 35 | m_BitExtractor = BitExtractorType::New(); 36 | } 37 | 38 | template 39 | void MaskExtractorFilter::GenerateData() { 40 | m_BitExtractor->SetInput(this->GetInput()); 41 | m_BitExtractor->GetOutput()->SetNumberOfComponentsPerPixel(1); 42 | m_BitExtractor->GraftOutput(this->GetOutput()); 43 | m_BitExtractor->Update(); 44 | 45 | this->GraftOutput(m_BitExtractor->GetOutput()); 46 | } 47 | 48 | template 49 | void MaskExtractorFilter::SetBitMask(const int &bit) { 50 | m_BitExtractor->GetFunctor().SetBitMask(bit); 51 | } 52 | 53 | } /* end namespace ts */ 54 | -------------------------------------------------------------------------------- /CompositePreprocessing/src/PreprocessingAdapter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #include "PreprocessingAdapter.h" 29 | 30 | using namespace ts::preprocessing; 31 | 32 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingAdapter::getFloatMask(const std::string &filename, const unsigned char &bit){ 33 | ExtractorFilterType::Pointer extractor = ExtractorFilterType::New(); 34 | extractor->SetBitMask(bit); 35 | ByteImageReaderType::Pointer reader = ByteImageReaderType::New(); 36 | reader->SetFileName(filename); 37 | extractor->SetInput(reader->GetOutput()); 38 | extractor->UpdateOutputInformation(); 39 | FloatImageType::Pointer cloudImage = extractor->GetOutput(); 40 | m_MaskList->PushBack(reader); 41 | m_ExtractorList->PushBack(extractor); 42 | return cloudImage; 43 | } 44 | 45 | void PreprocessingAdapter::setScatteringCoefficients(const std::vector &scatteringcoeffs){ 46 | m_scatteringCoeffs = scatteringcoeffs; 47 | } 48 | -------------------------------------------------------------------------------- /CompositePreprocessing/src/PreprocessingSentinel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #include "PreprocessingSentinel.h" 29 | #include "PreprocessingAdapter.h" 30 | #include "DirectionalCorrection.h" 31 | #include "MetadataHelperFactory.h" 32 | 33 | #include "otbWrapperApplication.h" 34 | 35 | using namespace ts::preprocessing; 36 | 37 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingSentinel::getCloudMask(const std::string &filename, const unsigned char &bit){ 38 | return getFloatMask(filename, bit); 39 | } 40 | 41 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingSentinel::getAotMask(const std::string &filename, const unsigned char &band){ 42 | 43 | m_aotReader = PreprocessingAdapter::FloatVectorImageReaderType::New(); 44 | m_aotReader->SetFileName(filename); 45 | return m_aotExtractor.ExtractImgResampledBand(m_aotReader->GetOutput(), band, Interpolator_Linear); 46 | } 47 | 48 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingSentinel::getWaterMask(const std::string &filename, const unsigned char &bit ){ 49 | return getFloatMask(filename, bit); 50 | } 51 | 52 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingSentinel::getSnowMask(const std::string &filename, const unsigned char &bit){ 53 | return getFloatMask(filename, bit); 54 | } 55 | 56 | std::vector PreprocessingSentinel::getCorrectedRasters( 57 | const std::string &filename, 58 | FloatImageType::Pointer cloudImage, FloatImageType::Pointer watImage, 59 | FloatImageType::Pointer snowImage){ 60 | 61 | std::vector outputRasters; 62 | 63 | auto factory = ts::MetadataHelperFactory::New(); 64 | auto pHelper = factory->GetMetadataHelper(filename); 65 | 66 | if(m_scatteringCoeffs.empty()){ 67 | itkExceptionMacro("Need to set scattering coefficients before running correction for S2."); 68 | } 69 | 70 | // Compute NDVI for Primary resolution 71 | m_computeNdvi.DoInit(filename); 72 | PreprocessingAdapter::FloatImageType::Pointer ndviImg = m_computeNdvi.DoExecute(); 73 | 74 | size_t totalNRes = pHelper->getResolutions().getNumberOfResolutions(); 75 | 76 | //For all possible resolutions, do the following 77 | for(size_t resolution = 0; resolution < totalNRes; resolution++){ 78 | CreateS2AnglesRaster createAngles; 79 | createAngles.DoInit(resolution, filename); 80 | PreprocessingAdapter::FloatVectorImageType::Pointer anglesImg = createAngles.DoExecute(); 81 | m_createAngles.push_back(createAngles); 82 | 83 | ts::DirectionalCorrection dirCorr; 84 | //If Resolution is not principal Resolution, then resize the additional images 85 | std::cout << "Current resolution: " << pHelper->getResolutions().getResolutionVector()[resolution].getBands()[0].getResolution() << std::endl; 86 | if(cloudImage.GetPointer()->GetSpacing()[0] != pHelper->getResolutions().getResolutionVector()[resolution].getBands()[0].getResolution()){ 87 | PreprocessingAdapter::FloatImageType::Pointer ndviImgResampled = m_Resampler.getResampler(ndviImg.GetPointer(), 0.5f)->GetOutput(); 88 | PreprocessingAdapter::FloatImageType::Pointer cldImgResampled = m_Resampler.getResampler(cloudImage.GetPointer(), 0.5f)->GetOutput(); 89 | PreprocessingAdapter::FloatImageType::Pointer watImgResampled = m_Resampler.getResampler(watImage.GetPointer(), 0.5f)->GetOutput(); 90 | PreprocessingAdapter::FloatImageType::Pointer snowImgResampled = m_Resampler.getResampler(snowImage.GetPointer(), 0.5f)->GetOutput(); 91 | dirCorr.Init(resolution, filename, m_scatteringCoeffs[resolution], cldImgResampled, watImgResampled, snowImgResampled, anglesImg, ndviImgResampled); 92 | }else{ 93 | dirCorr.Init(resolution, filename, m_scatteringCoeffs[resolution], cloudImage, watImage, snowImage, anglesImg, ndviImg); 94 | } 95 | dirCorr.DoExecute(); 96 | m_dirCorr.push_back(dirCorr); 97 | outputRasters.push_back(dirCorr.GetCorrectedImg().GetPointer()); 98 | } 99 | return outputRasters; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /CompositePreprocessing/src/PreprocessingVenus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #include "PreprocessingVenus.h" 29 | #include "PreprocessingAdapter.h" 30 | #include "DirectionalCorrection.h" 31 | #include "MetadataHelperFactory.h" 32 | 33 | using namespace ts::preprocessing; 34 | 35 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingVenus::getCloudMask(const std::string &filename, const unsigned char &bit){ 36 | return getFloatMask(filename, bit); 37 | } 38 | 39 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingVenus::getAotMask(const std::string &filename, const unsigned char &band){ 40 | m_aotReader = PreprocessingAdapter::FloatVectorImageReaderType::New(); 41 | m_aotReader->SetFileName(filename); 42 | return m_aotExtractor.ExtractImgResampledBand(m_aotReader->GetOutput(), band, Interpolator_Linear); 43 | } 44 | 45 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingVenus::getWaterMask(const std::string &filename, const unsigned char &bit ){ 46 | return getFloatMask(filename, bit); 47 | } 48 | 49 | PreprocessingAdapter::FloatImageType::Pointer PreprocessingVenus::getSnowMask(const std::string &filename, const unsigned char &bit){ 50 | return getFloatMask(filename, bit); 51 | } 52 | 53 | std::vector PreprocessingVenus::getCorrectedRasters( 54 | const std::string &filename, 55 | FloatImageType::Pointer cloudImage, FloatImageType::Pointer watImage, 56 | FloatImageType::Pointer snowImage){ 57 | 58 | m_ReaderList = ShortImageReaderListType::New(); 59 | std::vector outputRasters; 60 | 61 | auto factory = ts::MetadataHelperFactory::New(); 62 | auto pHelper = factory->GetMetadataHelper(filename); 63 | 64 | size_t totalNRes = pHelper->getResolutions().getNumberOfResolutions(); 65 | 66 | //For all possible resolutions, do the following 67 | for(size_t resolution = 0; resolution < totalNRes; resolution++){ 68 | std::vector inputImageFiles = pHelper->getResolutions().getNthResolutionFilenames(resolution); 69 | ShortImageListType::Pointer imgList = ShortImageListType::New(); 70 | for(auto filename : inputImageFiles){ 71 | std::cout << "Raster Filename: " << filename << std::endl; 72 | ShortImageReaderType::Pointer reader = ShortImageReaderType::New(); 73 | reader->SetFileName(filename); 74 | m_ReaderList->PushBack(reader); 75 | ShortImageType::Pointer inputImg = reader->GetOutput(); 76 | inputImg->UpdateOutputInformation(); 77 | imgList->PushBack(inputImg); 78 | } 79 | ShortImageListToVectorImageType::Pointer toVec = ShortImageListToVectorImageType::New(); 80 | toVec->SetInput(imgList); 81 | m_ImageList.push_back(imgList); 82 | m_RasterExtractorList.push_back(toVec); 83 | outputRasters.push_back(toVec->GetOutput()); 84 | } 85 | return outputRasters; 86 | } 87 | -------------------------------------------------------------------------------- /CompositePreprocessing/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(test_MaskExtractorFilter test_MaskExtractorFilter.cpp ../include/MaskExtractorFilter.h) 2 | target_link_libraries(test_MaskExtractorFilter 3 | MuscateMetadata 4 | MetadataHelper 5 | "${Boost_LIBRARIES}" 6 | "${OTB_LIBRARIES}" 7 | "${OTBITK_LIBRARIES}" 8 | ) 9 | 10 | target_include_directories(test_MaskExtractorFilter PUBLIC ../include) 11 | add_test(test_MaskExtractorFilter test_MaskExtractorFilter) 12 | 13 | add_executable(test_ComputeNDVI test_ComputeNDVI.cpp ../include/ComputeNDVI.h ../src/ComputeNDVI.cpp) 14 | target_link_libraries(test_ComputeNDVI 15 | MuscateMetadata 16 | MetadataHelper 17 | "${Boost_LIBRARIES}" 18 | "${OTB_LIBRARIES}" 19 | "${OTBITK_LIBRARIES}" 20 | ) 21 | 22 | target_include_directories(test_ComputeNDVI PUBLIC ../include) 23 | add_test(test_ComputeNDVI test_ComputeNDVI) 24 | 25 | add_executable(test_CreateS2AnglesRaster test_CreateS2AnglesRaster.cpp ../include/CreateS2AnglesRaster.h ../src/CreateS2AnglesRaster.cpp) 26 | target_link_libraries(test_CreateS2AnglesRaster 27 | MuscateMetadata 28 | MetadataHelper 29 | "${Boost_LIBRARIES}" 30 | "${OTB_LIBRARIES}" 31 | "${OTBITK_LIBRARIES}" 32 | ) 33 | 34 | target_include_directories(test_CreateS2AnglesRaster PUBLIC ../include) 35 | add_test(test_CreateS2AnglesRaster test_CreateS2AnglesRaster) 36 | 37 | add_executable(test_DirectionalCorrection test_DirectionalCorrection.cpp 38 | ../include/DirectionalCorrection.h 39 | ../include/DirectionalCorrectionFunctor.h 40 | ../include/DirectionalModel.h 41 | ../src/DirectionalModel.cpp 42 | ../src/DirectionalCorrectionFunctor.txx 43 | ../src/DirectionalCorrection.cpp) 44 | target_link_libraries(test_DirectionalCorrection 45 | MuscateMetadata 46 | MetadataHelper 47 | "${Boost_LIBRARIES}" 48 | "${OTB_LIBRARIES}" 49 | "${OTBITK_LIBRARIES}" 50 | ) 51 | 52 | target_include_directories(test_DirectionalCorrection PUBLIC ../include) 53 | add_test(test_DirectionalCorrection test_DirectionalCorrection) 54 | -------------------------------------------------------------------------------- /CompositePreprocessing/test/test_ComputeNDVI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #define BOOST_TEST_MODULE ComputeNDVI 29 | #include 30 | #include "ComputeNDVI.h" 31 | #include "GlobalDefs.h" 32 | #include "TestImageCreator.h" 33 | #include "otbImageFileReader.h" 34 | #include "otbImageFileWriter.h" 35 | #include "itkImageRegionIterator.h" 36 | 37 | using namespace ts; 38 | 39 | #define WASP_TEST "WASP_TEST" 40 | #define TEST_NAME "test_Preprocessing" 41 | 42 | typedef float OutputPixelType; 43 | typedef otb::Image OutputImageType; 44 | typedef ts::ComputeNDVI NDVIType; 45 | typedef otb::ImageFileReader OutputImageReaderType; 46 | typedef otb::ImageFileWriter OutputImageWriterType; 47 | 48 | BOOST_AUTO_TEST_CASE(testNDVI){ 49 | std::string wasp_test = getEnvVar(WASP_TEST); 50 | if(wasp_test.empty()){ 51 | std::cout << "Cannot find WASP_TEST environment variable. Exiting..." << std::endl; 52 | exit(1); 53 | } 54 | std::string xml = wasp_test + "/" 55 | + TEST_NAME + "/" 56 | "INPUTS/" 57 | "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6/" 58 | "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6_MTD_ALL.xml"; 59 | 60 | NDVIType ndvi; 61 | ndvi.DoInit(xml); 62 | OutputImageType::Pointer output = ndvi.DoExecute().GetPointer(); 63 | OutputImageReaderType::Pointer gReader = OutputImageReaderType::New(); 64 | gReader->SetFileName(wasp_test + "/" + TEST_NAME + "/INPUTS/" + "ndvi.tif"); 65 | OutputImageType::Pointer reference = gReader->GetOutput(); 66 | reference->Update(); 67 | output->Update(); 68 | itk::ImageRegionIterator imageIteratorRef(reference,reference->GetLargestPossibleRegion()); 69 | itk::ImageRegionIterator imageIteratorNew(output,output->GetLargestPossibleRegion()); 70 | 71 | BOOST_CHECK_EQUAL(reference->GetLargestPossibleRegion(), output->GetLargestPossibleRegion()); 72 | while(!imageIteratorRef.IsAtEnd()) 73 | { 74 | BOOST_CHECK_EQUAL(imageIteratorRef.Get(), imageIteratorNew.Get()); 75 | ++imageIteratorRef; 76 | ++imageIteratorNew; 77 | } 78 | }; 79 | 80 | -------------------------------------------------------------------------------- /CompositePreprocessing/test/test_CreateS2AnglesRaster.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #define BOOST_TEST_MODULE CreateS2AnglesRaster 29 | #include 30 | #include "CreateS2AnglesRaster.h" 31 | #include "GlobalDefs.h" 32 | #include "otbImageFileReader.h" 33 | #include "otbImageFileWriter.h" 34 | #include "itkImageRegionIterator.h" 35 | #include "otbWrapperApplication.h" 36 | 37 | using namespace ts; 38 | 39 | #define WASP_TEST "WASP_TEST" 40 | #define TEST_NAME "test_Preprocessing" 41 | 42 | typedef float OutputPixelType; 43 | typedef otb::Wrapper::FloatVectorImageType OutputImageType; 44 | typedef ts::CreateS2AnglesRaster RasterCreationType; 45 | typedef otb::ImageFileReader OutputImageReaderType; 46 | typedef otb::ImageFileWriter OutputImageWriterType; 47 | 48 | BOOST_AUTO_TEST_CASE(testS2AnglesRasterCreationR2){ 49 | int resolution = 1; 50 | std::string wasp_test = getEnvVar(WASP_TEST); 51 | if(wasp_test.empty()){ 52 | std::cout << "Cannot find WASP_TEST environment variable. Exiting..." << std::endl; 53 | exit(1); 54 | } 55 | std::string xml = wasp_test + "/" 56 | + TEST_NAME + "/" 57 | "INPUTS/" 58 | "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6/" 59 | "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6_MTD_ALL.xml"; 60 | std::cout << "XML : "<< xml << std::endl; 61 | RasterCreationType rasterCreator; 62 | rasterCreator.DoInit(resolution, xml); 63 | OutputImageType::Pointer output = rasterCreator.DoExecute(); 64 | OutputImageReaderType::Pointer gReader = OutputImageReaderType::New(); 65 | gReader->SetFileName(wasp_test + "/" + TEST_NAME + "/INPUTS/" + "s2angles_raster_r" + std::to_string(resolution+1) + ".tif"); 66 | OutputImageType::Pointer reference = gReader->GetOutput(); 67 | reference->Update(); 68 | output->Update(); 69 | itk::ImageRegionIterator imageIteratorRef(reference,reference->GetLargestPossibleRegion()); 70 | itk::ImageRegionIterator imageIteratorNew(output,output->GetLargestPossibleRegion()); 71 | 72 | BOOST_CHECK_EQUAL(reference->GetLargestPossibleRegion(), output->GetLargestPossibleRegion()); 73 | while(!imageIteratorRef.IsAtEnd()) 74 | { 75 | itk::VariableLengthVector referenceBands = imageIteratorRef.Get(); 76 | itk::VariableLengthVector newBands = imageIteratorNew.Get(); 77 | BOOST_CHECK_EQUAL(referenceBands.GetSize(), newBands.GetSize()); 78 | for(size_t i = 0; i < referenceBands.GetSize(); i++){ 79 | if(!std::isnan(referenceBands[i]) && !std::isnan(newBands[i])){ 80 | BOOST_CHECK_EQUAL(referenceBands[i], newBands[i]); 81 | } 82 | } 83 | ++imageIteratorRef; 84 | ++imageIteratorNew; 85 | } 86 | }; 87 | 88 | #ifdef R1 89 | BOOST_AUTO_TEST_CASE(testS2AnglesRasterCreationR1){ 90 | int resolution = 0; 91 | std::string wasp_test = getEnvVar(WASP_TEST); 92 | if(wasp_test.empty()){ 93 | std::cout << "Cannot find WASP_TEST environment variable. Exiting..." << std::endl; 94 | exit(1); 95 | } 96 | std::string xml = wasp_test + "/" 97 | + TEST_NAME + "/" 98 | "INPUTS/" 99 | "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6/" 100 | "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6_MTD_ALL.xml"; 101 | std::cout << "XML : "<< xml << std::endl; 102 | RasterCreationType rasterCreator; 103 | rasterCreator.DoInit(resolution, xml); 104 | OutputImageType::Pointer output = rasterCreator.DoExecute(); 105 | OutputImageReaderType::Pointer gReader = OutputImageReaderType::New(); 106 | gReader->SetFileName(wasp_test + "/" + TEST_NAME + "/INPUTS/" + "s2angles_raster_r" + std::to_string(resolution+1) + ".tif"); 107 | OutputImageType::Pointer reference = gReader->GetOutput(); 108 | reference->Update(); 109 | output->Update(); 110 | itk::ImageRegionIterator imageIteratorRef(reference,reference->GetLargestPossibleRegion()); 111 | itk::ImageRegionIterator imageIteratorNew(output,output->GetLargestPossibleRegion()); 112 | 113 | BOOST_CHECK_EQUAL(reference->GetLargestPossibleRegion(), output->GetLargestPossibleRegion()); 114 | while(!imageIteratorRef.IsAtEnd()) 115 | { 116 | itk::VariableLengthVector referenceBands = imageIteratorRef.Get(); 117 | itk::VariableLengthVector newBands = imageIteratorNew.Get(); 118 | BOOST_CHECK_EQUAL(referenceBands.GetSize(), newBands.GetSize()); 119 | for(size_t i = 0; i < referenceBands.GetSize(); i++){ 120 | if(!std::isnan(referenceBands[i]) && !std::isnan(newBands[i])){ 121 | BOOST_CHECK_EQUAL(referenceBands[i], newBands[i]); 122 | } 123 | } 124 | ++imageIteratorRef; 125 | ++imageIteratorNew; 126 | } 127 | }; 128 | #endif 129 | -------------------------------------------------------------------------------- /CompositePreprocessing/test/test_MaskExtractorFilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #define BOOST_TEST_MODULE MaskExtractorFilter 29 | #include 30 | #include "MaskExtractorFilter.h" 31 | #include "GlobalDefs.h" 32 | #include "TestImageCreator.h" 33 | 34 | using namespace ts; 35 | 36 | typedef unsigned char InputPixelType; 37 | typedef float OutputPixelType; 38 | 39 | typedef otb::Image OutputImageType; 40 | typedef otb::Image InputImageType; 41 | typedef ts::MaskExtractorFilter ExtractorType; 43 | 44 | 45 | BOOST_AUTO_TEST_CASE(testMaskExtractorFilterBit1){ 46 | size_t width = 1; 47 | size_t height = 255; 48 | unsigned char bit = 0; 49 | TestImageCreator c; 50 | InputImageType::Pointer img = c.createTestImage(height, width); 51 | 52 | ExtractorType::Pointer maskExtractor; 53 | maskExtractor = ExtractorType::New(); 54 | maskExtractor->SetBitMask(bit); 55 | maskExtractor->SetInput(img.GetPointer()); 56 | 57 | OutputImageType::Pointer output = maskExtractor->GetOutput(); 58 | try 59 | { 60 | output->Update(); 61 | } 62 | catch (itk::ExceptionObject& err) 63 | { 64 | std::cout << "ExceptionObject caught !" << std::endl; 65 | std::cout << err << std::endl; 66 | } 67 | 68 | size_t i = 0; 69 | for(unsigned int r = 0; r < width; r++) 70 | { 71 | for(unsigned int c = 0; c < height; c++) 72 | { 73 | InputImageType::IndexType pixelIndex; 74 | pixelIndex[0] = r; 75 | pixelIndex[1] = c; 76 | BOOST_CHECK_EQUAL(((i & (bit+1)) >> bit), output->GetPixel(pixelIndex)); 77 | i++; 78 | } 79 | } 80 | } 81 | 82 | BOOST_AUTO_TEST_CASE(testMaskExtractorFilterBit3){ 83 | size_t width = 1; 84 | size_t height = 6; 85 | unsigned char bit = 3; 86 | TestImageCreator c; 87 | InputImageType::Pointer img = c.createTestImage(height, width); 88 | 89 | ExtractorType::Pointer maskExtractor; 90 | maskExtractor = ExtractorType::New(); 91 | maskExtractor->SetBitMask(bit); 92 | maskExtractor->SetInput(img.GetPointer()); 93 | 94 | OutputImageType::Pointer output = maskExtractor->GetOutput(); 95 | try 96 | { 97 | output->Update(); 98 | } 99 | catch (itk::ExceptionObject& err) 100 | { 101 | std::cout << "ExceptionObject caught !" << std::endl; 102 | std::cout << err << std::endl; 103 | } 104 | 105 | size_t i = 0; 106 | for(unsigned int r = 0; r < width; r++) 107 | { 108 | for(unsigned int c = 0; c < height; c++) 109 | { 110 | InputImageType::IndexType pixelIndex; 111 | pixelIndex[0] = r; 112 | pixelIndex[1] = c; 113 | BOOST_CHECK_EQUAL(((i & (bit+1)) >> bit), output->GetPixel(pixelIndex)); 114 | i++; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /MuscateMetadata/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MuscateMetadata_HEADERS 2 | include/FluentXML.hpp 3 | include/tinyxml_utils.hpp 4 | include/string_utils.hpp 5 | include/MuscateMetadata.hpp 6 | include/MuscateMetadataReader.hpp 7 | include/MuscateMetadataWriter.hpp 8 | include/MetadataUtil.hpp 9 | include/ViewingAngles.hpp) 10 | 11 | set(MuscateMetadata_SOURCES 12 | src/FluentXML.cpp 13 | src/tinyxml_utils.cpp 14 | src/string_utils.cpp 15 | src/MuscateMetadataReader.cpp 16 | src/MuscateMetadataWriter.cpp 17 | src/ViewingAngles.cpp 18 | src/MetadataUtil.cpp) 19 | 20 | add_library(MuscateMetadata SHARED ${MuscateMetadata_HEADERS} ${MuscateMetadata_SOURCES}) 21 | target_link_libraries(MuscateMetadata 22 | "${Boost_LIBRARIES}" 23 | "${OTBCommon_LIBRARIES}" 24 | "${OTBTinyXML_LIBRARIES}" 25 | "${OTBITK_LIBRARIES}") 26 | 27 | target_include_directories(MuscateMetadata PUBLIC include) 28 | 29 | install(TARGETS MuscateMetadata DESTINATION lib/) 30 | 31 | if(BUILD_TESTING) 32 | add_subdirectory(test) 33 | endif() 34 | -------------------------------------------------------------------------------- /MuscateMetadata/include/FluentXML.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #pragma once 27 | 28 | #include "otb_tinyxml.h" 29 | #include 30 | #include 31 | 32 | struct XNode 33 | { 34 | private: 35 | std::unique_ptr node; 36 | 37 | public: 38 | XNode(TiXmlNode *node); 39 | 40 | void LinkEndChild(TiXmlNode *child); 41 | 42 | TiXmlDocument *AsDocument(); 43 | const TiXmlDocument *AsDocument() const; 44 | TiXmlElement *AsElement(); 45 | const TiXmlElement *AsElement() const; 46 | TiXmlNode *Node(); 47 | const TiXmlNode *Node() const; 48 | 49 | protected: 50 | TiXmlNode *Release(); 51 | }; 52 | 53 | template 54 | struct XNodeW : public XNode 55 | { 56 | template 57 | XNodeW(TiXmlNode *node, T &&... children) 58 | : XNode(node) 59 | { 60 | Link(std::forward(children)...); 61 | } 62 | 63 | template 64 | XNodeW &Append(T &&child) 65 | { 66 | Link(std::forward(child)); 67 | return *this; 68 | } 69 | 70 | private: 71 | void Link() 72 | { 73 | } 74 | 75 | template 76 | void Link(T &&firstChild, R &&... otherChildren) 77 | { 78 | std::forward(firstChild).AppendTo(static_cast(*this)); 79 | Link(std::forward(otherChildren)...); 80 | } 81 | }; 82 | 83 | struct XDocument : public XNodeW 84 | { 85 | template 86 | XDocument(T &&... children) 87 | : XNodeW(new TiXmlDocument, std::forward(children)...) 88 | { 89 | } 90 | 91 | void Save(const char *path) const; 92 | void Save(const std::string &path) const; 93 | }; 94 | 95 | struct XText 96 | { 97 | std::string text; 98 | 99 | XText(std::string text); 100 | 101 | void AppendTo(XNode &parent); 102 | }; 103 | 104 | struct XElement : public XNodeW 105 | { 106 | template 107 | XElement(Name &&name, std::string text) 108 | : XElement(std::forward(name), XText(std::move(text))) 109 | { 110 | } 111 | 112 | template 113 | XElement(Name &&name, T &&... children) 114 | : XNodeW(new TiXmlElement(std::forward(name)), std::forward(children)...) 115 | { 116 | } 117 | 118 | void AppendTo(XNode &parent); 119 | void SetAttribute(const char *name, const char *value); 120 | }; 121 | 122 | struct XAttribute 123 | { 124 | std::string name; 125 | std::string value; 126 | 127 | XAttribute(std::string name, std::string value); 128 | 129 | void AppendTo(XElement &parent); 130 | }; 131 | 132 | struct XDeclaration 133 | { 134 | std::unique_ptr declaration; 135 | 136 | XDeclaration(const char *version, const char *encoding, const char *standalone); 137 | 138 | void AppendTo(XNode &parent); 139 | }; 140 | 141 | struct XUnknown 142 | { 143 | std::unique_ptr unknown; 144 | 145 | XUnknown(const char *s); 146 | 147 | void AppendTo(XNode &parent); 148 | }; 149 | 150 | std::ostream & operator<<(std::ostream &o, const XDocument &doc); 151 | -------------------------------------------------------------------------------- /MuscateMetadata/include/MetadataUtil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include 27 | #include "MuscateMetadata.hpp" 28 | 29 | 30 | /** 31 | * @brief compares two image properties, each having a has*** and value. E.g. hasBitNum and bitNumber 32 | * @return True, if both have the property and they're equal or they don't have it and are not equal. False otherwise. 33 | */ 34 | bool compareImageProperties(const bool &a,const bool &b, const std::string &as, const std::string &bs); 35 | 36 | /** 37 | * @brief print Muscate angles as a string, for debugging 38 | * @param angles 39 | * @return String formatted to print to console 40 | */ 41 | std::string MuscateAnglesToString(const MuscateAngles &angles); 42 | 43 | ///////////////////////////////////////////// 44 | /// COMPARATORS FOR ALL METADATA STRUCTS /// 45 | /////////////////////////////////////////// 46 | 47 | bool operator==(MuscateHeaderMetadata const& lhs, MuscateHeaderMetadata const& rhs); 48 | bool operator==(MuscateMetadataIdentification const& lhs, MuscateMetadataIdentification const& rhs); 49 | bool operator==(MuscateDatasetIdentification const& lhs, MuscateDatasetIdentification const& rhs); 50 | bool operator!=(BandList const& lhs, BandList const& rhs); 51 | bool operator!=(BandGroup const& lhs, BandGroup const& rhs); 52 | bool operator==(BandGroup const& lhs, BandGroup const& rhs); 53 | bool operator==(MuscateProductCharacteristics const& lhs, MuscateProductCharacteristics const& rhs); 54 | bool operator==(ImageInformation const& lhs, ImageInformation const& rhs); 55 | bool operator!=(ImageInformation const& lhs, ImageInformation const& rhs); 56 | bool operator==(ImageProperty const& lhs, ImageProperty const& rhs); 57 | bool operator==(MuscateProductOrganisation const& lhs, MuscateProductOrganisation const& rhs); 58 | bool operator!=(CSInfo const& lhs, CSInfo const& rhs); 59 | bool operator==(GeoPoint const& lhs, GeoPoint const& rhs); 60 | bool operator==(GroupPositioning const& lhs, GroupPositioning const& rhs); 61 | bool operator==(MuscateGeopositionInformations const& lhs, MuscateGeopositionInformations const& rhs); 62 | bool operator==(SpecialValue const& lhs, SpecialValue const& rhs); 63 | bool operator==(MuscateRadiometricInformations const& lhs, MuscateRadiometricInformations const& rhs); 64 | bool operator==(MuscateQualityIndex const& lhs, MuscateQualityIndex const& rhs); 65 | bool operator==(MuscateQualityProduct const& lhs, MuscateQualityProduct const& rhs); 66 | bool operator==(MuscateQualityInformations const& lhs, MuscateQualityInformations const& rhs); 67 | -------------------------------------------------------------------------------- /MuscateMetadata/include/MuscateMetadataReader.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | #include "itkObjectFactory.h" 33 | #include "otb_tinyxml.h" 34 | 35 | #include "MuscateMetadata.hpp" 36 | 37 | /** 38 | * @brief Temporal synthesis namespace 39 | */ 40 | namespace ts { 41 | /** 42 | * @brief Muscate Metadata namespace 43 | */ 44 | 45 | namespace muscate { 46 | 47 | /** 48 | * @brief Reads muscate metadata files in format Muscate 3.1 (unified) and the old one (distributed) 49 | */ 50 | class MuscateMetadataReader : public itk::LightObject 51 | { 52 | public: 53 | /* ITK typedefs */ 54 | typedef MuscateMetadataReader Self; 55 | typedef itk::LightObject Superclass; 56 | typedef itk::SmartPointer Pointer; 57 | typedef itk::SmartPointer ConstPointer; 58 | 59 | /* ITK Macros */ 60 | itkNewMacro(Self) 61 | itkTypeMacro(MuscateMetadataReader, itk::LightObject) 62 | 63 | /** 64 | * @brief Read the main metadata file 65 | * @param path Reference to the input string 66 | * @return Pointer to the Muscate metadata file 67 | */ 68 | std::unique_ptr ReadMetadata(const std::string &path); 69 | 70 | /** 71 | * @brief Read all metadata fields inside the TiXml Document 72 | * @param doc The metadata file opened with TiXml 73 | * @return Pointer to the Muscate metadata file 74 | */ 75 | std::unique_ptr ReadMetadataXml(const TiXmlDocument &doc); 76 | 77 | private: 78 | 79 | /** 80 | * @brief checks if Element has Attribute of given name 81 | * @param el The element 82 | * @param s The name of the attribute 83 | * @return True, if Attribute exists, false if not 84 | */ 85 | bool hasAttribute(TiXmlElement *el, const std::string &s); 86 | 87 | /** 88 | * @brief Read the MetadataIdentification section of the main metadata file 89 | * @param el Pointer to the MetadataIdentification parent 90 | * @return MuscateMetadataIdentification struct containing all fields 91 | */ 92 | MuscateMetadataIdentification readMetadataIdentification(TiXmlElement *el); 93 | 94 | /** 95 | * @brief Read the DatasetIdentification section of the main metadata file 96 | * @param el Pointer to the DatasetIdentification parent 97 | * @return MuscateDatasetIdentification struct containing all fields 98 | */ 99 | MuscateDatasetIdentification readDatasetIdentification(TiXmlElement *el); 100 | 101 | /** 102 | * @brief Read the ProductCharacteristics section of the main metadata file 103 | * @param el Pointer to the ProductCharacteristics parent 104 | * @return MuscateProductCharacteristics struct containing all fields 105 | */ 106 | MuscateProductCharacteristics readProductCharacteristics(TiXmlElement *el); 107 | 108 | /** 109 | * @brief Read the ProductOrganisation section of the main metadata file 110 | * @param el Pointer to the ProductOrganisation parent 111 | * @return MuscateProductOrganisation struct containing all fields 112 | */ 113 | MuscateProductOrganisation readProductOrganisation(TiXmlElement *el); 114 | 115 | /** 116 | * @brief Read the GeopositionInformations section of the main metadata file 117 | * @param el Pointer to the GeopositionInformations parent 118 | * @return MuscateGeopositionInformations struct containing all fields 119 | */ 120 | MuscateGeopositionInformations readGeopositionInformations(TiXmlElement *el); 121 | 122 | /** 123 | * @brief Read the GeometricInformations section of the main metadata file 124 | * @param el Pointer to the GeometricInformations parent 125 | * @return MuscateGeometricInformations struct containing all fields 126 | */ 127 | MuscateGeometricInformations readGeometricInformations(TiXmlElement *el); 128 | 129 | /** 130 | * @brief Read the RadiometricInformations section of the main metadata file 131 | * @param el Pointer to the RadiometricInformations parent 132 | * @return MuscateRadiometricInformations struct containing all fields 133 | */ 134 | MuscateRadiometricInformations readRadiometricInformations(TiXmlElement *el); 135 | 136 | /** 137 | * @brief Read the QualityInformations section of the main metadata file 138 | * @param el Pointer to the QualityInformations parent 139 | * @return MuscateQualityInformations struct containing all fields 140 | */ 141 | MuscateQualityInformations readQualityInformations(TiXmlElement *el); 142 | 143 | }; /* class MuscateMetadataReader */ 144 | } /* namespace muscate */ 145 | } /* namespace ts */ 146 | 147 | -------------------------------------------------------------------------------- /MuscateMetadata/include/MuscateMetadataWriter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #pragma once 29 | 30 | #include "itkObjectFactory.h" 31 | 32 | #include "FluentXML.hpp" 33 | #include "MuscateMetadata.hpp" 34 | 35 | 36 | /** 37 | * @brief Temporal synthesis namespace 38 | */ 39 | namespace ts { 40 | 41 | /** 42 | * @brief Muscate Metadata namespace 43 | */ 44 | namespace muscate { 45 | 46 | /** 47 | * @brief Writes muscate metadata files in format Muscate 3.1 (unified) 48 | */ 49 | class MuscateMetadataWriter : public itk::LightObject 50 | { 51 | public: 52 | /* ITK typedefs */ 53 | typedef MuscateMetadataWriter Self; 54 | typedef itk::LightObject Superclass; 55 | typedef itk::SmartPointer Pointer; 56 | typedef itk::SmartPointer ConstPointer; 57 | 58 | /* ITK macros */ 59 | itkNewMacro(Self) 60 | itkTypeMacro(MuscateMetadataWriter, itk::LightObject) 61 | 62 | /** 63 | * @brief Creates the XDocument from the MuscateFileMetadata struct 64 | * @param struct Struct containing all metadata information for the new product 65 | * @return XDocument the document, formatted, to be written 66 | */ 67 | XDocument CreateMetadataXml(const MuscateFileMetadata &metadata); 68 | 69 | /** 70 | * @brief Creates the XDocument file and writes it to the given path 71 | * @param struct Struct containing all metadata information for the new product 72 | * @param path The path to write the file to 73 | * @return void 74 | */ 75 | void WriteMetadata(const MuscateFileMetadata &metadata, const std::string &path); 76 | 77 | private: 78 | /** 79 | * @brief Format functions to create an XDoc from the MuscateMetadataIdentification struct 80 | */ 81 | XElement Format(const MuscateMetadataIdentification &meta); 82 | /** 83 | * @brief Format functions to create an XDoc from the MuscateDatasetIdentification struct 84 | */ 85 | XElement Format(const MuscateDatasetIdentification &meta); 86 | /** 87 | * @brief Format functions to create an XDoc from the MuscateProductCharacteristics struct 88 | */ 89 | XElement Format(const MuscateProductCharacteristics &meta); 90 | /** 91 | * @brief Format functions to create an XDoc from the MuscateProductOrganisation struct 92 | */ 93 | XElement Format(const MuscateProductOrganisation &meta); 94 | /** 95 | * @brief Format functions to create an XDoc from the MuscateGeometricInformations struct 96 | */ 97 | XElement Format(const MuscateGeometricInformations &meta); 98 | /** 99 | * @brief Format functions to create an XDoc from the MuscateGeopositionInformations struct 100 | */ 101 | XElement Format(const MuscateGeopositionInformations &meta); 102 | /** 103 | * @brief Format functions to create an XDoc from the MuscateRadiometricInformations struct 104 | */ 105 | XElement Format(const MuscateRadiometricInformations &meta); 106 | /** 107 | * @brief Format functions to create an XDoc from the MuscateQualityInformations struct 108 | */ 109 | XElement Format(const MuscateQualityInformations &meta); 110 | /** 111 | * @brief Format functions to create an XDoc from the MuscateProductionInformations struct 112 | */ 113 | XElement Format(const MuscateProductionInformations &meta); 114 | 115 | //Specifies the Type of organizational product to be written 116 | typedef enum{ 117 | Image, 118 | Mask, 119 | Data 120 | }organisationType; 121 | 122 | }; /* class MuscateMetadataWriter */ 123 | } /* namespace muscate */ 124 | } /* namespace ts */ 125 | -------------------------------------------------------------------------------- /MuscateMetadata/include/ViewingAngles.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | #include "MuscateMetadata.hpp" 31 | 32 | /** 33 | * @brief Checks the given ViewingIncidenceAnglesGrids struct for completeness and adds up all detector-angles to a single grid per band 34 | * @param angleGrids The struct containing all Viewing angles 35 | * @return The new struct, containing one grid per band 36 | */ 37 | std::vector ComputeViewingAngles(const std::vector &angleGrids); 38 | -------------------------------------------------------------------------------- /MuscateMetadata/include/string_utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | /** 30 | * @brief Split string by a char delimiter 31 | * @param s The string to be splitted 32 | * @param delim The delimiter, occuring [0...*] 33 | * @return A vector containing all the splitted substrings 34 | */ 35 | std::vector split(const std::string &s, char delim); 36 | 37 | /** 38 | * @brief Read a double value from a given string 39 | * @param s The string containing only [0...9] and a single "." 40 | * @return The double value 41 | */ 42 | double ReadDouble(const std::string &s); 43 | 44 | /** 45 | * @brief Check if a string contains only digits 46 | * @param s The string to be checked 47 | * @return True, if only digits 0-9 are found, False if not 48 | */ 49 | bool is_number(const std::string& s); 50 | 51 | /** 52 | * @brief Returns a string with only uppercase letters 53 | * @param s The original string - Only ASCII characters allowed 54 | * @return The same string as s in uppercase only 55 | */ 56 | std::string toUppercase(const std::string & s); 57 | 58 | /** 59 | * @brief Append the current resolution to the parameter name 60 | * @param param The parameter name 61 | * @param resolution The current resolution as size_t [0;1] 62 | * @return The parameter with the current resolution 63 | * @example "in" + resolution 0 = "inr1"; "image" + resolution 1 = "imager2" 64 | */ 65 | std::string getParameterName(const std::string ¶m, const size_t &resolution); 66 | -------------------------------------------------------------------------------- /MuscateMetadata/include/tinyxml_utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | #include "otb_tinyxml.h" 31 | 32 | std::string GetAttribute(const TiXmlElement *element, const char *attributeName); 33 | std::string GetText(const TiXmlElement *element); 34 | std::string GetChildText(const TiXmlElement *element, const char *childName); 35 | std::string GetChildAttribute(const TiXmlElement *element, const char *childName, const char *attributeName); 36 | -------------------------------------------------------------------------------- /MuscateMetadata/src/FluentXML.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "FluentXML.hpp" 27 | 28 | XNode::XNode(TiXmlNode *node) : node(node) 29 | { 30 | } 31 | 32 | void XNode::LinkEndChild(TiXmlNode *child) 33 | { 34 | node->LinkEndChild(child); 35 | } 36 | 37 | TiXmlDocument *XNode::AsDocument() 38 | { 39 | return static_cast(node.get()); 40 | } 41 | 42 | const TiXmlDocument *XNode::AsDocument() const 43 | { 44 | return static_cast(node.get()); 45 | } 46 | 47 | TiXmlElement *XNode::AsElement() 48 | { 49 | return static_cast(node.get()); 50 | } 51 | 52 | const TiXmlElement *XNode::AsElement() const 53 | { 54 | return static_cast(node.get()); 55 | } 56 | 57 | TiXmlNode *XNode::Node() 58 | { 59 | return node.get(); 60 | } 61 | 62 | const TiXmlNode *XNode::Node() const 63 | { 64 | return node.get(); 65 | } 66 | 67 | TiXmlNode *XNode::Release() 68 | { 69 | return node.release(); 70 | } 71 | 72 | void XDocument::Save(const char *path) const 73 | { 74 | AsDocument()->SaveFile(path); 75 | } 76 | 77 | void XDocument::Save(const std::string &path) const 78 | { 79 | AsDocument()->SaveFile(path); 80 | } 81 | 82 | XText::XText(std::string text) : text(std::move(text)) 83 | { 84 | } 85 | 86 | void XText::AppendTo(XNode &parent) 87 | { 88 | if (!text.empty()) { 89 | parent.LinkEndChild(new TiXmlText(std::move(text))); 90 | } 91 | } 92 | 93 | void XElement::AppendTo(XNode &parent) 94 | { 95 | if (AsElement()->FirstChild() || AsElement()->FirstAttribute()) { 96 | parent.LinkEndChild(Release()); 97 | } 98 | } 99 | 100 | void XElement::SetAttribute(const char *name, const char *value) 101 | { 102 | AsElement()->SetAttribute(name, value); 103 | } 104 | 105 | XAttribute::XAttribute(std::string name, std::string value) 106 | : name(std::move(name)), value(std::move(value)) 107 | { 108 | } 109 | 110 | void XAttribute::AppendTo(XElement &parent) 111 | { 112 | parent.SetAttribute(name.c_str(), value.c_str()); 113 | } 114 | 115 | XDeclaration::XDeclaration(const char *version, const char *encoding, const char *standalone) 116 | : declaration(new TiXmlDeclaration(version, encoding, standalone)) 117 | { 118 | } 119 | 120 | void XDeclaration::AppendTo(XNode &parent) 121 | { 122 | parent.LinkEndChild(declaration.release()); 123 | } 124 | 125 | XUnknown::XUnknown(const char *s) : unknown(new TiXmlUnknown) 126 | { 127 | std::istringstream ss(s); 128 | ss >> *unknown; 129 | } 130 | 131 | void XUnknown::AppendTo(XNode &parent) 132 | { 133 | parent.LinkEndChild(unknown.release()); 134 | } 135 | 136 | std::ostream & operator<<(std::ostream &o, const XDocument &doc) 137 | { 138 | return o << *doc.AsDocument(); 139 | } 140 | -------------------------------------------------------------------------------- /MuscateMetadata/src/string_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "string_utils.hpp" 33 | 34 | std::vector split(const std::string &s, char delim) 35 | { 36 | std::vector result; 37 | 38 | std::istringstream is(s); 39 | std::string item; 40 | while (std::getline(is, item, delim)) { 41 | result.emplace_back(std::move(item)); 42 | } 43 | 44 | return result; 45 | } 46 | 47 | double ReadDouble(const std::string &s) 48 | { 49 | try { 50 | if (s.empty()) { 51 | return std::numeric_limits::quiet_NaN(); 52 | } 53 | double ret = std::stod(s); 54 | return ret; 55 | } catch (const std::exception &e) { 56 | otbMsgDevMacro("Invalid double value " << s << ": " << e.what()); 57 | 58 | return std::numeric_limits::quiet_NaN(); 59 | } 60 | } 61 | 62 | bool is_number(const std::string& s) 63 | { 64 | return !s.empty() && std::find_if(s.begin(), 65 | s.end(), [](char c) { return !std::isdigit(c); }) == s.end(); 66 | } 67 | 68 | std::string toUppercase(const std::string & s) 69 | { 70 | std::string ret(s.size(), char()); 71 | for(unsigned int i = 0; i < s.size(); ++i) 72 | ret[i] = (s[i] <= 'z' && s[i] >= 'a') ? s[i]-('a'-'A') : s[i]; 73 | return ret; 74 | } 75 | 76 | 77 | std::string getParameterName(const std::string ¶m, const size_t &resolution){ 78 | return std::string(param + "r" + std::to_string(resolution+1)).c_str(); 79 | } 80 | -------------------------------------------------------------------------------- /MuscateMetadata/src/tinyxml_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "tinyxml_utils.hpp" 27 | 28 | std::string GetAttribute(const TiXmlElement *element, const char *attributeName) 29 | { 30 | if (const char *at = element->Attribute(attributeName)) { 31 | return at; 32 | } 33 | 34 | return std::string(); 35 | } 36 | 37 | std::string GetText(const TiXmlElement *element) 38 | { 39 | if (const char *text = element->GetText()) { 40 | return text; 41 | } 42 | 43 | return std::string(); 44 | } 45 | 46 | std::string GetChildText(const TiXmlElement *element, const char *childName) 47 | { 48 | if (auto el = element->FirstChildElement(childName)) { 49 | if (const char *text = el->GetText()) 50 | return text; 51 | } 52 | 53 | return std::string(); 54 | } 55 | 56 | std::string 57 | GetChildAttribute(const TiXmlElement *element, const char *childName, const char *attributeName) 58 | { 59 | if (auto el = element->FirstChildElement(childName)) { 60 | if (const char *at = el->Attribute(attributeName)) { 61 | return at; 62 | } 63 | } 64 | 65 | return std::string(); 66 | } 67 | -------------------------------------------------------------------------------- /MuscateMetadata/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(test_MuscateMetadataReader test_MuscateMetadataReader.cpp) 2 | target_link_libraries(test_MuscateMetadataReader 3 | MuscateMetadata 4 | MetadataHelper 5 | "${Boost_LIBRARIES}") 6 | add_test(test_MuscateMetadataReader test_MuscateMetadataReader) 7 | 8 | add_executable(test_MuscateMetadataWriteRead test_MuscateMetadataWriteRead.cpp) 9 | target_link_libraries(test_MuscateMetadataWriteRead 10 | MuscateMetadata 11 | MetadataHelper 12 | "${Boost_LIBRARIES}") 13 | add_test(test_MuscateMetadataWriteRead test_MuscateMetadataWriteRead) 14 | 15 | add_executable(test_MuscateMetadataReadWrite test_MuscateMetadataReadWrite.cpp) 16 | target_link_libraries(test_MuscateMetadataReadWrite 17 | MuscateMetadata 18 | MetadataHelper 19 | "${Boost_LIBRARIES}") 20 | add_test(test_MuscateMetadataReadWrite test_MuscateMetadataReadWrite) 21 | -------------------------------------------------------------------------------- /ProductFormatter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | otb_create_application( 2 | NAME ProductFormatter 3 | SOURCES src/ProductFormatter.cpp 4 | src/ProductCreatorAdapter.cpp 5 | src/ProductCreatorSentinelMuscate.cpp 6 | src/ProductCreatorVenusMuscate.cpp 7 | 8 | LINK_LIBRARIES ${OTB_LIBRARIES} MuscateMetadata MetadataHelper) 9 | 10 | target_include_directories(otbapp_ProductFormatter PUBLIC include) 11 | install(TARGETS otbapp_ProductFormatter DESTINATION lib/otb/applications) 12 | 13 | if(BUILD_TESTING) 14 | add_subdirectory(test) 15 | endif() -------------------------------------------------------------------------------- /ProductFormatter/include/ProductCreatorSentinelMuscate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef PRODUCTFORMATTER_INCLUDE_PRODUCTCREATORSENTINELMUSCATE_H_ 29 | #define PRODUCTFORMATTER_INCLUDE_PRODUCTCREATORSENTINELMUSCATE_H_ 30 | 31 | #include "ProductCreatorAdapter.h" 32 | 33 | /** 34 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 35 | */ 36 | namespace ts { 37 | 38 | class ProductCreatorSentinelMuscate : public ProductCreatorAdapter{ 39 | public: 40 | 41 | /** 42 | * @brief Create a Sentinel-2 Muscate product inside the specified destination-folder 43 | * @param destination The destination directory 44 | * @return True, if the creation succeeded, false if not 45 | */ 46 | virtual bool createProduct(const std::string &destination) ; 47 | 48 | private: 49 | /** 50 | * @brief Read all metadata files and FillMetadataInfo for each S2-File. Also determines the GeoInfo to be used 51 | * @param descriptors Vector of strings of xml-filenames 52 | */ 53 | virtual void LoadAllDescriptors(const std::vector &descriptors); 54 | 55 | /** 56 | * @brief Get the Geoposition information from a Level-2 product 57 | * @param desc The filename to the L2-XML 58 | * @return Geoposition to be used in the L3 Metadata 59 | */ 60 | virtual MuscateGeopositionInformations GetGeopositionInformations(const std::string &desc); 61 | 62 | /** 63 | * @brief Set the BandInformation-vector for Sentinel-2 64 | * @return Vector, containing the Radiometric band-infos 65 | */ 66 | virtual std::vector getMissionBands(); 67 | 68 | /** 69 | * @brief Create the product directory name following the given conventions 70 | * @param productType The type of the product 71 | * @param productVersion The product version 72 | * @return string of the product directory name 73 | */ 74 | virtual std::string BuildProductDirectoryName(const std::string &productType, const std::string &productVersion); 75 | 76 | /** 77 | * @brief Build the product directory according to the Sentinel-2 Muscate conventions 78 | * @param datetime Product datetime 79 | * @param productType Type of the product 80 | * @param productVersion Version of the product 81 | * @return string of the S2-product directory 82 | */ 83 | std::string BuildFileNameSentinel(const std::string &datetime, const std::string &productType, const std::string &productVersion); 84 | 85 | /** 86 | * @brief Copy raster files and create metadata-info for each 87 | * @param raster The raster input name 88 | * @param rasterTypes The type of raster file to be copied (See rasterTypes enum) 89 | * @param bIsMask True if it's a mask file, false if not 90 | * @note If copying fails, the metadata info is also not created 91 | * @return true, if both copying and metadata creating succeeded, false if not 92 | */ 93 | template 94 | bool copyRaster(typename ExtractorType::Pointer splitter, const size_t &index, 95 | const rasterTypes &rasterType, resolutionTypesS2 resolution, const bool &bIsMask); 96 | 97 | /** 98 | * @brief determines the BandGroups depending on which mission was chosen 99 | * @return BandList struct containing all available bands in the output product 100 | */ 101 | virtual std::vector getBandGroupList(const std::vector &missionBands); 102 | 103 | /** 104 | * @brief Generates the metadata file for the output product in Muscate Unified format 105 | * @param strProductMetadataFilePath The path where the metadata file shall be written to 106 | * @param cloudPercent The percentage of clouds in the image 107 | * @return void - Writes Metadata inside the product folder, named {}_MTD_ALL.xml 108 | */ 109 | virtual void generateMetadataFile(const std::string &strProductMetadataFilePath, const std::string &cloudPercent = "1", const std::string &snowPercent = "1"); 110 | }; 111 | } /* namespace ts */ 112 | 113 | 114 | #endif /* PRODUCTFORMATTER_INCLUDE_PRODUCTCREATORSENTINELMUSCATE_H_ */ 115 | -------------------------------------------------------------------------------- /ProductFormatter/include/ProductCreatorVenusMuscate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef PRODUCTFORMATTER_INCLUDE_PRODUCTCREATORVENUSMUSCATE_H_ 29 | #define PRODUCTFORMATTER_INCLUDE_PRODUCTCREATORVENUSMUSCATE_H_ 30 | 31 | #include "ProductCreatorAdapter.h" 32 | 33 | 34 | /** 35 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 36 | */ 37 | namespace ts { 38 | 39 | class ProductCreatorVenusMuscate : public ProductCreatorAdapter{ 40 | public: 41 | 42 | /** 43 | * @brief Create a Venus Muscate product inside the specified destination-folder 44 | * @param destination The destination directory 45 | * @return True, if the creation succeeded, false if not 46 | */ 47 | virtual bool createProduct(const std::string &destination) ; 48 | 49 | private: 50 | /** 51 | * @brief Read all metadata files and FillMetadataInfo for each S2-File. Also determines the GeoInfo to be used 52 | * @param descriptors Vector of strings of xml-filenames 53 | */ 54 | virtual void LoadAllDescriptors(const std::vector &descriptors); 55 | 56 | /** 57 | * @brief Get the Geoposition information from a Level-2 product 58 | * @param desc The filename to the L2-XML 59 | * @return Geoposition to be used in the L3 Metadata 60 | */ 61 | virtual MuscateGeopositionInformations GetGeopositionInformations(const std::string &desc); 62 | 63 | /** 64 | * @brief Set the BandInformation-vector for Venus 65 | * @return Vector, containing the Radiometric band-infos 66 | */ 67 | virtual std::vector getMissionBands(); 68 | 69 | /** 70 | * @brief Create the product directory name following the given conventions 71 | * @param productType The type of the product 72 | * @param productVersion The product version 73 | * @return string of the product directory name 74 | */ 75 | virtual std::string BuildProductDirectoryName(const std::string &productType, const std::string &productVersion); 76 | 77 | /** 78 | * @brief Build the product directory according to the Venus Muscate conventions 79 | * @param datetime Product datetime 80 | * @param productType Type of the product 81 | * @param productVersion Version of the product 82 | * @return string of the Venus-product directory 83 | */ 84 | std::string BuildFileNameVenus(const std::string &datetime, const std::string &productType, const std::string &productVersion); 85 | 86 | /** 87 | * @brief Copy raster files and create metadata-info for each 88 | * @param raster The raster input name 89 | * @param rasterTypes The type of raster file to be copied (See rasterTypes enum) 90 | * @param bIsMask True if it's a mask file, false if not 91 | * @note If copying fails, the metadata info is also not created 92 | * @return true, if both copying and metadata creating succeeded, false if not 93 | */ 94 | template 95 | bool copyRaster(typename ExtractorType::Pointer splitter, const size_t &index, 96 | const rasterTypes &rasterType, resolutionTypesVenus resolution, const bool &bIsMask); 97 | 98 | /** 99 | * @brief determines the BandGroups depending on which mission was chosen 100 | * @return BandList struct containing all available bands in the output product 101 | */ 102 | virtual std::vector getBandGroupList(const std::vector &missionBands); 103 | 104 | /** 105 | * @brief Generates the metadata file for the output product in Muscate Unified format 106 | * @param strProductMetadataFilePath The path where the metadata file shall be written to 107 | * @param cloudPercent The percentage of clouds in the image 108 | * @return void - Writes Metadata inside the product folder, named {}_MTD_ALL.xml 109 | */ 110 | virtual void generateMetadataFile(const std::string &strProductMetadataFilePath, const std::string &cloudPercent = "1", const std::string &snowPercent = "1"); 111 | 112 | }; 113 | } /* namespace ts */ 114 | 115 | 116 | #endif /* PRODUCTFORMATTER_INCLUDE_PRODUCTCREATORVENUSMUSCATE_H_ */ 117 | -------------------------------------------------------------------------------- /ProductFormatter/include/ProductDefinitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef PRODUCTFORMATTER_INCLUDE_PRODUCTDEFINITIONS_H_ 29 | #define PRODUCTFORMATTER_INCLUDE_PRODUCTDEFINITIONS_H_ 30 | 31 | #define DEFAULT_PRODUCT_VERSION "0-8" 32 | #define PRODUCT_DISTRIBUTION_FLAG "C" 33 | #define CLOUD_INDEX 1 34 | #define SNOW_INDEX 2 35 | #define S2_RESOLUTION_R1 10 36 | #define S2_RESOLUTION_R2 20 37 | 38 | /** 39 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 40 | */ 41 | namespace ts { 42 | 43 | typedef enum{ 44 | COMPOSITE_REFLECTANCE_RASTER, 45 | COMPOSITE_WEIGHTS_RASTER, 46 | COMPOSITE_FLAGS_MASK, 47 | COMPOSITE_DATES_MASK, 48 | }rasterTypes; 49 | 50 | /** 51 | * @brief Struct to store the current version number 52 | */ 53 | typedef struct{ 54 | size_t minor; 55 | size_t major; 56 | 57 | std::string toString(std::string delimiter = "-"){ 58 | return std::to_string(major) + delimiter + std::to_string(minor); 59 | } 60 | }versionType; 61 | 62 | /** 63 | * @brief Types of resolutions for Sentinel-2 64 | */ 65 | typedef enum{ 66 | S2_R1 = -2,//!< R1 67 | S2_R2 = -1,//!< R2 68 | S2_B2, //!< B2 69 | S2_B3, //!< B3 70 | S2_B4, //!< B4 71 | S2_B5, //!< B5 72 | S2_B6, //!< B6 73 | S2_B7, //!< B7 74 | S2_B8, //!< B8 75 | S2_B8A, //!< B8A 76 | S2_B11, //!< B11 77 | S2_B12, //!< B12 78 | }resolutionTypesS2; 79 | 80 | 81 | /** 82 | * @brief Types of resolutions for Venus 83 | */ 84 | typedef enum{ 85 | VNS_XS = -1,//!< XS 86 | VNS_B1, //!< B2 87 | VNS_B2, //!< B2 88 | VNS_B3, //!< B3 89 | VNS_B4, //!< B4 90 | VNS_B5, //!< B5 91 | VNS_B6, //!< B6 92 | VNS_B7, //!< B7 93 | VNS_B8, //!< B8 94 | VNS_B9, //!< B9 95 | VNS_B10, //!< B10 96 | VNS_B11, //!< B11 97 | VNS_B12, //!< B12 98 | }resolutionTypesVenus; 99 | 100 | /** 101 | * @brief Specifies the type of the mission that is found in the product 102 | */ 103 | typedef enum{ 104 | NoMission = 0,//!< NoMission 105 | S2A_Only, //!< S2A_Only 106 | S2B_Only, //!< S2B_Only 107 | S2_Only, //!< S2_Only 108 | L8_Only, 109 | Multisat, 110 | Venus, //!< Venus 111 | }missionTypes; 112 | 113 | 114 | ////////////////////////// 115 | /// CO-GeoTiff Config /// 116 | //////////////////////// 117 | 118 | #define GDAL_ADDO "gdaladdo" 119 | #define GDAL_TRANSLATE "gdal_translate" 120 | #define CoG_TRANSLATE_PREPARE "?&gdal:co:TILED=YES&gdal:co:COMPRESS=DEFLATE" 121 | 122 | /** 123 | * @brief Struct to store the Geotiff config for all rasters 124 | */ 125 | struct GeoTiffConfig_t{ 126 | std::string resamplingMethod; 127 | std::string filename; 128 | std::vector levels; 129 | std::string tiled; 130 | std::string compress; 131 | std::string copySrcOverviews; 132 | bool quiet; 133 | /** 134 | * @brief Init the struct to the default values according to the GeoTiff-Doc 135 | * @note Doc can be found under https://trac.osgeo.org/gdal/wiki/CloudOptimizedGeoTIFF#Performancetesting 136 | */ 137 | void initToDefaultValues(const std::string &f){ 138 | resamplingMethod = "average"; 139 | levels = {2,4,8,16,32}; 140 | filename = f; 141 | tiled = "YES"; 142 | compress = "DEFLATE"; 143 | copySrcOverviews = "YES"; 144 | } 145 | 146 | /** 147 | * @brief Create config to be used with gdaladdo 148 | * @return Vector containing string of current values 149 | */ 150 | std::vector toString(){ 151 | std::vector str {"-r", resamplingMethod, filename}; 152 | for(auto level : levels){ 153 | str.push_back(std::to_string(level)); 154 | } 155 | str.push_back("-q"); 156 | return str; 157 | } 158 | 159 | /** 160 | * @brief Return the config for gdal_translate 161 | * @return Vector containing the config strings 162 | */ 163 | std::vector getTranslateConfig(){ 164 | return {"-co", "TILED=" + tiled, "-co", "COPY_SRC_OVERVIEWS=" + copySrcOverviews, "-co", "COMPRESS=" + compress, "-a_nodata", NO_DATA_VALUE_STR, "-q"}; 165 | } 166 | }; 167 | 168 | } /* namespace ts */ 169 | 170 | #endif /* PRODUCTFORMATTER_INCLUDE_PRODUCTDEFINITIONS_H_ */ 171 | -------------------------------------------------------------------------------- /ProductFormatter/test/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CNES/WASP/88d3f649832e59ffb6227d1d7f1c004e9433594a/ProductFormatter/test/CMakeLists.txt -------------------------------------------------------------------------------- /PythonScripts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES WASP.py DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) 2 | 3 | add_test(NAME test_S2B_T31TGL_1_20180321 4 | COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_S2B_T31TGL_1_20180321.py 5 | WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} 6 | ) 7 | 8 | add_test(NAME test_VNS_FR-LUS_4_20180207 9 | COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_VNS_FR-LUS_4_20180207.py 10 | WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} 11 | ) 12 | 13 | add_test(NAME test_S2B_T31TCH_1_20171008 14 | COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_S2B_T31TCH_1_20171008.py 15 | WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} 16 | ) 17 | 18 | add_test(NAME test_S2A_T33UUU_8_20150727 19 | COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_S2A_T33UUU_8_20150727.py 20 | WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} 21 | ) 22 | 23 | set_tests_properties(test_S2A_T33UUU_8_20150727 PROPERTIES TIMEOUT 5000) 24 | 25 | add_test(NAME test_S2X_T31TCJ_11_20180511 26 | COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_S2X_T31TCJ_11_20180511.py 27 | WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} 28 | ) 29 | 30 | set_tests_properties(test_S2X_T31TCJ_11_20180511 PROPERTIES TIMEOUT 7000) 31 | -------------------------------------------------------------------------------- /PythonScripts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CNES/WASP/88d3f649832e59ffb6227d1d7f1c004e9433594a/PythonScripts/__init__.py -------------------------------------------------------------------------------- /PythonScripts/base_comparison.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 5 | All rights reserved 6 | 7 | This file is part of Weighted Average Synthesis Processor (WASP) 8 | 9 | Authors: 10 | - Peter KETTIG 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or (at 15 | your option) any later version. 16 | 17 | See the LICENSE.md file for more details. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | 27 | SPDX-License-Identifier: GPL-3.0-or-later 28 | """ 29 | 30 | import os 31 | import argparse 32 | 33 | 34 | class BaseComparison(): 35 | WASP_TEST_ENV_VAR = "WASP_TEST" 36 | 37 | @staticmethod 38 | def createArgs(in_path, out_path, date = None, synthalf = None): 39 | args = argparse.Namespace() 40 | args.input = in_path 41 | args.out = out_path 42 | args.verbose = "True" 43 | args.removeTemp = "True" 44 | args.tempout = None 45 | args.version = "1.0" 46 | args.synthalf = synthalf 47 | args.date = date 48 | args.cog = "False" 49 | args.pathprevL3A = None 50 | args.weightaotmin = None 51 | args.weightaotmax = None 52 | args.aotmax = None 53 | args.coarseres = None 54 | args.kernelwidth = None 55 | args.sigmasmallcld = None 56 | args.sigmalargecld = None 57 | args.weightdatemin = None 58 | args.scatteringcoeffpath = None 59 | args.logging = "" #Disable logging 60 | return args 61 | 62 | def setupEnvironment(self): 63 | try: 64 | self.wasp_test_path = os.environ[self.WASP_TEST_ENV_VAR] 65 | except: 66 | raise ValueError("Cannot find env-variable " + self.WASP_TEST_ENV_VAR) 67 | 68 | self.execPath = os.getcwd() 69 | return 70 | -------------------------------------------------------------------------------- /PythonScripts/test_S2A_T33UUU_8_20150727.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 5 | All rights reserved 6 | 7 | This file is part of Weighted Average Synthesis Processor (WASP) 8 | 9 | Authors: 10 | - Peter KETTIG 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or (at 15 | your option) any later version. 16 | 17 | See the LICENSE.md file for more details. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | 27 | SPDX-License-Identifier: GPL-3.0-or-later 28 | """ 29 | 30 | import unittest 31 | import os 32 | import WASP 33 | import CompareL3AProducts 34 | from base_comparison import BaseComparison 35 | 36 | class T33UUU_20150727(unittest.TestCase, BaseComparison): 37 | test_name = "test_S2A_T33UUU_8_20150727" 38 | out_path = os.path.join("SENTINEL2A_20150727-102256-960_L3A_T33UUU_C_V1-0", 39 | "SENTINEL2A_20150727-102256-960_L3A_T33UUU_C_V1-0_MTD_ALL.xml") 40 | inputs = [os.path.join("SENTINEL2A_20150627-102531-456_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150627-102531-456_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 41 | os.path.join("SENTINEL2A_20150704-101337-922_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150704-101337-922_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 42 | os.path.join("SENTINEL2A_20150724-101008-461_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150724-101008-461_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 43 | os.path.join("SENTINEL2A_20150806-102012-461_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150806-102012-461_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 44 | os.path.join("SENTINEL2A_20150813-101020-457_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150813-101020-457_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 45 | os.path.join("SENTINEL2A_20150816-102023-459_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150816-102023-459_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 46 | os.path.join("SENTINEL2A_20150823-101019-462_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150823-101019-462_L2A_T33UUU_D_V1-0_MTD_ALL.xml"), 47 | os.path.join("SENTINEL2A_20150826-102022-464_L2A_T33UUU_D_V1-0", "SENTINEL2A_20150826-102022-464_L2A_T33UUU_D_V1-0_MTD_ALL.xml")] 48 | 49 | def setUp(self): 50 | self.setupEnvironment() 51 | 52 | def test_run(self): 53 | input_path = [os.path.join(self.wasp_test_path, 54 | self.test_name, "INPUTS", i) for i in self.inputs] 55 | print('[%s]' % ', '.join(map(str, input_path))) 56 | for xml in input_path: 57 | if(not self.assertTrue(os.path.exists(xml))): 58 | print("Cannot find %s".format(xml)) 59 | out = self.execPath 60 | ts = WASP.TemporalSynthesis(self.createArgs(input_path, out)) 61 | ts.run() 62 | out_new = os.path.join(out, self.out_path) 63 | out_golden = os.path.join(self.wasp_test_path, self.test_name, 64 | self.out_path) 65 | self.assertTrue(os.path.exists(out_new)) 66 | self.assertTrue(os.path.exists(out_golden)) 67 | 68 | comparator = CompareL3AProducts.Comparator(out_golden, out_new) 69 | self.assertTrue(comparator.run()) 70 | return 71 | 72 | 73 | if __name__ == '__main__': 74 | unittest.main() 75 | -------------------------------------------------------------------------------- /PythonScripts/test_S2B_T31TCH_1_20171008.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 5 | All rights reserved 6 | 7 | This file is part of Weighted Average Synthesis Processor (WASP) 8 | 9 | Authors: 10 | - Peter KETTIG 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or (at 15 | your option) any later version. 16 | 17 | See the LICENSE.md file for more details. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | 27 | SPDX-License-Identifier: GPL-3.0-or-later 28 | """ 29 | 30 | import unittest 31 | import os 32 | import WASP 33 | import CompareL3AProducts 34 | from base_comparison import BaseComparison 35 | 36 | class T31TCH_20171008(unittest.TestCase, BaseComparison): 37 | test_name = "test_S2B_T31TCH_1_20171008" 38 | out_path = os.path.join("SENTINEL2B_20171008-105012-463_L3A_T31TCH_C_V1-0", 39 | "SENTINEL2B_20171008-105012-463_L3A_T31TCH_C_V1-0_MTD_ALL.xml") 40 | inputs = [os.path.join("SENTINEL2B_20171008-105012-463_L2A_T31TCH_C_V1-0", 41 | "SENTINEL2B_20171008-105012-463_L2A_T31TCH_C_V1-0_MTD_ALL.xml")] 42 | 43 | def setUp(self): 44 | self.setupEnvironment() 45 | 46 | def test_run(self): 47 | input_path = [os.path.join(self.wasp_test_path, 48 | self.test_name, "INPUTS", i) for i in self.inputs] 49 | print('[%s]' % ', '.join(map(str, input_path))) 50 | for xml in input_path: 51 | if(not self.assertTrue(os.path.exists(xml))): 52 | print("Cannot find %s".format(xml)) 53 | out = self.execPath 54 | ts = WASP.TemporalSynthesis(self.createArgs(input_path, out)) 55 | ts.run() 56 | out_new = os.path.join(out, self.out_path) 57 | out_golden = os.path.join(self.wasp_test_path, self.test_name, 58 | self.out_path) 59 | self.assertTrue(os.path.exists(out_new)) 60 | self.assertTrue(os.path.exists(out_golden)) 61 | 62 | comparator = CompareL3AProducts.Comparator(out_golden, out_new) 63 | self.assertTrue(comparator.run()) 64 | return 65 | 66 | 67 | if __name__ == '__main__': 68 | unittest.main() 69 | -------------------------------------------------------------------------------- /PythonScripts/test_S2B_T31TGL_1_20180321.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 5 | All rights reserved 6 | 7 | This file is part of Weighted Average Synthesis Processor (WASP) 8 | 9 | Authors: 10 | - Peter KETTIG 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or (at 15 | your option) any later version. 16 | 17 | See the LICENSE.md file for more details. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | 27 | SPDX-License-Identifier: GPL-3.0-or-later 28 | """ 29 | 30 | import unittest 31 | import os 32 | import WASP 33 | import CompareL3AProducts 34 | from base_comparison import BaseComparison 35 | 36 | class T31TGL_20180321(unittest.TestCase, BaseComparison): 37 | test_name = "test_S2B_T31TGL_1_20180321" 38 | out_path = os.path.join("SENTINEL2B_20180321-103345-708_L3A_T31TGL_C_V1-0", 39 | "SENTINEL2B_20180321-103345-708_L3A_T31TGL_C_V1-0_MTD_ALL.xml") 40 | inputs = [os.path.join("SENTINEL2B_20180321-103345-708_L2A_T31TGL_D_V1-6", 41 | "SENTINEL2B_20180321-103345-708_L2A_T31TGL_D_V1-6_MTD_ALL.xml")] 42 | 43 | def setUp(self): 44 | self.setupEnvironment() 45 | 46 | def test_run(self): 47 | input_path = [os.path.join(self.wasp_test_path, 48 | self.test_name, "INPUTS", i) for i in self.inputs] 49 | print('[%s]' % ', '.join(map(str, input_path))) 50 | for xml in input_path: 51 | if(not self.assertTrue(os.path.exists(xml))): 52 | print("Cannot find %s".format(xml)) 53 | out = self.execPath 54 | ts = WASP.TemporalSynthesis(self.createArgs(input_path, out)) 55 | ts.run() 56 | out_new = os.path.join(out, self.out_path) 57 | out_golden = os.path.join(self.wasp_test_path, self.test_name, 58 | self.out_path) 59 | self.assertTrue(os.path.exists(out_new)) 60 | self.assertTrue(os.path.exists(out_golden)) 61 | 62 | comparator = CompareL3AProducts.Comparator(out_golden, out_new) 63 | self.assertTrue(comparator.run()) 64 | return 65 | 66 | if __name__ == '__main__': 67 | unittest.main() 68 | -------------------------------------------------------------------------------- /PythonScripts/test_S2X_T31TCJ_11_20180511.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 5 | All rights reserved 6 | 7 | This file is part of Weighted Average Synthesis Processor (WASP) 8 | 9 | Authors: 10 | - Peter KETTIG 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or (at 15 | your option) any later version. 16 | 17 | See the LICENSE.md file for more details. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | 27 | SPDX-License-Identifier: GPL-3.0-or-later 28 | """ 29 | 30 | import unittest 31 | import os 32 | import WASP 33 | import CompareL3AProducts 34 | from base_comparison import BaseComparison 35 | 36 | class T31TCJ_11_20180511(unittest.TestCase, BaseComparison): 37 | test_name = "test_S2X_T31TCJ_11_20180511" 38 | out_path = os.path.join("SENTINEL2X_20180510-224307-416_L3A_T31TCJ_C_V1-0", 39 | "SENTINEL2X_20180510-224307-416_L3A_T31TCJ_C_V1-0_MTD_ALL.xml") 40 | inputs = [os.path.join("SENTINEL2A_20180418-104512-083_L2A_T31TCJ_D_V1-7", "SENTINEL2A_20180418-104512-083_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 41 | os.path.join("SENTINEL2A_20180421-105629-233_L2A_T31TCJ_D_V1-7", "SENTINEL2A_20180421-105629-233_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 42 | os.path.join("SENTINEL2A_20180424-110609-057_L2A_T31TCJ_D_V1-7", "SENTINEL2A_20180424-110609-057_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 43 | os.path.join("SENTINEL2A_20180511-105804-037_L2A_T31TCJ_D_V1-7", "SENTINEL2A_20180511-105804-037_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 44 | os.path.join("SENTINEL2A_20180521-105702-711_L2A_T31TCJ_D_V1-7", "SENTINEL2A_20180521-105702-711_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 45 | os.path.join("SENTINEL2B_20180419-110127-730_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180419-110127-730_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 46 | os.path.join("SENTINEL2B_20180423-104701-920_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180423-104701-920_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 47 | os.path.join("SENTINEL2B_20180426-105202-871_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180426-105202-871_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 48 | os.path.join("SENTINEL2B_20180506-105423-569_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180506-105423-569_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 49 | os.path.join("SENTINEL2B_20180519-110334-001_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180519-110334-001_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 50 | os.path.join("SENTINEL2B_20180523-104124-396_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180523-104124-396_L2A_T31TCJ_D_V1-7_MTD_ALL.xml"), 51 | os.path.join("SENTINEL2B_20180602-104102-749_L2A_T31TCJ_D_V1-7", "SENTINEL2B_20180602-104102-749_L2A_T31TCJ_D_V1-7_MTD_ALL.xml")] 52 | def setUp(self): 53 | self.setupEnvironment() 54 | 55 | def test_run(self): 56 | input_path = [os.path.join(self.wasp_test_path, 57 | self.test_name, "INPUTS", i) for i in self.inputs] 58 | for xml in input_path: 59 | try: 60 | self.assertTrue(os.path.exists(xml)) 61 | except AssertionError as e: 62 | print("Cannot find {0}".format(xml)) 63 | exit(1) 64 | out = self.execPath 65 | ts = WASP.TemporalSynthesis(self.createArgs(input_path, out)) 66 | ts.run() 67 | out_new = os.path.join(out, self.out_path) 68 | out_golden = os.path.join(self.wasp_test_path, self.test_name, 69 | self.out_path) 70 | self.assertTrue(os.path.exists(out_new)) 71 | self.assertTrue(os.path.exists(out_golden)) 72 | 73 | comparator = CompareL3AProducts.Comparator(out_golden, out_new) 74 | self.assertTrue(comparator.run()) 75 | return 76 | 77 | 78 | if __name__ == '__main__': 79 | unittest.main() 80 | -------------------------------------------------------------------------------- /PythonScripts/test_VNS_FR-LUS_4_20180207.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 5 | All rights reserved 6 | 7 | This file is part of Weighted Average Synthesis Processor (WASP) 8 | 9 | Authors: 10 | - Peter KETTIG 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or (at 15 | your option) any later version. 16 | 17 | See the LICENSE.md file for more details. 18 | 19 | This program is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | 27 | SPDX-License-Identifier: GPL-3.0-or-later 28 | """ 29 | 30 | import unittest 31 | import os 32 | import WASP 33 | import CompareL3AProducts 34 | from base_comparison import BaseComparison 35 | 36 | class FR_LUS_20180315(unittest.TestCase, BaseComparison): 37 | test_name = "test_VNS_FR-LUS_4_20180207" 38 | out_path = os.path.join("VENUS-XS_20180207-000000-000_L3A_FR-LUS_C_V1-0", 39 | "VENUS-XS_20180207-000000-000_L3A_FR-LUS_C_V1-0_MTD_ALL.xml") 40 | inputs = [os.path.join("VENUS-XS_20180212-105550-000_L2A_FR-LUS_C_V1-0","VENUS-XS_20180212-105550-000_L2A_FR-LUS_C_V1-0_MTD_ALL.xml"), 41 | os.path.join("VENUS-XS_20180210-105551-000_L2A_FR-LUS_C_V1-0","VENUS-XS_20180210-105551-000_L2A_FR-LUS_C_V1-0_MTD_ALL.xml"), 42 | os.path.join("VENUS-XS_20180208-105552-000_L2A_FR-LUS_C_V1-0","VENUS-XS_20180208-105552-000_L2A_FR-LUS_C_V1-0_MTD_ALL.xml"), 43 | os.path.join("VENUS-XS_20180202-105554-000_L2A_FR-LUS_C_V1-0","VENUS-XS_20180202-105554-000_L2A_FR-LUS_C_V1-0_MTD_ALL.xml")] 44 | 45 | def setUp(self): 46 | self.setupEnvironment() 47 | 48 | def test_run(self): 49 | input_path = [os.path.join(self.wasp_test_path, 50 | self.test_name, "INPUTS", i) for i in self.inputs] 51 | print('[%s]' % ', '.join(map(str, input_path))) 52 | for xml in input_path: 53 | if(not self.assertTrue(os.path.exists(xml))): 54 | print("Cannot find %s".format(xml)) 55 | out = self.execPath 56 | date = "20180207" 57 | synthalf = 5 58 | ts = WASP.TemporalSynthesis(self.createArgs(input_path, out, date, synthalf)) 59 | ts.run() 60 | out_new = os.path.join(out, self.out_path) 61 | out_golden = os.path.join(self.wasp_test_path, self.test_name, 62 | self.out_path) 63 | self.assertTrue(os.path.exists(out_new)) 64 | self.assertTrue(os.path.exists(out_golden)) 65 | 66 | comparator = CompareL3AProducts.Comparator(out_golden, out_new) 67 | self.assertTrue(comparator.run()) 68 | return 69 | 70 | 71 | if __name__ == '__main__': 72 | unittest.main() 73 | -------------------------------------------------------------------------------- /Scripts/WASP: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) CNES - All Rights Reserved 3 | # This file is subject to the terms and conditions defined in 4 | # file 'LICENSE.md', which is part of this source code package. 5 | # 6 | # Author: Peter KETTIG 7 | # Project: Weighted Average Synthesis Processor (WASP) 8 | # Filename: WASP 9 | # Created on: 4 Sep 2018 10 | 11 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 12 | 13 | # Throw error when sourced (This would delete the PYTHON-variables): 14 | if [[ ${BASH_SOURCE[0]} != $0 ]]; then 15 | printf "ERROR: Script %s must not run sourced\n" "${BASH_SOURCE[0]}" 16 | return 1 17 | fi 18 | 19 | # Unset Environment variables if necessary: 20 | if [[ ! -z "${PYTHONPATH}" ]]; then 21 | unset PYTHONPATH 22 | fi 23 | 24 | if [[ ! -z "${PYTHONHOME}" ]]; then 25 | unset PYTHONHOME 26 | fi 27 | 28 | # Check availability: 29 | if [ ! -f $DIR/python3 ] || [ ! -f $DIR/WASP.py ]; then 30 | echo "Cannot find WASP executable."; return 1 31 | fi 32 | 33 | # Forward all other arguments: 34 | $DIR/python3 $DIR/WASP.py $@ 35 | -------------------------------------------------------------------------------- /UpdateSynthesis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | otb_create_application( 2 | NAME UpdateSynthesis 3 | SOURCES include/UpdateSynthesisFunctor.h src/UpdateSynthesisFunctor.txx src/UpdateSynthesis.cpp 4 | LINK_LIBRARIES MuscateMetadata MetadataHelper ${OTB_LIBRARIES}) 5 | 6 | if(BUILD_TESTING) 7 | add_subdirectory(test) 8 | endif() 9 | 10 | target_include_directories(otbapp_UpdateSynthesis PUBLIC include) 11 | install(TARGETS otbapp_UpdateSynthesis DESTINATION lib/otb/applications/) 12 | -------------------------------------------------------------------------------- /UpdateSynthesis/include/BandsDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef BANDSDEFS_H 27 | #define BANDSDEFS_H 28 | 29 | #define S2_L2A_10M_BANDS_NO 4 30 | 31 | #define WEIGHTED_REFLECTANCE_10M_BANDS_NO S2_L2A_10M_BANDS_NO 32 | 33 | //S2 10m Bands defines 34 | #define S2_L2A_10M_BLUE_BAND_IDX 0 35 | #define S2_L2A_10M_RED_BAND_IDX 2 36 | 37 | // 20M Positions Definition 38 | #define S2_L2A_20M_BANDS_NO 6 39 | #define WEIGHTED_REFLECTANCE_20M_BANDS_NO S2_L2A_20M_BANDS_NO 40 | 41 | //S2 20m Bands defines 42 | #define S2_L2A_20M_BLUE_BAND_IDX -1 43 | #define S2_L2A_10M_BLUE_BAND_NAME "FRE_B2" 44 | #define S2_L2A_20M_RED_BAND_IDX -1 45 | 46 | // These defines are for the case when all the bands of 10 AND 20m are resampled at the specified resolution 47 | // and are all present 48 | 49 | #define S2_L2A_ALL_BANDS_NO 10 50 | #define WEIGHTED_REFLECTANCE_ALL_BANDS_NO S2_L2A_ALL_BANDS_NO 51 | 52 | #endif // BANDSDEFS_H 53 | 54 | -------------------------------------------------------------------------------- /UpdateSynthesis/test/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CNES/WASP/88d3f649832e59ffb6227d1d7f1c004e9433594a/UpdateSynthesis/test/CMakeLists.txt -------------------------------------------------------------------------------- /WeightCalculation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(TotalWeight) 2 | add_subdirectory(WeightAOT) 3 | add_subdirectory(WeightOnClouds) 4 | 5 | -------------------------------------------------------------------------------- /WeightCalculation/TotalWeight/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | otb_create_application( 2 | NAME TotalWeight 3 | SOURCES src/TotalWeight.cpp src/TotalWeightComputation.cpp 4 | LINK_LIBRARIES MuscateMetadata MetadataHelper ${OTB_LIBRARIES}) 5 | 6 | target_include_directories(otbapp_TotalWeight PUBLIC include) 7 | install(TARGETS otbapp_TotalWeight DESTINATION lib/otb/applications/) 8 | 9 | if(BUILD_TESTING) 10 | add_subdirectory(test) 11 | endif() -------------------------------------------------------------------------------- /WeightCalculation/TotalWeight/include/TotalWeightComputation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef TOTALWEIGHTCOMPUTATION_H 27 | #define TOTALWEIGHTCOMPUTATION_H 28 | 29 | #include "otbWrapperTypes.h" 30 | #include "itkBinaryFunctorImageFilter.h" 31 | #include "otbImageFileReader.h" 32 | #include "otbImageFileWriter.h" 33 | #include "GlobalDefs.h" 34 | #include "ImageResampler.h" 35 | 36 | /** 37 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 38 | */ 39 | namespace ts 40 | { 41 | /** 42 | * @brief Namespace around Functors to be used in the filters defined below 43 | */ 44 | namespace Functor 45 | { 46 | 47 | /** 48 | * @brief Functor to calculate the TotalWeight 49 | */ 50 | template< class TPixel> 51 | class TotalWeightCalculationFunctor 52 | { 53 | public: 54 | TotalWeightCalculationFunctor() {} 55 | ~TotalWeightCalculationFunctor() {} 56 | bool operator!=(const TotalWeightCalculationFunctor &) const 57 | { 58 | return false; 59 | } 60 | 61 | bool operator==(const TotalWeightCalculationFunctor & other) const 62 | { 63 | return !( *this != other ); 64 | } 65 | 66 | void SetFixedWeight(float weightSensor, float weightDate) 67 | { 68 | m_fixedWeight = weightSensor * weightDate; 69 | } 70 | 71 | inline TPixel operator()(const TPixel & A, 72 | const TPixel & B) const 73 | { 74 | const float dA = static_cast< float >( A ); 75 | const float dB = static_cast< float >( B ); 76 | if(dA < 0 || dB < 0) { 77 | return WEIGHT_NO_DATA_VALUE; 78 | } 79 | const float totalWeight = fabs(dA * dB * m_fixedWeight); 80 | 81 | return static_cast< TPixel >( totalWeight ); 82 | } 83 | private: 84 | float m_fixedWeight; 85 | }; 86 | 87 | }//namespace Functor 88 | 89 | class TotalWeightComputation 90 | { 91 | public: 92 | typedef otb::Wrapper::FloatImageType ImageType; 93 | typedef enum {S2, VNS, UNKNOWN} SensorType; 94 | typedef itk::BinaryFunctorImageFilter< ImageType, ImageType, ImageType, 95 | Functor::TotalWeightCalculationFunctor > FilterType; 96 | typedef otb::ImageFileReader ReaderType; 97 | typedef otb::ImageFileWriter WriterType; 98 | 99 | typedef itk::ImageSource ImageSource; 100 | typedef FilterType::Superclass::Superclass OutImageSource; 101 | 102 | public: 103 | TotalWeightComputation(); 104 | 105 | void SetMissionName(std::string &missionName); 106 | void SetDates(std::string &L2ADate, std::string &L3ADate); 107 | void SetHalfSynthesisPeriodAsDays(int deltaMax); 108 | void SetWeightOnDateMin(float fMinWeight); 109 | void SetAotWeightFile(std::string &aotWeightFileName); 110 | void SetCloudsWeightFile(std::string &cloudsWeightFileName); 111 | void SetTotalWeightOutputFileName(std::string &outFileName); 112 | 113 | const char *GetNameOfClass() { return "TotalWeightComputation";} 114 | OutImageSource::Pointer GetOutputImageSource(); 115 | 116 | void WriteToOutputFile(); 117 | 118 | protected: 119 | void ComputeTotalWeight(); 120 | void ComputeWeightOnSensor(); 121 | void ComputeWeightOnDate(); 122 | 123 | protected: 124 | float m_fWeightOnSensor; 125 | float m_fWeightOnDate; 126 | int m_res; 127 | 128 | private: 129 | void BuildOutputImageSource(); 130 | 131 | SensorType m_sensorType; 132 | int m_nDaysTimeInterval; 133 | int m_nDeltaMax; 134 | float m_fWeightOnDateMin; 135 | std::string m_strOutFileName; 136 | 137 | ImageSource::Pointer m_inputReaderAot; 138 | ImageSource::Pointer m_inputReaderCld; 139 | 140 | FilterType::Pointer m_filter; 141 | ImageResampler m_AotResampler; 142 | void CheckTolerance(); 143 | }; 144 | }//namespace ts 145 | 146 | #endif // TOTALWEIGHTCOMPUTATION_H 147 | -------------------------------------------------------------------------------- /WeightCalculation/TotalWeight/test/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CNES/WASP/88d3f649832e59ffb6227d1d7f1c004e9433594a/WeightCalculation/TotalWeight/test/CMakeLists.txt -------------------------------------------------------------------------------- /WeightCalculation/WeightAOT/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | otb_create_application( 2 | NAME WeightAOT 3 | SOURCES src/WeightAOT.cpp src/WeightAOTComputation.cpp 4 | LINK_LIBRARIES MuscateMetadata MetadataHelper ${OTB_LIBRARIES}) 5 | 6 | target_include_directories(otbapp_WeightAOT PUBLIC include) 7 | install(TARGETS otbapp_WeightAOT DESTINATION lib/otb/applications/) 8 | 9 | if(BUILD_TESTING) 10 | add_subdirectory(test) 11 | endif() -------------------------------------------------------------------------------- /WeightCalculation/WeightAOT/include/WeightAOTComputation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #ifndef WEIGHTONAOT_H 27 | #define WEIGHTONAOT_H 28 | 29 | #include "otbWrapperTypes.h" 30 | #include "otbImageFileReader.h" 31 | #include "otbImageFileWriter.h" 32 | #include "itkImageSource.h" 33 | #include "otbObjectList.h" 34 | #include "itkUnaryFunctorImageFilter.h" 35 | 36 | /** 37 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 38 | */ 39 | namespace ts 40 | { 41 | /** 42 | * @brief Namespace around Functors to be used in the filters defined below 43 | */ 44 | namespace Functor 45 | { 46 | 47 | /** 48 | * @brief Functor to calculate the AOT-weight 49 | */ 50 | template< class TInput, class TOutput> 51 | class AotWeightCalculationFunctor 52 | { 53 | public: 54 | AotWeightCalculationFunctor() {} 55 | ~AotWeightCalculationFunctor() {} 56 | bool operator!=( const AotWeightCalculationFunctor & ) const 57 | { 58 | return false; 59 | } 60 | bool operator==( const AotWeightCalculationFunctor & other ) const 61 | { 62 | return !(*this != other); 63 | } 64 | void Initialize(int nBand, float fQuantif, float fAotMax, float fMinWeight, float fMaxWeight) { 65 | m_nBand = nBand; 66 | m_fAotQuantificationVal = fQuantif; 67 | m_fAotMax = fAotMax; 68 | m_fMinWeightAot = fMinWeight; 69 | m_fMaxWeightAot = fMaxWeight; 70 | } 71 | 72 | inline TOutput operator()( const TInput & A ) const 73 | { 74 | float val = static_cast< float >( A[m_nBand] )/m_fAotQuantificationVal; 75 | if(val < 0) { 76 | return 0; 77 | } 78 | 79 | float fRetAOT; 80 | if(val < m_fAotMax) { 81 | fRetAOT = m_fMinWeightAot + (m_fMaxWeightAot - m_fMinWeightAot) * (1.0 - val/m_fAotMax); 82 | } else { 83 | fRetAOT = m_fMinWeightAot; 84 | } 85 | 86 | return fRetAOT; 87 | } 88 | 89 | private: 90 | int m_nBand; 91 | float m_fAotQuantificationVal; 92 | float m_fAotMax; 93 | float m_fMinWeightAot; 94 | float m_fMaxWeightAot; 95 | }; 96 | } //namespace Functor 97 | 98 | class WeightOnAOT 99 | { 100 | public: 101 | typedef otb::Wrapper::FloatVectorImageType ImageType; 102 | typedef otb::Wrapper::FloatImageType OutImageType; 103 | 104 | typedef itk::ImageSource ImageSource; 105 | 106 | typedef otb::ImageFileReader ReaderType; 107 | typedef otb::ImageFileWriter WriterType; 108 | 109 | typedef itk::UnaryFunctorImageFilter > FilterType; 113 | typedef FilterType::Superclass::Superclass::Superclass OutImageSource; 114 | 115 | public: 116 | WeightOnAOT(); 117 | 118 | void SetInputFileName(std::string &inputImageStr); 119 | void SetInputImageReader(ImageSource::Pointer inputReader); 120 | void SetOutputFileName(std::string &outFile); 121 | 122 | void Initialize(int nBand, float fQuantif, float fAotMax, float fMinWeight, float fMaxWeight); 123 | 124 | const char *GetNameOfClass() { return "WeightOnAOT";} 125 | OutImageSource::Pointer GetOutputImageSource(); 126 | int GetInputImageResolution(); 127 | 128 | void WriteToOutputFile(); 129 | 130 | private: 131 | void BuildOutputImageSource(); 132 | ImageSource::Pointer m_inputReader; 133 | std::string m_outputFileName; 134 | 135 | int m_nBand; 136 | float m_fAotQuantificationVal; 137 | float m_fAotMax; 138 | float m_fMinWeightAot; 139 | float m_fMaxWeightAot; 140 | 141 | FilterType::Pointer m_filter; 142 | }; 143 | 144 | } //namespace ts 145 | #endif // WEIGHTONAOT_H 146 | -------------------------------------------------------------------------------- /WeightCalculation/WeightAOT/src/WeightAOT.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "otbWrapperApplication.h" 27 | #include "otbWrapperApplicationFactory.h" 28 | 29 | #include "WeightAOTComputation.h" 30 | #include "MetadataHelperFactory.h" 31 | 32 | /** 33 | * @brief otb Namespace for all OTB-related Filters and Applications 34 | */ 35 | namespace otb 36 | { 37 | /** 38 | * @brief Wrapper namespace for all OTB-Applications 39 | */ 40 | namespace Wrapper 41 | { 42 | 43 | /** 44 | * @brief Calculate the AOT-weight from a given AOT-mask 45 | */ 46 | class WeightAOT : public Application 47 | { 48 | 49 | public: 50 | /** Standard class typedefs. */ 51 | typedef WeightAOT Self; 52 | typedef Application Superclass; 53 | typedef itk::SmartPointer Pointer; 54 | typedef itk::SmartPointer ConstPointer; 55 | 56 | /** Standard macro */ 57 | itkNewMacro(Self); 58 | 59 | itkTypeMacro(WeightAOT, otb::Application); 60 | 61 | private: 62 | void DoInit() 63 | { 64 | SetName("WeightAOT"); 65 | SetDescription("Calculate the AOT-weight from a given AOT-mask"); 66 | 67 | SetDocName("WeightAOT"); 68 | SetDocLongDescription("Calculate the AOT-weight from a given AOT-mask"); 69 | SetDocLimitations("None"); 70 | SetDocAuthors("Peter Kettig"); 71 | SetDocSeeAlso(" "); 72 | 73 | AddParameter(ParameterType_String, "in", "Input image"); 74 | SetParameterDescription("in", "Image containing AOT."); 75 | 76 | AddParameter(ParameterType_String, "xml", "XML metadata file"); 77 | SetParameterDescription("xml", "XML metadata file for the product."); 78 | 79 | AddParameter(ParameterType_OutputImage, "out", "Output Image"); 80 | SetParameterDescription("out","Output image."); 81 | 82 | AddParameter(ParameterType_Float, "waotmin", "WeightAOTMin"); 83 | SetParameterDescription("waotmin", "min weight depending on AOT"); 84 | 85 | AddParameter(ParameterType_Float, "waotmax", "WeightAOTMax"); 86 | SetParameterDescription("waotmax", "max weight depending on AOT"); 87 | 88 | AddParameter(ParameterType_Float, "aotmax", "AOTMax"); 89 | SetParameterDescription("aotmax", "maximum value of the linear range for weights w.r.t AOT"); 90 | 91 | AddRAMParameter(); 92 | 93 | // Doc example parameter settings 94 | SetDocExampleParameterValue("in", "verySmallFSATSW_r.tif"); 95 | SetDocExampleParameterValue("xml", "metadata.xml"); 96 | SetDocExampleParameterValue("waotmin", "0.33"); 97 | SetDocExampleParameterValue("waotmax", "1"); 98 | SetDocExampleParameterValue("aotmax", "50"); 99 | SetDocExampleParameterValue("out", "apAOTWeightOutput.tif"); 100 | } 101 | 102 | void DoUpdateParameters() 103 | { 104 | } 105 | 106 | void DoExecute() 107 | { 108 | // Get the input image list 109 | std::string inImgStr = GetParameterString("in"); 110 | if (inImgStr.empty()) 111 | { 112 | itkExceptionMacro("No input Image set...; please set the input image"); 113 | } 114 | 115 | std::string inMetadataXml = GetParameterString("xml"); 116 | if (inMetadataXml.empty()) 117 | { 118 | itkExceptionMacro("No input metadata XML set...; please set the input image"); 119 | } 120 | 121 | float fAotMax = GetParameterFloat("aotmax"); 122 | float fWaotMin = GetParameterFloat("waotmin"); 123 | float fWaotMax = GetParameterFloat("waotmax"); 124 | 125 | m_weightOnAot.SetInputFileName(inImgStr); 126 | auto factory = ts::MetadataHelperFactory::New(); 127 | auto pHelper = factory->GetMetadataHelper(inMetadataXml); 128 | float fAotQuantificationVal = pHelper->GetAotQuantificationValue(); 129 | // the bands in XML are 1 based 130 | int nBand = 0;//pHelper->GetAotBandIndex()-1; 131 | std::cout << "fAotQuantificationVal " << fAotQuantificationVal << std::endl; 132 | m_weightOnAot.Initialize(nBand, fAotQuantificationVal, fAotMax, fWaotMin, fWaotMax); 133 | 134 | // Set the output image 135 | SetParameterOutputImage("out", m_weightOnAot.GetOutputImageSource()->GetOutput()); 136 | } 137 | 138 | ts::WeightOnAOT m_weightOnAot; 139 | }; 140 | 141 | } // namespace Wrapper 142 | } // namespace otb 143 | 144 | OTB_APPLICATION_EXPORT(otb::Wrapper::WeightAOT) 145 | 146 | -------------------------------------------------------------------------------- /WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016, CS Romania 3 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 4 | * All rights reversed 5 | * 6 | * This file is part of: 7 | * - Sen2agri-Processors (initial work) 8 | * - Weighted Average Synthesis Processor (WASP) 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | * SPDX-License-Identifier: GPL-3.0-or-later 24 | */ 25 | 26 | #include "WeightAOTComputation.h" 27 | 28 | using namespace ts; 29 | 30 | WeightOnAOT::WeightOnAOT() 31 | { 32 | } 33 | 34 | void WeightOnAOT::SetInputFileName(std::string &inputImageStr) 35 | { 36 | if (inputImageStr.empty()) 37 | { 38 | std::cout << "No input Image set...; please set the input image!" << std::endl; 39 | itkExceptionMacro("No input Image set...; please set the input image"); 40 | } 41 | // Read the image 42 | ReaderType::Pointer reader = ReaderType::New(); 43 | reader->SetFileName(inputImageStr); 44 | try 45 | { 46 | //reader->Update(); 47 | //m_image = reader->GetOutput(); 48 | m_inputReader = reader; 49 | } 50 | catch (itk::ExceptionObject& err) 51 | { 52 | std::cout << "ExceptionObject caught !" << std::endl; 53 | std::cout << err << std::endl; 54 | itkExceptionMacro("Error reading input"); 55 | } 56 | } 57 | 58 | void WeightOnAOT::SetInputImageReader(ImageSource::Pointer inputReader) 59 | { 60 | if (inputReader.IsNull()) 61 | { 62 | std::cout << "No input Image set...; please set the input image!" << std::endl; 63 | itkExceptionMacro("No input Image set...; please set the input image"); 64 | } 65 | m_inputReader = inputReader; 66 | } 67 | 68 | void WeightOnAOT::SetOutputFileName(std::string &outFile) 69 | { 70 | m_outputFileName = outFile; 71 | } 72 | 73 | void WeightOnAOT::Initialize(int nBand, float fQuantif, float fAotMax, float fMinWeight, float fMaxWeight) { 74 | m_nBand = nBand; 75 | m_fAotQuantificationVal = fQuantif; 76 | m_fAotMax = fAotMax; 77 | m_fMinWeightAot = fMinWeight; 78 | m_fMaxWeightAot = fMaxWeight; 79 | } 80 | 81 | WeightOnAOT::OutImageSource::Pointer WeightOnAOT::GetOutputImageSource() 82 | { 83 | BuildOutputImageSource(); 84 | return (OutImageSource::Pointer)m_filter; 85 | } 86 | 87 | int WeightOnAOT::GetInputImageResolution() 88 | { 89 | m_inputReader->UpdateOutputInformation(); 90 | ImageType::Pointer inputImage = m_inputReader->GetOutput(); 91 | return inputImage->GetSpacing()[0]; 92 | } 93 | 94 | 95 | void WeightOnAOT::BuildOutputImageSource() 96 | { 97 | m_inputReader->UpdateOutputInformation(); 98 | int nBands = m_inputReader->GetOutput()->GetNumberOfComponentsPerPixel(); 99 | if(m_nBand >= nBands) { 100 | itkExceptionMacro("Invalid band number " << m_nBand << ". It should be less than " << nBands); 101 | } 102 | m_filter = FilterType::New(); 103 | m_filter->GetFunctor().Initialize(m_nBand, m_fAotQuantificationVal, 104 | m_fAotMax, m_fMinWeightAot, m_fMaxWeightAot); 105 | m_filter->SetInput(m_inputReader->GetOutput()); 106 | } 107 | 108 | void WeightOnAOT::WriteToOutputFile() 109 | { 110 | if(!m_outputFileName.empty()) 111 | { 112 | if(!m_outputFileName.empty()) 113 | { 114 | WriterType::Pointer writer; 115 | writer = WriterType::New(); 116 | writer->SetFileName(m_outputFileName); 117 | writer->SetInput(GetOutputImageSource()->GetOutput()); 118 | try 119 | { 120 | writer->Update(); 121 | } 122 | catch (itk::ExceptionObject& err) 123 | { 124 | std::cout << "ExceptionObject caught !" << std::endl; 125 | std::cout << err << std::endl; 126 | itkExceptionMacro("Error writing output"); 127 | } 128 | } 129 | } 130 | } 131 | 132 | 133 | -------------------------------------------------------------------------------- /WeightCalculation/WeightAOT/test/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CNES/WASP/88d3f649832e59ffb6227d1d7f1c004e9433594a/WeightCalculation/WeightAOT/test/CMakeLists.txt -------------------------------------------------------------------------------- /WeightCalculation/WeightOnClouds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(WeightOnCloud_HEADERS 2 | include/CloudMaskBinarization.h 3 | include/CloudsInterpolation.h 4 | include/CloudWeightComputation.h 5 | include/CuttingImageFilter.h 6 | include/GaussianFilter.h 7 | include/PaddingImageHandler.h 8 | include/ROIImageFilter.h 9 | ) 10 | 11 | otb_create_application( 12 | NAME WeightOnClouds 13 | SOURCES ${WeightOnCloud_HEADERS} 14 | src/WeightOnClouds.cpp 15 | LINK_LIBRARIES MuscateMetadata MetadataHelper ${OTB_LIBRARIES}) 16 | 17 | target_include_directories(otbapp_WeightOnClouds PUBLIC include) 18 | install(TARGETS otbapp_WeightOnClouds DESTINATION lib/otb/applications/) 19 | 20 | if(BUILD_TESTING) 21 | add_subdirectory(test) 22 | endif() -------------------------------------------------------------------------------- /WeightCalculation/WeightOnClouds/include/ROIImageFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) 3 | * All rights reserved 4 | * 5 | * This file is part of Weighted Average Synthesis Processor (WASP) 6 | * 7 | * Authors: 8 | * - Peter KETTIG 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * See the LICENSE.md file for more details. 16 | * 17 | * This program is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | * SPDX-License-Identifier: GPL-3.0-or-later 26 | */ 27 | 28 | #ifndef ROIIMAGEHANDLER_H 29 | #define ROIIMAGEHANDLER_H 30 | 31 | #include "otbVectorImage.h" 32 | #include "otbWrapperTypes.h" 33 | 34 | //Transform 35 | #include "otbImageFileWriter.h" 36 | #include "otbExtractROI.h" 37 | #include "itkCropImageFilter.h" 38 | #include "ImageResampler.h" 39 | 40 | /** 41 | * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain 42 | */ 43 | namespace ts 44 | { 45 | 46 | /** 47 | * @brief Crop an image from a given ROI 48 | */ 49 | template 50 | class ROIImageHandler 51 | { 52 | public: 53 | 54 | typedef otb::ImageFileWriter WriterType; 55 | typedef itk::ImageSource ImageSource; 56 | //typedef itk::ImageSource ResampledImageSource; 57 | typedef itk::CropImageFilter ROIFilterType; 58 | typedef itk::ImageSource OutImageSource; 59 | 60 | public: 61 | ROIImageHandler() { 62 | m_outForcedWidth = -1; 63 | m_outForcedHeight = -1; 64 | } 65 | 66 | void SetOutputFileName(std::string &outFile) { 67 | m_outputFileName = outFile; 68 | } 69 | 70 | void SetInputImageReader(typename ImageSource::Pointer inputImgReader, int width, int height) { 71 | if (inputImgReader.IsNull()) 72 | { 73 | std::cout << "No input Image set...; please set the input image!" << std::endl; 74 | itkExceptionMacro("No input Image set...; please set the input image"); 75 | } 76 | m_inputImgReader = inputImgReader; 77 | m_outForcedWidth = width; 78 | m_outForcedHeight = height; 79 | } 80 | 81 | const char *GetNameOfClass() { return "CuttingImageHandler";} 82 | 83 | typename OutImageSource::Pointer GetOutputImageSource() { 84 | BuildOutputImage(); 85 | if(m_extractor.IsNull()) { 86 | return m_inputImgReader; 87 | } 88 | 89 | return (typename OutImageSource::Pointer)m_extractor; 90 | } 91 | 92 | void WriteToOutputFile() { 93 | if(!m_outputFileName.empty()) 94 | { 95 | //Empty for now 96 | } 97 | } 98 | 99 | void BuildOutputImageAndUpdate() { 100 | BuildOutputImage(); 101 | m_extractor->Update(); 102 | } 103 | 104 | private: 105 | void BuildOutputImage() { 106 | m_inputImgReader->UpdateOutputInformation(); 107 | 108 | int width = m_inputImgReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]; 109 | int height = m_inputImgReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; 110 | int fMinWidth = width; 111 | int fMinHeight = height; 112 | if(m_outForcedWidth > 0 && width >= m_outForcedWidth) { 113 | fMinWidth = m_outForcedWidth; 114 | } 115 | if(m_outForcedHeight > 0 && height >= m_outForcedHeight) { 116 | fMinHeight = m_outForcedHeight; 117 | } 118 | std::cout << "---------ROIImageFilter---------" << std::endl; 119 | std::cout << "width: " << width << " height: " << height << std::endl; 120 | std::cout << "fMinWidth: " << fMinWidth << " fMinHeight: " << fMinHeight << std::endl; 121 | std::cout << "m_outForcedWidth: " << m_outForcedWidth << " m_outForcedHeight: " << m_outForcedHeight << std::endl; 122 | 123 | m_extractor = ROIFilterType::New(); 124 | m_extractor->SetInput( m_inputImgReader->GetOutput() ); 125 | typename TInput2::SizeType size; 126 | size[0] = int((width - m_outForcedWidth) /2); 127 | size[1] = int((height - m_outForcedHeight) /2); 128 | m_extractor->SetBoundaryCropSize(size); 129 | std::cout << "CropSize: " << size[0] << " : " << size[1] << std::endl; 130 | m_extractor->UpdateOutputInformation(); 131 | 132 | float widthNew = m_extractor->GetOutput()->GetLargestPossibleRegion().GetSize()[0]; 133 | float heightNew = m_extractor->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; 134 | std::cout << "widthNew: " << widthNew << " heightNew: " << heightNew << std::endl; 135 | std::cout << "---------ROIImageFilter---------" << std::endl; 136 | } 137 | 138 | typename ImageSource::Pointer m_inputImgReader; 139 | typename ROIFilterType::Pointer m_extractor; 140 | std::string m_outputFileName; 141 | // during resampling at higher resolutions it might be needed to return with a specified dimension 142 | int m_outForcedWidth; 143 | int m_outForcedHeight; 144 | }; 145 | } //namespace ts; 146 | #endif // ROIIMAGEHANDLER_H 147 | -------------------------------------------------------------------------------- /WeightCalculation/WeightOnClouds/test/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CNES/WASP/88d3f649832e59ffb6227d1d7f1c004e9433594a/WeightCalculation/WeightOnClouds/test/CMakeLists.txt --------------------------------------------------------------------------------