Skip to content

Commit

Permalink
Merge pull request #86 from kuanshi/master
Browse files Browse the repository at this point in the history
kz - USGS seismic disagg. in EVENTS and minor patch for Existing PEER
  • Loading branch information
fmckenna authored Jan 19, 2022
2 parents 8798fa9 + a2430d4 commit 62f96fd
Show file tree
Hide file tree
Showing 8 changed files with 785 additions and 6 deletions.
108 changes: 105 additions & 3 deletions EVENTS/ExistingPEER_Records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PeerRecord::PeerRecord(RandomVariablesContainer *theRV_IW, QWidget *parent)

layout->addWidget(button);
layout->addWidget(labelFile);
layout->addWidget(file, 1.0);
layout->addWidget(file,1);
layout->addWidget(chooseFile);
layout->addWidget(labelDirn);
layout->addWidget(dirn);
Expand Down Expand Up @@ -166,7 +166,7 @@ PeerEvent::PeerEvent(RandomVariablesContainer *theRV_IW, QWidget *parent)
//theName->setReadOnly(true);

layout->addWidget(button);
layout->addWidget(theName);
layout->addWidget(theName,1);

// QVBox Holding Peer Records, could be multiple
recordLayout = new QVBoxLayout();
Expand All @@ -188,7 +188,7 @@ PeerEvent::PeerEvent(RandomVariablesContainer *theRV_IW, QWidget *parent)
theRecords.append(theRecord);
// connect(theRecord,SIGNAL(removeRecord()), this, SLOT(onRemoveRecord()));

layout->addLayout(recordLayout, 1.0);
layout->addLayout(recordLayout, 5);


