Commit 245e586b authored by remi cresson's avatar remi cresson
Browse files

FIX: use correct dates for residues and ndvi trend

parent cb1f7d8a
......@@ -146,8 +146,6 @@ private:
{
p[i] = i*2;
}
// p = {65,63,67,64,68,62,70,66,68,67,69,71};
// Y = [68,66,68,65,69,66,68,65,71,67,68,70]
std::cout << f(p) << std::endl;
}
......@@ -379,6 +377,7 @@ private:
// NDVI Trend
m_NDVITimeSeriesRegressionFilter = SlopeAndPValueFilterType::New();
m_NDVITimeSeriesRegressionFilter->SetInput(reducedNDVI);
m_NDVITimeSeriesRegressionFilter->GetFunctor().SetDates(ndviDates);
// Write reduced ndvi
if (HasValue("ndvicumul"))
......@@ -464,6 +463,14 @@ private:
<< "and rainfall last year " << lastYearForRF << ".");
}
// Computes new dates of the reduced time series
std::vector<DateType> reducedTimeSeriesDates;
for (int year = firstYearForNDVI; year <= lastYearForNDVI; year++)
{
DateType newDate(year,1,1);
reducedTimeSeriesDates.push_back(newDate);
}
// Reduce rainfall
m_RFCumulReduceFilter = TSCumulatedRangeReduceFilterType::New();
m_RFCumulReduceFilter->SetInput(m_RFConcatener->GetOutput());
......@@ -488,7 +495,6 @@ private:
SetParameterOutputImage("rainfcumul", m_ResampleFilter->GetOutput());
}
// Compute residues
m_ResiduesFilter = ResiduesFilterType::New();
m_ResiduesFilter->SetInput1(reducedNDVI);
......@@ -503,6 +509,7 @@ private:
// Regression (residues)
m_NDVIResiduesRegressionFilter = SlopeAndPValueFilterType::New();
m_NDVIResiduesRegressionFilter->SetInput(m_ResiduesFilter->GetOutput());
m_NDVIResiduesRegressionFilter->GetFunctor().SetDates(reducedTimeSeriesDates);
// Output residues trend
if (HasValue("restrend"))
......
......@@ -26,6 +26,47 @@ namespace otb
namespace functor
{
/*
* \class TFunctorWithDates
*
* \brief Base class for functors which use input dates
*
* \ingroup NDVITimeSeries
*/
template<class TDateType>
class TFunctorWithDates
{
public:
typedef typename std::vector<TDateType> DatesType;
TFunctorWithDates() {}
~TFunctorWithDates() {}
bool operator!=( const TFunctorWithDates & ) const { return false; }
bool operator==( const TFunctorWithDates & other ) const { return !(*this != other); }
// Set dates
void SetDates(DatesType dates)
{
unsigned int n = dates.size();
// Check that dates are ordered in chronological
for (unsigned int i = 0 ; i < n - 1 ; i++)
{
assert(dates[i].julianday < dates[i+1].julianday);
}
// Assign dates
m_Dates = dates;
}
// Get dates
DatesType GetDates() const { return m_Dates; }
private:
DatesType m_Dates;
}; // TFunctorWithDates
/**
* \class TSReduceFunctorBase
*
......@@ -36,7 +77,7 @@ namespace functor
* \ingroup NDVITimeSeries
*/
template< class TInputPixel, class TOutputPixel>
class TSReduceFunctorBase
class TSReduceFunctorBase: public TFunctorWithDates<otb::dates::SingleDate>
{
public:
typedef otb::dates::SingleDate DateType;
......@@ -51,34 +92,22 @@ public:
inline unsigned int GetOutputSize() const { return nbOfYears; }
/* Set dates */
// Set / Get input no-data value
void SetInputNoDataValue(PixelValueType value) { m_InputNoDataValue = value; }
PixelValueType GetInputNoDataValue() const { return m_InputNoDataValue; }
// Set dates
void SetDates(DatesType dates)
{
unsigned int n = dates.size();
// Check that dates are ordered
for (unsigned int i = 0 ; i < n - 1 ; i++)
{
assert(dates[i].julianday < dates[i+1].julianday);
}
// Assign dates
m_Dates = dates;
TFunctorWithDates<otb::dates::SingleDate>::SetDates(dates);
// Compute the number of years
nbOfYears = m_Dates[n-1].year - m_Dates[0].year + 1;
unsigned int n = GetDates().size();
nbOfYears = GetDates()[n-1].year - GetDates()[0].year + 1;
}
/* Get dates */
DatesType GetDates() const { return m_Dates; }
/* Set / Get input no-data value */
void SetInputNoDataValue(PixelValueType value) { m_InputNoDataValue = value; }
PixelValueType GetInputNoDataValue() const { return m_InputNoDataValue; }
private:
unsigned int nbOfYears;
DatesType m_Dates;
PixelValueType m_InputNoDataValue;
}; // TSReduceFunctorBase
......@@ -308,12 +337,14 @@ inline TOutputPixel operator ()(const TInputPixel& input) const
*
*/
template< class TInputPixel, class TOutputPixel>
class SlopeAndPValueFunctor
class SlopeAndPValueFunctor: public TFunctorWithDates<otb::dates::SingleDate>
{
public:
typedef typename TInputPixel::ValueType InputPixelValueType;
typedef typename TOutputPixel::ValueType OutputPixelValueType;
typedef otb::dates::SingleDate DateType;
typedef std::vector<DateType> DatesType;
// Constructor
SlopeAndPValueFunctor()
......@@ -337,7 +368,6 @@ public:
// Compute output pixel
inline TOutputPixel operator ()(const TInputPixel& input) const
{
TOutputPixel outpixel;
outpixel.SetSize(numberOfComponentsPerPixel);
outpixel.Fill(m_OutputNoDataValue);
......@@ -355,7 +385,7 @@ public:
if (input[i] != m_InputNoDataValue)
{
OutputPixelValueType val = static_cast<OutputPixelValueType>(input[i]);
OutputPixelValueType ival = static_cast<OutputPixelValueType>(i);
OutputPixelValueType ival = static_cast<OutputPixelValueType>(GetDates()[i].julianday);
sum += val;
isum += ival;
sqSum += val*val;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment