Skip to content

Commit

Permalink
Minor xfit refactoring (#654)
Browse files Browse the repository at this point in the history
Move RemoveNegativeXsec to cc file outside class.
Improve xfit version check.
  • Loading branch information
olemke authored Aug 11, 2023
1 parent 04f7d34 commit 9526caf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/xml_io_compound_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1942,8 +1942,6 @@ void xml_read_from_stream(istream& is_xml,
}
xd.SetSpecies(species);

ARTS_USER_ERROR_IF(version != 2, "Only XsecRecord version 2 is supported")

xml_read_from_stream(is_xml, xd.FitMinPressures(), pbifs, verbosity);
xml_read_from_stream(is_xml, xd.FitMaxPressures(), pbifs, verbosity);
xml_read_from_stream(is_xml, xd.FitMinTemperatures(), pbifs, verbosity);
Expand Down
36 changes: 18 additions & 18 deletions src/xsec_fit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,32 @@
#include "interpolation.h"
#include "physics_funcs.h"


void RemoveNegativeXsec(Vector& xsec) {
Numeric sum_xsec{};
Numeric sum_xsec_non_negative{};
for (auto& x : xsec) {
sum_xsec += x;
if (x < 0.) x = 0.;
sum_xsec_non_negative += x;
}

if (sum_xsec > 0. && sum_xsec != sum_xsec_non_negative) {
xsec *= sum_xsec / sum_xsec_non_negative;
}
}

String XsecRecord::SpeciesName() const {
// The function species_name_from_species_index internally does an assertion
// that the species with this index really exists.
return Species::toShortName(mspecies);
}

void XsecRecord::SetVersion(const Index version) {
if (version != 2) {
ARTS_USER_ERROR("Invalid version, only 2 supported")
if (version != mversion) {
ARTS_USER_ERROR(
"Invalid version ", version, ", only version ", mversion, " supported")
}

mversion = version;
}

void XsecRecord::Extract(VectorView result,
Expand Down Expand Up @@ -186,20 +200,6 @@ void XsecRecord::CalcXsec(VectorView xsec,
// }
// }

void XsecRecord::RemoveNegativeXsec(VectorView xsec) const {
Numeric sum_xsec{};
Numeric sum_xsec_non_negative{};
for (auto& x : xsec) {
sum_xsec += x;
if (x < 0.) x = 0.;
sum_xsec_non_negative += x;
}

if (sum_xsec > 0. && sum_xsec != sum_xsec_non_negative) {
xsec *= sum_xsec / sum_xsec_non_negative;
}
}

/** Get the index in xsec_fit_data for the given species.
\param[in] xsec_fit_data Hitran Xsec data array
Expand Down
5 changes: 1 addition & 4 deletions src/xsec_fit.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,12 @@ class XsecRecord {
// Index dataset,
// Numeric pressure) const;

/** Remove negative cross sections and adjust integral */
void RemoveNegativeXsec(VectorView xsec) const;

static constexpr Index P00 = 0;
static constexpr Index P10 = 1;
static constexpr Index P01 = 2;
static constexpr Index P20 = 3;

Index mversion{2};
static constexpr Index mversion{2};
Species::Species mspecies;
/* VERSION 2 */
Vector mfitminpressures;
Expand Down

0 comments on commit 9526caf

Please sign in to comment.