//this->setLayout(layout)
Expand Down Expand Up @@ -445,6 +445,13 @@ void ExistingPEER_Records::loadEventsFromDir(void) {

} else {

QString recordsCsv(directory.filePath("_SearchResults.csv"));
QFileInfo checkCsvFile(recordsCsv);
if (checkCsvFile.exists() && checkCsvFile.isFile()) {
this->parseSearchResults(directory.filePath("_SearchResults.csv"));
return;
}

QStringList fileList= directory.entryList(QStringList() << "*.AT2",QDir::Files);
foreach(QString fileName, fileList) {

Expand Down Expand Up @@ -595,4 +602,99 @@ ExistingPEER_Records::copyFiles(QString &dirName) {
return true;
}

void ExistingPEER_Records::parseSearchResults(QString searchResultsFilePath)
{
QFile searchResultsFile(searchResultsFilePath);
if(!searchResultsFile.exists())
return;

if(!searchResultsFile.open(QFile::ReadOnly))
return;

QFileInfo fileInfo(searchResultsFile.fileName());
QDir recordDir(fileInfo.dir());

QTextStream searchResultsStream(&searchResultsFile);
while (!searchResultsStream.atEnd())
{
QString line = searchResultsStream.readLine();

//Parsing selected records information
if(line.contains("Metadata of Selected Records"))
{
//skip header
searchResultsStream.readLine();
line = searchResultsStream.readLine();

while(!line.isEmpty())
{
auto values = line.split(',');
qDebug() << values;
if (values[0].isEmpty()) {
break;
}
PeerEvent *theEvent = new PeerEvent(theRandVariableIW); // new PEER event
QString Ordination = values[1].trimmed();
double ScaleFactor = values[4].toDouble();
QString Horizontal1File = values[19].trimmed();
QString Horizontal2File = values[20].trimmed();
QString VerticalFile = values[21].trimmed();
QString EventName(Horizontal1File);
EventName.chop(4); // remove ".AT"
EventName.chop(3); // remove direction key (last three
theEvent->theName->setText(EventName);

if (Ordination.compare("H1")==0 || Ordination.compare("H2")==0) {
// single horizontal component
PeerRecord *theRecord = theEvent->theRecords.at(0);
if (theRecord != NULL) {
if (Ordination.compare("H1")==0)
theRecord->file->setText(recordDir.filePath(Horizontal1File));
else
theRecord->file->setText(recordDir.filePath(Horizontal2File));
theRecord->factor->setText(QString::number(ScaleFactor));
theRecord->dirn->setValue(1);
}
} else {
// single vertical component
if (Ordination.compare("V")==0) {
PeerRecord *theRecord = theEvent->theRecords.at(0);
if (theRecord != NULL) {
theRecord->file->setText(recordDir.filePath(VerticalFile));
theRecord->factor->setText(QString::number(ScaleFactor));
theRecord->dirn->setValue(3);
}
} else {
// 2d horizontal components
PeerRecord *Record1 = theEvent->theRecords.at(0);
if (Record1 != NULL) {
Record1->file->setText(recordDir.filePath(Horizontal1File));
Record1->factor->setText(QString::number(ScaleFactor));
Record1->dirn->setValue(1);
}
PeerRecord *Record2 = new PeerRecord(theRandVariableIW);
theEvent->recordLayout->addWidget(Record2);
theEvent->theRecords.append(Record2);
Record2 = theEvent->theRecords.at(1);
if (Record2 != NULL) {
Record2->file->setText(recordDir.filePath(Horizontal2File));
Record2->factor->setText(QString::number(ScaleFactor));
Record2->dirn->setValue(2);
}
}
}
theEvents.append(theEvent);
eventLayout->insertWidget(eventLayout->count()-1, theEvent);

line = searchResultsStream.readLine();
qDebug() << line;
}
}
}

searchResultsFile.close();
qDebug() << "searchResultsFile closed.";

return;
}

4 changes: 2 additions & 2 deletions EVENTS/ExistingPEER_Records.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public slots:
void removeEvents(void);
void clear(void);
void loadEventsFromDir(void);

void parseSearchResults(QString searchResultsFilePath);

private:
QVBoxLayout *verticalLayout;
QVBoxLayout *eventLayout;

QVector<PeerEvent *>theEvents;
RandomVariablesContainer *theRandVariableIW;
RandomVariablesContainer *theRandVariableIW;
};

#endif // EXISTING_PEER_RECORDS_H
77 changes: 77 additions & 0 deletions EVENTS/groundMotionModel/BakerJayaram2008.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* *****************************************************************************
Copyright (c) 2016-2017, The Regents of the University of California (Regents).
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS
PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*************************************************************************** */

// Written: kuanshi

#include "math.h"
#include <algorithm>
#define PI 3.14159265

double BakerJayaram2008(double T1, double T2) {

// min and max periods
double Tmin = std::min(T1,T2);
double Tmax = std::max(T1,T2);

// coefficients
double C1 = (1.0-cos(PI/2.0)-0.366*log(Tmax/std::max(Tmin,0.109)));
double C2 = 1000.0;
if (Tmax < 0.2) {
C2 = 1.0-0.105*(1.0-1.0/(1.0+exp(100.0*Tmax-5.0)))*(Tmax-Tmin)/(Tmax-0.0099);
}
double C3 = C1;
if (Tmax < 0.109) {
C3 = C2;
}
double C4 = C1+0.5*(sqrt(C3)-C3)*(1.0+cos(PI*Tmin/0.109));

// rho
double rho = C2;
if (Tmax > 0.109) {
if (Tmin > 0.109) {
rho = C1;
} else {
if (Tmax < 0.2) {
rho = std::min(C2,C4);
} else {
rho = C4;
}
}
}

// return
return rho;
}
44 changes: 44 additions & 0 deletions EVENTS/groundMotionModel/BakerJayaram2008.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef BAKER_JAYARAM_2008_H
#define BAKER_JAYARAM_2008_H

/* *****************************************************************************
Copyright (c) 2016-2017, The Regents of the University of California (Regents).
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS
PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*************************************************************************** */

// Written: kuanshi

double BakerJayaram2008(double T1, double T2);

#endif // BAKER_JAYARAM_2008_H
Loading

0 comments on commit 62f96fd

Please sign in to comment.