Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MLa variants with amplitude prefilters #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/magnitudes/mla/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ SET(PLUGIN_TARGET mla)
SET(
PLUGIN_SOURCES
mla.cpp
variants.cpp
)
SET(
PLUGIN_HEADERS
mla.h
variants.h
)

SC_ADD_PLUGIN_LIBRARY(PLUGIN ${PLUGIN_TARGET} "")
Expand Down
50 changes: 41 additions & 9 deletions plugins/magnitudes/mla/mla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ ADD_SC_PLUGIN(
( "MLa magnitude. Calculates magnitude based on universal formulae "
"MLa=c0_log10(Amp)+c1*log10(delta*c3+c4)+c5*(delta+c6), "
"where coefficients c1...6 vary based on epicentral location."),
"Geoscience Australia", 0, 0, 2);
"Geoscience Australia", 0, 0, 2)

// Register the amplitude processor.
IMPLEMENT_SC_CLASS_DERIVED(Amplitude_MLA, AmplitudeProcessor, "AmplitudeProcessor_MLA");
IMPLEMENT_SC_CLASS_DERIVED(Amplitude_MLA, AmplitudeProcessor, "Amplitude_MLA");
REGISTER_AMPLITUDEPROCESSOR(Amplitude_MLA, GA_ML_AUS_AMP_TYPE);

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand All @@ -39,19 +39,47 @@ REGISTER_AMPLITUDEPROCESSOR(Amplitude_MLA, GA_ML_AUS_AMP_TYPE);
Amplitude_MLA::Amplitude_MLA(const std::string& type)
: Seiscomp::Processing::AmplitudeProcessor_MLv()
{
// Change max distance to 11 degrees.
setMaxDist(11);
this->_type = type;
}

Amplitude_MLA::Amplitude_MLA(const Seiscomp::Core::Time& trigger, const std::string& type)
: Seiscomp::Processing::AmplitudeProcessor_MLv(trigger)
{
// Change max distance to 11 degrees.
setMaxDist(11);
this->_type = type;
}

bool Amplitude_MLA::setup(const Seiscomp::Processing::Settings &settings)
{
if ( !AmplitudeProcessor_MLv::setup(settings) ) {
return false;
}

std::string filterString;
try {
std::string cfgName = "amplitudes." + _type + ".filter";
filterString = settings.getString(cfgName);
}
catch(...) {
filterString = defaultFilter();
}

if (!filterString.empty()) {
SEISCOMP_DEBUG("Initializing %s with filter %s", _type.c_str(), filterString.c_str());
_preFilter = filterString; // ML has built-in prefiltering; just turn it on
} else {
SEISCOMP_DEBUG("Initializing %s with no filter", _type.c_str());
}

double maxDist;
if ( settings.getValue(maxDist, "amplitudes." + _type + ".maxDist") ) {
setMaxDist(maxDist);
} else {
setMaxDist(11);
}

return true;
}

