Skip to content

Commit

Permalink
Merge pull request #33 from mattias42/mattias/custom-spectrometer-off…
Browse files Browse the repository at this point in the history
…set-range

Custom spectrometer offset range + conversion to std::vector
  • Loading branch information
mattias42 authored Nov 11, 2024
2 parents e852918 + e0d8e7c commit db0cab1
Show file tree
Hide file tree
Showing 25 changed files with 866 additions and 419 deletions.
8 changes: 4 additions & 4 deletions UnitTests/IntegrationTests_DoasFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ TEST_CASE("DoasFit - IntegrationTest with good scan - scan file 1", "[DoasFit][I
// Change the settings to use HP500 filtering and make sure to filter the references
// (but keep the unit in molec/cm2 as this makes it possible to have the same values in the assertions here as in the test above).
so2FitWindow.fitType = FIT_TYPE::FIT_HP_DIV;
for (size_t refIdx = 0; refIdx < so2FitWindow.nRef; ++refIdx)
for (size_t refIdx = 0; refIdx < so2FitWindow.reference.size(); ++refIdx)
{
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, CrossSectionUnit::cm2_molecule);
HighPassFilter(*so2FitWindow.reference[refIdx].m_data, CrossSectionUnit::cm2_molecule);
}

// Setup the DOAS Fit
Expand Down Expand Up @@ -119,9 +119,9 @@ TEST_CASE("DoasFit - IntegrationTest with good scan - scan file 1", "[DoasFit][I
// Change the settings to use HP500 filtering and make sure to filter the references
// (but keep the unit in molec/cm2 as this makes it possible to have the same values in the assertions here as in the test above).
so2FitWindow.fitType = FIT_TYPE::FIT_HP_SUB;
for (size_t refIdx = 0; refIdx < so2FitWindow.nRef; ++refIdx)
for (size_t refIdx = 0; refIdx < so2FitWindow.reference.size(); ++refIdx)
{
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, novac::CrossSectionUnit::cm2_molecule);
HighPassFilter(*so2FitWindow.reference[refIdx].m_data, novac::CrossSectionUnit::cm2_molecule);
}

// Setup the DOAS Fit
Expand Down
29 changes: 14 additions & 15 deletions UnitTests/IntegrationTests_EvaluationBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ static CFitWindow PrepareFitWindow()
window.fitLow = 475;
window.fitHigh = 643;
window.fitType = novac::FIT_TYPE::FIT_HP_DIV;
window.nRef = (int)references.size();
int refIdx = 0;
window.reference.reserve(references.size());
for (auto& reference : references)
{
window.ref[refIdx].m_path = reference;
window.ref[refIdx].m_columnOption = novac::SHIFT_TYPE::SHIFT_FREE;
window.ref[refIdx].m_shiftOption = novac::SHIFT_TYPE::SHIFT_FIX;
window.ref[refIdx].m_shiftValue = 0.0;
window.ref[refIdx].m_squeezeOption = novac::SHIFT_TYPE::SHIFT_FIX;
window.ref[refIdx].m_squeezeValue = 1.0;

window.ref[refIdx].ReadCrossSectionDataFromFile();

++refIdx;
CReferenceFile ref;
ref.m_path = reference;
ref.m_columnOption = novac::SHIFT_TYPE::SHIFT_FREE;
ref.m_shiftOption = novac::SHIFT_TYPE::SHIFT_FIX;
ref.m_shiftValue = 0.0;
ref.m_squeezeOption = novac::SHIFT_TYPE::SHIFT_FIX;
ref.m_squeezeValue = 1.0;
ref.ReadCrossSectionDataFromFile();

window.reference.push_back(ref);
}

