neic-glass3  1.4.6
Hypo.h
Go to the documentation of this file.
1 /*****************************************
2  * This file is documented for Doxygen.
3  * If you modify this file please update
4  * the comments so that Doxygen will still
5  * be able to work.
6  ****************************************/
7 #ifndef HYPO_H
8 #define HYPO_H
9 
10 #include <json.h>
11 #include <geo.h>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 #include <mutex>
16 #include <atomic>
17 #include "TTT.h"
18 
19 namespace glasscore {
20 
21 // forward declarations
22 class CPick;
23 class CCorrelation;
24 class CTrigger;
25 class CSiteList;
26 class CHypoList;
27 
35  double dtOrigin;
36  double dtCreated;
37  double dtNucleated;
39  double dtLastBigMove;
46  double dLatPrev;
47  double dLonPrev;
48  double dDepthPrev;
50 
75 class CHypo {
76  public:
84  CHypo();
85 
111  CHypo(std::shared_ptr<json::Object> detection, double thresh, int cut,
112  std::shared_ptr<traveltime::CTravelTime> firstTrav,
113  std::shared_ptr<traveltime::CTravelTime> secondTrav,
114  std::shared_ptr<traveltime::CTTT> ttt, double resolution = 100,
115  double aziTaper = 360.0, double maxDepth = 800.0,
116  CSiteList *pSiteList = NULL);
117 
149  CHypo(double lat, double lon, double z, double time, std::string pid,
150  std::string web, double bayes, double thresh, int cut,
151  std::shared_ptr<traveltime::CTravelTime> firstTrav,
152  std::shared_ptr<traveltime::CTravelTime> secondTrav,
153  std::shared_ptr<traveltime::CTTT> ttt, double resolution = 100,
154  double aziTaper = 360.0, double maxDepth = 800.0);
155 
167  explicit CHypo(std::shared_ptr<CTrigger> trigger,
168  std::shared_ptr<traveltime::CTTT> ttt);
169 
185  explicit CHypo(std::shared_ptr<CCorrelation> corr,
186  std::shared_ptr<traveltime::CTravelTime> firstTrav,
187  std::shared_ptr<traveltime::CTravelTime> secondTrav,
188  std::shared_ptr<traveltime::CTTT> ttt);
189 
196  ~CHypo();
197 
201  void clear();
202 
233  bool initialize(double lat, double lon, double z, double time,
234  std::string pid, std::string web, double bayes,
235  double thresh, int cut,
236  std::shared_ptr<traveltime::CTravelTime> firstTrav,
237  std::shared_ptr<traveltime::CTravelTime> secondTrav,
238  std::shared_ptr<traveltime::CTTT> ttt, double resolution =
239  100,
240  double aziTaper = 360.0, double maxDepth = 800.0);
241 
255  bool addPickReference(std::shared_ptr<CPick> pck);
256 
269  void removePickReference(std::shared_ptr<CPick> pck);
270 
283  bool hasPickReference(std::shared_ptr<CPick> pck);
284 
292  void clearPickReferences();
293 
308  void addCorrelationReference(std::shared_ptr<CCorrelation> corr);
309 
323  void removeCorrelationReference(std::shared_ptr<CCorrelation> corr);
324 
338  bool hasCorrelationReference(std::shared_ptr<CCorrelation> corr);
339 
348  void clearCorrelationReferences();
349 
357  std::shared_ptr<json::Object> generateHypoMessage();
358 
367  std::shared_ptr<json::Object> generateEventMessage();
368 
377  std::shared_ptr<json::Object> generateCancelMessage();
378 
390  std::shared_ptr<json::Object> generateExpireMessage();
391 
408  bool canAssociate(std::shared_ptr<CPick> pick, double sigma,
409  double sdassoc, bool p_only = false,
410  bool debug = false);
411 
423  double getTravelTimeForPhase(std::shared_ptr<CPick> pick,
424  std::string phaseName);
425 
437  double calculateDistanceToPick(std::shared_ptr<CPick> pick);
438 
456  double calculateResidual(std::shared_ptr<CPick> pick,
457  bool * useForLocations = NULL,
458  std::string * phaseName = NULL,
459  bool p_only = false);
460 
473  bool canAssociate(std::shared_ptr<CCorrelation> corr, double tWindow,
474  double xWindow);
475 
476  /* \brief Calculate pick affinity
477  *
478  * Calculate the association affinity between the given
479  * supporting pick and the current hypocenter based on a number of factors
480  * including the identified phase, distance to picked station,
481  * observation error, and other hypocentral properties
482  *
483  * \param pck - A std::shared_ptr to the pick to consider.
484  * \return Returns a double value containing the pick affinity
485  */
486  double calculateAffinity(std::shared_ptr<CPick> pck);
487 
488  /* \brief Calculate correlation affinity
489  *
490  * Calculate the association affinity between the given
491  * supporting correlation and the current hypocenter based on a number of
492  * factors including distance to correlation station,
493  * time to correlation, and other properties
494  *
495  * \param corr - A std::shared_ptr to the correlation to consider.
496  * \return Returns a double value containing the correlation affinity
497  */
498  double calculateAffinity(std::shared_ptr<CCorrelation> corr);
499 
500  /* \brief Remove data that no longer fit association criteria
501  *
502  * Calculate the association affinity between it's associated
503  * supporting data and the current hypocenter based on a number of factors
504  * including the identified phase, distance to picked station,
505  * observation error, and other hypocentral properties
506  *
507  * \param parentThread - A pointer to a parent Hypolist thread to
508  * reprt status to.
509  * \return Returns true if any data removed
510  */
511  bool pruneData(CHypoList* parentThread = NULL);
512 
524  bool cancelCheck();
525 
534  bool reportCheck();
535 
543  void calculateStatistics();
544 
566  double anneal(int nIter = 5000, double dStart = 100.0, double dStop = 1.0,
567  double tStart = 5., double tStop = .5);
568 
581  double localize();
582 
599  void annealingLocateBayes(int nIter, double dStart, double dStop,
600  double tStart, double tStop, bool nucleate =
601  false);
602 
619  void annealingLocateResidual(int nIter, double dStart, double dStop,
620  double tStart, double tStop, bool nucleate =
621  false);
622 
634  double calculateGap(double lat, double lon, double z);
635 
644  double calculateCurrentBayes();
645 
662  double calculateBayes(double xlat, double xlon, double xZ, double oT,
663  bool nucleate);
664 
680  double calculateAbsResidualSum(double xlat, double xlon, double xZ,
681  double oT, bool nucleate);
682 
694  double calculateWeightedResidual(std::string sPhase, double tObs,
695  double tCal);
696 
701  void graphicsOutput();
702 
720  bool resolveData(std::shared_ptr<CHypo> hypo, bool allowStealing = true,
721  CHypoList* parentThread = NULL);
722 
729  void trap();
730 
736  double getAzimuthTaper() const;
737 
742  double getMaxDepth() const;
743 
748  double getLatitude() const;
749 
754  void setLatitude(double lat);
755 
760  double getLongitude() const;
761 
767  void setLongitude(double lon);
768 
773  double getDepth() const;
774 
779  void setDepth(double z);
780 
786  glass3::util::Geo getGeo() const;
787 
792  double getTOrigin() const;
793 
798  void setTOrigin(double newTOrg);
799 
804  double getBayesValue() const;
805 
816  bool getCorrelationAdded() const;
817 
828  void setCorrelationAdded(bool corrAdded);
829 
836  bool getEventGenerated() const;
837 
844  bool getHypoGenerated() const;
845 
852  bool getFixed() const;
853 
860  void setFixed(bool fixed);
861 
867  double getInitialBayesValue() const;
868 
875  double getAssociationDistanceCutoff() const;
876 
882  double getDistanceCutoffFactor() const;
883 
895  int getNucleationDataThreshold() const;
896 
908  void setNucleationDataThreshold(int cut);
909 
916  double getNucleationStackThreshold() const;
917 
924  void setNucleationStackThreshold(double thresh);
925 
930  double getGap() const;
931 
938  int getTeleseismicPhaseCount() const;
939 
945  double getMedianDistance() const;
946 
952  double getMinDistance() const;
953 
959  std::mutex & getProcessingMutex();
960 
966  double getWebResolution() const;
967 
973  double getDistanceSD() const;
974 
980  int getProcessCount() const;
981 
987  int setProcessCount(int newCycle);
988 
993  int getTotalProcessCount() const;
994 
999  int incrementTotalProcessCount();
1000 
1005  const std::string& getID() const;
1006 
1012  const std::string& getWebName() const;
1013 
1019  int getPickDataSize() const;
1020 
1025  std::vector<std::shared_ptr<CPick>> getPickData() const;
1026 
1032  int getCorrelationDataSize() const;
1033 
1039  double getTCreate() const;
1040 
1049  std::shared_ptr<traveltime::CTravelTime> getNucleationTravelTime1() const;
1050 
1059  std::shared_ptr<traveltime::CTravelTime> getNucleationTravelTime2() const;
1060 
1069  std::shared_ptr<traveltime::CTTT> getTravelTimeTables() const;
1070 
1075  int getReportCount() const;
1076 
1082  bool isLockedForProcessing();
1083 
1088  int64_t getTSort() const;
1089 
1094  void setTSort(double newTSort);
1095 
1101  void setTCreate(double newTCreate);
1102 
1109  void setNucleationAuditingInfo(double tNucleation,
1110  double tNucleationKeyPickInsertion);
1115  const HypoAuditingPerformanceStruct * getHypoAuditingPerformanceInfo();
1116 
1117  // constants
1121  static constexpr double k_dResidualSigmaLengthSeconds = 1.0;
1122 
1126  static constexpr double k_dGapTaperDownBegin = 270.0;
1127 
1131  static constexpr double k_dGapTaperDownEnd = 360.0;
1132 
1136  static constexpr double k_dTimeToDistanceCorrectionFactor = 10.0;
1137 
1141  static constexpr double k_dVerticalToHorizontalDistanceCorrectionFactor = 2.0; // NOLINT
1142 
1146  static constexpr double k_dBayesFactorMaximumRange = 0.2;
1147 
1151  static constexpr double k_dBayesFactorExponent = 2.0;
1152 
1156  static constexpr double k_dBayesFactorStepSizeReduction = 500.0;
1157 
1158  /* \brief Indicates what portion of the Web Resolution is required to
1159  * indicate an epicentral location change was significant(big, large, etc..)
1160  * Used for auditing purposes.
1161  */
1162  static constexpr double k_dLocationChangeWebResolutionRatio = 0.5;
1163 
1168  static constexpr double k_dMinimumDepthChangeKMThreshold = 7.5;
1169 
1175  static constexpr double k_dMinimumDepthChangeRatioThreshold = 0.25;
1176 
1180  static constexpr double k_dInitialAnnealStepReducationFactor = .5;
1181 
1185  static constexpr double k_dFinalAnnealStepReducationFactor = 100.0;
1186 
1190  static constexpr double k_dLocationMinDistanceStepSize = 1.0;
1191 
1195  static constexpr double k_dLocationMinTimeStepSize = 0.1;
1196 
1200  static constexpr double k_dLocationSearchRadiusToTime = 30.0;
1201 
1205  static constexpr double k_dLocationTaperConstant = 0.0001;
1206 
1210  static constexpr double k_dLocationMaxTaperThreshold = 30.0;
1211 
1215  static const int k_iLocationNPicksToSkipSmall = 5;
1216 
1220  static const int k_iLocationNPicksToSkipMedium = 10;
1221 
1225  static const int k_iLocationNPicksToSkipLarge = 25;
1226 
1230  static const int k_iLocationNPickThresholdSmall = 25;
1231 
1235  static const int k_iLocationNPickThresholdMedium = 50;
1236 
1240  static const int k_iLocationNPickThresholdLarge = 150;
1241 
1245  static const int k_iLocationNumIterationsSmall = 500;
1246 
1250  static const int k_iLocationNumIterationsMedium = 1250;
1251 
1255  static const int k_iLocationNumIterationsLarge = 10000;
1256 
1261  static constexpr double k_dSearchRadiusResolutionFactor = 1.0;
1262 
1267  static constexpr double k_dSearchRadiusTaperFactor = 0.75;
1268 
1272  static constexpr double k_dSearchRadiusFactor = 0.5;
1273 
1274  private:
1279  std::string m_sWebName;
1280 
1285  std::atomic<int> m_iNucleationDataThreshold;
1286 
1291  std::atomic<double> m_dNucleationStackThreshold;
1292 
1297  std::atomic<double> m_dAzimuthTaper;
1298 
1302  std::atomic<double> m_dMaxDepth;
1303 
1307  std::atomic<int> m_iProcessCount;
1308 
1313  std::atomic<double> m_tOrigin;
1314 
1318  std::atomic<double> m_dLatitude;
1319 
1323  std::atomic<double> m_dLongitude;
1324 
1328  std::atomic<double> m_dDepth;
1329 
1333  std::atomic<bool> m_bEventGenerated;
1334 
1339  std::atomic<bool> m_bHypoGenerated;
1340 
1344  std::atomic<double> m_dBayesValue;
1345 
1349  std::atomic<double> m_dInitialBayesValue;
1350 
1355  std::atomic<double> m_dMinDistance;
1356 
1361  std::atomic<double> m_dMedianDistance;
1362 
1367  std::atomic<double> m_dGap;
1368 
1374  std::atomic<int> m_iTeleseismicPhaseCount;
1375 
1379  std::atomic<double> m_dDistanceSD;
1380 
1384  std::atomic<double> m_dWebResolution;
1385 
1390  std::atomic<double> m_dAssociationDistanceCutoff;
1391 
1395  std::string m_sID;
1396 
1400  std::atomic<bool> m_bFixed;
1401 
1406  std::atomic<double> m_bCorrelationAdded;
1407 
1412  std::atomic<int> m_iTotalProcessCount;
1413 
1418  std::atomic<int> m_iReportCount;
1419 
1424  std::atomic<double> m_tCreate;
1425 
1436  std::atomic<int64_t> m_tSort;
1437 
1445  std::vector<std::shared_ptr<CPick>> m_vPickData;
1446 
1455  std::vector<std::shared_ptr<CCorrelation>> m_vCorrelationData;
1456 
1463  std::shared_ptr<traveltime::CTravelTime> m_pNucleationTravelTime1;
1464 
1471  std::shared_ptr<traveltime::CTravelTime> m_pNucleationTravelTime2;
1472 
1480  std::shared_ptr<traveltime::CTTT> m_pTravelTimeTables;
1481 
1489  mutable std::recursive_mutex m_HypoMutex;
1490 
1494  std::mutex m_ProcessingMutex;
1495 
1499  HypoAuditingPerformanceStruct m_hapsAudit;
1500 };
1501 } // namespace glasscore
1502 #endif // HYPO_H
double dMaxStackSinceMove
Definition: Hypo.h:43
double dtOrigin
Definition: Hypo.h:35
double dLatPrev
Definition: Hypo.h:46
glasscore site list class
Definition: SiteList.h:40
int nMaxPhasesSinceMove
Definition: Hypo.h:41
double dtFirstEventMessage
Definition: Hypo.h:44
struct glasscore::_HypoAuditingPerformanceStruct HypoAuditingPerformanceStruct
glasscore hypo auditing structure
double dMaxStackBeforeMove
Definition: Hypo.h:42
double dtFirstHypoMessage
Definition: Hypo.h:45
geographic coordinate conversion class
Definition: geo.h:25
int nMaxPhasesBeforeMove
Definition: Hypo.h:40
double dtNucleationPickInsertion
Definition: Hypo.h:38
glasscore hypocenter list class
Definition: HypoList.h:67
glasscore hypo auditing structure
Definition: Hypo.h:34
glasscore hypocenter class
Definition: Hypo.h:75
double dtCreated
Definition: Hypo.h:36
double dtLastBigMove
Definition: Hypo.h:39
The namespace containing the core algorithm.
Definition: Correlation.h:17
double dLonPrev
Definition: Hypo.h:47
double dDepthPrev
Definition: Hypo.h:48
double dtNucleated
Definition: Hypo.h:37