Skip to content
Snippets Groups Projects
Commit 266ee2c7 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: Change satAzimuth computation for Formosat

parent 9f310b0e
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@
#include <boost/algorithm/string.hpp>
#include "otbMacro.h"
#include "otbMath.h"
#include "itkMetaDataObject.h"
#include "otbImageKeywordlist.h"
......@@ -547,23 +548,67 @@ FormosatImageMetadataInterface::GetSatAzimuth() const
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
if (!imageKeywordlist.HasKey("support_data.step_count") ||
!imageKeywordlist.HasKey("support_data.scene_orientation"))
if (!imageKeywordlist.HasKey("support_data.incident_angle"))
{
return 0;
}
std::string valueString = imageKeywordlist.GetMetadataByKey("support_data.step_count");
int step = atoi(valueString.c_str());
valueString = imageKeywordlist.GetMetadataByKey("support_data.scene_orientation");
std::string valueString = imageKeywordlist.GetMetadataByKey("support_data.sat_azimuth_angle");
double satAz = atof(valueString.c_str());
if ((step - 48) < 0)
{
satAz += 90.;
}
else satAz = satAz - 90.;
return satAz;
// In some software version, a bug exists.
// We have to check the version t correct the satellite azimuth angle contained in the metadata
std::string softVersion = imageKeywordlist.GetMetadataByKey("support_data.software_version");
if( (softVersion == "R2P_02.03.P1") || (softVersion == "R2P_02.02") || (softVersion == "R2P_02.03") )
{
if (!imageKeywordlist.HasKey("support_data.viewing_angle_across_track"))
{
return 0;
}
if (!imageKeywordlist.HasKey("support_data.viewing_angle_along_track"))
{
return 0;
}
if (!imageKeywordlist.HasKey("support_data.scene_orientation"))
{
return 0;
}
valueString = imageKeywordlist.GetMetadataByKey("support_data.viewing_angle_across_track");
double viewingAngleAcrossTrack( atof(valueString.c_str()) );
valueString = imageKeywordlist.GetMetadataByKey("support_data.viewing_angle_along_track");
double viewingAngleAlongTrack( atof(valueString.c_str()) );
valueString = imageKeywordlist.GetMetadataByKey("support_data.scene_orientation");
double sceneOrientation( atof(valueString.c_str()) );
double alpha = vcl_atan( vcl_tan( viewingAngleAcrossTrack * CONST_PI_180 ) / vcl_tan( viewingAngleAlongTrack * CONST_PI_180 ) ) * CONST_180_PI;
if( viewingAngleAlongTrack < 0 )
{
if (alpha >0)
{
alpha = alpha - 180;
}
else
{
alpha = alpha + 180;
}
}
alpha -= sceneOrientation;
if (alpha >0)
{
satAz += 180;
}
else
{
satAz = 180 - satAz;
}
}
return satAz;
}
FormosatImageMetadataInterface::VariableLengthVectorType
......
......@@ -37,12 +37,16 @@ ossimFormosatDimapSupportData::ossimFormosatDimapSupportData ()
theImageID(),
theMetadataFile(),
theProductionDate(),
theSoftwareVersion(),
theInstrument(),
theInstrumentIndex(0),
theInstrumentIndex(0),
theSunAzimuth(0.0),
theSunElevation(0.0),
theSatAzimuth(0.0),
theIncidenceAngle(0.0),
theViewingAngle(0.0),
theViewingAngleAlongTrack(0.0),
theViewingAngleAcrossTrack(0.0),
theSceneOrientation(0.0),
theImageSize(0.0, 0.0),
theRefGroundPoint(0.0, 0.0, 0.0),
......@@ -73,12 +77,16 @@ ossimFormosatDimapSupportData::ossimFormosatDimapSupportData(const ossimFormosat
theImageID(rhs.theImageID),
theMetadataFile (rhs.theMetadataFile),
theProductionDate(rhs.theProductionDate),
theSoftwareVersion(rhs.theSoftwareVersion),
theInstrument(rhs.theInstrument),
theInstrumentIndex(rhs.theInstrumentIndex),
theSunAzimuth(rhs.theSunAzimuth),
theSunElevation(rhs.theSunElevation),
theSunElevation(rhs.theSunElevation),
theSatAzimuth(rhs.theSatAzimuth),
theIncidenceAngle(rhs.theIncidenceAngle),
theViewingAngle(rhs.theViewingAngle),
theViewingAngleAlongTrack(rhs.theViewingAngle),
theViewingAngleAcrossTrack(rhs.theViewingAngle),
theSceneOrientation(rhs.theSceneOrientation),
theImageSize(rhs.theImageSize),
theRefGroundPoint(rhs.theRefGroundPoint),
......@@ -111,12 +119,16 @@ ossimFormosatDimapSupportData::ossimFormosatDimapSupportData (const ossimFilenam
theImageID(),
theMetadataFile (dimapFile),
theProductionDate(),
theSoftwareVersion(),
theInstrument(),
theInstrumentIndex(0),
theSunAzimuth(0.0),
theSunElevation(0.0),
theSatAzimuth(0.0),
theIncidenceAngle(0.0),
theViewingAngle(0.0),
theViewingAngleAlongTrack(0.0),
theViewingAngleAcrossTrack(0.0),
theSceneOrientation(0.0),
theImageSize(0.0, 0.0),
theRefGroundPoint(0.0, 0.0, 0.0),
......@@ -175,12 +187,16 @@ void ossimFormosatDimapSupportData::clearFields()
theImageID = "";
theMetadataFile = "";
theProductionDate = "";
theSoftwareVersion = "";
theInstrument = "";
theInstrumentIndex = 0;
theSunAzimuth = 0.0;
theSunElevation = 0.0;
theSatAzimuth = 0.0;
theIncidenceAngle = 0.0;
theViewingAngle = 0.0;
theViewingAngleAlongTrack = 0.0;
theViewingAngleAcrossTrack = 0.0;
theSceneOrientation = 0.0;
theImageSize.makeNan();
theRefGroundPoint.makeNan();
......@@ -780,24 +796,28 @@ void ossimFormosatDimapSupportData::printInfo(ostream& os) const
os << "\n----------------- Info on Formosat Image -------------------"
<< "\n "
<< "\n Job Number (ID): " << theImageID
<< "\n Acquisition Date: " << theAcquisitionDate
<< "\n Instrument: " << theInstrument
<< "\n Instrument Index: " << theInstrumentIndex
<< "\n Production Date: " << theProductionDate
<< "\n Number of Bands: " << theNumBands
<< "\n Geo Center Point: " << theRefGroundPoint
<< "\n Image Size: " << theImageSize
<< "\n Incidence Angle: " << theIncidenceAngle
<< "\n Viewing Angle: " << theViewingAngle
<< "\n Scene Orientation: " << theSceneOrientation
<< "\n Corrected Attitude: " << corr_att
<< "\n Sun Azimuth: " << theSunAzimuth
<< "\n Sun Elevation: " << theSunElevation
<< "\n Sub image offset: " << theSubImageOffset
<< "\n PolynomialLookAngleX size: " << thePolynomialLookAngleX.size()
<< "\n thePosEcfSamples size: " << thePosEcfSamples.size()
<< "\n theFrameVertexPosImagePoints size : " << theFrameVertexPosImagePoints.size()
<< "\n Job Number (ID): " << theImageID
<< "\n Acquisition Date: " << theAcquisitionDate
<< "\n Instrument: " << theInstrument
<< "\n Instrument Index: " << theInstrumentIndex
<< "\n Production Date: " << theProductionDate
<< "\n Production Softwrae version: " << theSoftwareVersion
<< "\n Number of Bands: " << theNumBands
<< "\n Geo Center Point: " << theRefGroundPoint
<< "\n Image Size: " << theImageSize
<< "\n Incidence Angle: " << theIncidenceAngle
<< "\n Viewing Angle: " << theViewingAngle
<< "\n Viewing Angle Along Track: " << theViewingAngleAlongTrack
<< "\n Viewing Angle Across Track: " << theViewingAngleAcrossTrack
<< "\n Scene Orientation: " << theSceneOrientation
<< "\n Corrected Attitude: " << corr_att
<< "\n Sun Azimuth: " << theSunAzimuth
<< "\n Sun Elevation: " << theSunElevation
<< "\n Sat Azimuth: " << theSatAzimuth
<< "\n Sub image offset: " << theSubImageOffset
<< "\n PolynomialLookAngleX size: " << thePolynomialLookAngleX.size()
<< "\n thePosEcfSamples size: " << thePosEcfSamples.size()
<< "\n theFrameVertexPosImagePoints size : " << theFrameVertexPosImagePoints.size()
<< "\n"
<< "\n---------------------------------------------------------"
<< "\n " << std::endl;
......@@ -831,6 +851,11 @@ ossimString ossimFormosatDimapSupportData::getProductionDate() const
return theProductionDate;
}
ossimString ossimFormosatDimapSupportData::getSoftwareVersion() const
{
return theSoftwareVersion;
}
ossimString ossimFormosatDimapSupportData::getImageID() const
{
return theImageID;
......@@ -861,6 +886,11 @@ void ossimFormosatDimapSupportData::getSunElevation(ossim_float64& el) const
el = theSunElevation;
}
void ossimFormosatDimapSupportData::getSatAzimuth(ossim_float64& az) const
{
az = theSatAzimuth;
}
void ossimFormosatDimapSupportData::getImageSize(ossimDpt& sz) const
{
sz = theImageSize;
......@@ -892,6 +922,16 @@ void ossimFormosatDimapSupportData::getViewingAngle(ossim_float64& va) const
va = theViewingAngle;
}
void ossimFormosatDimapSupportData::getViewingAngleAlongTrack(ossim_float64& va) const
{
va = theViewingAngleAlongTrack;
}
void ossimFormosatDimapSupportData::getViewingAngleAcrossTrack(ossim_float64& va) const
{
va = theViewingAngleAcrossTrack;
}
void ossimFormosatDimapSupportData::getSceneOrientation(ossim_float64& so) const
{
so = theSceneOrientation;
......@@ -965,6 +1005,11 @@ bool ossimFormosatDimapSupportData::saveState(ossimKeywordlist& kwl,
theSunElevation,
true);
kwl.add(prefix,
"sat_azimuth_angle",
theSatAzimuth,
true);
//---
// Note: since this is a new keyword, use the point.toString as there is
// no backwards compatibility issues.
......@@ -1157,6 +1202,11 @@ bool ossimFormosatDimapSupportData::saveState(ossimKeywordlist& kwl,
theProductionDate,
true);
kwl.add(prefix,
"software_version",
theSoftwareVersion,
true);
kwl.add(prefix,
"incident_angle",
theIncidenceAngle,
......@@ -1167,6 +1217,16 @@ bool ossimFormosatDimapSupportData::saveState(ossimKeywordlist& kwl,
theViewingAngle,
true);
kwl.add(prefix,
"viewing_angle_along_track",
theViewingAngleAlongTrack,
true);
kwl.add(prefix,
"viewing_angle_across_track",
theViewingAngleAcrossTrack,
true);
kwl.add(prefix,
"scene_orientation",
theSceneOrientation,
......@@ -1227,6 +1287,7 @@ bool ossimFormosatDimapSupportData::loadState(const ossimKeywordlist& kwl,
theSunAzimuth = ossimString(kwl.find(prefix, ossimKeywordNames::AZIMUTH_ANGLE_KW)).toDouble();
theSunElevation = ossimString(kwl.find(prefix, ossimKeywordNames::ELEVATION_ANGLE_KW)).toDouble();
theSatAzimuth = ossimString(kwl.find(prefix, "sat_azimuth_angle")).toDouble();
theImageSize = createDpt(kwl.find(prefix, "image_size"));
theRefGroundPoint = createGround(kwl.find(prefix, "reference_ground_point"));
......@@ -1356,13 +1417,16 @@ bool ossimFormosatDimapSupportData::loadState(const ossimKeywordlist& kwl,
theNumBands = ossimString(kwl.find(prefix, ossimKeywordNames::NUMBER_BANDS_KW)).toUInt32();
theAcquisitionDate = kwl.find(prefix, ossimKeywordNames::IMAGE_DATE_KW);
theProductionDate = kwl.find(prefix, "production_date");
theSoftwareVersion = kwl.find(prefix, "software_version");
theImageID = kwl.find(prefix, "image_id");
theInstrument = kwl.find(prefix, "instrument");
theInstrumentIndex = ossimString(kwl.find(prefix, "instrument_index")).toUInt32();
theIncidenceAngle = ossimString(kwl.find(prefix, "incident_angle")).toDouble();
theViewingAngle = ossimString(kwl.find(prefix, "viewing_angle")).toDouble();
theSceneOrientation= ossimString(kwl.find(prefix, "scene_orientation")).toDouble();
theIncidenceAngle = ossimString(kwl.find(prefix, "incident_angle")).toDouble();
theViewingAngle = ossimString(kwl.find(prefix, "viewing_angle")).toDouble();
theViewingAngleAlongTrack = ossimString(kwl.find(prefix, "viewing_angle_along_track")).toDouble();
theViewingAngleAcrossTrack = ossimString(kwl.find(prefix, "viewing_angle_across_track")).toDouble();
theSceneOrientation = ossimString(kwl.find(prefix, "scene_orientation")).toDouble();
/* TODO add reading FrameVertex point */
......@@ -1536,7 +1600,6 @@ bool ossimFormosatDimapSupportData::parsePart1(
theSubImageOffset.line = xml_nodes[0]->getText().toDouble() - 1.0;
}
//---
// Fetch the RefLineTime:
//---
......@@ -1577,7 +1640,26 @@ bool ossimFormosatDimapSupportData::parsePart1(
return false;
}
theProductionDate = xml_nodes[0]->getText();
//---
// Fetch the SoftwareVersion:
//---
xml_nodes.clear();
xpath = "/Dimap_Document/Production/Production_Facility/SOFTWARE_VERSION";
xmlDocument->findNodes(xpath, xml_nodes);
if (xml_nodes.size() == 0)
{
setErrorStatus();
if(traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
<< MODULE << " DEBUG:"
<< "\nCould not find: " << xpath
<< std::endl;
}
return false;
}
theSoftwareVersion = xml_nodes[0]->getText();
//---
// Fetch the Instrument:
//---
......@@ -1618,7 +1700,6 @@ bool ossimFormosatDimapSupportData::parsePart1(
}
theInstrumentIndex = xml_nodes[0]->getText().toUInt32();
return true;
}
......@@ -2342,7 +2423,7 @@ bool ossimFormosatDimapSupportData::initSceneSource(
theSensorID = "Formosat 2";
//---
// Fetch the Sun Azimuth:
// Fetch the Viewing Angle Along Track:
//---
xml_nodes.clear();
xpath = "/Dimap_Document/Dataset_Sources/Source_Information/Scene_Source/SUN_AZIMUTH";
......@@ -2360,6 +2441,44 @@ bool ossimFormosatDimapSupportData::initSceneSource(
}
theSunAzimuth = xml_nodes[0]->getText().toDouble();
//---
// Fetch the Viewing Angle Across Track:
//---
xml_nodes.clear();
xpath = "/Dimap_Document/Dataset_Sources/Source_Information/Scene_Source/VIEWING_ANGLE_ALONG_TRACK";
xmlDocument->findNodes(xpath, xml_nodes);
if (xml_nodes.size() == 0)
{
setErrorStatus();
if(traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
<< "DEBUG:\nCould not find: " << xpath
<< std::endl;
}
return false;
}
theViewingAngleAlongTrack = xml_nodes[0]->getText().toDouble();
//---
// Fetch the Sun Azimuth:
//---
xml_nodes.clear();
xpath = "/Dimap_Document/Dataset_Sources/Source_Information/Scene_Source/VIEWING_ANGLE_ACROSS_TRACK";
xmlDocument->findNodes(xpath, xml_nodes);
if (xml_nodes.size() == 0)
{
setErrorStatus();
if(traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
<< "DEBUG:\nCould not find: " << xpath
<< std::endl;
}
return false;
}
theViewingAngleAcrossTrack = xml_nodes[0]->getText().toDouble();
//---
// Fetch the Sun Elevation:
//---
......@@ -2398,6 +2517,25 @@ bool ossimFormosatDimapSupportData::initSceneSource(
}
theIncidenceAngle = xml_nodes[0]->getText().toDouble();
//---
// Fetch incidence angle:
//---
xml_nodes.clear();
xpath = "/Dimap_Document/Dataset_Sources/Source_Information/Scene_Source/SATELLITE_AZIMUTH_ANGLE";
xmlDocument->findNodes(xpath, xml_nodes);
if (xml_nodes.size() == 0)
{
setErrorStatus();
if(traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
<< "DEBUG:\nCould not find: " << xpath
<< std::endl;
}
return false;
}
theSatAzimuth = xml_nodes[0]->getText().toDouble();
//---
// Fetch viewing angle:
/*
......@@ -2430,7 +2568,7 @@ bool ossimFormosatDimapSupportData::initSceneSource(
double theSatelliteAltitude = xml_nodes[0]->getText().toDouble();
double RT = 63710087714.0;
theViewingAngle = asin((RT/(RT+theSatelliteAltitude))*sin(theIncidenceAngle));
return true;
}
......
......@@ -56,24 +56,28 @@ public:
void clearFields();
bool loadXmlFile(const ossimFilename& file);
ossimString getSensorID() const;
ossimString getMetadataVersionString() const;
ossimString getAcquisitionDate() const;
ossimString getProductionDate() const;
ossimString getImageID() const;
ossimString getInstrument() const;
ossim_uint32 getInstrumentIndex() const;
ossimFilename getMetadataFile() const;
void getSunAzimuth(ossim_float64& az) const;
void getSunElevation(ossim_float64& el) const;
void getImageSize(ossimDpt& sz) const;
void getLineSamplingPeriod(ossim_float64& pe) const;
void getIncidenceAngle(ossim_float64& ia) const;
void getViewingAngle(ossim_float64& va) const;
void getSceneOrientation(ossim_float64& so) const;
ossim_uint32 getNumberOfBands() const;
bool isStarTrackerUsed() const;
bool isSwirDataUsed() const;
ossimString getSensorID() const;
ossimString getMetadataVersionString() const;
ossimString getAcquisitionDate() const;
ossimString getProductionDate() const;
ossimString getSoftwareVersion() const;
ossimString getImageID() const;
ossimString getInstrument() const;
ossim_uint32 getInstrumentIndex() const;
ossimFilename getMetadataFile() const;
void getSunAzimuth(ossim_float64& az) const;
void getSunElevation(ossim_float64& el) const;
void getSatAzimuth(ossim_float64& az) const;
void getImageSize(ossimDpt& sz) const;
void getLineSamplingPeriod(ossim_float64& pe) const;
void getIncidenceAngle(ossim_float64& ia) const;
void getViewingAngle(ossim_float64& va) const;
void getViewingAngleAlongTrack(ossim_float64& va) const;
void getViewingAngleAcrossTrack(ossim_float64& va) const;
void getSceneOrientation(ossim_float64& so) const;
ossim_uint32 getNumberOfBands() const;
bool isStarTrackerUsed() const;
bool isSwirDataUsed() const;
//---
// Image center point:
......@@ -192,6 +196,7 @@ private:
* Initializes:
* theSunAzimuth
* theSunElevation
* theSatAzimuth;
* theIncidenceAngle
* @return true on success, false if not found.
*/
......@@ -206,6 +211,8 @@ private:
* Initializes:
* theRefGroundPoint
* theViewingAngle
* theViewingAngleAlongTrack
* theViewingAngleAcrossTrack
*
* Note that the theRefImagePoint will be the zero based center of the
* frame.
......@@ -218,6 +225,7 @@ private:
ossimString theImageID;
ossimFilename theMetadataFile;
ossimString theProductionDate;
ossimString theSoftwareVersion;
ossimString theInstrument;
ossim_uint32 theInstrumentIndex;
......@@ -228,8 +236,11 @@ private:
*/
ossim_float64 theSunAzimuth;
ossim_float64 theSunElevation;
ossim_float64 theSatAzimuth;
ossim_float64 theIncidenceAngle;
ossim_float64 theViewingAngle;
ossim_float64 theViewingAngleAlongTrack;
ossim_float64 theViewingAngleAcrossTrack;
ossim_float64 theSceneOrientation;
ossimDpt theImageSize;
......
......@@ -74,6 +74,7 @@ ossimplugins::ossimFormosatModel::ossimFormosatModel()
theMetaDataFile ("NOT ASSIGNED"),
theIllumAzimuth (0.0),
theIllumElevation (0.0),
theSatAzimuth (0.0),
thePositionError (0.0),
theRefImagingTime (0.0),
theRefImagingTimeLine (0.0),
......@@ -98,6 +99,7 @@ ossimplugins::ossimFormosatModel::ossimFormosatModel(ossimFormosatDimapSupportDa
theMetaDataFile ("NOT ASSIGNED"),
theIllumAzimuth (0.0),
theIllumElevation (0.0),
theSatAzimuth (0.0),
thePositionError (0.0),
theRefImagingTime (0.0),
theRefImagingTimeLine (0.0),
......@@ -378,6 +380,8 @@ void ossimplugins::ossimFormosatModel::loadSupportData()
theSupportData->getSunAzimuth(theIllumAzimuth);
theSupportData->getSunElevation(theIllumElevation);
theSupportData->getSatAzimuth(theSatAzimuth);
ossimDpt sz;
theSupportData->getImageSize(sz);
theImageSize = sz;
......@@ -461,6 +465,7 @@ std::ostream& ossimplugins::ossimFormosatModel::print(std::ostream& out) const
<< "\n theMetadataFile = " << theMetaDataFile
<< "\n theIllumAzimuth = " << theIllumAzimuth
<< "\n theIllumElevation = " << theIllumElevation
<< "\n theSatAzimuth = " << theSatAzimuth
<< "\n thePositionError = " << thePositionError
<< "\n theImageSize = " << theImageSize
<< "\n theRefGndPt = " << theRefGndPt
......@@ -759,6 +764,7 @@ ossimplugins::ossimFormosatModel::initFromMetadata(ossimFormosatDimapSupportData
theMetaDataFile = "NOT ASSIGNED";
theIllumAzimuth = 0.0;
theIllumElevation = 0.0;
theSatAzimuth = 0.0;
thePositionError = 0.0;
theRefImagingTime = 0.0;
theLineSamplingPeriod = 0.0;
......
......@@ -136,6 +136,7 @@ protected:
ossimFilename theMetaDataFile;
ossim_float64 theIllumAzimuth;
ossim_float64 theIllumElevation;
ossim_float64 theSatAzimuth;
ossim_float64 thePositionError;
ossim_float64 theRefImagingTime;
......@@ -158,6 +159,7 @@ protected:
ossim_float64 theYawRate; // degrees/sec
ossim_float64 theFocalLenOffset; // percent deviation from nominal
TYPE_DATA
};
}
......
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