return window;
Expand Down Expand Up @@ -92,7 +91,7 @@ TEST_CASE("Evaluate Avaspec spectrum number eight in scan", "[Evaluate][Evaluati
// Assert
REQUIRE(returnCode == 0);

REQUIRE(window.nRef == sut.m_result.m_referenceResult.size());
REQUIRE(window.reference.size() == sut.m_result.m_referenceResult.size());

REQUIRE(sut.m_result.m_delta == Approx(0.0752).margin(0.001));
REQUIRE(sut.m_result.m_chiSquare == Approx(0.0119).margin(0.001));
Expand Down Expand Up @@ -145,7 +144,7 @@ TEST_CASE("Evaluate Avaspec spectrum number 21 in scan", "[Evaluate][EvaluationB
// Assert
REQUIRE(returnCode == 0);

REQUIRE(window.nRef == sut.m_result.m_referenceResult.size());
REQUIRE(window.reference.size() == sut.m_result.m_referenceResult.size());

REQUIRE(sut.m_result.m_delta == Approx(0.0429).margin(0.001));
REQUIRE(sut.m_result.m_chiSquare == Approx(0.0066).margin(0.001));
Expand Down Expand Up @@ -177,7 +176,7 @@ TEST_CASE("EvaluateShift Avaspec spectrum number 28 in scan", "[Evaluate][Evalua
novac::LogContext context;

CFitWindow window = PrepareFitWindow();
window.UV = 0; // Avaspec and the UV option are not great together
window.offsetRemovalRange = novac::IndexRange(2, 20);
window.fraunhoferRef.m_path = TestData::GetSyntheticFraunhoferSpectrumName_2009175M1();
window.fraunhoferRef.ReadCrossSectionDataFromFile();
novac::HighPassFilter_Ring(*window.fraunhoferRef.m_data); // filter the fraunhofer reference, to match the other references.
Expand Down
49 changes: 25 additions & 24 deletions UnitTests/IntegrationTests_FitWindowFileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace novac
{
TEST_CASE("FitWindowFileHandler can read .nfw file for SO2 from the NovacProgram", "[FitWindowFileHandler][IntegrationTest]")
{
{
const std::string& filename = TestData::GetBrORatioFitWindowFileSO2();

CFitWindowFileHandler sut;
Expand All @@ -28,22 +28,23 @@ TEST_CASE("FitWindowFileHandler can read .nfw file for SO2 from the NovacProgram
REQUIRE(result.front().specLength == 2048);

REQUIRE(result.front().findOptimalShift == 0);
REQUIRE(result.front().UV == 1);
REQUIRE(result.front().offsetRemovalRange.from == 50);
REQUIRE(result.front().offsetRemovalRange.to == 200);
REQUIRE(result.front().shiftSky == 0);
REQUIRE(result.front().interlaceStep == 1);

REQUIRE(result.front().fraunhoferRef.m_path == "../TestData/BrORatio/D2J2124_SolarSpec_Master.txt");

// finally the references
REQUIRE(result.front().nRef == 2);
REQUIRE(result.front().ref[0].m_specieName == "SO2");
REQUIRE(result.front().ref[0].m_path == "../TestData/BrORatio/D2J2124_SO2_Bogumil_293K_Master.txt");
REQUIRE(result.front().ref[1].m_specieName == "O3");
REQUIRE(result.front().ref[1].m_path == "../TestData/BrORatio/D2J2124_O3_Voigt_223K_Master.txt");
}
REQUIRE(result.front().reference.size() == 2);
REQUIRE(result.front().reference[0].m_specieName == "SO2");
REQUIRE(result.front().reference[0].m_path == "../TestData/BrORatio/D2J2124_SO2_Bogumil_293K_Master.txt");
REQUIRE(result.front().reference[1].m_specieName == "O3");
REQUIRE(result.front().reference[1].m_path == "../TestData/BrORatio/D2J2124_O3_Voigt_223K_Master.txt");
}

TEST_CASE("FitWindowFileHandler can read .nfw file for BrO from the NovacProgram", "[FitWindowFileHandler][IntegrationTest]")
{
{
const std::string& filename = TestData::GetBrORatioFitWindowFileBrO();

CFitWindowFileHandler sut;
Expand All @@ -65,24 +66,25 @@ TEST_CASE("FitWindowFileHandler can read .nfw file for BrO from the NovacProgram
REQUIRE(result.front().specLength == 2048);

REQUIRE(result.front().findOptimalShift == 0);
REQUIRE(result.front().UV == 1);
REQUIRE(result.front().offsetRemovalRange.from == 50);
REQUIRE(result.front().offsetRemovalRange.to == 200);
REQUIRE(result.front().shiftSky == 0);
REQUIRE(result.front().interlaceStep == 1);

REQUIRE(result.front().fraunhoferRef.m_path == "../TestData/BrORatio/D2J2124_SolarSpec_Master.txt");

// finally the references
REQUIRE(result.front().nRef == 3);
REQUIRE(result.front().ref[0].m_specieName == "BrO");
REQUIRE(result.front().ref[0].m_path == "../TestData/BrORatio/D2J2124_BrO_Fleischmann_298K.txt");
REQUIRE(result.front().ref[1].m_specieName == "SO2");
REQUIRE(result.front().ref[1].m_path == "../TestData/BrORatio/D2J2124_SO2_Bogumil_293K_Master.txt");
REQUIRE(result.front().ref[2].m_specieName == "O3");
REQUIRE(result.front().ref[2].m_path == "../TestData/BrORatio/D2J2124_O3_Voigt_223K_Master.txt");
}
REQUIRE(result.front().reference.size() == 3);
REQUIRE(result.front().reference[0].m_specieName == "BrO");
REQUIRE(result.front().reference[0].m_path == "../TestData/BrORatio/D2J2124_BrO_Fleischmann_298K.txt");
REQUIRE(result.front().reference[1].m_specieName == "SO2");
REQUIRE(result.front().reference[1].m_path == "../TestData/BrORatio/D2J2124_SO2_Bogumil_293K_Master.txt");
REQUIRE(result.front().reference[2].m_specieName == "O3");
REQUIRE(result.front().reference[2].m_path == "../TestData/BrORatio/D2J2124_O3_Voigt_223K_Master.txt");
}

TEST_CASE("FitWindowFileHandler can read back one saved fit window", "[FitWindowFileHandler][IntegrationTest]")
{
{
const std::string filename = TestData::GetTemporaryFitWindowFileName();

// Setup a fit-window to write to file. Add some odd values here such that we know we're not getting defaults back
Expand All @@ -102,8 +104,8 @@ TEST_CASE("FitWindowFileHandler can read back one saved fit window", "[FitWindow
originalWindow.skyShift = 3.141;
originalWindow.skySqueeze = 0.98765;
originalWindow.specLength = 1234;
originalWindow.UV = 0;
originalWindow.nRef = 6;
originalWindow.offsetRemovalRange = IndexRange(4, 73);
originalWindow.reference.resize(6);

// Act: save the fit window to file and then read it back again.
CFitWindowFileHandler sut;
Expand All @@ -127,7 +129,6 @@ TEST_CASE("FitWindowFileHandler can read back one saved fit window", "[FitWindow
REQUIRE(originalWindow.skyShift == readBackWindow.front().skyShift);
REQUIRE(originalWindow.skySqueeze == readBackWindow.front().skySqueeze);
REQUIRE(originalWindow.specLength == readBackWindow.front().specLength);
REQUIRE(originalWindow.UV == readBackWindow.front().UV);

}
REQUIRE(originalWindow.offsetRemovalRange == readBackWindow.front().offsetRemovalRange);
}
}
Loading

0 comments on commit db0cab1

Please sign in to comment.