Skip to content

Commit

Permalink
Merge pull request #78 from jinyan1214/jzGMToolUpdate
Browse files Browse the repository at this point in the history
Adding PGV to EQ gen tool and addressed some feedbacks from symposium regarding the EQ event generation tool
  • Loading branch information
fmckenna authored Feb 29, 2024
2 parents 6a20d00 + cabe71d commit 2cdc33a
Show file tree
Hide file tree
Showing 13 changed files with 489 additions and 109 deletions.
22 changes: 22 additions & 0 deletions Events/UI/ConventionalScenarioWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ bool ConventionalScenarioWidget::LoadRupturesTable(QString pathToRuptureFile){
QJsonObject firstFeat = features[0].toObject();
QJsonObject firstProp = firstFeat["properties"].toObject();
QStringList keys = firstProp.keys();
// Reorder the keys:
int removed;
removed = keys.removeAll("MeanAnnualRate");
if (removed==1){
keys.prepend("MeanAnnualRate");
}
removed = keys.removeAll("Magnitude");
if (removed==1){
keys.prepend("Magnitude");
}
removed = keys.removeAll("Name");
if (removed==1){
keys.prepend("Name");
}
removed = keys.removeAll("Rupture");
if (removed==1){
keys.prepend("Rupture");
}
removed = keys.removeAll("Source");
if (removed==1){
keys.prepend("Source");
}
int index = 1; // rupture index starts from 1 to be consistent with QGIS attribute table
for (const QJsonValue& valueIt : features) {
QJsonObject feat = valueIt.toObject();
Expand Down
97 changes: 79 additions & 18 deletions Events/UI/GMPEWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,81 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QLabel>
#include <QStringListModel>

GMPEWidget::GMPEWidget(GMPE& gmpe, QWidget *parent): SimCenterAppWidget(parent), m_gmpe(gmpe)
GMPEWidget::GMPEWidget(GMPE& gmpe, QStringList* selectedIMTypes, QWidget *parent): SimCenterAppWidget(parent), m_gmpe(gmpe)
{
QVBoxLayout* layout = new QVBoxLayout(this);
gmpeGroupBox = new QGroupBox();
gmpeGroupBox->setTitle("Ground Motion Prediction Equation");
gmpeGroupBox->setTitle("Ground Motion Model");

const QStringList validType = this->m_gmpe.validTypes();


QHBoxLayout* formLayout = new QHBoxLayout(gmpeGroupBox);
m_typeBox = new SC_ComboBox("Type",validType);
QGridLayout* formLayout = new QGridLayout(gmpeGroupBox);
PGAtypeBox = new SC_ComboBox("Type",validType);
PGAtypeBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Maximum);
PGVtypeBox = new SC_ComboBox("Type",validType);
PGVtypeBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Maximum);
SAtypeBox = new SC_ComboBox("Type",validType);
SAtypeBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Maximum);

m_typeBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Maximum);
formLayout->addWidget(PGAtypeLabel,0, 0);
formLayout->addWidget(PGAtypeBox,0,1);

QLabel* typeLabel = new QLabel(tr("Type:"));
formLayout->addWidget(SAtypeLabel,1, 0);
formLayout->addWidget(SAtypeBox,1,1);

formLayout->addWidget(typeLabel);
formLayout->addWidget(m_typeBox);
formLayout->addWidget(PGVtypeLabel,2, 0);
formLayout->addWidget(PGVtypeBox,2,1);


toggleIMselection(selectedIMTypes);
_selectedIMTypes = selectedIMTypes;

layout->addWidget(gmpeGroupBox);


QStringListModel* typeModel = new QStringListModel(validType);
m_typeBox->setModel(typeModel);
m_typeBox->setCurrentIndex(validType.indexOf(m_gmpe.type()));
PGAtypeBox->setModel(typeModel);
PGAtypeBox->setCurrentIndex(validType.indexOf(m_gmpe.type()));
PGVtypeBox->setModel(typeModel);
PGVtypeBox->setCurrentIndex(validType.indexOf(m_gmpe.type()));
SAtypeBox->setModel(typeModel);
SAtypeBox->setCurrentIndex(validType.indexOf(m_gmpe.type()));
this->setupConnections();
}

void GMPEWidget::toggleIMselection(QStringList* selectedIMTypes){
PGAtypeLabel->hide();
PGAtypeBox->hide();
SAtypeLabel->hide();
SAtypeBox->hide();
PGVtypeLabel->hide();
PGVtypeBox->hide();
_selectedIMTypes = selectedIMTypes;
if (selectedIMTypes->contains("PGA")){
PGAtypeLabel->show();
PGAtypeBox->show();
}
if (selectedIMTypes->contains("SA")){
SAtypeLabel->show();
SAtypeBox->show();
}
if (selectedIMTypes->contains("PGV")){
PGVtypeLabel->show();
PGVtypeBox->show();
}
return;
}

void GMPEWidget::setupConnections()
{
connect(this->m_typeBox, &QComboBox::currentTextChanged,
connect(this->PGAtypeBox, &QComboBox::currentTextChanged,
&this->m_gmpe, &GMPE::setType);

connect(&this->m_gmpe, &GMPE::typeChanged,
this->m_typeBox, &QComboBox::setCurrentText);
this->PGAtypeBox, &QComboBox::setCurrentText);
}


