Commit f86c3894 authored by Thibaut ROMAIN's avatar Thibaut ROMAIN

REFAC: Change default behavior for reading gain and bias, we read DIMAP values...

REFAC: Change default behavior for reading gain and bias, we read DIMAP values by default, hard-coded tables values instead
parent 5fd52eb0
Pipeline #7025 canceled with stages
in 3 minutes and 44 seconds
......@@ -413,9 +413,9 @@ private:
<< "\tAcquisition Viewing Elevation Angle: " << metadata[MDNum::SatElevation] << std::endl
<< "\tAcquisition Viewing Azimuth Angle: " << metadata[MDNum::SatAzimuth] << std::endl;
// The Gain and Bias are read in the GetImageMetadata, we will display in DoExecute what gain and bias the user finally chose,
// but for now we have gain and bias values from hard-coded tables in MTD, so we can disable the parameter and use those values as default
// The user is able to enable it by giving a txt file or "dimap" as a parameter of acqui.gainbias
// The Gain and Bias are read in the GetImageMetadata, we will display in DoExecute what gain and bias the user finally chose.
// For now we have gain and bias values from dimap if available, else from hard-coded tables in MTD, so we can disable the parameter and use those values as default
// The user is able to enable it by giving a txt file containing its own values (-acqui.gainbias PathToTxtFile)
DisableParameter("acqui.gainbias");
MandatoryOff("acqui.gainbias");
......@@ -645,111 +645,73 @@ private:
// Set Gain and Bias to corresponding filters
if (IsParameterEnabled("acqui.gainbias") && HasValue("acqui.gainbias"))
{
std::string gainbiasParam = GetParameterString("acqui.gainbias");
// Try to retrieve information from file provided by user
std::string filename(GetParameterString("acqui.gainbias"));
//If the user wants to use dimap gain and biases
if (gainbiasParam.compare("dimap") == 0)
std::ifstream file(filename, std::ios::in);
if (file)
{
if (metadata.Has("DIMAP_Gain"))
std::string line;
unsigned int numLine = 0;
while (getline(file, line))
{
itk::VariableLengthVector<double> vlvectorGain;
std::vector<double> values;
std::string errormsg;
// clean line
std::string::size_type startPos = line.find_first_not_of(std::string(" \t\n\r"));
if (startPos == std::string::npos)
continue;
otb::Utils::ConvertStringToVector(metadata["DIMAP_Gain"],values,errormsg," ");
if(!errormsg.empty())
line = line.substr(startPos);
if (line[0] != '#')
{
otbAppLogWARNING("An error occured while parsing DIMAP Gain values : " << errormsg);
}
vlvectorGain.SetData(values.data(), values.size(), false);
m_ImageToRadianceFilter->SetAlpha(vlvectorGain);
m_RadianceToImageFilter->SetAlpha(vlvectorGain);
otbAppLogINFO("Using Acquisition gain from DIMAP (per band): " << vlvectorGain);
m_ImageToRadianceFilter->SetBeta(metadata.GetAsVector(MDNum::PhysicalBias));
m_RadianceToImageFilter->SetBeta(metadata.GetAsVector(MDNum::PhysicalBias));
otbAppLogINFO("Using Acquisition biases from DIMAP (per band): " << metadata.GetAsVector(MDNum::PhysicalBias));
}
else
{
itkExceptionMacro("Gain and Bias values from DIMAP could not be read, ensure the DIMAP file contains Band_Radiance.GAIN and BIAS")
}
}
else
{
// Try to retrieve information from file provided by user
std::string filename(gainbiasParam);
numLine++;
std::vector<double> values;
std::istringstream iss(line);
std::string value;
double dvalue;
while (getline(iss, value, ':'))
{
std::istringstream iss2(value);
iss2 >> dvalue;
values.push_back(dvalue);
}
std::ifstream file(filename, std::ios::in);
if (file)
{
std::string line;
unsigned int numLine = 0;
while (getline(file, line))
{
// clean line
std::string::size_type startPos = line.find_first_not_of(std::string(" \t\n\r"));
if (startPos == std::string::npos)
continue;
itk::VariableLengthVector<double> vlvector;
vlvector.SetData(values.data(), values.size(), false);
line = line.substr(startPos);
if (line[0] != '#')
switch (numLine)
{
numLine++;
std::vector<double> values;
std::istringstream iss(line);
std::string value;
double dvalue;
while (getline(iss, value, ':'))
{
std::istringstream iss2(value);
iss2 >> dvalue;
values.push_back(dvalue);
}
itk::VariableLengthVector<double> vlvector;
vlvector.SetData(values.data(), values.size(), false);
switch (numLine)
{
case 1:
m_ImageToRadianceFilter->SetAlpha(vlvector);
m_RadianceToImageFilter->SetAlpha(vlvector);
otbAppLogINFO("Using Acquisition gain from file (per band): " << vlvector);
break;
case 2:
m_ImageToRadianceFilter->SetBeta(vlvector);
m_RadianceToImageFilter->SetBeta(vlvector);
otbAppLogINFO("Using Acquisition biases from file (per band): " << vlvector);
break;
default:
itkExceptionMacro(<< "File : " << filename << " contains wrong number of lines (needs two, one for gains and one for biases)");
}
case 1:
m_ImageToRadianceFilter->SetAlpha(vlvector);
m_RadianceToImageFilter->SetAlpha(vlvector);
otbAppLogINFO("Using Acquisition gain from the user file (per band): " << vlvector);
break;
case 2:
m_ImageToRadianceFilter->SetBeta(vlvector);
m_RadianceToImageFilter->SetBeta(vlvector);
otbAppLogINFO("Using Acquisition biases from the user file (per band): " << vlvector);
break;
default:
itkExceptionMacro(<< "File : " << filename << " contains wrong number of lines (needs two, one for gains and one for biases)");
}
}
file.close();
}
else
itkExceptionMacro(<< "File : " << filename << " couldn't be opened");
file.close();
}
else
itkExceptionMacro(<< "File : " << filename << " couldn't be opened");
}
else
{
// Try to retrieve information from image metadata (hard-coded tables from CNES calibration team)
// Try to retrieve information from image metadata (either DIMAP if available, or hard-coded tables)
if (hasOpticalSensorMetadata)
{
auto vlvector = metadata.GetAsVector(MDNum::PhysicalGain);
otbAppLogINFO("Using Acquisition gain from image metadata (per band): " << vlvector);
vlvector = metadata.GetAsVector(MDNum::PhysicalBias);
otbAppLogINFO("Using Acquisition bias from image metadata (per band): " << vlvector);
otbAppLogINFO("Using Acquisition gain from image metadata (per band): " << metadata.GetAsVector(MDNum::PhysicalGain));
m_ImageToRadianceFilter->SetAlpha(metadata.GetAsVector(MDNum::PhysicalGain));
m_RadianceToImageFilter->SetAlpha(metadata.GetAsVector(MDNum::PhysicalGain));
otbAppLogINFO("Using Acquisition bias from image metadata (per band): " << metadata.GetAsVector(MDNum::PhysicalBias));
m_ImageToRadianceFilter->SetBeta(metadata.GetAsVector(MDNum::PhysicalBias));
m_RadianceToImageFilter->SetBeta(metadata.GetAsVector(MDNum::PhysicalBias));
}
......
......@@ -347,12 +347,13 @@ public:
ParseVector(mds, "IMD/Geometric_Data.Use_Area.Located_Geometric_Values",
"Acquisition_Angles.AZIMUTH_ANGLE", m_Data.AzimuthAngle);
std::vector<double> gainbiasUnavail={};
ParseVector(mds, "IMD/Radiometric_Data.Radiometric_Calibration.Instrument_Calibration.Band_Measurement_List.Band_Radiance",
"BIAS", m_Data.PhysicalBias);
"BIAS", m_Data.PhysicalBias,gainbiasUnavail);
ParseVector(mds, "IMD/Radiometric_Data.Radiometric_Calibration.Instrument_Calibration.Band_Measurement_List.Band_Radiance",
"GAIN", m_Data.PhysicalGain);
"GAIN", m_Data.PhysicalGain,gainbiasUnavail);
ParseVector(mds, "IMD/Radiometric_Data.Radiometric_Calibration.Instrument_Calibration.Band_Measurement_List.Band_Solar_Irradiance",
"VALUE" , m_Data.SolarIrradiance);
......
......@@ -1890,7 +1890,7 @@ void PleiadesImageMetadataInterface::FetchTabulatedPhysicalGain(const MetaData::
bandNameToPhysicalGain = { {"P", 11.52},
{"B0", 8.96}, {"B1", 9.01}, {"B2", 10.09}, {"B3", 15.31}};
}
// From 01/10/2019 to nowadays
// From 01/01/2020 to nowadays
else
{
bandNameToPhysicalGain = { {"P", 11.49},
......@@ -2381,22 +2381,21 @@ void PleiadesImageMetadataInterface::Parse(const MetadataSupplierInterface & mds
FetchSolarIrradiance(dimapData.SolarIrradiance);
//Store hard-coded values for gain
FetchTabulatedPhysicalGain(m_Imd[MDTime::ProductionDate]);
//Store gain values from the dimap
//Store gain values from the dimap, if present
if (dimapData.PhysicalGain.size() == m_Imd.Bands.size())
{
auto gain = dimapData.PhysicalGain.begin();
std::stringstream ssGain;
while(gain != dimapData.PhysicalGain.end())
for (auto & band: m_Imd.Bands)
{
ssGain << *gain;
gain++;
if(gain != dimapData.PhysicalGain.end())
ssGain << " ";
band.Add(MDNum::PhysicalGain, *gain);
gain++;
}
m_Imd.Add("DIMAP_Gain",ssGain.str());
}
else
{
//Store hard-coded values for gain
FetchTabulatedPhysicalGain(m_Imd[MDTime::ProductionDate]);
otbLogMacro(Info, << "Gain values from DIMAP could not be retrieved, reading hard-coded tables instead");
}
FetchSpectralSensitivity(m_Imd[MDStr::SensorID]);
......@@ -2412,8 +2411,12 @@ void PleiadesImageMetadataInterface::Parse(const MetadataSupplierInterface & mds
}
else
{
otbGenericExceptionMacro(MissingMetadataException,
<< "The number of bands in image metadatas is incoherent with the DIMAP product")
//Default Bias value
for (auto & band: m_Imd.Bands)
{
band.Add(MDNum::PhysicalBias, 0.0);
}
otbLogMacro(Info, << "Bias values from DIMAP could not be retrieved, reading default values instead");
}
}
......
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