Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More clear option on desired unit when filtering a reference. #24

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions UnitTests/IntegrationTests_DoasFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TEST_CASE("DoasFit - IntegrationTest with good scan - scan file 1", "[DoasFit][I
so2FitWindow.fitType = FIT_TYPE::FIT_HP_DIV;
for (int refIdx = 0; refIdx < so2FitWindow.nRef; ++refIdx)
{
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, false);
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, CrossSectionUnit::cm2_molecule);
}

// Setup the DOAS Fit
Expand Down Expand Up @@ -121,7 +121,7 @@ TEST_CASE("DoasFit - IntegrationTest with good scan - scan file 1", "[DoasFit][I
so2FitWindow.fitType = FIT_TYPE::FIT_HP_SUB;
for (int refIdx = 0; refIdx < so2FitWindow.nRef; ++refIdx)
{
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, false);
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, novac::CrossSectionUnit::cm2_molecule);
}

// Setup the DOAS Fit
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/IntegrationTests_RatioEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ TEST_CASE("RatioEvaluation - IntegrationTest with good scan - scan file 1", "[Ra
broFitWindow.fitType = FIT_TYPE::FIT_HP_DIV;
for (int refIdx = 0; refIdx < so2FitWindow.nRef; ++refIdx)
{
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, false);
HighPassFilter(*so2FitWindow.ref[refIdx].m_data, novac::CrossSectionUnit::cm2_molecule);
}
for (int refIdx = 0; refIdx < broFitWindow.nRef; ++refIdx)
{
HighPassFilter(*broFitWindow.ref[refIdx].m_data, false);
HighPassFilter(*broFitWindow.ref[refIdx].m_data, novac::CrossSectionUnit::cm2_molecule);
}

// Setup the sut
Expand Down
23 changes: 13 additions & 10 deletions include/SpectralEvaluation/Evaluation/CrossSectionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vector>
#include <string>
#include <SpectralEvaluation/Units.h>

namespace MathFit
{
Expand Down Expand Up @@ -83,21 +84,23 @@ class CCrossSectionData
int SaveToFile(const std::string& filename) const;
};

/** Performs a high-pass filtering of this cross section file.
This will:
1) multiply by 2.5e15
2) exponentiate the cross section
3) high-pass filter (binomial, 500 passes)
4) log the cross section and
5) divide by 2.5e15 (optional)
If 'scaleToPpmm' is true then the reference is mutliplied by 2.5e15 before the filtering and divide by the same number after. */
int HighPassFilter(CCrossSectionData& crossSection, bool scaleToPpmm = true);
// Performs a high-pass filtering of this cross section file.
// This will:
// 1) multiply by 2.5e15
// 2) exponentiate the cross section
// 3) high-pass filter (binomial, 500 passes)
// 4) log the cross section and
// 5) divide by 2.5e15 (optional)
// If is here assumed that the input cross section has a unit of cm2 / molecule.
// @param desiredOutputUnit if set to CrossSectionUnit::cm2_molecule then the reference is mutliplied by 2.5e15
// before the filtering and divide by the same number after. */
void HighPassFilter(CCrossSectionData& crossSection, CrossSectionUnit desiredOutputUnit);

/** Performs a high-pass filtering of a ring spectrum.
This will:
1) high-pass filter (binomial, 500 passes).
2) log the cross section. */
int HighPassFilter_Ring(CCrossSectionData& crossSection);
void HighPassFilter_Ring(CCrossSectionData& crossSection);

/** Multiplies this cross section with the given constant */
int Multiply(CCrossSectionData& crossSection, double scalar);
Expand Down
3 changes: 0 additions & 3 deletions include/SpectralEvaluation/Evaluation/FitWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ class CFitWindow
@throws novac::InvalidReferenceException if any of the references could not be read. */
void ReadReferences(CFitWindow& window);

/** Performs a high-pass filtering on all references which are not labelled as m_isFiltered. */
void HighPassFilterReferences(CFitWindow& window);

/** Performs a rescaling of all read in references to the unit of Molecules/cm2.
It is here assumed that any reference which is NOT filtered is in the unit of Molecules/cm2
and any reference which IS filtered is in the unit of PPMM. The reference will be scaled accordingly. */
Expand Down
1 change: 1 addition & 0 deletions include/SpectralEvaluation/Units.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace novac
{

/** Simple structure for remembering the scaling unit of a reference or absorption cross section */
enum class CrossSectionUnit
{
Expand Down
11 changes: 3 additions & 8 deletions src/Evaluation/CrossSectionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int CCrossSectionData::SaveToFile(const std::string& filename) const
return 0;
}

int HighPassFilter(CCrossSectionData& crossSection, bool scaleToPpmm)
void HighPassFilter(CCrossSectionData& crossSection, CrossSectionUnit desiredOutputUnit)
{
CBasicMath mathObject;

Expand All @@ -289,27 +289,22 @@ int HighPassFilter(CCrossSectionData& crossSection, bool scaleToPpmm)
mathObject.HighPassBinomial(crossSection.m_crossSection.data(), length, 500);
mathObject.Log(crossSection.m_crossSection.data(), length);

if (!scaleToPpmm)
if (desiredOutputUnit == CrossSectionUnit::cm2_molecule)
{
mathObject.Div(crossSection.m_crossSection.data(), length, ppmmScaleFactor);
}

return 0;
}

int HighPassFilter_Ring(CCrossSectionData& crossSection)
void HighPassFilter_Ring(CCrossSectionData& crossSection)
{
CBasicMath mathObject;

const int length = (int)crossSection.m_crossSection.size();

mathObject.HighPassBinomial(crossSection.m_crossSection.data(), length, 500);
mathObject.Log(crossSection.m_crossSection.data(), length);

return 0;
}


int Multiply(CCrossSectionData& crossSection, double scalar)
{
CBasicMath mathObject;
Expand Down
32 changes: 0 additions & 32 deletions src/Evaluation/FitWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,38 +169,6 @@ void ReadReferences(CFitWindow& window)
}
}

void HighPassFilterReferences(CFitWindow& window)
{
// If children are defined, then handle them as well
for (CFitWindow& c : window.child)
{
HighPassFilterReferences(c);
}

if (window.fitType != novac::FIT_TYPE::FIT_HP_DIV && window.fitType != novac::FIT_TYPE::FIT_HP_SUB)
{
return;
}

for (int referenceIndex = 0; referenceIndex < window.nRef; ++referenceIndex)
{
// Local handle for more convenient syntax.
CReferenceFile& thisReference = window.ref[referenceIndex];

if (!thisReference.m_isFiltered)
{
if (EqualsIgnoringCase(thisReference.m_specieName, "ring"))
{
HighPassFilter_Ring(*thisReference.m_data);
}
else
{
HighPassFilter(*thisReference.m_data);
}
}
}
}

void ScaleReferencesToMolecCm2(CFitWindow& window)
{
// If children are defined, then handle them as well
Expand Down
Loading