Commit cb21d58d authored by Peter Kettig's avatar Peter Kettig
Browse files

Initial commit of WASP v1.0

parent 280fa141
project(NewTemporalSynthesis)
cmake_minimum_required(VERSION 2.8)
include(CTest)
find_package(OTB REQUIRED)
find_program(BASH_Program bash)
include(${OTB_USE_FILE})
include(FindPythonInterp)
# Set a default build type if none was specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wno-missing-field-initializers")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
find_package(Boost REQUIRED COMPONENTS unit_test_framework filesystem)
add_definitions(-DBOOST_TEST_DYN_LINK)
message("Project binary folder:" ${PROJECT_BINARY_DIR})
add_definitions(-DVCL_CAN_STATIC_CONST_INIT_FLOAT=0)
add_subdirectory(Common)
add_subdirectory(MuscateMetadata)
add_subdirectory(CompositePreprocessing)
add_subdirectory(WeightCalculation)
add_subdirectory(UpdateSynthesis)
add_subdirectory(ProductFormatter)
add_subdirectory(PythonScripts)
install(FILES ./Scripts/WASP PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
# first we can indicate the documentation build as an option and set it to ON by default
option(BUILD_DOC "Build documentation" ON)
# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
message("Installing WASP to: " ${CMAKE_INSTALL_PREFIX})
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Weighted Average Synthesis Processor (WASP)
Upstream-Contact: CNES <peter.kettig@cnes.fr>, CESBIO <olivier.hagolle@cnes.fr>
Files: *
Copyright: <2018-2019> Centre national d'études spatiales (CNES), France
Comment: WASP project, initialy named TemporalSynthesis, for MUSCATE/THEIA
License: GPL-3+
Files: Common/include/GlobalDefs.h
Common/include/ImageResampler.h
Common/include/MetadataAngles.h
Common/include/MetadataHelperFactory.h
Common/include/MetadataHelper.h
Common/include/ResamplingBandExtractor.h
Common/src/MetadataHelper.cpp
Common/src/MetadataHelperFactory.cpp
CompositePreprocessing/include/ComputeNDVI.h
CompositePreprocessing/include/CreateS2AnglesRaster.h
CompositePreprocessing/include/DirectionalCorrectionFilter.h
CompositePreprocessing/include/DirectionalCorrectionFunctor.h
CompositePreprocessing/include/DirectionalCorrection.h
CompositePreprocessing/include/DirectionalModel.h
CompositePreprocessing/include/MaskExtractorFilter.h
CompositePreprocessing/src/ComputeNDVI.cpp
CompositePreprocessing/src/CreateS2AnglesRaster.cpp
CompositePreprocessing/src/DirectionalCorrection.cpp
CompositePreprocessing/src/DirectionalCorrectionFunctor.txx
CompositePreprocessing/src/DirectionalModel.cpp
CompositePreprocessing/src/MaskExtractorFilter.txx
MuscateMetadata/include/FluentXML.hpp
MuscateMetadata/include/MetadataUtil.hpp
MuscateMetadata/include/string_utils.hpp
MuscateMetadata/include/tinyxml_utils.hpp
MuscateMetadata/include/ViewingAngles.hpp
MuscateMetadata/src/FluentXML.cpp
MuscateMetadata/src/MetadataUtil.cpp
MuscateMetadata/src/string_utils.cpp
MuscateMetadata/src/tinyxml_utils.cpp
MuscateMetadata/src/ViewingAngles.cpp
ProductFormatter/src/ProductFormatter.cpp
UpdateSynthesis/include/BandsDefs.h
UpdateSynthesis/include/UpdateSynthesisFunctor.h
UpdateSynthesis/src/UpdateSynthesis.cpp
UpdateSynthesis/src/UpdateSynthesisFunctor.txx
WeightCalculation/TotalWeight/include/TotalWeightComputation.h
WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp
WeightCalculation/TotalWeight/src/TotalWeight.cpp
WeightCalculation/WeightAOT/include/WeightAOTComputation.h
WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp
WeightCalculation/WeightAOT/src/WeightAOT.cpp
WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h
WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h
WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h
WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h
WeightCalculation/WeightOnClouds/include/GaussianFilter.h
WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h
WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp
Copyright: <2014-2018> CS-Romania SA, Romania
<2018-2019> Centre national d'études spatiales (CNES), France
Comment: Initial work funded by ESA during the ESA DUE Sentinel-2 For
Agriculture Project. Modified for WASP project
License: GPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
set(MetadataHelper_HEADERS
include/MuscateMetadataHelper.h
include/MetadataHelperFactory.h
include/MetadataHelper.h
include/MetadataBands.h
include/MetadataAngles.h
include/GlobalDefs.h
include/ResamplingBandExtractor.h
include/ImageResampler.h
include/TestImageCreator.h
)
set(MetadataHelper_SOURCES
src/MuscateMetadataHelper.cpp
src/GlobalDefs.cpp
src/MetadataHelper.cpp
src/MetadataBands.cpp
src/MetadataHelperFactory.cpp
)
add_library(MetadataHelper SHARED ${MetadataHelper_HEADERS} ${MetadataHelper_SOURCES})
target_link_libraries(MetadataHelper MuscateMetadata
"${Boost_LIBRARIES}"
"${OTBCommon_LIBRARIES}"
"${OTBITK_LIBRARIES}")
target_include_directories(MetadataHelper PUBLIC include)
install(TARGETS MetadataHelper DESTINATION lib/)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
/*
* Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES)
* All rights reserved
*
* This file is part of Weighted Average Synthesis Processor (WASP)
*
* Authors:
* - Peter KETTIG <peter.kettig@cnes.fr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* See the LICENSE.md file for more details.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef COMMON_INCLUDE_BASEIMAGETYPES_H_
#define COMMON_INCLUDE_BASEIMAGETYPES_H_
#include "itkLightObject.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbObjectList.h"
#include "otbImageList.h"
#include "otbWrapperApplication.h"
/**
* @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain
*/
namespace ts {
/**
* @brief Stores all base typedefs used in the processing chain
*/
class BaseImageTypes{
public:
typedef unsigned char BytePixelType;
typedef otb::Image<BytePixelType, 2> ByteImageType;
typedef otb::ImageFileReader<ByteImageType> ByteImageReaderType;
typedef otb::ObjectList<ByteImageReaderType> ByteImageReaderListType;
typedef otb::ImageList<ByteImageType> ByteImageListType;
typedef short ShortPixelType;
typedef otb::Image<ShortPixelType, 2> ShortImageType;
typedef otb::ImageFileReader<ShortImageType> ShortImageReaderType;
typedef otb::ObjectList<ShortImageReaderType> ShortImageReaderListType;
typedef otb::ImageList<ShortImageType> ShortImageListType;
typedef otb::Wrapper::Int16VectorImageType ShortVectorImageType;
typedef otb::ImageFileReader<ShortVectorImageType> ShortVectorImageReaderType;
typedef otb::ObjectList<ShortVectorImageReaderType> ShortVectorImageReaderListType;
typedef otb::ImageList<ShortVectorImageType> ShortVectorImageListType;
typedef float FloatPixelType;
typedef otb::Image<FloatPixelType, 2> FloatImageType;
typedef otb::ImageFileReader<FloatImageType> FloatImageReaderType;
typedef otb::ObjectList<FloatImageReaderType> FloatImageReaderListType;
typedef otb::ImageList<FloatImageType> FloatImageListType;
typedef otb::Wrapper::FloatVectorImageType FloatVectorImageType;
typedef otb::ImageFileReader<FloatVectorImageType> FloatVectorImageReaderType;
typedef otb::ObjectList<FloatVectorImageReaderType> FloatVectorImageReaderListType;
typedef otb::ImageList<FloatVectorImageType> FloatVectorImageListType;
};
} // namespace ts
#endif /* COMMON_INCLUDE_BASEIMAGETYPES_H_ */
/*
* Copyright (C) 2015-2016, CS Romania <office@c-s.ro>
* Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES)
* All rights reversed
*
* This file is part of:
* - Sen2agri-Processors (initial work)
* - Weighted Average Synthesis Processor (WASP)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef GLOBALDEFS_H
#define GLOBALDEFS_H
#include <string>
#include <vector>
/**
* @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain
*/
namespace ts {
/* The product return Type used for all products */
using productReturnType = std::vector<std::string>;
#define DEFAULT_QUANTIFICATION_VALUE 1000
#define NO_DATA_VALUE -10000
#define WEIGHT_NO_DATA_VALUE -10000
#define EPSILON 0.0001f
#define TIF_EXTENSION ".tif"
#define JPEG_EXTENSION ".jpg"
#define XML_EXTENSION ".xml"
#define COMPOSITE_REFLECTANCE_SUFFIX "FRC"
#define REFLECTANCE_SUFFIX "SRE"
#define FLAT_REFLECTANCE_SUFFIX "FRE"
#define QUICKLOOK_SUFFIX "QKL_ALL"
#define COMPOSITE_WEIGHTS_SUFFIX "WGT"
#define COMPOSITE_DATES_SUFFIX "DTS"
#define COMPOSITE_FLAGS_SUFFIX "FLG"
#define METADATA_CATEG "MTD_ALL"
#define IPP_DATA_SUFFIX "IPP_ALL"
#define NO_DATA_VALUE_STR "-10000"
#define DATA_FOLDER_NAME "DATA"
#define MASKS_FOLDER_NAME "MASKS"
#define SENTINEL_MISSION_STR "SENTINEL"
#define VENUS_MISSION_STR "VENUS"
#define LANDSAT8 "LANDSAT8"
#define SENTINEL2X "SENTINEL2X"
#define SENTINEL2A "SENTINEL2A"
#define SENTINEL2B "SENTINEL2B"
#define MULTISAT "S2AS2BL8"
#define VENUS VENUS_MISSION_STR
#define NONE_STRING "None"
#define MAIN_RESOLUTION_INDEX 0
#define N_RESOLUTIONS_SENTINEL 2
/**
* @brief Output Flag-mask definitions
*/
typedef enum {
IMG_FLG_NO_DATA=0, //!< IMG_FLG_NO_DATA
IMG_FLG_CLOUD=1, //!< IMG_FLG_CLOUD
IMG_FLG_SNOW=2, //!< IMG_FLG_SNOW
IMG_FLG_WATER=3, //!< IMG_FLG_WATER
IMG_FLG_LAND=4, //!< IMG_FLG_LAND
IMG_FLG_CLOUD_SHADOW=5,//!< IMG_FLG_CLOUD_SHADOW
IMG_FLG_SATURATION=6 //!< IMG_FLG_SATURATION
} FlagType;
/**
* @brief Interpolator types
*/
typedef enum
{
Interpolator_NNeighbor,//!< Interpolator_NNeighbor
Interpolator_Linear, //!< Interpolator_Linear
Interpolator_BCO //!< Interpolator_BCO
} Interpolator_Type;
/**
* @brief Used to determine whether the underlying structure has a size()-method or not.
* @note Used in the ShortToFloat- and FloatToShort-TranslationFunctors
*/
template<typename T>
struct HasSizeMethod
{
template<typename U, unsigned int (U::*)() const> struct SFINAE {};
template<typename U> static char Test(SFINAE<U, &U::Size>*);
template<typename U> static int Test(...);
static const bool Has = sizeof(Test<T>(0)) == sizeof(char);
};
/////////////////////////
/// GLOBAL FUNCTIONS ///
///////////////////////
/**
* @brief Returns the base name in a string
* @param path Reference to the input string
* @return string containing the base name
*/
std::string getDirname(const std::string &path);
/**
*@brief Returns the directory name in a string
*@param path Reference to the input string
*@return string containing the directory name
*/
std::string getBasename(const std::string &path);
/**
* @brief get Environment Variable by key name
* @param key The name of the key, e.g. PATH
* @return The value of the variable, if existing
*/
std::string getEnvVar( std::string const & key );
} // namespace ts
#endif //GLOBALDEFS_H
/*
* Copyright (C) 2015-2016, CS Romania <office@c-s.ro>
* Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES)
* All rights reversed
*
* This file is part of:
* - Sen2agri-Processors (initial work)
* - Weighted Average Synthesis Processor (WASP)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef IMAGE_RESAMPLER_H
#define IMAGE_RESAMPLER_H
#include "otbWrapperTypes.h"
#include "otbStreamingResampleImageFilter.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbImageListToVectorImageFilter.h"
#include "libgen.h"
//Transform
#include "itkScalableAffineTransform.h"
#include "GlobalDefs.h"
/**
* @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain
*/
namespace ts {
/**
* @brief Resample an image to either a given size or a given scale
* @note Can use the following interpolators: BCO, NearestNeighbor and Linear
*/
template <class TInput, class TOutput>
class ImageResampler
{
public:
typedef otb::StreamingResampleImageFilter<TInput, TOutput, double> ResampleFilterType;
typedef otb::ObjectList<ResampleFilterType> ResampleFilterListType;
typedef itk::NearestNeighborInterpolateImageFunction<TOutput, double> NearestNeighborInterpolationType;
typedef itk::LinearInterpolateImageFunction<TOutput, double> LinearInterpolationType;
typedef otb::BCOInterpolateImageFunction<TOutput> BCOInterpolationType;
typedef itk::IdentityTransform<double, TOutput::ImageDimension> IdentityTransformType;
typedef itk::ScalableAffineTransform<double, TOutput::ImageDimension> ScalableTransformType;
typedef typename ScalableTransformType::OutputVectorType OutputVectorType;
typedef typename NearestNeighborInterpolationType::Pointer NearestNeighborInterpolationTypePtr;
typedef typename LinearInterpolationType::Pointer LinearInterpolationTypePtr;
typedef typename IdentityTransformType::Pointer IdentityTransformTypePtr;
typedef typename TInput::Pointer ResamplerInputImgPtr;
typedef typename TInput::PixelType ResamplerInputImgPixelType;
typedef typename TInput::SpacingType ResamplerInputImgSpacingType;
typedef typename ResampleFilterType::Pointer ResamplerPtr;
typedef typename ResampleFilterType::SizeType ResamplerSizeType;
typedef typename otb::ObjectList<ResampleFilterType>::Pointer ResampleFilterListTypePtr;
public:
const char * GetNameOfClass() { return "ImageResampler"; }
ImageResampler()
{
m_ResamplersList = ResampleFilterListType::New();
m_BCORadius = 2;
m_fBCOAlpha = -0.5;
}
void SetBicubicInterpolatorParameters(int BCORadius, float BCOAlpha = -0.5) {
m_BCORadius = BCORadius;
m_fBCOAlpha = BCOAlpha;
}
/**
* @brief Get Resampler by a wanted size (X,Y)
* @param image image pointer
* @param wantedWidth Width in pixels
* @param wantedHeight Height in pixels
* @param interpolator Interpolator type
* @return Pointer to the resampler-filter
*/
ResamplerPtr getResamplerWantedSize(const ResamplerInputImgPtr& image, const int wantedWidth,
const int wantedHeight, Interpolator_Type interpolator=Interpolator_Linear)
{
auto sz = image->GetLargestPossibleRegion().GetSize();
OutputVectorType scale;
scale[0] = (float)sz[0] / wantedWidth;
scale[1] = (float)sz[1] / wantedHeight;
ResamplerPtr resampler = getResampler(image, scale, wantedWidth, wantedHeight, interpolator);
ResamplerSizeType recomputedSize;
recomputedSize[0] = wantedWidth;
recomputedSize[1] = wantedHeight;
resampler->SetOutputSize(recomputedSize);
return resampler;
}
/**
* @brief Get Resampler by a Given Ratio
* @param image image pointer
* @param ratio ratio of the new image
* @param interpolator Interpolator type
* @return Pointer to the resampler-filter
*/
ResamplerPtr getResampler(const ResamplerInputImgPtr& image, const float& ratio,
Interpolator_Type interpolator=Interpolator_Linear) {
// Scale Transform
OutputVectorType scale;
scale[0] = 1.0 / ratio;
scale[1] = 1.0 / ratio;
return getResampler(image, scale, -1, -1, interpolator);
}
/**
* @brief Get Resampler by a Given Ratio and origin
* @param image image pointer
* @param ratio ratio of the new image
* @brief origin The origin of the output image
* @param interpolator Interpolator type
* @return Pointer to the resampler-filter
*/
ResamplerPtr getResampler(const ResamplerInputImgPtr& image, const float& ratio,
typename TOutput::PointType origin, Interpolator_Type interpolator=Interpolator_Linear) {
// Scale Transform
OutputVectorType scale;
scale[0] = 1.0 / ratio;
scale[1] = 1.0 / ratio;
return getResampler(image, scale, -1, -1, origin, interpolator);
}
/**
* @brief Get resampler by scale and enforce a given size
* @param image Image pointer
* @param scale Scale of the output
* @param forcedWidth Forced width of the output
* @param forcedHeight Forced height of the output
* @param interpolatorType Interpolator type
* @return
*/
ResamplerPtr getResampler(const ResamplerInputImgPtr& image, const OutputVectorType& scale,
int forcedWidth, int forcedHeight, Interpolator_Type interpolatorType=Interpolator_Linear) {
ResamplerInputImgSpacingType spacing = image->GetSpacing();
typename TOutput::PointType origin = image->GetOrigin();
typename TOutput::PointType outputOrigin;
outputOrigin[0] = std::round(origin[0] + 0.5 * spacing[0] * (scale[0] - 1.0));
outputOrigin[1] = std::round(origin[1] + 0.5 * spacing[1] * (scale[1] - 1.0));
return getResampler(image, scale, forcedWidth, forcedHeight, outputOrigin, interpolatorType);
}
/**
* @brief Get a resampler using the scale, forced size and origin
* @param image Image Pointer
* @param scale Scale of the output
* @param forcedWidth Forced width of output
* @param forcedHeight Forced height of output
* @param origin Origin of the output
* @param interpolatorType Interpolator type
* @return
*/
ResamplerPtr getResampler(const ResamplerInputImgPtr& image, const OutputVectorType& scale,
int forcedWidth, int forcedHeight, typename TOutput::PointType origin,
Interpolator_Type interpolatorType=Interpolator_Linear) {
ResamplerPtr resampler = ResampleFilterType::New();
resampler->SetInput(image);
// Set the interpolator
switch ( interpolatorType )
{
case Interpolator_Linear:
{
typename LinearInterpolationType::Pointer interpolatorPtr = LinearInterpolationType::New();
resampler->SetInterpolator(interpolatorPtr);
}
break;
case Interpolator_NNeighbor:
{
typename NearestNeighborInterpolationType::Pointer interpolatorPtr = NearestNeighborInterpolationType::New();
resampler->SetInterpolator(interpolatorPtr);
}
break;
case Interpolator_BCO:
{
typename BCOInterpolationType::Pointer interpolatorPtr = BCOInterpolationType::New();
interpolatorPtr->SetRadius(m_BCORadius);
interpolatorPtr->SetAlpha(m_fBCOAlpha);
resampler->SetInterpolator(interpolatorPtr);
}
break;
}
IdentityTransformTypePtr transform = IdentityTransformType::New();
resampler->SetOutputParametersFromImage( image );
// Evaluate spacing
ResamplerInputImgSpacingType spacing = image->GetSpacing();
ResamplerInputImgSpacingType OutputSpacing;
OutputSpacing[0] = std::round(spacing[0] * scale[0]);
OutputSpacing[1] = std::round(spacing[1] * scale[1]);
resampler->SetOutputSpacing(OutputSpacing);
resampler->SetOutputOrigin(origin);
resampler->SetTransform(transform);
// Evaluate size