OTB  9.0.0
Orfeo Toolbox
otbDateUtils.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: gapfilling
4  Language: C++
5 
6  Copyright (c) Jordi Inglada. All rights reserved.
7 
8  See LICENCE for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notices for more information.
13 
14 =========================================================================*/
15 #ifndef _DATEUTILS_H_
16 #define _DATEUTILS_H_
17 
18 #include <ctime>
19 #include <vector>
20 #include <string>
21 #include <map>
22 #include <vnl/vnl_vector.h>
23 #include <boost/algorithm/string.hpp>
24 
26 bool operator<(std::tm x, std::tm y);
27 
28 namespace GapFilling {
29 using PrecisionType = double;
30 using VectorType = vnl_vector<PrecisionType>;
31 using DateVector=std::vector<std::tm>;
32 
34 std::vector<std::string> string_split(const std::string& s, const std::string& sep);
35 
37 std::string pad_int(int x);
38 
40 std::tm make_date(const std::string& d);
41 
43 int delta_days(std::tm t1, std::tm t2);
44 
46 unsigned int doy(const std::tm& d);
47 
48 
54 {
55  doy_multi_year() = default;
56  doy_multi_year(unsigned int d_prev_init) : d_prev{d_prev_init}
57  {
58  first_date = false;
59  }
60  unsigned int operator()(const std::tm& d)
61  {
62  auto tmp_doy = doy(d);
63  if(!first_date)
64  {
65  if(tmp_doy < d_prev-365*year_count)
66  ++year_count;
67  tmp_doy += 365*year_count;
68  }
69  else
70  {
71  first_date = false;
72  }
73  d_prev = tmp_doy;
74  return tmp_doy;
75  };
76  unsigned int year_count = 0;
77  unsigned int d_prev = 0;
78  bool first_date = true;
79 };
81 
85 DateVector parse_date_file(const std::string& df);
86 
92 std::pair<DateVector, int> parse_dates_csv_file(const std::string& df, int year);
93 
97 std::vector<VectorType> get_csv_profiles(const std::string& fname, int pos, int ndates);
98 
103 DateVector parse_dates_sirhyus(const std::string& fname);
104 
108 std::vector<std::pair<long int, VectorType>> get_sirhyus_profiles(const std::string& df,
109  unsigned int nbDates);
111 int months(const std::string& m);
112 }
114 
115 #endif
GapFilling
Definition: otbDateUtils.h:28
GapFilling::VectorType
vnl_vector< PrecisionType > VectorType
Definition: otbDateUtils.h:30
GapFilling::PrecisionType
double PrecisionType
Definition: otbDateUtils.h:29
GapFilling::get_csv_profiles
std::vector< VectorType > get_csv_profiles(const std::string &fname, int pos, int ndates)
GapFilling::parse_date_file
DateVector parse_date_file(const std::string &df)
GapFilling::make_date
std::tm make_date(const std::string &d)
Makes a date (std::tm struct) from a string with format YYYYMMDD.
GapFilling::doy_multi_year::doy_multi_year
doy_multi_year(unsigned int d_prev_init)
Definition: otbDateUtils.h:56
GapFilling::pad_int
std::string pad_int(int x)
return a string with a 0 at the front if the int is < 10
GapFilling::delta_days
int delta_days(std::tm t1, std::tm t2)
Returns the difference in days between 2 time structures.
GapFilling::string_split
std::vector< std::string > string_split(const std::string &s, const std::string &sep)
Split a string using a given separator.
GapFilling::DateVector
std::vector< std::tm > DateVector
Definition: otbDateUtils.h:31
GapFilling::doy_multi_year::doy_multi_year
doy_multi_year()=default
GapFilling::months
int months(const std::string &m)
Map to convert months from text to int.
GapFilling::doy_multi_year::d_prev
unsigned int d_prev
Definition: otbDateUtils.h:77
GapFilling::doy_multi_year
Definition: otbDateUtils.h:53
GapFilling::parse_dates_sirhyus
DateVector parse_dates_sirhyus(const std::string &fname)
GapFilling::get_sirhyus_profiles
std::vector< std::pair< long int, VectorType > > get_sirhyus_profiles(const std::string &df, unsigned int nbDates)
GapFilling::doy
unsigned int doy(const std::tm &d)
Return the day of year.
GapFilling::doy_multi_year::year_count
unsigned int year_count
Definition: otbDateUtils.h:76
GapFilling::doy_multi_year::first_date
bool first_date
Definition: otbDateUtils.h:78
GapFilling::doy_multi_year::operator()
unsigned int operator()(const std::tm &d)
Definition: otbDateUtils.h:60
operator<
bool operator<(std::tm x, std::tm y)
Compare 2 dates.
GapFilling::parse_dates_csv_file
std::pair< DateVector, int > parse_dates_csv_file(const std::string &df, int year)