36 : map<string, double>(),
63 : map<string, double>(other),
105 map<string, double>::operator=(other);
151 const map<string, element_information>* element_info,
152 bool keep_isotope_bases)
const
155 if (element_info ==
nullptr) {
170 std::set<string> isotope_bases;
171 if (keep_isotope_bases)
172 for (
const auto& [
name, info] : *element_info)
174 isotope_bases.insert(info.base_element);
177 for (
const auto& element_entry : *
this) {
178 const string& element_name = element_entry.first;
179 const double concentration = element_entry.second;
182 auto info_iter = element_info->find(element_name);
183 if (info_iter == element_info->end()) {
195 isotope_bases.count(element_name) > 0;
197 if (should_include) {
199 filtered_profile[element_name] = concentration;
209 return filtered_profile;
259 bool exclude_elements,
260 bool apply_corrections,
261 const vector<double>& reference_om_size,
263 const map<string, element_information>* element_info)
const
269 if (apply_corrections) {
270 if (regression_models ==
nullptr) {
272 std::cerr <<
"Warning: apply_corrections=true but regression_models is null. "
273 <<
"Skipping corrections." << std::endl;
285 if (exclude_elements) {
286 if (element_info ==
nullptr) {
288 std::cerr <<
"Warning: exclude_elements=true but element_info is null. "
289 <<
"Skipping filtering." << std::endl;
349 const map<string, element_information>* element_info,
350 bool include_isotopes)
const
353 if (element_info ==
nullptr) {
356 std::cerr <<
"Error: ExtractChemicalElements called with null element_info. "
357 <<
"Returning empty profile." << std::endl;
364 for (
const auto& [element_name, concentration] : *
this) {
367 auto info_iter = element_info->find(element_name);
368 if (info_iter == element_info->end()) {
378 bool should_include =
false;
382 should_include =
true;
386 should_include = include_isotopes;
390 if (should_include) {
391 extracted_profile[element_name] = concentration;
395 return extracted_profile;
440 const vector<string>& element_names)
const
448 for (
const string& element_name : element_names) {
450 auto it = find(element_name);
453 extracted_profile[element_name] = it->second;
458 return extracted_profile;
470 auto it = find(element_name);
472 throw std::out_of_range(
473 "Element '" + element_name +
"' does not exist in profile"
504 auto it = find(element_name);
527 if (find(element_name) == end()) {
545 if (find(element_name) == end()) {
572 if (find(element_name) != end()) {
576 (*this)[element_name] = value;
595 vector<double> values;
596 values.reserve(size());
598 for (
const auto& [element_name, concentration] : *
this) {
599 values.push_back(concentration);
621 for (
const auto& [element_name, concentration] : *
this) {
622 output += element_name +
":" + aquiutils::numbertostring(concentration) +
"\n";
652 QTableWidget* table =
new QTableWidget();
653 table->setEditTriggers(QAbstractItemView::NoEditTriggers);
654 table->setColumnCount(1);
655 table->setRowCount(size());
658 QStringList element_names;
661 for (
const auto& [element_name, concentration] : *
this) {
662 element_names << QString::fromStdString(element_name);
663 table->setItem(row, 0,
new QTableWidgetItem(QString::number(concentration)));
668 table->item(row, 0)->setForeground(QColor(Qt::red));
675 table->setHorizontalHeaderLabels(headers);
676 table->setVerticalHeaderLabels(element_names);
694 QJsonObject json_object;
695 QJsonObject element_contents;
699 for (
const auto& [element_name, concentration] : *
this) {
700 element_contents[QString::fromStdString(element_name)] = concentration;
703 json_object[
"Element Contents"] = element_contents;
737 auto read_values = [&](
const QJsonObject& values,
bool skip_labels) {
738 for (
const QString& key : values.keys()) {
739 if (skip_labels && (key ==
"XAxisLabel" || key ==
"YAxisLabel"))
744 error = QStringLiteral(
"constituent '%1': %2").arg(key, reason);
747 (*this)[key.toStdString()] = value;
752 if (json_object.contains(
"Include")) {
756 if (!read_values(json_object[
"Element Contents"].toObject(),
false))
761 if (!read_values(json_object,
true))
765 if (json_object.contains(
"XAxisLabel")) {
769 if (json_object.contains(
"YAxisLabel")) {
795 for (
const QString& line : string_list) {
796 QStringList parts = line.split(
":");
797 if (parts.size() > 1) {
822 file->write(QString::fromStdString(
ToString()).toUtf8());
841 double max_value = -1e12;
842 for (
const auto& [element_name, concentration] : *
this) {
843 if (concentration > max_value) {
844 max_value = concentration;
866 double min_value = 1e12;
867 for (
const auto& [element_name, concentration] : *
this) {
868 if (concentration < min_value) {
869 min_value = concentration;
883 vector<string> names;
884 names.reserve(size());
886 for (
const auto& [element_name, concentration] : *
this) {
887 names.push_back(element_name);
901 return (find(element_name) != end());
921 const vector<double>& reference_om_size,
923 const map<string, element_information>* element_info)
const
927 for (
const auto& [element_name, concentration] : *
this) {
936 corrected_profile[element_name] = concentration;
941 corrected_profile[element_name] = concentration;
944 if (regression_models->count(element_name) == 0) {
949 const auto& var_names =
mlr->GetIndependentVariableNames();
950 const auto& coefficients =
mlr->CoefficientsIntercept();
954 if (
mlr->Effective(0) && var_names[0] != element_name) {
955 double reference = reference_om_size[0];
956 double measured = this->at(var_names[0]);
959 corrected_profile[element_name] += (reference - measured) * coefficients[1];
962 corrected_profile[element_name] *= pow(reference / measured, coefficients[1]);
967 if (var_names.size() > 1 &&
mlr->Effective(1) && var_names[1] != element_name) {
968 double reference = reference_om_size[1];
969 double measured = this->at(var_names[1]);
972 corrected_profile[element_name] += (reference - measured) * coefficients[2];
975 corrected_profile[element_name] *= pow(reference / measured, coefficients[2]);
980 if (corrected_profile[element_name] < 0 &&
982 std::cerr <<
"Warning: Corrected value for " << element_name
983 <<
" is negative: " << corrected_profile[element_name] << std::endl;
987 return corrected_profile;
1007 if (size() != weights.getsize()) {
1014 for (
const auto& [element_name, concentration] : *
this) {
1015 sum += concentration * weights[index];
1037 vector<string> processed_elements;
1039 for (
size_t i = 0; i < size(); i++) {
1040 double target_value = ascending ? 1e6 : -1e6;
1041 string target_element;
1043 for (
const auto& [element_name, concentration] : *
this) {
1045 if (lookup(processed_elements, element_name) != -1) {
1050 bool is_better = ascending ? (concentration < target_value)
1051 : (concentration > target_value);
1054 target_element = element_name;
1055 target_value = concentration;
1059 processed_elements.push_back(target_element);
1060 sorted_result.
append(target_element, target_value);
1063 return sorted_result;
1081 vector<string> top_elements;
1083 for (
int i = 0; i < n && i < sorted.num; i++) {
1084 top_elements.push_back(sorted.
Label(i));
1087 return top_elements;
Vector class with string labels for Chemical Mass Balance analysis.
void append(const string &label, const double &val)
Appends a labeled element to the vector.
string Label(int i) const
Gets label at specified index.
Elemental_Profile & operator=(const Elemental_Profile &other)
Copy assignment operator.
Elemental_Profile ExtractChemicalElements(const map< string, element_information > *elementinfo, bool include_isotopes=false) const
Extract chemical elements only (exclude isotopes, metadata).
Elemental_Profile ExtractElements(const vector< string > &element_names) const
Extract subset of specified elements.
Elemental_Profile ApplyOrganicMatterAndSizeCorrections(const vector< double > &reference_om_size, const MultipleLinearRegressionSet *regression_models, const map< string, element_information > *elementinfo=nullptr) const
Apply organic matter and particle size corrections.
bool IsMarked(const string &name) const
Check if element is marked.
map< string, bool > marked_elements_
Map tracking marked elements for quality control.
double GetMaximum() const
Get maximum concentration value.
vector< string > GetElementNames() const
Get list of all element names.
double CalculateDotProduct(const CMBVector &weights) const
Calculate dot product with weight vector.
CMBVector SortByConcentration(bool ascending=true) const
Sort elements by concentration value.
bool included_in_analysis_
Whether profile should be included in analysis.
double GetMinimum() const
Get minimum concentration value.
vector< double > GetAllValues() const
Get all concentration values as vector.
bool SetMarked(const string &name, bool marked)
Set marked status for an element.
QTableWidget * ToTable() override
Create Qt table widget representation.
Elemental_Profile CreateAnalysisProfile(const map< string, element_information > *elementinfo=nullptr, bool keep_isotope_bases=false) const
Create profile with only analyzed elements.
void SetIncludedInAnalysis(bool included)
Set analysis inclusion status.
Elemental_Profile CreateCorrectedProfile(bool exclude_elements, bool apply_corrections, const vector< double > &reference_om_size, const MultipleLinearRegressionSet *regression_models=nullptr, const map< string, element_information > *elementinfo=nullptr) const
Create corrected profile with filtering and corrections.
bool AppendElement(const string &name, double val=0.0)
Add new element to profile.
double GetValue(const string &name) const
Get element concentration by name.
vector< string > SelectTopElements(int n, bool ascending=true) const
Select top N elements by concentration.
Elemental_Profile()
Default constructor - creates empty profile.
string ToString() const override
Convert profile to string representation.
bool writetofile(QFile *file) override
Write profile to file.
bool ReadFromJsonObject(const QJsonObject &json) override
Deserialize from JSON object.
QJsonObject toJsonObject() const override
Serialize to JSON object.
bool IsIncludedInAnalysis() const
Check if profile is included in analysis.
bool SetValue(const string &name, double val)
Set concentration value for existing element.
bool Read(const QStringList &string_list) override
Read profile from string list.
bool Contains(const string &name) const
Check if element exists in profile.
double lowlimit
Lower threshold for value highlighting (when enabled).
Interface()
Default constructor.
Interface & operator=(const Interface &intf)
Assignment operator.
QString XAxisLabel() const
Get the X-axis label.
bool SetXAxisLabel(const QString &label)
Set the X-axis label.
QString YAxisLabel() const
Get the Y-axis label.
bool highlightoutsideoflimit
Flag indicating whether to highlight values outside defined limits.
bool SetYAxisLabel(const QString &label)
Set the Y-axis label.
double highlimit
Upper threshold for value highlighting (when enabled).
Elemental concentration profile for sediment source fingerprinting.
bool parseNumericJson(const QJsonValue &value, double &out, QString &error)
Parses a project-file value as a finite number.
bool parseNumericCell(const QString &text, double &out, QString &error)
Parses text as a finite number.
The one place where data values entering SedSAT3 are checked.