Create profile containing only elements included in analysis.
Create profile containing only elements included in analysisFilters the profile based on element_information metadata, keeping only elements that should be included in statistical analysis. Excludes:
The marked status of elements is preserved in the filtered profile.
#include <iostream>
#include "Utilities.h"
#include <QStringList>
#include <QFile>
included_in_analysis_(true),
marked_elements_()
{
}
included_in_analysis_(other.included_in_analysis_),
marked_elements_(other.marked_elements_)
{
}
{
if (this == &other) {
return *this;
}
map<string, double>::operator=(other);
return *this;
}
const map<string, element_information>* element_info) const
{
if (element_info == nullptr) {
return *this;
}
for (const auto& element_entry : *this) {
const string& element_name = element_entry.first;
const double concentration = element_entry.second;
auto info_iter = element_info->find(element_name);
if (info_iter == element_info->end()) {
continue;
}
if (should_include) {
filtered_profile[element_name] = concentration;
}
}
}
return filtered_profile;
}
bool exclude_elements,
bool apply_corrections,
const vector<double>& reference_om_size,
const map<string, element_information>* element_info) const
{
if (apply_corrections) {
if (regression_models == nullptr) {
std::cerr << "Warning: apply_corrections=true but regression_models is null. "
<< "Skipping corrections." << std::endl;
}
else {
reference_om_size,
regression_models,
element_info
);
}
}
if (exclude_elements) {
if (element_info == nullptr) {
std::cerr << "Warning: exclude_elements=true but element_info is null. "
<< "Skipping filtering." << std::endl;
}
else {
}
}
return result;
}
const map<string, element_information>* element_info,
bool include_isotopes) const
{
if (element_info == nullptr) {
std::cerr << "Error: ExtractChemicalElements called with null element_info. "
<< "Returning empty profile." << std::endl;
}
for (const auto& [element_name, concentration] : *this) {
auto info_iter = element_info->find(element_name);
if (info_iter == element_info->end()) {
continue;
}
bool should_include = false;
should_include = true;
}
should_include = include_isotopes;
}
if (should_include) {
extracted_profile[element_name] = concentration;
}
}
return extracted_profile;
}
const vector<string>& element_names) const
{
for (const string& element_name : element_names) {
auto it = find(element_name);
if (it != end()) {
extracted_profile[element_name] = it->second;
}
}
return extracted_profile;
}
{
auto it = find(element_name);
if (it == end()) {
throw std::out_of_range(
"Element '" + element_name + "' does not exist in profile"
);
}
return it->second;
}
{
auto it = find(element_name);
if (it == end()) {
return false;
}
it->second = value;
return true;
}
{
if (find(element_name) == end()) {
return false;
}
return true;
}
{
if (find(element_name) == end()) {
return false;
}
}
{
if (find(element_name) != end()) {
return false;
}
(*this)[element_name] = value;
return true;
}
{
vector<double> values;
values.reserve(size());
for (const auto& [element_name, concentration] : *this) {
values.push_back(concentration);
}
return values;
}
{
string output;
for (const auto& [element_name, concentration] : *this) {
output += element_name + ":" + aquiutils::numbertostring(concentration) + "\n";
}
return output;
}
{
QTableWidget* table = new QTableWidget();
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setColumnCount(1);
table->setRowCount(size());
QStringList headers;
QStringList element_names;
int row = 0;
for (const auto& [element_name, concentration] : *this) {
element_names << QString::fromStdString(element_name);
table->setItem(row, 0, new QTableWidgetItem(QString::number(concentration)));
table->item(row, 0)->setForeground(QColor(Qt::red));
}
row++;
}
table->setHorizontalHeaderLabels(headers);
table->setVerticalHeaderLabels(element_names);
return table;
}
{
QJsonObject json_object;
QJsonObject element_contents;
for (const auto& [element_name, concentration] : *this) {
element_contents[QString::fromStdString(element_name)] = concentration;
}
json_object["Element Contents"] = element_contents;
return json_object;
}
{
clear();
if (json_object.contains("Include")) {
QJsonObject contents = json_object["Element Contents"].toObject();
for (const QString& key : contents.keys()) {
(*this)[key.toStdString()] = contents[key].toDouble();
}
}
else {
for (const QString& key : json_object.keys()) {
(*this)[key.toStdString()] = json_object[key].toDouble();
}
}
if (json_object.contains("XAxisLabel")) {
}
if (json_object.contains("YAxisLabel")) {
}
return true;
}
{
clear();
for (const QString& line : string_list) {
QStringList parts = line.split(":");
if (parts.size() > 1) {
}
}
return true;
}
{
file->write(QString::fromStdString(
ToString()).toUtf8());
return true;
}
{
if (empty()) {
return -1e12;
}
double max_value = -1e12;
for (const auto& [element_name, concentration] : *this) {
if (concentration > max_value) {
max_value = concentration;
}
}
return max_value;
}
{
if (empty()) {
return 1e12;
}
double min_value = 1e12;
for (const auto& [element_name, concentration] : *this) {
if (concentration < min_value) {
min_value = concentration;
}
}
return min_value;
}
{
vector<string> names;
names.reserve(size());
for (const auto& [element_name, concentration] : *this) {
names.push_back(element_name);
}
return names;
}
{
return (find(element_name) != end());
}
const vector<double>& reference_om_size,
const map<string, element_information>* element_info) const
{
for (const auto& [element_name, concentration] : *this) {
continue;
}
corrected_profile[element_name] = concentration;
if (regression_models->count(element_name) == 0) {
continue;
}
const auto& var_names =
mlr->GetIndependentVariableNames();
const auto& coefficients =
mlr->CoefficientsIntercept();
if (
mlr->Effective(0) && var_names[0] != element_name) {
double reference = reference_om_size[0];
double measured = this->at(var_names[0]);
if (is_linear) {
corrected_profile[element_name] += (reference - measured) * coefficients[1];
}
else {
corrected_profile[element_name] *= pow(reference / measured, coefficients[1]);
}
}
if (var_names.size() > 1 &&
mlr->Effective(1) && var_names[1] != element_name) {
double reference = reference_om_size[1];
double measured = this->at(var_names[1]);
if (is_linear) {
corrected_profile[element_name] += (reference - measured) * coefficients[2];
}
else {
corrected_profile[element_name] *= pow(reference / measured, coefficients[2]);
}
}
if (corrected_profile[element_name] < 0 &&
std::cerr << "Warning: Corrected value for " << element_name
<< " is negative: " << corrected_profile[element_name] << std::endl;
}
}
return corrected_profile;
}
{
if (size() != weights.getsize()) {
return -999;
}
double sum = 0.0;
int index = 0;
for (const auto& [element_name, concentration] : *this) {
sum += concentration * weights[index];
index++;
}
return sum;
}
{
vector<string> processed_elements;
for (size_t i = 0; i < size(); i++) {
double target_value = ascending ? 1e6 : -1e6;
string target_element;
for (const auto& [element_name, concentration] : *this) {
if (lookup(processed_elements, element_name) != -1) {
continue;
}
bool is_better = ascending ? (concentration < target_value)
: (concentration > target_value);
if (is_better) {
target_element = element_name;
target_value = concentration;
}
}
processed_elements.push_back(target_element);
sorted_result.
append(target_element, target_value);
}
return sorted_result;
}
{
vector<string> top_elements;
for (int i = 0; i < n && i < sorted.num; i++) {
top_elements.push_back(sorted.
Label(i));
}
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.
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.
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.
Abstract base class providing common serialization and visualization interface.
double lowlimit
Lower threshold for value highlighting (when enabled)
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.