Skip to content

Commit

Permalink
ENH: add option --inherit-mag
Browse files Browse the repository at this point in the history
Origins inherit the source origin magnitudes when combined with
--xmlout option
  • Loading branch information
luca-s committed May 14, 2024
1 parent 356f5cd commit 22c9193
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
10 changes: 7 additions & 3 deletions apps/scrtdd/rtddtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ void RTDD::createCommandLineDescription()
commandline().addOption("ModeOptions", "xmlout",
"Enable XML output when combined with "
"--reloc-catalog or --oring-id options");
commandline().addOption("ModeOptions", "inherit-mag",
"Origins inherit the source origin magnitudes "
"when combined with --xmlout option");
}

bool RTDD::validateParameters()
Expand Down Expand Up @@ -1287,9 +1290,10 @@ bool RTDD::run()

DataModel::OriginPtr newOrg;
std::vector<DataModel::PickPtr> newOrgPicks;
bool includeMagnitude = commandline().hasOption("inherit-mag");
convertOrigin(dataSrc, *ev, srcOrg.get(), author(), agencyID(),
profile->methodID, profile->earthModelID, true, false,
true, newOrg, newOrgPicks);
profile->methodID, profile->earthModelID,
includeMagnitude, true, newOrg, newOrgPicks);

evParam->add(newOrg.get());
for (DataModel::PickPtr p : newOrgPicks) evParam->add(p.get());
Expand Down Expand Up @@ -1858,7 +1862,7 @@ void RTDD::relocateOrigin(DataModel::Origin *org,
DataSource dataSrc(query(), &_cache, _eventParameters.get());
convertOrigin(dataSrc, *relocatedOrg, org, author(), agencyID(),
profile->methodID, profile->earthModelID, includeMagnitude,
true, false, newOrg, newOrgPicks);
false, newOrg, newOrgPicks);
}

std::unique_ptr<HDD::Catalog>
Expand Down
45 changes: 19 additions & 26 deletions libs/hddsc/scutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ void convertOrigin(DataSource &dataSrc,
const string &methodID,
const string &earthModelID,
bool includeMagnitude,
bool fullMagnitude,
bool includeExistingPicks,
DataModel::OriginPtr &newOrg, // return value
std::vector<DataModel::PickPtr> &newOrgPicks) // return value
Expand Down Expand Up @@ -475,20 +474,17 @@ void convertOrigin(DataSource &dataSrc,
//
if (includeMagnitude)
{
dataSrc.loadMagnitudes(org, fullMagnitude, fullMagnitude);
dataSrc.loadMagnitudes(org, true, true);

unordered_map<string, string> staMagIdMap;
if (fullMagnitude)
for (size_t i = 0; i < org->stationMagnitudeCount(); i++)
{
for (size_t i = 0; i < org->stationMagnitudeCount(); i++)
{
DataModel::StationMagnitude *staMag = org->stationMagnitude(i);
DataModel::StationMagnitude *newStaMag =
DataModel::StationMagnitude::Create();
*newStaMag = *staMag;
newOrg->add(newStaMag);
staMagIdMap[staMag->publicID()] = newStaMag->publicID();
}
DataModel::StationMagnitude *staMag = org->stationMagnitude(i);
DataModel::StationMagnitude *newStaMag =
DataModel::StationMagnitude::Create();
*newStaMag = *staMag;
newOrg->add(newStaMag);
staMagIdMap[staMag->publicID()] = newStaMag->publicID();
}

for (size_t i = 0; i < org->magnitudeCount(); i++)
Expand All @@ -497,23 +493,20 @@ void convertOrigin(DataSource &dataSrc,
DataModel::Magnitude *newMag = DataModel::Magnitude::Create();
*newMag = *mag;

if (fullMagnitude)
for (size_t j = 0; j < mag->stationMagnitudeContributionCount(); j++)
{
for (size_t j = 0; j < mag->stationMagnitudeContributionCount(); j++)
DataModel::StationMagnitudeContribution *contrib =
mag->stationMagnitudeContribution(j);
DataModel::StationMagnitudeContributionPtr newContrib =
new DataModel::StationMagnitudeContribution(*contrib);
try
{
DataModel::StationMagnitudeContribution *contrib =
mag->stationMagnitudeContribution(j);
DataModel::StationMagnitudeContributionPtr newContrib =
new DataModel::StationMagnitudeContribution(*contrib);
try
{
newContrib->setStationMagnitudeID(
staMagIdMap.at(contrib->stationMagnitudeID()));
}
catch (...)
{}
newMag->add(newContrib.get());
newContrib->setStationMagnitudeID(
staMagIdMap.at(contrib->stationMagnitudeID()));
}
catch (...)
{}
newMag->add(newContrib.get());
}
newOrg->add(newMag);
}
Expand Down
1 change: 0 additions & 1 deletion libs/hddsc/scutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ void convertOrigin(DataSource &dataSrc,
const std::string &methodID,
const std::string &earthModelID,
bool includeMagnitude,
bool fullMagnitude,
bool includeExistingPicks,
Seiscomp::DataModel::OriginPtr &newOrg,
std::vector<Seiscomp::DataModel::PickPtr> &newOrgPicks);
Expand Down

0 comments on commit 22c9193

Please sign in to comment.