int Amplitude_MLA::capabilities() const
{
// To get the correct calculation, we need to ensure the base MLv class
Expand Down Expand Up @@ -118,8 +146,8 @@ bool Amplitude_MLA::computeAmplitude(const Seiscomp::DoubleArray &data,
// Register the magnitude processor.
REGISTER_MAGNITUDEPROCESSOR(Magnitude_MLA, GA_ML_AUS_MAG_TYPE);

Magnitude_MLA::Magnitude_MLA()
: Seiscomp::Processing::MagnitudeProcessor(GA_ML_AUS_MAG_TYPE)
Magnitude_MLA::Magnitude_MLA(const std::string& type)
: Seiscomp::Processing::MagnitudeProcessor(type)
{
m_regions = new Seiscomp::Geo::GeoFeatureSet();
m_fileCat = new Seiscomp::Geo::Category(1);
Expand All @@ -141,6 +169,10 @@ void Magnitude_MLA::setupRegionToCalc()

bool Magnitude_MLA::setup(const Seiscomp::Processing::Settings &settings)
{
if ( !MagnitudeProcessor::setup(settings) ) {
return false;
}

std::string filePath = "";
try{
filePath = settings.getString("mla.regionfilepath");
Expand All @@ -149,7 +181,7 @@ bool Magnitude_MLA::setup(const Seiscomp::Processing::Settings &settings)
{
SEISCOMP_ERROR(
"%s can not read region file path from configuration file",
GA_ML_AUS_MAG_TYPE
type().c_str()
);
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion plugins/magnitudes/mla/mla.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Amplitude_MLA : public Seiscomp::Processing::AmplitudeProcessor_MLv
*/
virtual int capabilities() const;

bool setup(const Seiscomp::Processing::Settings &settings);

/*
Creates the parameter options associated with the capability.
@param cap: The capability to create parameters for.
Expand All @@ -77,6 +79,8 @@ class Amplitude_MLA : public Seiscomp::Processing::AmplitudeProcessor_MLv

protected:

virtual std::string defaultFilter() const { return ""; };

/*
Computes the amplitude of data in the range[i1, i2].
Input parameters:
Expand Down Expand Up @@ -134,7 +138,7 @@ class Magnitude_MLA : public Seiscomp::Processing::MagnitudeProcessor
#####################################################################*/

// Constructor. Return a new Magnitude_MLA object.
Magnitude_MLA();
explicit Magnitude_MLA(const std::string& type = GA_ML_AUS_MAG_TYPE);

// Destructor. Cleans up all data created on the heap.
virtual ~Magnitude_MLA();
Expand Down
13 changes: 13 additions & 0 deletions plugins/magnitudes/mla/variants.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "variants.h"

#define _MLA_VARIANT_IMPL(AMPCLASS, MAGCLASS, NAME) \
IMPLEMENT_SC_CLASS_DERIVED(AMPCLASS, Amplitude_MLA, "Amplitude_" #NAME); \
REGISTER_AMPLITUDEPROCESSOR(AMPCLASS, #NAME); \
REGISTER_MAGNITUDEPROCESSOR(MAGCLASS, #NAME)

#define IMPLEMENT_MLA_VARIANT(NAME) \
_MLA_VARIANT_IMPL(Amplitude_##NAME, Magnitude_##NAME, NAME)

IMPLEMENT_MLA_VARIANT(MLa01);
IMPLEMENT_MLA_VARIANT(MLa05);
IMPLEMENT_MLA_VARIANT(MLa075);
27 changes: 27 additions & 0 deletions plugins/magnitudes/mla/variants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __MLA_PLUGIN_VARIANTS_H__
#define __MLA_PLUGIN_VARIANTS_H__
#include "mla.h"

#define _MLA_VARIANT(AMPCLASS, MAGCLASS, NAME, DEFAULTFILTER) \
class AMPCLASS : public Amplitude_MLA { \
DECLARE_SC_CLASS(AMPCLASS); \
public: \
AMPCLASS() : Amplitude_MLA(#NAME) {}; \
protected: \
std::string defaultFilter() const override { return DEFAULTFILTER; }; \
}; \
class MAGCLASS : public Magnitude_MLA { \
public: \
MAGCLASS() : Magnitude_MLA(#NAME) {}; \
std::string amplitudeType() const override { return #NAME; }; \
}

#define DEFINE_MLA_VARIANT(NAME, DEFAULTFILTER) \
_MLA_VARIANT(Amplitude_##NAME, Magnitude_##NAME, NAME, DEFAULTFILTER)


DEFINE_MLA_VARIANT(MLa01, "BW_HP(3, 0.1)");
DEFINE_MLA_VARIANT(MLa05, "BW_HP(3, 0.5)");
DEFINE_MLA_VARIANT(MLa075, "BW_HP(3, 0.75)");

#endif /* __MLA_PLUGIN_VARIANTS_H__ */