Expand All @@ -93,8 +129,33 @@ bool GMPEWidget::inputFromJSON(QJsonObject& /*obj*/)

bool GMPEWidget::outputToJSON(QJsonObject& obj)
{
m_typeBox->outputToJSON(obj);

if (_selectedIMTypes->size()==1){
if (_selectedIMTypes->contains("PGA")){
PGAtypeBox->outputToJSON(obj);
}
if (_selectedIMTypes->contains("SA")){
SAtypeBox->outputToJSON(obj);
}
if (_selectedIMTypes->contains("PGV")){
PGVtypeBox->outputToJSON(obj);
}
} else {
if (_selectedIMTypes->contains("PGA")){
QJsonObject PGAgmpe;
PGAtypeBox->outputToJSON(PGAgmpe);
obj["PGA"] = PGAgmpe;
}
if (_selectedIMTypes->contains("SA")){
QJsonObject SAgmpe;
SAtypeBox->outputToJSON(SAgmpe);
obj["SA"] = SAgmpe;
}
if (_selectedIMTypes->contains("PGV")){
QJsonObject PGVgmpe;
PGVtypeBox->outputToJSON(PGVgmpe);
obj["PGV"] = PGVgmpe;
}
}
obj["Parameters"] = QJsonObject();

return true;
Expand All @@ -108,19 +169,19 @@ void GMPEWidget::handleAvailableGMPE(const QString sourceType)
{
// users are expected to upload a GMPE logic tree, so the GMPE
// widget needs to be hiden
m_typeBox->hide();
PGAtypeBox->hide();
gmpeGroupBox->hide();
this->setVisible(false);
}
else if (sourceType.compare("OpenQuake User-Specified")==0)
{
m_typeBox->hide();
PGAtypeBox->hide();
gmpeGroupBox->hide();
this->setVisible(false);
}
else
{
m_typeBox->show();
PGAtypeBox->show();
gmpeGroupBox->show();
this->setVisible(true);
}
Expand Down
16 changes: 13 additions & 3 deletions Events/UI/GMPEWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
// Written by: Stevan Gavrilovic

#include "SimCenterAppWidget.h"
#include <QLabel>

#include "GMPE.h"

Expand All @@ -49,7 +50,7 @@ class GMPEWidget : public SimCenterAppWidget
{
Q_OBJECT
public:
explicit GMPEWidget(GMPE& gmpe, QWidget *parent = nullptr);
explicit GMPEWidget(GMPE& gmpe, QStringList* selectedIMTypes, QWidget *parent = nullptr);

bool outputToJSON(QJsonObject& obj);
bool inputFromJSON(QJsonObject& obj);
Expand All @@ -58,11 +59,20 @@ class GMPEWidget : public SimCenterAppWidget

public slots:
void handleAvailableGMPE(const QString sourceType);

void toggleIMselection(QStringList* selectedIMTypes);
private:
GMPE& m_gmpe;

SC_ComboBox* m_typeBox = nullptr;
SC_ComboBox* PGAtypeBox = nullptr;
SC_ComboBox* PGVtypeBox = nullptr;
SC_ComboBox* SAtypeBox = nullptr;

QLabel* PGAtypeLabel = new QLabel(tr("PGA:"));
QLabel* SAtypeLabel = new QLabel(tr("SA:"));
QLabel* PGVtypeLabel = new QLabel(tr("PGV:"));

QStringList* _selectedIMTypes;


QGroupBox* gmpeGroupBox = nullptr;

Expand Down
11 changes: 8 additions & 3 deletions Events/UI/GMWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void GMWidget::setupConnections()
connect(&peerClient, &PeerNgaWest2Client::statusUpdated, this, [this](QString statusUpdate)
{
this->statusMessage(statusUpdate);
QApplication::processEvents();
});

//connect(m_settingButton, &QPushButton::clicked, this, &GMWidget::setAppConfig);
Expand Down Expand Up @@ -415,7 +416,7 @@ GMWidget::outputAppDataToJSON(QJsonObject &jsonObj) {

if(simulationComplete == false)
{
this->errorMessage("Earthquake Scenario Simulation is not completed - please click \"Run Hazard Simulation\"");
this->errorMessage("Earthquake Event Generation is not completed - please click \"Run Hazard Simulation\"");
return false;
}
QJsonObject appData;
Expand Down Expand Up @@ -661,10 +662,14 @@ void GMWidget::runHazardSimulation(void)
QJsonObject eventObj;

// get the spatial correlation, IM, and GMPEs
groundMotionModelsWidget->outputToJSON(eventObj);
if (!groundMotionModelsWidget->outputToJSON(eventObj)){
return;
}

// Get the database, scaling, and number of events per site
m_selectionWidget->outputToJSON(eventObj);
if (!m_selectionWidget->outputToJSON(eventObj)){
return;
}

// Some hardcoded things
eventObj["SaveIM"]=true;
Expand Down
64 changes: 56 additions & 8 deletions Events/UI/GroundMotionModelsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include <QVBoxLayout>
#include <QStackedWidget>
#include <QComboBox>
#include <QSet>
#include <QMessageBox>

GroundMotionModelsWidget::GroundMotionModelsWidget(QWidget *parent) : SimCenterAppWidget(parent)
{
auto mainLayout = new QVBoxLayout(this);

spatialCorrWidget = new SpatialCorrelationWidget();

m_gmpe = new GMPE(this);
m_gmpeWidget = new GMPEWidget(*this->m_gmpe);

m_intensityMeasure = new IntensityMeasure(this);
m_intensityMeasureWidget = new IntensityMeasureWidget(*this->m_intensityMeasure);

spatialCorrWidget = new SpatialCorrelationWidget(m_intensityMeasureWidget->getSelectedIMTypes());

m_gmpe = new GMPE(this);
m_gmpeWidget = new GMPEWidget(*this->m_gmpe, m_intensityMeasureWidget->getSelectedIMTypes());

// GMPE options (link between source type and GMPE options)
// connect(erfWidget->ruptureWidget(), SIGNAL(widgetTypeChanged(QString)),
// m_gmpeWidget, SLOT(handleAvailableGMPE(QString)));
Expand All @@ -76,6 +78,11 @@ GroundMotionModelsWidget::GroundMotionModelsWidget(QWidget *parent) : SimCenterA
mainLayout->addWidget(spatialCorrWidget);
mainLayout->addStretch(0);

connect(m_intensityMeasureWidget, &IntensityMeasureWidget::IMSelectionChanged,
m_gmpeWidget, &GMPEWidget::toggleIMselection);
connect(m_intensityMeasureWidget, &IntensityMeasureWidget::IMSelectionChanged,
spatialCorrWidget, &SpatialCorrelationWidget::toggleIMselection);

}


Expand All @@ -99,16 +106,20 @@ bool GroundMotionModelsWidget::inputFromJSON(QJsonObject& /*obj*/)

bool GroundMotionModelsWidget::outputToJSON(QJsonObject& obj)
{
QStringList* selectedIMtypes = m_intensityMeasureWidget->getSelectedIMTypes();
if (selectedIMtypes->size()==0){
errorMessage("Ground Motion Models: At least one intensity measure needs to be selected." );
return false;
}
bool vectorIM = selectedIMtypes->size()>1;

// Get the correlation model Json object
QJsonObject spatCorrObj;
if (!spatialCorrWidget->outputToJSON(spatCorrObj))
return false;


// Get the intensity measure Json object
QJsonObject IMObj;
if (!m_intensityMeasure->outputToJSON(IMObj))
if (!m_intensityMeasureWidget->outputToJSON(IMObj))
return false;


Expand All @@ -117,10 +128,47 @@ bool GroundMotionModelsWidget::outputToJSON(QJsonObject& obj)
return false;


if (vectorIM){
QSet<QString> intraEventCorrModels;
for(int i = 0; i < selectedIMtypes->size(); i++){
QString imType_i = selectedIMtypes->at(i);
QJsonObject gmpe_i = GMPEObj[imType_i].toObject();
GMPEObj.remove(imType_i);
QJsonObject spatCorr_i = spatCorrObj[imType_i].toObject();
spatCorrObj.remove(imType_i);
QJsonObject IMObj_i = IMObj[imType_i].toObject();
IMObj_i["GMPE"] = gmpe_i["Type"].toString();
IMObj_i["InterEventCorr"] = spatCorr_i["InterEventCorr"].toString();
IMObj_i["IntraEventCorr"] = spatCorr_i["IntraEventCorr"].toString();
IMObj[imType_i] = IMObj_i;
intraEventCorrModels.insert(spatCorr_i["IntraEventCorr"].toString());
}
if (intraEventCorrModels.size()>1){
QMessageBox msgBox;

msgBox.setText("Warning:\n"
"Different Intra-event Spatial Correlation models are selected, and the cross correlation of the intra-event residuals between Intensity Measures can not be captured.\n"
"Continue running?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);

auto res = msgBox.exec();

if(res != QMessageBox::Yes)
return false;
// errorMessage("Warning: The cross correlation of the intra-event residuals between Intensity Measures can not be captured if different intra-event spatial correlation models are chosen.");
}
GMPEObj.insert("Type", "Vector");
IMObj.insert("Type", "Vector");
spatCorrObj.insert("Type", "Vector");
}
obj.insert("CorrelationModel", spatCorrObj);
obj.insert("IntensityMeasure", IMObj);
obj.insert("GMPE", GMPEObj);

return true;
}

//void GroundMotionModelsWidget::addGMMforSA(bool SAenabled){

//}

2 changes: 2 additions & 0 deletions Events/UI/GroundMotionModelsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class GroundMotionModelsWidget : public SimCenterAppWidget
IntensityMeasure *intensityMeasure() const;

public slots:
// void addGMMforSA(bool SAenabled);
// void addGMMforPGV(bool PGVenabled);

private:

Expand Down
Loading

0 comments on commit 2cdc33a

Please sign in to comment.