Commit 86261af7 authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Implement CreateCalibrationLookupData for Radarsat2ImageMetadataInterface

parent 77583d2a
Pipeline #7440 failed with stages
in 92 minutes and 37 seconds
......@@ -75,6 +75,12 @@ public:
otbLogMacro(Error, << "GetNumberOf() not yet implemented in otbGeomMetadataSupplier");
}
/** If multiple keys have the same path, gives the position of the one with value value*/
unsigned int GetAttributId(std::string const& path, std::string const& value) const override
{
otbLogMacro(Error, << "GetAttributId() not yet implemented in otbGeomMetadataSupplier");
}
/**
* @brief Writes the content of the Geom file into a string
*
......
......@@ -78,6 +78,9 @@ public:
/** Get the number of keys starting with path */
virtual unsigned int GetNumberOf(std::string const& path) const = 0;
/** If multiple keys have the same path, gives the position of the one with value value*/
virtual unsigned int GetAttributId(std::string const& path, std::string const& value) const = 0;
};
// TODO : for complex types ...
......
......@@ -105,6 +105,9 @@ public:
/** Get the number of keys starting with path */
unsigned int GetNumberOf(std::string const& path) const override;
/** If multiple keys have the same path, gives the position of the one with value value*/
unsigned int GetAttributId(std::string const& path, std::string const& value) const override;
/**
* @brief Writes the content of the XML file into a string
*
......
......@@ -53,55 +53,64 @@ bool Radarsat2ImageMetadataInterface::CanRead() const
bool Radarsat2ImageMetadataInterface::HasCalibrationLookupDataFlag() const
{
itkExceptionMacro("HasCalibrationLookupDataFlag(mds) not yet implemented in Radarsat2ImageMetadataInterface"); // TODO
return true; // TODO
}
bool Radarsat2ImageMetadataInterface::CreateCalibrationLookupData(SARCalib&, const ImageMetadata&, const MetadataSupplierInterface&, const bool) const
bool Radarsat2ImageMetadataInterface::CreateCalibrationLookupData(SARCalib& sarCalib,
const ImageMetadata& imd,
const MetadataSupplierInterface& mds,
const bool geom) const
{
// std::string lut = "SigmaNought";
// switch (type)
// {
// case SarCalibrationLookupData::BETA:
// {
// lut = "BetaNought";
// }
// break;
// case SarCalibrationLookupData::GAMMA:
// {
// lut = "GammaNought";
// }
// break;
// case SarCalibrationLookupData::DN:
// {
// lut = "DN";
// }
// break;
// case SarCalibrationLookupData::SIGMA:
// default:
// {
// lut = "SigmaNought";
// }
// break;
// }
// const ImageKeywordlistType imageKeywordlist = this->GetImageKeywordlist();
// const std::string key = "referenceNoiseLevel[" + lut + "].gain";
// Radarsat2CalibrationLookupData::GainListType glist;
// int offset = 0;
// Utils::ConvertStringToVector(imageKeywordlist.GetMetadataByKey("referenceNoiseLevel[" + lut + "].gain"), glist, "referenceNoiseLevel[" + lut + "].gain");
// Utils::LexicalCast<int>(imageKeywordlist.GetMetadataByKey("referenceNoiseLevel[" + lut + "].offset"), "referenceNoiseLevel[" + lut + "].offset");
// Radarsat2CalibrationLookupData::Pointer sarLut;
// sarLut = Radarsat2CalibrationLookupData::New();
// sarLut->InitParameters(type, offset, glist);
// return static_cast<Radarsat2ImageMetadataInterface::LookupDataPointerType> (sarLut);
if(SarImageMetadataInterface::CreateCalibrationLookupData(sarCalib, imd, mds, geom))
return true;
int offset = 0;
std::ostringstream ossSigma;
std::ostringstream ossBeta;
std::ostringstream ossGamma;
if(geom)
{
ossSigma << "referenceNoiseLevel[SigmaNought].gain";
ossBeta << "referenceNoiseLevel[BetaNought].gain";
ossGamma << "referenceNoiseLevel[GammaNought].gain";
}
else
{
ossSigma << "product.sourceAttributes.radarParameters.referenceNoiseLevel_"
<< mds.GetAttributId("product.sourceAttributes.radarParameters.referenceNoiseLevel_#.incidenceAngleCorrection",
"Sigma Nought")
<< ".noiseLevelValues";
ossBeta << "product.sourceAttributes.radarParameters.referenceNoiseLevel_"
<< mds.GetAttributId("product.sourceAttributes.radarParameters.referenceNoiseLevel_#.incidenceAngleCorrection",
"Beta Nought")
<< ".noiseLevelValues";
ossGamma << "product.sourceAttributes.radarParameters.referenceNoiseLevel_"
<< mds.GetAttributId("product.sourceAttributes.radarParameters.referenceNoiseLevel_#.incidenceAngleCorrection",
"gamma")
<< ".noiseLevelValues";
}
Radarsat2CalibrationLookupData::Pointer sigmaSarLut = Radarsat2CalibrationLookupData::New();
auto glist = mds.GetAsVector<float>(ossSigma.str());
sigmaSarLut->InitParameters(SarCalibrationLookupData::SIGMA, offset, glist);
sarCalib.calibrationLookupData[SarCalibrationLookupData::SIGMA] = std::move(sigmaSarLut);
Radarsat2CalibrationLookupData::Pointer betaSarLut = Radarsat2CalibrationLookupData::New();
glist = mds.GetAsVector<float>(ossSigma.str());
betaSarLut->InitParameters(SarCalibrationLookupData::BETA, offset, glist);
sarCalib.calibrationLookupData[SarCalibrationLookupData::BETA] = std::move(betaSarLut);
Radarsat2CalibrationLookupData::Pointer gammaSarLut = Radarsat2CalibrationLookupData::New();
glist = mds.GetAsVector<float>(ossSigma.str());
gammaSarLut->InitParameters(SarCalibrationLookupData::GAMMA, offset, glist);
sarCalib.calibrationLookupData[SarCalibrationLookupData::GAMMA] = std::move(gammaSarLut);
Radarsat2CalibrationLookupData::Pointer dnSarLut = Radarsat2CalibrationLookupData::New();
sarCalib.calibrationLookupData[SarCalibrationLookupData::DN] = std::move(dnSarLut);
return true;
}
void Radarsat2ImageMetadataInterface::ParseDateTime(const char* key, std::vector<int>& dateFields) const
......@@ -292,7 +301,8 @@ void Radarsat2ImageMetadataInterface::ParseGdal(ImageMetadata & imd)
imd.Bands[bandId].Add(MDGeom::SAR, sarParam);
}
SARCalib sarCalib;
LoadRadiometricCalibrationData(sarCalib, *m_MetadataSupplierInterface, imd);
LoadRadiometricCalibrationData(sarCalib, ProductMS, imd);
CreateCalibrationLookupData(sarCalib, imd, ProductMS, false);
imd.Add(MDGeom::SARCalib, sarCalib);
}
}
......@@ -338,6 +348,7 @@ void Radarsat2ImageMetadataInterface::ParseGeom(ImageMetadata & imd)
}
SARCalib sarCalib;
LoadRadiometricCalibrationData(sarCalib, *m_MetadataSupplierInterface, imd);
CreateCalibrationLookupData(sarCalib, imd, *m_MetadataSupplierInterface, true);
imd.Add(MDGeom::SARCalib, sarCalib);
}
......
......@@ -166,9 +166,9 @@ bool Sentinel1ImageMetadataInterface::CreateCalibrationLookupData(SARCalib& sarC
sarCalib.calibrationLookupData[SarCalibrationLookupData::GAMMA] = gammaSarLut;
Sentinel1CalibrationLookupData::Pointer dnSarLut = Sentinel1CalibrationLookupData::New();
dnSarLut->InitParameters(SarCalibrationLookupData::SIGMA, firstLineTime.GetModifiedJulian(),
dnSarLut->InitParameters(SarCalibrationLookupData::DN, firstLineTime.GetModifiedJulian(),
lastLineTime.GetModifiedJulian(), numOfLines, count, dnCalibrationVectorList);
sarCalib.calibrationLookupData[SarCalibrationLookupData::SIGMA] = sigmaSarLut;
sarCalib.calibrationLookupData[SarCalibrationLookupData::DN] = dnSarLut;
return true;
}
......
......@@ -253,6 +253,31 @@ unsigned int XMLMetadataSupplier::GetNumberOf(std::string const & path) const
}
return idx.size();
}
unsigned int XMLMetadataSupplier::GetAttributId(std::string const& path, std::string const& value) const
{
// Search for the joker
std::size_t found = path.find("_#");
// Looking for the keys corresponding to the part of the path before the joker
std::vector<std::string> values = this->FetchPartialNameValueMultiple(m_MetadataDic, path.substr(0, found).c_str());
// Position of the beginning of the path after the joker
std::size_t start = found + 2;
// Looking for the keys corresponding to the part of the path after the joker
values = this->FetchPartialNameValueMultiple(values, path.substr(start));
if ((values.size() == 0) || (values[0].empty()))
return 0;
for(auto const& s: values)
{
auto val = s.substr(s.find('=') + 1);
if (val == value)
{
val = s.substr(found + 1, s.find(".", found) - found - 1);
return std::stoi(val);
}
}
return 0;
}
std::string XMLMetadataSupplier::PrintSelf() const
{
......
......@@ -226,6 +226,13 @@ public:
"GetNumberOf() not yet implemented in otbGDALImageIO");
}
/** If multiple keys have the same path, gives the position of the one with value value*/
unsigned int GetAttributId(std::string const& path, std::string const& value) const override
{
itkExceptionMacro(
"GetAttributId() not yet implemented in otbGDALImageIO");
}
protected:
/**
* Constructor.
......
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