Skip to content
Snippets Groups Projects
Commit 8711f46f authored by Gaëlle USSEGLIO's avatar Gaëlle USSEGLIO
Browse files

ENH : Add a selection for orbit nodes into SARMetadataCorrection

parent f5708bfb
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@
#include <fstream>
#include <complex>
#include <cmath>
#include <ctime>
#include <iosfwd>
#include "otb_tinyxml.h"
......@@ -355,9 +356,72 @@ int updateGCPAndKWL(std::vector<double> * vector_hgt, unsigned int gcpcount, otb
return 0;
}
// Selection for fine orbits (choose only orbits that fit with the image)
int selectOrbits(std::vector<std::string> * vector_time,
const otb::ImageKeywordlist inKWL, int & ind_first, int & ind_last)
{
// Initialize indexes
ind_first = 0;
ind_last = vector_time->size() - 1;
// Get time for first and last original orbit states
int orbitCount = std::atoi(inKWL.GetMetadataByKey(ORBIT_NUMBER_KEY).c_str());
char prefix_first[1024];
sprintf(prefix_first, "%s[%d].%s", ORBIT_PREFIX.c_str(), 0, keyTime.c_str());
std::string UTC_first = inKWL.GetMetadataByKey(std::string (prefix_first));
char prefix_last[1024];
sprintf(prefix_last, "%s[%d].%s", ORBIT_PREFIX.c_str(), (orbitCount-1), keyTime.c_str());
std::string UTC_last = inKWL.GetMetadataByKey(std::string (prefix_last));
// Transform string to t_time (in seconds)
struct tm tm1;
struct tm tm2;
strptime(UTC_first.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm1);
strptime(UTC_last.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm2);
time_t t_first = mktime(&tm1);
time_t t_last = mktime(&tm2);
// Selection of indexes into vector_time
// ind_first = last elt to be inferior to t_first
// ind_last = first elt to be superior to t_last
for (unsigned int i = 0; i < vector_time->size(); i++)
{
struct tm tm;
strptime(vector_time->at(i).c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm);
time_t t = mktime(&tm);
if (difftime(t, t_first) > 0 && ind_first == 0)
{
if (i !=0)
{
ind_first = i - 1;
}
}
if (difftime(t_last, t) < 0)
{
ind_last = i;
break;
}
}
std::cout << "UTC_first = " << UTC_first << std::endl;
std::cout << "UTC_last = " << UTC_last << std::endl;
std::cout << "ind_first = " << ind_first << std::endl;
std::cout << "ind_last = " << ind_last << std::endl;
std::cout << "first = " << vector_time->at(ind_first) << std::endl;
std::cout << "last = " << vector_time->at(ind_last) << std::endl;
}
// Create new Orbits and update outKWL //
int createOrbitsAndUpdateKWL(std::vector<double *>* vector_posvel,
std::vector<std::string> * vector_time,
int ind_first, int ind_last,
otb::ImageKeywordlist & outKWL)
{
// Check size (same size for all vectors)
......@@ -376,11 +440,11 @@ int createOrbitsAndUpdateKWL(std::vector<double *>* vector_posvel,
return 1;
}
std::string orbitFineCount = std::to_string(vecSize);
std::string orbitFineCount = std::to_string(ind_last - ind_first + 1);
outKWL.AddKey(ORBIT_NUMBER_KEY, orbitFineCount);
// Create or update each Orbit state
for (unsigned int i = 0; i < vecSize; i++)
for (unsigned int i = 0; i < std::atoi(orbitFineCount.c_str()); i++)
{
// Add the orbit to kwl
char prefix[1024];
......@@ -389,38 +453,38 @@ int createOrbitsAndUpdateKWL(std::vector<double *>* vector_posvel,
// time
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyTime.c_str());
outKWL.AddKey(prefix, vector_time->at(i));
outKWL.AddKey(prefix, vector_time->at(ind_first + i));
// position
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyPosX.c_str());
stream.str("");
stream << std::fixed << std::setprecision(6) << vector_posvel->at(i)[0];
stream << std::fixed << std::setprecision(6) << vector_posvel->at(ind_first + i)[0];
outKWL.AddKey(prefix, stream.str());
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyPosY.c_str());
stream.str("");
stream << std::fixed << std::setprecision(6) << vector_posvel->at(i)[1];
stream << std::fixed << std::setprecision(6) << vector_posvel->at(ind_first + i)[1];
outKWL.AddKey(prefix, stream.str());
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyPosZ.c_str());
stream.str("");
stream << std::fixed << std::setprecision(6) << vector_posvel->at(i)[2];
stream << std::fixed << std::setprecision(6) << vector_posvel->at(ind_first + i)[2];
outKWL.AddKey(prefix, stream.str());
// velocity
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyVelX.c_str());
stream.str("");
stream << std::fixed << std::setprecision(6) << vector_posvel->at(i)[3];
stream << std::fixed << std::setprecision(6) << vector_posvel->at(ind_first + i)[3];
outKWL.AddKey(prefix, stream.str());
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyVelY.c_str());
stream.str("");
stream << std::fixed << std::setprecision(6) << vector_posvel->at(i)[4];
stream << std::fixed << std::setprecision(6) << vector_posvel->at(ind_first + i)[4];
outKWL.AddKey(prefix, stream.str());
sprintf(prefix, "%s[%d].%s", ORBIT_PREFIX.c_str(), i, keyVelZ.c_str());
stream.str("");
stream << std::fixed << std::setprecision(6) << vector_posvel->at(i)[5];
stream << std::fixed << std::setprecision(6) << vector_posvel->at(ind_first + i)[5];
outKWL.AddKey(prefix, stream.str());
}
return 0;
......@@ -753,6 +817,10 @@ private:
++count_loop;
}
int ind_first, ind_last;
selectOrbits(vector_time, outputKWL, ind_first, ind_last);
// Check coherency between the number of orbits
if (count != count_loop)
{
......@@ -760,7 +828,8 @@ private:
}
int ret = createOrbitsAndUpdateKWL(vector_posvel, vector_time, outputKWL);
int ret = createOrbitsAndUpdateKWL(vector_posvel, vector_time, ind_first,
ind_last, outputKWL);
if (ret == 1)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment