Skip to content

Commit

Permalink
Merge pull request #89 from aglowacki/master
Browse files Browse the repository at this point in the history
Added function to load fit params from csv
  • Loading branch information
aglowacki authored Aug 16, 2024
2 parents 444d39f + aad4b84 commit 88d73da
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 36 deletions.
5 changes: 0 additions & 5 deletions src/gstar/Annotation/ScanRegionGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ void ScanRegionGraphicsItem::onScanUpdated(const BlueskyPlan& plan)
setPropertyValue(DEF_STR_DISPLAY_NAME, _scan_dialog.getScanName());
BlueskyPlan nplan = plan;
nplan.name = _scan_dialog.getScanName();
BlueskyParam meta_data;
meta_data.name = "md";
meta_data.default_val = nplan.name;
meta_data.description = "Link to scan name";
nplan.parameters["md"] = meta_data;
emit scanUpdated(nplan);

}
Expand Down
66 changes: 57 additions & 9 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,34 @@ class BlueskyComm : public QThread

item["name"] = plan.type;
item["item_type"] = "plan";

QJsonObject meta;
meta["name"] = plan.name;
item["meta"] = meta;
QJsonArray args;
QJsonObject kwargs;
for(auto itr: plan.parameters)
{
kwargs[itr.first] = itr.second.default_val;
if(itr.second.name == "detectors")
{
QJsonArray inner_args; // need this for bluesky or it doesn't work
QStringList sarr = itr.second.default_val.split(",");
for(auto sitr : sarr)
{
inner_args.append(QJsonValue::fromVariant(sitr));
}
args.append(inner_args);
}
else if(itr.second.kind == BlueskyParamType::String && itr.second.default_val.length() > 0)
{
kwargs[itr.first] = itr.second.default_val;
}
else if(itr.second.kind == BlueskyParamType::Numeral && itr.second.default_val.length() > 0)
{
kwargs[itr.first] = QJsonValue::fromVariant(itr.second.default_val.toDouble());
}
}
item["kwargs"] = kwargs;

item["args"] = args;
return item;
}

Expand Down Expand Up @@ -349,13 +369,35 @@ class BlueskyComm : public QThread
plans[pobj["name"].toString()].parameters[param["name"].toString()].name = param["name"].toString();
if(param.contains("default"))
{
plans[pobj["name"].toString()].parameters[param["name"].toString()].default_val = param["default"].toString();
if(param["default"].toString() != "None")
{
plans[pobj["name"].toString()].parameters[param["name"].toString()].default_val = param["default"].toString();
}
}
if(param.contains("description"))
{
plans[pobj["name"].toString()].parameters[param["name"].toString()].description = param["description"].toString();
}
}
if(param.contains("kind"))
{
QJsonObject kind = param["kind"].toObject();
if(kind.contains("value"))
{
int tval = kind["value"].toInt();
switch (tval)
{
case 1:
plans[pobj["name"].toString()].parameters[param["name"].toString()].kind = BlueskyParamType::Numeral;
break;
case 3:
plans[pobj["name"].toString()].parameters[param["name"].toString()].kind = BlueskyParamType::String;
break;
default:
break;
}
}
}
}
}
}
Expand Down Expand Up @@ -437,16 +479,20 @@ class BlueskyComm : public QThread
bsp.name = pitr;
bsp.default_val = kwargs[pitr].toString();
plan.parameters[pitr] = bsp;
if(pitr == "md") // use meta data to link to scan name
{
plan.name = bsp.default_val;
}
}
}
if(param.contains("user"))
{
plan.user = param["user"].toString();
}
if(param.contains("meta"))
{
QJsonObject meta = param["meta"].toObject();
if(meta.contains("name"))
{
plan.name = meta["name"].toString();
}
}
if(param.contains("item_uid"))
{
plan.uuid = param["item_uid"].toString();
Expand Down Expand Up @@ -533,7 +579,9 @@ public slots:
QJsonObject rootJson = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(rootJson.contains("msg"))
{
emit newData(rootJson["msg"].toString());
QString msg = rootJson["msg"].toString();
msg.chop(1);
emit newData(msg);
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion src/mvc/BlueskyPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@

#include <unordered_map>

enum class BlueskyParamType { Numeral = 1, String = 3 };


//---------------------------------------------------------------------------
struct BlueskyParam
{
BlueskyParam()
{
default_val = "0.0";
default_val = "";
}
QString name;
QString description;
QString default_val;
BlueskyParamType kind;
};

//---------------------------------------------------------------------------
Expand Down
19 changes: 15 additions & 4 deletions src/mvc/FitParamsTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*---------------------------------------------------------------------------*/

#include "FitParamsTableModel.h"
#include "fitting/models/gaussian_model.h"
#include <QColor>

//---------------------------------------------------------------------------
Expand All @@ -18,7 +17,7 @@ FitParamsTableModel::FitParamsTableModel(QObject* parent) : QAbstractTableModel(
m_headers[BOUND_TYPE] = tr("Is Fixed");
m_headers[MIN_VAL] = tr("Min Value");
m_headers[MAX_VAL] = tr("Max Value");
m_headers[STEP_SIZE] = tr("Step Size");
//m_headers[STEP_SIZE] = tr("Step Size");
_editable = true;
_optimizer_supports_min_max = false;

Expand Down Expand Up @@ -54,6 +53,16 @@ int FitParamsTableModel::columnCount(const QModelIndex &parent) const

//---------------------------------------------------------------------------

void FitParamsTableModel::setOptimizerPreset(fitting::models::Fit_Params_Preset preset)
{
fitting::models::Gaussian_Model<double> gmodel;
gmodel.update_fit_params_values(&_fit_parameters);
gmodel.set_fit_params_preset(preset);
updateFitParams(&gmodel.fit_parameters());
}

//---------------------------------------------------------------------------

void FitParamsTableModel::setOptimizerSupportsMinMax(bool val)
{
_optimizer_supports_min_max = val;
Expand All @@ -65,7 +74,7 @@ void FitParamsTableModel::setOptimizerSupportsMinMax(bool val)

//---------------------------------------------------------------------------

void FitParamsTableModel::updateFitParams(data_struct::Fit_Parameters<double>* fit_params)
void FitParamsTableModel::updateFitParams(const data_struct::Fit_Parameters<double>* fit_params)
{
if(fit_params != nullptr)
{
Expand Down Expand Up @@ -157,7 +166,7 @@ QVariant FitParamsTableModel::data(const QModelIndex &index, int role) const
else if (index.column() == VALUE) return fitp.value;
else if (index.column() == MIN_VAL) return fitp.min_val;
else if (index.column() == MAX_VAL) return fitp.max_val;
else if (index.column() == STEP_SIZE) return fitp.step_size;
// else if (index.column() == STEP_SIZE) return fitp.step_size;
else if (index.column() == BOUND_TYPE)
{
if (_optimizer_supports_min_max)
Expand Down Expand Up @@ -403,13 +412,15 @@ bool FitParamsTableModel::setData(const QModelIndex &index,
else
return false;
}
/*
else if (column == STEP_SIZE)
{
if(ok)
_fit_parameters[fitp_name].step_size = dval;
else
return false;
}
*/
else if (column == BOUND_TYPE)
{
_fit_parameters[fitp_name].bound_type = (data_struct::E_Bound_Type)value.toInt();
Expand Down
7 changes: 5 additions & 2 deletions src/mvc/FitParamsTableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QModelIndex>
#include <QVariant>
#include "data_struct/fit_parameters.h"
#include "fitting/models/gaussian_model.h"


//---------------------------------------------------------------------------
Expand All @@ -36,7 +37,7 @@ class FitParamsTableModel
BOUND_TYPE,
MIN_VAL,
MAX_VAL,
STEP_SIZE,
//STEP_SIZE,
NUM_PROPS
};

Expand All @@ -49,9 +50,11 @@ class FitParamsTableModel

void setOptimizerSupportsMinMax(bool val);

void setOptimizerPreset(fitting::models::Fit_Params_Preset preset);

void setFitParams(data_struct::Fit_Parameters<double> fit_params);

void updateFitParams(data_struct::Fit_Parameters<double>* fit_params);
void updateFitParams(const data_struct::Fit_Parameters<double>* fit_params);

void only_keep_these_keys(data_struct::Fit_Parameters<double> fit_params);

Expand Down
Loading

0 comments on commit 88d73da

Please sign in to comment.