Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Main Repositories
otb
Commits
a3c8415c
Commit
a3c8415c
authored
Nov 17, 2021
by
Cédric Traizet
Browse files
REFAC: remove MetaData::Time (replaced by MetaData::TimePoint)
parent
3e5c3a8f
Pipeline
#9129
failed with stages
in 98 minutes and 37 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Modules/Core/Metadata/include/otbMetaDataKey.h
View file @
a3c8415c
...
...
@@ -232,65 +232,6 @@ namespace MetaData
using
Keywordlist
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
;
struct
OTBMetadata_EXPORT
Time
:
tm
{
double
frac_sec
;
friend
OTBMetadata_EXPORT
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Time
&
val
);
friend
OTBMetadata_EXPORT
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
Time
&
val
);
friend
OTBMetadata_EXPORT
bool
operator
==
(
const
Time
&
lhs
,
const
Time
&
rhs
)
{
tm
tmLhs
=
lhs
;
tm
tmRhs
=
rhs
;
return
mktime
(
&
tmLhs
)
+
lhs
.
frac_sec
==
mktime
(
&
tmRhs
)
+
rhs
.
frac_sec
;
}
friend
OTBMetadata_EXPORT
bool
operator
!=
(
const
Time
&
lhs
,
const
Time
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
friend
OTBMetadata_EXPORT
bool
operator
<
(
const
Time
&
lhs
,
const
Time
&
rhs
)
{
tm
tmLhs
=
lhs
;
tm
tmRhs
=
rhs
;
return
mktime
(
&
tmLhs
)
+
lhs
.
frac_sec
<
mktime
(
&
tmRhs
)
+
rhs
.
frac_sec
;
}
friend
OTBMetadata_EXPORT
bool
operator
>
(
const
Time
&
lhs
,
const
Time
&
rhs
)
{
return
rhs
<
lhs
;
}
friend
OTBMetadata_EXPORT
bool
operator
<=
(
const
Time
&
lhs
,
const
Time
&
rhs
)
{
return
!
(
lhs
>
rhs
);
}
friend
OTBMetadata_EXPORT
bool
operator
>=
(
const
Time
&
lhs
,
const
Time
&
rhs
)
{
return
!
(
lhs
<
rhs
);
}
/** @name Getters
* Getters on the date components
*/
///@{
int
GetDay
()
const
;
int
GetMonth
()
const
;
int
GetYear
()
const
;
int
GetHour
()
const
;
int
GetMinute
()
const
;
double
GetSecond
()
const
;
double
GetJulianDay
()
const
;
double
GetModifiedJulian
()
const
;
///@}
};
struct
LUTAxis
{
/** number of measurements on this axis */
...
...
@@ -403,25 +344,6 @@ std::string EnumToString(std::string value);
}
// end namespace MetaData
namespace
Utils
{
template
<
>
inline
MetaData
::
Time
LexicalCast
<
MetaData
::
Time
,
std
::
string
>
(
std
::
string
const
&
in
,
std
::
string
const
&
kind
)
{
MetaData
::
Time
output
;
std
::
istringstream
iss
(
in
);
iss
>>
output
;
if
(
iss
.
fail
())
{
std
::
ostringstream
oss
;
oss
<<
"Cannot decode '"
<<
in
<<
"' as this is not a valid value for '"
<<
kind
<<
"'"
;
throw
std
::
runtime_error
(
oss
.
str
());
}
return
output
;
}
}
// end namespace Utils
}
// end namespace otb
#endif
Modules/Core/Metadata/include/otbSARMetadata.h
View file @
a3c8415c
...
...
@@ -48,7 +48,7 @@ class SarCalibrationLookupData;
struct
OTBMetadata_EXPORT
AzimuthFmRate
{
/** Zero Doppler azimuth time to which azimuth FM rate parameters apply */
MetaData
::
Time
azimuthTime
;
MetaData
::
Time
Point
azimuthTime
;
/** Two way slant range time origin used for azimuth FM rate calculation */
double
t0
;
/** Azimuth FM rate coefficients c0 c1 c2 */
...
...
@@ -68,7 +68,7 @@ struct OTBMetadata_EXPORT AzimuthFmRate
struct
OTBMetadata_EXPORT
DopplerCentroid
{
/** Zero Doppler azimuth time of this Doppler centroid estimate */
MetaData
::
Time
azimuthTime
;
MetaData
::
Time
Point
azimuthTime
;
/* Two-way slant range time origin for Doppler centroid estimate */
double
t0
;
/* Doppler centroid estimated from data */
...
...
@@ -233,8 +233,8 @@ struct OTBMetadata_EXPORT SARCalib
bool
calibrationLookupFlag
=
false
;
double
rescalingFactor
;
MetaData
::
Time
calibrationStartTime
;
MetaData
::
Time
calibrationStopTime
;
MetaData
::
Time
Point
calibrationStartTime
;
MetaData
::
Time
Point
calibrationStopTime
;
ArrayType
radiometricCalibrationNoisePolynomialDegree
;
ArrayType
radiometricCalibrationAntennaPatternNewGainPolynomialDegree
;
ArrayType
radiometricCalibrationAntennaPatternOldGainPolynomialDegree
;
...
...
Modules/Core/Metadata/src/otbMetaDataKey.cxx
View file @
a3c8415c
...
...
@@ -115,136 +115,6 @@ MetaDataKey::KeyType MetaDataKey::GetKeyType(const std::string& name)
namespace
MetaData
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Time
&
val
)
{
os
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
4
)
<<
val
.
tm_year
+
1900
<<
'-'
;
os
<<
std
::
setw
(
2
)
<<
val
.
tm_mon
+
1
<<
'-'
<<
std
::
setw
(
2
)
<<
val
.
tm_mday
;
os
<<
'T'
<<
std
::
setw
(
2
)
<<
val
.
tm_hour
<<
':'
;
os
<<
std
::
setw
(
2
)
<<
val
.
tm_min
<<
':'
;
double
sec
=
(
double
)
val
.
tm_sec
+
val
.
frac_sec
;
int
prec
=
8
;
if
(
sec
<
10.0
)
{
os
<<
'0'
;
prec
=
7
;
}
os
<<
std
::
setprecision
(
prec
)
<<
sec
<<
'Z'
;
os
<<
std
::
setfill
(
' '
);
return
os
;
}
#define _OTB_ISTREAM_FAIL_IF(x) \
if ( x ) \
{ \
is.setstate( std::ios_base::failbit); \
return is; \
}
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
Time
&
val
)
{
// Year
is
>>
val
.
tm_year
;
val
.
tm_year
-=
1900
;
_OTB_ISTREAM_FAIL_IF
(
is
.
fail
()
)
_OTB_ISTREAM_FAIL_IF
(
is
.
get
()
!=
'-'
)
// Month
is
>>
val
.
tm_mon
;
_OTB_ISTREAM_FAIL_IF
(
is
.
fail
()
)
_OTB_ISTREAM_FAIL_IF
(
val
.
tm_mon
<
1
||
val
.
tm_mon
>
12
)
val
.
tm_mon
-=
1
;
_OTB_ISTREAM_FAIL_IF
(
is
.
get
()
!=
'-'
)
// Day
is
>>
val
.
tm_mday
;
_OTB_ISTREAM_FAIL_IF
(
is
.
fail
()
)
_OTB_ISTREAM_FAIL_IF
(
val
.
tm_mday
<
1
||
val
.
tm_mday
>
31
)
_OTB_ISTREAM_FAIL_IF
(
is
.
get
()
!=
'T'
)
// Hour
is
>>
val
.
tm_hour
;
_OTB_ISTREAM_FAIL_IF
(
is
.
fail
()
)
_OTB_ISTREAM_FAIL_IF
(
val
.
tm_hour
<
0
||
val
.
tm_hour
>
23
)
_OTB_ISTREAM_FAIL_IF
(
is
.
get
()
!=
':'
)
// Minutes
is
>>
val
.
tm_min
;
_OTB_ISTREAM_FAIL_IF
(
is
.
fail
()
)
_OTB_ISTREAM_FAIL_IF
(
val
.
tm_min
<
0
||
val
.
tm_min
>
59
)
_OTB_ISTREAM_FAIL_IF
(
is
.
get
()
!=
':'
)
// Seconds
double
sec
=
0.0
;
is
>>
sec
;
_OTB_ISTREAM_FAIL_IF
(
is
.
fail
()
)
val
.
tm_sec
=
(
int
)
sec
;
val
.
frac_sec
=
sec
-
(
double
)
val
.
tm_sec
;
_OTB_ISTREAM_FAIL_IF
(
val
.
tm_sec
<
0
||
val
.
tm_sec
>
60
)
_OTB_ISTREAM_FAIL_IF
(
val
.
frac_sec
<
0.0
||
val
.
frac_sec
>=
1.0
)
// Disable Daylight Saving Time
val
.
tm_isdst
=
0
;
if
(
!
is
.
eof
())
{
_OTB_ISTREAM_FAIL_IF
(
is
.
get
()
!=
'Z'
)
}
return
is
;
}
#undef _OTB_ISTREAM_EXPECT
int
Time
::
GetDay
()
const
{
return
tm_mday
;
}
int
Time
::
GetMonth
()
const
{
return
tm_mon
+
1
;
}
int
Time
::
GetYear
()
const
{
return
tm_year
+
1900
;
}
int
Time
::
GetHour
()
const
{
return
tm_hour
;
}
int
Time
::
GetMinute
()
const
{
return
tm_min
;
}
double
Time
::
GetSecond
()
const
{
return
tm_sec
+
frac_sec
;
}
double
Time
::
GetJulianDay
()
const
{
// Conversion to julian day
// according to http://en.wikipedia.org/wiki/Julian_day
// division are integer divisions:
int
a
=
(
14
-
GetMonth
())
/
12
;
int
y
=
GetYear
()
+
4800
-
a
;
int
m
=
GetMonth
()
+
12
*
a
-
3
;
double
julianDay
=
GetDay
()
+
(
153
*
m
+
2
)
/
5
+
365
*
y
+
y
/
4
-
y
/
100
+
y
/
400
-
32045
;
// now, the division are NOT integer
julianDay
+=
GetHour
()
/
24.
+
GetMinute
()
/
1440.
+
GetSecond
()
/
86400.
;
return
julianDay
;
}
double
Time
::
GetModifiedJulian
()
const
{
return
GetJulianDay
()
-
2400000.5
;;
}
std
::
string
LUTAxis
::
ToJSON
(
bool
multiline
)
const
{
std
::
ostringstream
oss
;
...
...
Modules/Core/Metadata/src/otbSentinel1ImageMetadataInterface.cxx
View file @
a3c8415c
...
...
@@ -101,9 +101,9 @@ bool Sentinel1ImageMetadataInterface::CreateCalibrationLookupData(SARCalib& sarC
// TODO: don't manipulate doubles, but ModifiedJulianDate for a better type
// safety
MetaData
::
Time
tmpDate
;
MetaData
::
Time
Point
tmpDate
;
std
::
istringstream
(
mds
.
GetAs
<
std
::
string
>
(
sPrefix
+
"azimuthTime"
))
>>
tmpDate
;
sigmaCalibrationVector
.
timeMJD
=
tmpDate
.
GetModifiedJulian
();
sigmaCalibrationVector
.
timeMJD
=
tmpDate
.
GetModifiedJulian
Day
();
sigmaCalibrationVector
.
deltaMJD
=
sigmaCalibrationVector
.
timeMJD
-
lastMJD
;
lastMJD
=
sigmaCalibrationVector
.
timeMJD
;
...
...
@@ -137,23 +137,23 @@ bool Sentinel1ImageMetadataInterface::CreateCalibrationLookupData(SARCalib& sarC
}
Sentinel1CalibrationLookupData
::
Pointer
sigmaSarLut
=
Sentinel1CalibrationLookupData
::
New
();
sigmaSarLut
->
InitParameters
(
SarCalibrationLookupData
::
SIGMA
,
firstLineTime
.
GetModifiedJulian
(),
lastLineTime
.
GetModifiedJulian
(),
numOfLines
,
count
,
sigmaCalibrationVectorList
);
sigmaSarLut
->
InitParameters
(
SarCalibrationLookupData
::
SIGMA
,
firstLineTime
.
GetModifiedJulian
Day
(),
lastLineTime
.
GetModifiedJulian
Day
(),
numOfLines
,
count
,
sigmaCalibrationVectorList
);
sarCalib
.
calibrationLookupData
[
SarCalibrationLookupData
::
SIGMA
]
=
sigmaSarLut
;
Sentinel1CalibrationLookupData
::
Pointer
betaSarLut
=
Sentinel1CalibrationLookupData
::
New
();
betaSarLut
->
InitParameters
(
SarCalibrationLookupData
::
BETA
,
firstLineTime
.
GetModifiedJulian
(),
lastLineTime
.
GetModifiedJulian
(),
numOfLines
,
count
,
betaCalibrationVectorList
);
betaSarLut
->
InitParameters
(
SarCalibrationLookupData
::
BETA
,
firstLineTime
.
GetModifiedJulian
Day
(),
lastLineTime
.
GetModifiedJulian
Day
(),
numOfLines
,
count
,
betaCalibrationVectorList
);
sarCalib
.
calibrationLookupData
[
SarCalibrationLookupData
::
BETA
]
=
betaSarLut
;
Sentinel1CalibrationLookupData
::
Pointer
gammaSarLut
=
Sentinel1CalibrationLookupData
::
New
();
gammaSarLut
->
InitParameters
(
SarCalibrationLookupData
::
GAMMA
,
firstLineTime
.
GetModifiedJulian
(),
lastLineTime
.
GetModifiedJulian
(),
numOfLines
,
count
,
gammaCalibrationVectorList
);
gammaSarLut
->
InitParameters
(
SarCalibrationLookupData
::
GAMMA
,
firstLineTime
.
GetModifiedJulian
Day
(),
lastLineTime
.
GetModifiedJulian
Day
(),
numOfLines
,
count
,
gammaCalibrationVectorList
);
sarCalib
.
calibrationLookupData
[
SarCalibrationLookupData
::
GAMMA
]
=
gammaSarLut
;
Sentinel1CalibrationLookupData
::
Pointer
dnSarLut
=
Sentinel1CalibrationLookupData
::
New
();
dnSarLut
->
InitParameters
(
SarCalibrationLookupData
::
DN
,
firstLineTime
.
GetModifiedJulian
(),
lastLineTime
.
GetModifiedJulian
(),
numOfLines
,
count
,
dnCalibrationVectorList
);
dnSarLut
->
InitParameters
(
SarCalibrationLookupData
::
DN
,
firstLineTime
.
GetModifiedJulian
Day
(),
lastLineTime
.
GetModifiedJulian
Day
(),
numOfLines
,
count
,
dnCalibrationVectorList
);
sarCalib
.
calibrationLookupData
[
SarCalibrationLookupData
::
DN
]
=
dnSarLut
;
return
true
;
...
...
@@ -178,7 +178,7 @@ NoiseVectorLists ReadNoiseVectorListsFromGeom(const MetadataSupplierInterface& m
// Path: noise.noiseVector[<listId>].{azimuthTime,line,noiseLut,pixel,pixel_count}
const
std
::
string
prefix
=
"noise.noiseVector["
+
std
::
to_string
(
listId
)
+
"]."
;
Sentinel1CalibrationStruct
rangeNoiseVector
;
rangeNoiseVector
.
timeMJD
=
mds
.
GetAs
<
MetaData
::
Time
>
(
prefix
+
"azimuthTime"
).
GetModifiedJulian
();
rangeNoiseVector
.
timeMJD
=
MetaData
::
ReadFormattedDate
(
mds
.
GetAs
<
std
::
string
>
(
prefix
+
"azimuthTime"
)
)
.
GetModifiedJulian
Day
();
rangeNoiseVector
.
deltaMJD
=
rangeNoiseVector
.
timeMJD
-
lastMJD
;
lastMJD
=
rangeNoiseVector
.
timeMJD
;
...
...
@@ -246,7 +246,7 @@ NoiseVectorLists ReadNoiseVectorListsFromXML(const MetadataSupplierInterface& md
const
auto
prefix
=
rangeNoisePrefix
+
rangeVectorName
+
std
::
to_string
(
i
+
1
)
+
"."
;
Sentinel1CalibrationStruct
rangeNoiseVector
;
rangeNoiseVector
.
timeMJD
=
mds
.
GetAs
<
MetaData
::
Time
>
(
prefix
+
"azimuthTime"
).
GetModifiedJulian
();
rangeNoiseVector
.
timeMJD
=
MetaData
::
ReadFormattedDate
(
mds
.
GetAs
<
std
::
string
>
(
prefix
+
"azimuthTime"
)
)
.
GetModifiedJulian
Day
();
rangeNoiseVector
.
deltaMJD
=
rangeNoiseVector
.
timeMJD
-
lastMJD
;
lastMJD
=
rangeNoiseVector
.
timeMJD
;
rangeNoiseVector
.
line
=
mds
.
GetAs
<
int
>
(
prefix
+
"line"
);
...
...
@@ -298,8 +298,8 @@ bool Sentinel1ImageMetadataInterface::CreateThermalNoiseLookupData(SARCalib& sar
const
MetadataSupplierInterface
&
mds
,
const
bool
geom
)
const
{
auto
firstLineTime
=
sarCalib
.
calibrationStartTime
.
GetModifiedJulian
();
auto
lastLineTime
=
sarCalib
.
calibrationStopTime
.
GetModifiedJulian
();
auto
firstLineTime
=
sarCalib
.
calibrationStartTime
.
GetModifiedJulian
Day
();
auto
lastLineTime
=
sarCalib
.
calibrationStopTime
.
GetModifiedJulian
Day
();
int
numOfLines
=
0
;
if
(
imd
.
Has
(
MDNum
::
NumberOfLines
))
...
...
Modules/Core/Metadata/test/otbImageMetadataTest.cxx
View file @
a3c8415c
...
...
@@ -27,6 +27,7 @@
#include
<cstdlib>
#include
"otbStopwatch.h"
#include
"otbTestTools.h"
#include
"otbMissingMetadataException.h"
void
SetUpImageMetadata
(
otb
::
ImageMetadata
&
md
,
unsigned
int
nbBands
)
{
...
...
@@ -62,17 +63,17 @@ void otbMetadataKeyTest(char* argv[])
const
char
*
outFileName
=
argv
[
2
];
std
::
ofstream
outfile
(
outFileName
);
MetaData
::
Time
mytime
;
MetaData
::
Time
Point
mytime
;
std
::
string
bufferStr
(
"2009-08-10T10:30:08.142149Z"
);
try
{
mytime
=
Utils
::
LexicalCast
<
MetaData
::
Time
,
std
::
string
>
(
bufferStr
,
std
::
string
(
"T"
)
);
mytime
=
MetaData
::
ReadFormattedDate
(
bufferStr
);
}
catch
(
std
::
runtime_error
&
)
catch
(
const
MissingMetadataException
&
)
{
outfile
<<
"
Bad Utils::LexicalCast into MetaData::Time
\n
"
;
outfile
<<
"
Cannot parse input buffer
\n
"
;
}
outfile
<<
"mytime : "
<<
mytime
<<
"
\n
"
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment