1package main
2
3import (
4 "ewdetect/calibration"
5 "ewdetect/comms"
6 "ewdetect/config"
7 "ewdetect/detect"
8 "ewdetect/locate"
9 "ewdetect/stations"
10 "ewdetect/webui"
11 "os"
12 "time"
13
14 "github.com/rs/zerolog"
15 "github.com/rs/zerolog/log"
16 "github.com/rs/zerolog/pkgerrors"
17)
18
19func main() {
20 log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC1123})
21 zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
22 zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
23 zerolog.SetGlobalLevel(config.GlobalLogLevel)
24 detect.Init()
25 locate.Init()
26 stations.Init()
27 go webui.Init()
28 go calibration.Init()
29
30 for _, url := range stations.URLs /*[]string{"link.geonet.org.nz:18000"}*/ /* you could also retrict this to a single network if need be */ {
31 go comms.StreamThread(url)
32 time.Sleep(config.DelayBetweenHandshakes)
33 }
34 select {}
35 /*
36 // Example https://www.mtu.edu/geo/community/seismology/learn/earthquake-epicenter/
37 fmt.Println(locate.NelderMeadOptimization("mtu.edu example", &[]locate.Observation{
38 {StationName: "TEIG", Lat: (20.0 + 14.0/.60 + 30.0/3600.) * math.Pi / 180, Lon: -(88 + 2.0/60 + 30.0/3600) * math.Pi / 180, PWaveArrival: 1.0 * 60, SWaveArrival: 2.5 * 60}, // TEIG
39 {StationName: "SOCO", Lat: (18.0 + 47.0/.60 + 04.0/3600.) * math.Pi / 180, Lon: -(110 + 58.0/60 + 30.0/3600) * math.Pi / 180, PWaveArrival: 3.0 * 60, SWaveArrival: 6.0 * 60}, // SOCO
40 {StationName: "SSPA", Lat: (41.0 + 44.0/60 + 30.0/3600.) * math.Pi / 180, Lon: -(76 + 21.0/60 + 59.0/3600) * math.Pi / 180, PWaveArrival: 4.3 * 60, SWaveArrival: 9.1 * 60}, // SSPA
41 }))
42
43 // Converges to 20.2967558432, -93.5205907499, not bad
44
45 // Example https://stationview.raspberryshake.org/#/?lat=35.57462&lon=139.73858&zoom=10.925&event=rs2025fvnavr&sta=R7F8D
46 // time 0 is 12:50:00 UTC
47
48 fmt.Println(locate.NelderMeadOptimization("rs2025fvnavr", &[]locate.Observation{
49 {StationName: "R7F8D", Lat: 35.63214 * math.Pi / 180, Lon: 139.73389 * math.Pi / 180, PWaveArrival: -6, SWaveArrival: 53.}, // R7F8D
50 {StationName: "S9AF3", Lat: 36.12860 * math.Pi / 180, Lon: 140.07353 * math.Pi / 180, PWaveArrival: -2.5, SWaveArrival: 79}, // S9AF3
51 {StationName: "R38DC", Lat: 35.13378 * math.Pi / 180, Lon: 138.92544 * math.Pi / 180, PWaveArrival: 1.5, SWaveArrival: 196}, // R38DC
52 }))
53
54 // Converges to 41.3762277742, 149.672389364, ass
55
56 // Example https://stationview.raspberryshake.org/#/?lat=36.83152&lon=136.82668&zoom=7.859&event=rs2025flrsdg&sta=R44C0
57 // time 0 is 04:25:00 UTC (epoch is t +15s according to USGS)
58 fmt.Println(locate.NelderMeadOptimization("rs2025flrsdg", &[]locate.Observation{
59 //{StationName: "R7F8D", Lat: 36.72115 * math.Pi / 180, Lon: 138.89604 * math.Pi / 180, PWaveArrival: 46.8, SWaveArrival: 2*60 + 14.8}, // R7F8D
60 //{StationName: "R38DC", Lat: 35.13137 * math.Pi / 180, Lon: 138.92348 * math.Pi / 180, PWaveArrival: 60.5, SWaveArrival: 2*60 + 51}, // R38DC
61 //{StationName: "R28BA", Lat: 35.39698 * math.Pi / 180, Lon: 133.87849 * math.Pi / 180, PWaveArrival: 61, SWaveArrival: 2*60 + 52}, // R28BA
62 {StationName: "RBB9C", Lat: 37.09561 * math.Pi / 180, Lon: 127.02144 * math.Pi / 180, PWaveArrival: 2*60 + 55, SWaveArrival: 4*60 + 23}, // RBB9C
63 {StationName: "R74A7", Lat: 34.91235 * math.Pi / 180, Lon: 135.79596 * math.Pi / 180, PWaveArrival: 52, SWaveArrival: 60 + 40}, // R74A7
64 {StationName: "RDBC2", Lat: 35.99544 * math.Pi / 180, Lon: 140.16287 * math.Pi / 180, PWaveArrival: 51, SWaveArrival: 60 + 27}, // RDBC2
65
66 }))
67
68 // Converges to 0.6474711480835122 2.4033395498559242, in rad, not bad
69
70 // Example https://stationview.raspberryshake.org/#/?lat=-45.41139&lon=168.89573&zoom=5.934&event=rs2025fwmrzv&sta=RF862
71 //
72 // time 0 is 01:43:00 UTC (epoch is t +12s according to USGS)
73 fmt.Println(locate.NelderMeadOptimization("rs2025fwmrzv", &[]locate.Observation{
74 {StationName: "RF862", Lat: -45.05554 * math.Pi / 180, Lon: 168.55697 * math.Pi / 180, PWaveArrival: 53.5, SWaveArrival: 60 + 27},
75 {StationName: "SC651", Lat: -17.75192 * math.Pi / 180, Lon: 168.31555 * math.Pi / 180, PWaveArrival: 6*60 + 15, SWaveArrival: 13 * 60},
76 //{StationName: "R6707", Lat: -35.20988 * math.Pi / 180, Lon: 149.08611 * math.Pi / 180, PWaveArrival: 4*60+10, SWaveArrival: 9*60+50},
77 {StationName: "R7A67", Lat: -42.85049 * math.Pi / 180, Lon: 147.35653 * math.Pi / 180, PWaveArrival: 3*60 + 20, SWaveArrival: 6 * 60},
78
79 /*R7A67
80 -42.85049
81 147.35653*/
82 /*}))
83 */
84}