Commit 28e07a0c authored by Julien Osman's avatar Julien Osman
Browse files

BUG: Deal with SARCalib metadata stored in bands

parent 6a2321f7
Pipeline #7475 failed with stages
in 92 minutes and 58 seconds
......@@ -11,22 +11,24 @@ TileHintX 17663
TileHintY 1
DataType 11
OrbitNumber 6447
NumberOfLines 31106
NumberOfColumns 17663
AverageSceneHeight 19
PRF 1663.48
RadarFrequency 5.405e+09
CenterIncidenceAngle 44.7171
LineSpacing 4.08568
PixelSpacing 3.19483
AcquisitionDate 2015-06-19T19:50:43.223221Z
ProductionDate 2015-06-20T01:51:06.838854Z
AcquisitionStartTime 2015-06-19T19:50:43.223221Z
AcquisitionStopTime 2015-06-19T19:51:01.921994Z
SARCalib <SARCalib>
GCP <GCPParam>
Extra.FACILITY_IDENTIFIER UPA_
Polarization VV
Swath S6
NumberOfLines 31106
NumberOfColumns 17663
AverageSceneHeight 19
CalScale 1
PRF 1663.48
RadarFrequency 5.405e+09
SAR <SARParam>
{"Projection": "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]",
[{"GCP_Id": "1", "GCP_Info": "", "GCP_Row": "0", "GCP_Col": "0", "GCP_X": "-24.4551", "GCP_Y": "14.4996", "GCP_Z": "0", },
......
......@@ -67,7 +67,8 @@ bool Sentinel1ImageMetadataInterface::CreateCalibrationLookupData(SARCalib& sarC
if(SarImageMetadataInterface::CreateCalibrationLookupData(sarCalib, imd, mds, geom))
return true;
std::stringstream prefix("calibration.");
std::stringstream prefix;
prefix << "calibration.";
if(!geom)
prefix << "CalibrationVectorList.";
const std::string sPrefixBase = prefix.str();
......
......@@ -1089,7 +1089,6 @@ void TerraSarImageMetadataInterface::ParseGdal(ImageMetadata &imd)
imd.Add(MDNum::PixelSpacing, MainXMLFileMetadataSupplier.GetAs<double>("level1Product.productSpecific.complexImageInfo.projectedSpacingRange.slantRange"));
imd.Add(MDStr::Mission, MainXMLFileMetadataSupplier.GetAs<std::string>("level1Product.generalHeader.mission"));
imd.Add(MDStr::ProductType, MainXMLFileMetadataSupplier.GetAs<std::string>("level1Product.productInfo.productVariantInfo.productType"));
// imd.Add(MDStr::Mode, MainXMLFileMS.GetAs<std::string>("level1Product.productInfo.acquisitionInfo.imagingMode"));
imd.Add(MDStr::SensorID, MainXMLFileMetadataSupplier.GetAs<std::string>("level1Product.productInfo.acquisitionInfo.sensor"));
imd.Add(MDNum::RadarFrequency, MainXMLFileMetadataSupplier.GetAs<double>("level1Product.instrument.radarParameters.centerFrequency"));
imd.Add(MDTime::AcquisitionStartTime, MainXMLFileMetadataSupplier.GetFirstAs<MetaData::Time>("level1Product.productInfo.sceneInfo.start.timeUTC"));
......@@ -1098,7 +1097,19 @@ void TerraSarImageMetadataInterface::ParseGdal(ImageMetadata &imd)
imd.Add(MDNum::RangeTimeLastPixel, MainXMLFileMetadataSupplier.GetFirstAs<double>("level1Product.productInfo.sceneInfo.rangeTime.lastPixel"));
imd.Add(MDNum::PRF, MainXMLFileMetadataSupplier.GetAs<double>("level1Product.productSpecific.complexImageInfo.commonPRF"));
imd.Add(MDNum::RSF, MainXMLFileMetadataSupplier.GetAs<double>("level1Product.productSpecific.complexImageInfo.commonRSF"));
imd.Add(MDNum::CalFactor, MainXMLFileMetadataSupplier.GetAs<double>("level1Product.calibration.calibrationConstant.calFactor"));
auto numberOfCalFactor = MainXMLFileMetadataSupplier.GetNumberOf("level1Product.calibration.calibrationConstant");
if(numberOfCalFactor == 1)
imd.Add(MDNum::CalFactor, MainXMLFileMetadataSupplier.GetAs<double>("level1Product.calibration.calibrationConstant.calFactor"));
else
{
std::stringstream path;
for (int layer = 1 ; layer <= numberOfCalFactor ; ++layer)
{
path.str("");
path << "level1Product.calibration.calibrationConstant_" << layer << ".calFactor";
imd.Add(MDNum::CalFactor, MainXMLFileMetadataSupplier.GetAs<double>(path.str()));
}
}
SARCalib sarCalib;
LoadRadiometricCalibrationData(sarCalib, MainXMLFileMetadataSupplier, imd);
imd.Add(MDGeom::SARCalib, sarCalib);
......
......@@ -45,33 +45,42 @@ void SarBrightnessToImageFilter<TInputImage, TOutputImage>::BeforeThreadedGenera
/** Retrieve the ImageMetadata */
auto imd = this->GetInput()->GetImageMetadata();
/** Fetch the SARCalib */
if (!imd.Has(MDGeom::SARCalib))
throw std::runtime_error("otbSarBrightnessToImageFilter was not able to fetch the SARCalib metadata.");
auto sarCalib = boost::any_cast<SARCalib>(imd[MDGeom::SARCalib]);
std::unique_ptr<SARCalib> sarCalibPtr;
if (imd.Has(MDGeom::SARCalib))
{
sarCalibPtr = std::make_unique<SARCalib>(boost::any_cast<SARCalib>(imd[MDGeom::SARCalib]));
}
else if ((imd.Bands.size() > 0) && imd.Bands[0].Has(MDGeom::SARCalib))
{
sarCalibPtr = std::make_unique<SARCalib>(boost::any_cast<SARCalib>(imd.Bands[0][MDGeom::SARCalib]));
}
else
throw std::runtime_error("otbSarBrightnessToImageFilter was not able to fetch the SARCalib metadata.");
FunctionPointer function = this->GetFunction();
function->SetScale(imd[MDNum::CalScale]);
ParametricFunctionPointer noise = function->GetNoise();
noise->SetPointSet(sarCalib.radiometricCalibrationNoise);
noise->SetPolynomalSize(sarCalib.radiometricCalibrationNoisePolynomialDegree);
noise->SetPointSet(sarCalibPtr->radiometricCalibrationNoise);
noise->SetPolynomalSize(sarCalibPtr->radiometricCalibrationNoisePolynomialDegree);
noise->EvaluateParametricCoefficient();
ParametricFunctionPointer antennaPatternNewGain = function->GetAntennaPatternNewGain();
antennaPatternNewGain->SetPointSet(sarCalib.radiometricCalibrationAntennaPatternNewGain);
antennaPatternNewGain->SetPolynomalSize(sarCalib.radiometricCalibrationAntennaPatternNewGainPolynomialDegree);
antennaPatternNewGain->SetPointSet(sarCalibPtr->radiometricCalibrationAntennaPatternNewGain);
antennaPatternNewGain->SetPolynomalSize(sarCalibPtr->radiometricCalibrationAntennaPatternNewGainPolynomialDegree);
antennaPatternNewGain->EvaluateParametricCoefficient();
ParametricFunctionPointer antennaPatternOldGain = function->GetAntennaPatternOldGain();
antennaPatternOldGain->SetPointSet(sarCalib.radiometricCalibrationAntennaPatternOldGain);
antennaPatternOldGain->SetPolynomalSize(sarCalib.radiometricCalibrationAntennaPatternOldGainPolynomialDegree);
antennaPatternOldGain->SetPointSet(sarCalibPtr->radiometricCalibrationAntennaPatternOldGain);
antennaPatternOldGain->SetPolynomalSize(sarCalibPtr->radiometricCalibrationAntennaPatternOldGainPolynomialDegree);
antennaPatternOldGain->EvaluateParametricCoefficient();
ParametricFunctionPointer rangeSpreadLoss = function->GetRangeSpreadLoss();
rangeSpreadLoss->SetPointSet(sarCalib.radiometricCalibrationRangeSpreadLoss);
rangeSpreadLoss->SetPolynomalSize(sarCalib.radiometricCalibrationRangeSpreadLossPolynomialDegree);
rangeSpreadLoss->SetPointSet(sarCalibPtr->radiometricCalibrationRangeSpreadLoss);
rangeSpreadLoss->SetPolynomalSize(sarCalibPtr->radiometricCalibrationRangeSpreadLossPolynomialDegree);
rangeSpreadLoss->EvaluateParametricCoefficient();
#if 0
......
......@@ -68,10 +68,19 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
/** Retrieve the ImageMetadata */
auto imd = this->GetInput()->GetImageMetadata();
/** Fetch the SARModel */
if (!imd.Has(MDGeom::SARCalib))
throw std::runtime_error("otbSarRadiometricCalibrationTiImageFilter was not able to fetch the SARCalib metadata.");
auto sarCalib = boost::any_cast<SARCalib>(imd[MDGeom::SARCalib]);
/** Fetch the SARCalib */
std::unique_ptr<SARCalib> sarCalibPtr;
if (imd.Has(MDGeom::SARCalib))
{
sarCalibPtr = std::make_unique<SARCalib>(boost::any_cast<SARCalib>(imd[MDGeom::SARCalib]));
}
else if ((imd.Bands.size() > 0) && imd.Bands[0].Has(MDGeom::SARCalib))
{
sarCalibPtr = std::make_unique<SARCalib>(boost::any_cast<SARCalib>(imd.Bands[0][MDGeom::SARCalib]));
}
else
throw std::runtime_error("otbSarRadiometricCalibrationTiImageFilter was not able to fetch the SARCalib metadata.");
/** Get the SarRadiometricCalibrationFunction function instance. */
FunctionPointer function = this->GetFunction();
......@@ -82,7 +91,7 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
* depends on the given product.*
* B. The other value such as antenna pattern gain, rangespread loss, incidence
* angle has no effect in calibration */
bool apply = sarCalib.calibrationLookupFlag;
bool apply = sarCalibPtr->calibrationLookupFlag;
/* Below lines will toggle the necessary flags which can help skip some
* computation. For example, if there is lookup value and ofcourse antenna
......@@ -107,8 +116,8 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
{
ParametricFunctionPointer noise;
noise = function->GetNoise();
noise->SetPointSet(sarCalib.radiometricCalibrationNoise);
noise->SetPolynomalSize(sarCalib.radiometricCalibrationNoisePolynomialDegree);
noise->SetPointSet(sarCalibPtr->radiometricCalibrationNoise);
noise->SetPolynomalSize(sarCalibPtr->radiometricCalibrationNoisePolynomialDegree);
noise->EvaluateParametricCoefficient();
}
......@@ -117,14 +126,14 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
{
ParametricFunctionPointer antennaPatternNewGain;
antennaPatternNewGain = function->GetAntennaPatternNewGain();
antennaPatternNewGain->SetPointSet(sarCalib.radiometricCalibrationAntennaPatternNewGain);
antennaPatternNewGain->SetPolynomalSize(sarCalib.radiometricCalibrationAntennaPatternNewGainPolynomialDegree);
antennaPatternNewGain->SetPointSet(sarCalibPtr->radiometricCalibrationAntennaPatternNewGain);
antennaPatternNewGain->SetPolynomalSize(sarCalibPtr->radiometricCalibrationAntennaPatternNewGainPolynomialDegree);
antennaPatternNewGain->EvaluateParametricCoefficient();
ParametricFunctionPointer antennaPatternOldGain;
antennaPatternOldGain = function->GetAntennaPatternOldGain();
antennaPatternOldGain->SetPointSet(sarCalib.radiometricCalibrationAntennaPatternOldGain);
antennaPatternOldGain->SetPolynomalSize(sarCalib.radiometricCalibrationAntennaPatternOldGainPolynomialDegree);
antennaPatternOldGain->SetPointSet(sarCalibPtr->radiometricCalibrationAntennaPatternOldGain);
antennaPatternOldGain->SetPolynomalSize(sarCalibPtr->radiometricCalibrationAntennaPatternOldGainPolynomialDegree);
antennaPatternOldGain->EvaluateParametricCoefficient();
}
......@@ -133,8 +142,8 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
{
ParametricFunctionPointer incidenceAngle;
incidenceAngle = function->GetIncidenceAngle();
incidenceAngle->SetPointSet(sarCalib.radiometricCalibrationIncidenceAngle);
incidenceAngle->SetPolynomalSize(sarCalib.radiometricCalibrationIncidenceAnglePolynomialDegree);
incidenceAngle->SetPointSet(sarCalibPtr->radiometricCalibrationIncidenceAngle);
incidenceAngle->SetPolynomalSize(sarCalibPtr->radiometricCalibrationIncidenceAnglePolynomialDegree);
incidenceAngle->EvaluateParametricCoefficient();
}
......@@ -143,8 +152,8 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
{
ParametricFunctionPointer rangeSpreadLoss;
rangeSpreadLoss = function->GetRangeSpreadLoss();
rangeSpreadLoss->SetPointSet(sarCalib.radiometricCalibrationRangeSpreadLoss);
rangeSpreadLoss->SetPolynomalSize(sarCalib.radiometricCalibrationRangeSpreadLossPolynomialDegree);
rangeSpreadLoss->SetPointSet(sarCalibPtr->radiometricCalibrationRangeSpreadLoss);
rangeSpreadLoss->SetPolynomalSize(sarCalibPtr->radiometricCalibrationRangeSpreadLossPolynomialDegree);
rangeSpreadLoss->EvaluateParametricCoefficient();
}
......@@ -159,13 +168,13 @@ void SarRadiometricCalibrationToImageFilter<TInputImage, TOutputImage>::BeforeTh
*/
if (function->GetApplyLookupDataCorrection())
{
function->SetCalibrationLookupData(sarCalib.calibrationLookupData[this->GetLookupSelected()]);
function->SetCalibrationLookupData(sarCalibPtr->calibrationLookupData[this->GetLookupSelected()]);
}
/** This was introduced for cosmoskymed which required a rescaling factor */
if (function->GetApplyRescalingFactor())
{
function->SetRescalingFactor(sarCalib.rescalingFactor);
function->SetRescalingFactor(sarCalibPtr->rescalingFactor);
}
}
......
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