Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #61 from jpatton-USGS/detection-formats-update
Browse files Browse the repository at this point in the history
Detection formats update
  • Loading branch information
mguy-usgs authored Jul 23, 2019
2 parents 70a609d + e65f415 commit ac015aa
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ if (BUILD_GLASS-APP OR BUILD_GLASS-BROKER-APP)
if (GIT_CLONE_PUBLIC)
ExternalProject_Add(DetectionFormats
GIT_REPOSITORY https://github.com/usgs/earthquake-detection-formats.git
# GIT_TAG v0.9.7
GIT_TAG v0.9.10
TIMEOUT 10
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${INSTALL_LOCATION}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
Expand All @@ -153,7 +153,7 @@ if (BUILD_GLASS-APP OR BUILD_GLASS-BROKER-APP)
else()
ExternalProject_Add(DetectionFormats
GIT_REPOSITORY [email protected]:usgs/earthquake-detection-formats.git
# GIT_TAG v0.9.7
GIT_TAG v0.9.10
TIMEOUT 10
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${INSTALL_LOCATION}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
Expand Down
4 changes: 2 additions & 2 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# version.cmake - a CMake script that defines the overall project version
set (PROJECT_VERSION_MAJOR 1)
set (PROJECT_VERSION_MINOR 0)
set (PROJECT_VERSION_PATCH 8)
set (PROJECT_VERSION_MINOR 1)
set (PROJECT_VERSION_PATCH 0)
2 changes: 1 addition & 1 deletion glass-broker-app/brokerOutput/outputTopic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ outputTopic::outputTopic(hazdevbroker::Producer * producer) {
m_OutputProducer = NULL;

clear();

m_OutputProducer = producer;
}

Expand Down
20 changes: 20 additions & 0 deletions glasscore/glasslib/src/Hypo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,16 @@ std::shared_ptr<json::Object> CHypo::generateHypoMessage() {
// which has the site, source, time, etc
pickObj = json::Object(*jPick.get());

// add the lat/lon/elev to site
if (pickObj.HasKey("Site")) {
// get the site object
json::Object siteobj = pickObj["Site"].ToObject();
siteobj["Latitude"] = site->getRawLatitude();
siteobj["Longitude"] = site->getRawLongitude();
siteobj["Elevation"] = site->getRawElevation();
pickObj["Site"] = siteobj;
}

// add the association info
json::Object assocobj;
assocobj["Phase"] = m_pTravelTimeTables->m_sPhase;
Expand Down Expand Up @@ -2261,6 +2271,16 @@ std::shared_ptr<json::Object> CHypo::generateHypoMessage() {
// which has the site, source, time, etc
correlationObj = json::Object(*jCorrelation.get());

// add the lat/lon/elev to site
if (correlationObj.HasKey("Site")) {
// get the site object
json::Object siteobj = correlationObj["Site"].ToObject();
siteobj["Latitude"] = site->getRawLatitude();
siteobj["Longitude"] = site->getRawLongitude();
siteobj["Elevation"] = site->getRawElevation();
correlationObj["Site"] = siteobj;
}

// add the association info
json::Object assocobj;
assocobj["Phase"] = m_pTravelTimeTables->m_sPhase;
Expand Down
66 changes: 47 additions & 19 deletions glasscore/glasslib/src/Site.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CSite::CSite(std::shared_ptr<json::Object> site) {
// optional values
double quality = 0;
bool enable = true;
bool useForTelesiesmic = true;
bool useForTeleseismic = true;

// get site information from json
// scnl
Expand Down Expand Up @@ -128,44 +128,65 @@ CSite::CSite(std::shared_ptr<json::Object> site) {
if (location == "--") {
location = "";
}

// get station location, note that the error returns are commented
// out for now to make glass backwards compatible with format changes in
// detection formats
// latitude for this site
if ((siteobj.HasKey("Latitude"))
&& (siteobj["Latitude"].GetType() == json::ValueType::DoubleVal)) {
latitude = siteobj["Latitude"].ToDouble();
} // else {
// glass3::util::Logger::log(
// "error", "CSite::CSite: Missing required Latitude Key.");
// return;
// }

// longitude for this site
if ((siteobj.HasKey("Longitude"))
&& (siteobj["Longitude"].GetType() == json::ValueType::DoubleVal)) {
longitude = siteobj["Longitude"].ToDouble();
} // else {
// glass3::util::Logger::log(
// "error", "CSite::CSite: Missing required Longitude Key.");
// return;
// }

// elevation for this site
if ((siteobj.HasKey("Elevation"))
&& (siteobj["Elevation"].GetType() == json::ValueType::DoubleVal)) {
elevation = siteobj["Elevation"].ToDouble();
} // else {
// glass3::util::Logger::log(
// "error", "CSite::CSite: Missing required Elevation Key.");
// return;
// }
} else {
glass3::util::Logger::log(
"error", "CSite::CSite: Missing required Site Object.");

return;
}

// check the old location for lat/lon/elev as well, it may or may not be there
// this is to make glass backwards compatible with format changes in
// detection formats
// latitude for this site
if (((*site).HasKey("Latitude"))
&& ((*site)["Latitude"].GetType() == json::ValueType::DoubleVal)) {
latitude = (*site)["Latitude"].ToDouble();
} else {
glass3::util::Logger::log(
"error", "CSite::CSite: Missing required Latitude Key.");

return;
}

// longitude for this site
if (((*site).HasKey("Longitude"))
&& ((*site)["Longitude"].GetType() == json::ValueType::DoubleVal)) {
longitude = (*site)["Longitude"].ToDouble();
} else {
glass3::util::Logger::log(
"error", "CSite::CSite: Missing required Longitude Key.");

return;
}

// elevation for this site
if (((*site).HasKey("Elevation"))
&& ((*site)["Elevation"].GetType() == json::ValueType::DoubleVal)) {
elevation = (*site)["Elevation"].ToDouble();
} else {
glass3::util::Logger::log(
"error", "CSite::CSite: Missing required Elevation Key.");

return;
}

// quality for this site (if present)
Expand All @@ -188,14 +209,21 @@ CSite::CSite(std::shared_ptr<json::Object> site) {
if (((*site).HasKey("UseForTeleseismic"))
&& ((*site)["UseForTeleseismic"].GetType()
== json::ValueType::BoolVal)) {
useForTelesiesmic = (*site)["UseForTeleseismic"].ToBool();
useForTeleseismic = (*site)["UseForTeleseismic"].ToBool();
} else {
useForTelesiesmic = true;
useForTeleseismic = true;
}

// make sure we got a valid lat/lon/elev
if ((latitude == 0) && (longitude == 0) && (elevation == 0)) {
glass3::util::Logger::log(
"error", "CSite::CSite: Invalid Latitude / Longitude / Elevation (=0).");
return;
}

// pass to initialization function
initialize(station, channel, network, location, latitude, longitude,
elevation, quality, enable, useForTelesiesmic);
elevation, quality, enable, useForTeleseismic);
}

// --------------------------------------------------------initialize
Expand Down
2 changes: 1 addition & 1 deletion glasscore/tests/sitelist_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#define BADSITE "{\"Elevation\":2326.000000,\"Latitude\":45.822170,\"Longitude\":-112.451000,\"Site\":{\"Station\":\"LRM\",\"Channel\":\"EHZ\",\"Network\":\"MB\",\"Location\":\"--\"},\"Enable\":true,\"Quality\":1.0,\"UseForTeleseismic\":true}" // NOLINT
#define BADSITE2 "{\"Type\":\"FEH\",\"Elevation\":2326.000000,\"Latitude\":45.822170,\"Longitude\":-112.451000,\"Site\":{\"Station\":\"LRM\",\"Channel\":\"EHZ\",\"Network\":\"MB\",\"Location\":\"--\"},\"Enable\":true,\"Quality\":1.0,\"UseForTeleseismic\":true}" // NOLINT
#define BADSITE3 "{\"Type\":\"StationInfo\",\"Latitude\":45.822170,\"Longitude\":-112.451000,\"Site\":{\"Station\":\"LRM\",\"Channel\":\"EHZ\",\"Network\":\"MB\",\"Location\":\"--\"},\"Enable\":true,\"Quality\":1.0,\"UseForTeleseismic\":true}" // NOLINT
#define BADSITE3 "{\"Type\":\"StationInfo\",\"Site\":{\"Station\":\"LRM\",\"Channel\":\"EHZ\",\"Network\":\"MB\",\"Location\":\"--\"},\"Enable\":true,\"Quality\":1.0,\"UseForTeleseismic\":true}" // NOLINT

// test to see if the sitelist can be constructed
TEST(SiteListTest, Construction) {
Expand Down
26 changes: 23 additions & 3 deletions parse/src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ std::string hypoToJSONDetection(std::shared_ptr<json::Object> data,
pick.site.location = (siteobj)["Location"].ToString();
}

pick.site.latitude = (siteobj)["Latitude"].ToDouble();
pick.site.longitude = (siteobj)["Longitude"].ToDouble();
pick.site.elevation = (siteobj)["Elevation"].ToDouble();

// source
pick.source.agencyid = (sourceobj)["AgencyID"].ToString();
pick.source.author = (sourceobj)["Author"].ToString();
Expand Down Expand Up @@ -289,6 +293,10 @@ std::string hypoToJSONDetection(std::shared_ptr<json::Object> data,
(siteobj)["Location"].ToString();
}

correlation.site.latitude = (siteobj)["Latitude"].ToDouble();
correlation.site.longitude = (siteobj)["Longitude"].ToDouble();
correlation.site.elevation = (siteobj)["Elevation"].ToDouble();

// source
correlation.source.agencyid =
(sourceobj)["AgencyID"].ToString();
Expand Down Expand Up @@ -603,9 +611,9 @@ std::string siteListToStationList(std::shared_ptr<json::Object> data) {
}

// site location
stationObject.latitude = (siteObject)["Lat"].ToDouble();
stationObject.longitude = (siteObject)["Lon"].ToDouble();
stationObject.elevation = (siteObject)["Z"].ToDouble();
stationObject.site.latitude = (siteObject)["Lat"].ToDouble();
stationObject.site.longitude = (siteObject)["Lon"].ToDouble();
stationObject.site.elevation = (siteObject)["Z"].ToDouble();

// site quality metrics
stationObject.quality = (siteObject)["Qual"].ToDouble();
Expand All @@ -619,6 +627,18 @@ std::string siteListToStationList(std::shared_ptr<json::Object> data) {
rapidjson::Document stationJSON(rapidjson::kObjectType);
stationObject.tojson(stationJSON, allocator);
stationListArray.PushBack(stationJSON, allocator);
} else {
std::vector<std::string> errors = stationObject.geterrors();

std::string errorString = stationObject.site.station + "."
+ stationObject.site.network;
for (int errorCount = 0; errorCount < errors.size(); errorCount++) {
errorString += " " + errors[errorCount];
}

glass3::util::Logger::log(
"warning",
"siteListToStationList: " + errorString);
}
} catch (const std::exception &e) {
glass3::util::Logger::log(
Expand Down
2 changes: 1 addition & 1 deletion parse/testdata/siteList.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion parse/tests/convert_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ TEST(Convert, CancelTest) {
}

TEST(Convert, SiteListTest) {
// glass3::util::log_init("converttest", spdlog::level::debug, ".", true);
// glass3::util::Logger::log_init("converttest", "debug", ".", true);

// failure cases
ASSERT_STREQ(glass3::parse::siteListToStationList(NULL).c_str(), "");
Expand Down
2 changes: 1 addition & 1 deletion parse/tests/jsonparser_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define TESTPICKSTRING "{\"Type\":\"Pick\",\"ID\":\"12GFH48776857\",\"Site\":{\"Station\":\"BMN\",\"Network\":\"LB\",\"Channel\":\"HHZ\",\"Location\":\"01\"},\"Source\":{\"AgencyID\":\"US\",\"Author\":\"TestAuthor\"},\"Time\":\"2015-12-28T21:32:24.017Z\",\"Phase\":\"P\",\"Polarity\":\"up\",\"Onset\":\"questionable\",\"Picker\":\"manual\",\"Filter\":[{\"HighPass\":1.05,\"LowPass\":2.65},{\"HighPass\":2.10,\"LowPass\":3.58}],\"Amplitude\":{\"Amplitude\":21.5,\"Period\":2.65,\"SNR\":3.8},\"AssociationInfo\":{\"Phase\":\"P\",\"Distance\":0.442559,\"Azimuth\":0.418479,\"Residual\":-0.025393,\"Sigma\":0.086333}}" // NOLINT

// Input station data that should work.
#define TESTSTATIONSTRING "{\"Elevation\":150.000000,\"Enable\":true,\"InformationRequestor\":{\"AgencyID\":\"US\",\"Author\":\"glasstest\"},\"Latitude\":32.888901,\"Longitude\":-117.105103,\"Quality\":1.000000,\"Site\":{\"Channel\":\"BHZ\",\"Location\":\"--\",\"Network\":\"TA\",\"Station\":\"109C\"},\"Type\":\"StationInfo\",\"UseForTeleseismic\":true}" // NOLINT
#define TESTSTATIONSTRING "{\"Enable\":true,\"InformationRequestor\":{\"AgencyID\":\"US\",\"Author\":\"glasstest\"},\"Quality\":1.000000,\"Site\":{\"Channel\":\"BHZ\",\"Location\":\"--\",\"Network\":\"TA\",\"Station\":\"109C\",\"Latitude\":32.888901,\"Longitude\":-117.105103,\"Elevation\":150.000000},\"Type\":\"StationInfo\",\"UseForTeleseismic\":true}" // NOLINT

// Input detection data that should fail, missing hypocenter
#define TESTFAILDETECTIONSTRING "{\"Type\":\"Detection\",\"ID\":\"12GFH48776857\",\"Source\":{\"AgencyID\":\"US\",\"Author\":\"TestAuthor\"},\"DetectionType\":\"New\",\"EventType\":\"earthquake\",\"Bayes\":2.65,\"MinimumDistance\":2.14,\"RMS\":3.8,\"Gap\":33.67,\"Data\":[{\"Type\":\"Pick\",\"ID\":\"12GFH48776857\",\"Site\":{\"Station\":\"BMN\",\"Network\":\"LB\",\"Channel\":\"HHZ\",\"Location\":\"01\"},\"Source\":{\"AgencyID\":\"US\",\"Author\":\"TestAuthor\"},\"Time\":\"2015-12-28T21:32:24.017Z\",\"Phase\":\"P\",\"Polarity\":\"up\",\"Onset\":\"questionable\",\"Picker\":\"manual\",\"Filter\":[{\"HighPass\":1.05,\"LowPass\":2.65}],\"Amplitude\":{\"Amplitude\":21.5,\"Period\":2.65,\"SNR\":3.8},\"AssociationInfo\":{\"Phase\":\"P\",\"Distance\":0.442559,\"Azimuth\":0.418479,\"Residual\":-0.025393,\"Sigma\":0.086333}},{\"Type\":\"Correlation\",\"ID\":\"12GFH48776857\",\"Site\":{\"Station\":\"BMN\",\"Network\":\"LB\",\"Channel\":\"HHZ\",\"Location\":\"01\"},\"Source\":{\"AgencyID\":\"US\",\"Author\":\"TestAuthor\"},\"Phase\":\"P\",\"Time\":\"2015-12-28T21:32:24.017Z\",\"Correlation\":2.65,\"Hypocenter\":{\"Latitude\":40.3344,\"Longitude\":-121.44,\"Depth\":32.44,\"Time\":\"2015-12-28T21:30:44.039Z\"},\"EventType\":\"earthquake\",\"Magnitude\":2.14,\"SNR\":3.8,\"ZScore\":33.67,\"DetectionThreshold\":1.5,\"ThresholdType\":\"minimum\",\"AssociationInfo\":{\"Phase\":\"P\",\"Distance\":0.442559,\"Azimuth\":0.418479,\"Residual\":-0.025393,\"Sigma\":0.086333}}]}" // NOLINT
Expand Down

0 comments on commit ac015aa

Please sign in to comment.