From 3776fe1c2ab248fe42149a85ced2a1522779cb01 Mon Sep 17 00:00:00 2001 From: Jean-Marie Saurel Date: Tue, 5 Jul 2022 14:01:14 +0000 Subject: [PATCH 1/3] First tentative to compute S-P from true phases --- CODE/cgi-bin/fdsnws-event2mc3.pl | 90 +++++++++++++++++++------------- CODE/cgi-bin/seiscomp2mc3.pl | 89 ++++++++++++++++++------------- 2 files changed, 105 insertions(+), 74 deletions(-) diff --git a/CODE/cgi-bin/fdsnws-event2mc3.pl b/CODE/cgi-bin/fdsnws-event2mc3.pl index 80c9c855..d9159c5d 100755 --- a/CODE/cgi-bin/fdsnws-event2mc3.pl +++ b/CODE/cgi-bin/fdsnws-event2mc3.pl @@ -44,6 +44,7 @@ =head1 DEPENDENCIES use FindBin; use lib $FindBin::Bin; use POSIX; +use Time::Piece; use WebObs::Config; use QML; @@ -296,46 +297,61 @@ =head1 DEPENDENCIES # --- selects first pick # sorting pick:time:value = chronological order - @tab = sort(findvalues('/pick/time/value=',\@event)); - my $evt_pick = $tab[0]; - my @pick = findnode('/pick',"/time/value=$evt_pick",\@event); - my $evt_pickID = findvalue('/\@publicID=',\@pick); - my $evt_sdate = substr($evt_pick,0,10) // ''; - my $evt_stime = substr($evt_pick,11,11) // ''; - $evt_stime =~ s/[A-Z]/0/g; # sometimes time value is "2012-05-07T18:46:53.7Z" - my $NET = findvalue('/waveformID/@networkCode=',\@pick) // ''; - my $STA = findvalue('/waveformID/@stationCode=',\@pick) // ''; - my $LOC = findvalue('/waveformID/@locationCode=',\@pick) // ''; - my $CHA = findvalue('/waveformID/@channelCode=',\@pick) // ''; - my $evt_scode = "$NET.$STA.$LOC.$CHA"; - print "station pickID = $evt_pickID\n"; - print "station time = $evt_pick\n"; - print "station code = $evt_scode\n"; - - - my @arrival = findnode('/arrival',"/pickID=$evt_pickID",\@origin); - - my $evt_pha = ''; + my $evt_sdate = ''; + my $evt_stime = ''; + my $evt_SP = ''; + my $evt_scode = ''; my $evt_dist = ''; my $evt_unique = 0; - my $evt_SP = ''; - if (@arrival) { - # --- unique arrival or not - if (scalar(@arrival) == 1) { - $evt_unique = 1; - } - # --- finds first station phase and distance (using "origin:arrival") - $evt_pha = findvalue('/phase=',\@arrival); - $evt_dist = findvalue('/distance=',\@arrival); - $evt_dist *= 111 if ($evt_dist); - print "station phase = $evt_pha\n"; - print "station distance = ".($evt_dist ? "$evt_dist":"")."\n"; - # --- computes S-P and duration from distance and magnitude - $evt_SP = ($evt_dist ? sprintf("%1.2f",$evt_dist/8):""); - print "station S-P = $evt_SP\n"; - } else { - print "* Warning: no arrivals (phase, distance, S-P)!\n"; + @tab = sort(findvalues('/pick/time/value=',\@event)); + # --- Iterate to find first P phase + foreach my $evt_pick_time (@tab) { + my @pick = findnode('/pick',"/time/value=$evt_pick_time",\@event); + my $phase = findvalue('/phaseHint=',\@pick); + $evt_pick_time =~ s/[A-Z]$/0/g; # sometimes time value is "2012-05-07T18:46:53.7Z" + + if ($phase == 'P') { + my $evt_pickID = findvalue('/\@publicID=',\@pick); + $evt_sdate = substr($evt_pick_time,0,10); + $evt_stime = substr($evt_pick_time,11,11); + my $NET = findvalue('/waveformID/@networkCode=',\@pick) // ''; + my $STA = findvalue('/waveformID/@stationCode=',\@pick) // ''; + my $LOC = findvalue('/waveformID/@locationCode=',\@pick) // ''; + my $CHA = findvalue('/waveformID/@channelCode=',\@pick) // ''; + $evt_scode = "$NET.$STA.$LOC.$CHA"; + print "station pickID = $evt_pickID\n"; + print "station time = $evt_pick_time\n"; + print "station code = $evt_scode\n"; + + my @arrival = findnode('/arrival',"/pickID=$evt_pickID",\@origin); + + my $evt_pha = ''; + if (@arrival) { + # --- unique arrival or not + if (scalar(@arrival) == 1) { + $evt_unique = 1; + } + + # --- finds first station phase and distance (using "origin:arrival") + $evt_pha = findvalue('/phase=',\@arrival); + $evt_dist = findvalue('/distance=',\@arrival); + $evt_dist *= 111 if ($evt_dist); + print "station phase = $evt_pha\n"; + print "station distance = ".($evt_dist ? "$evt_dist":"")."\n"; + } else { + print "* Warning: no arrivals (phase, distance, S-P)!\n"; + } + } + # --- Search matching S phase to compute S-P + if ( ($phase == 'S') && (findvalue('/waveformID/@stationCode=',\@pick) == split('.',$evt_scode)[1]) ) { + # --- convert P and S times as epochs + my $ptime = Time::Piece->strptime($evt_sdate . 'T' . substr($evt_stime,0,9), '%Y-%m-%dT%H:%M:%S') + my $stime = Time::Piece->strptime(substr($evt_pick_time,0,19), '%Y-%m-%dT%H:%M:%S') + $evt_SP = ($stime - $ptime) + (substr($evt_pick_time,19,2) - substr($evt_stime,9,2)) / 100 + print "station S-P = $evt_SP\n"; + last; + } } # --- computes duration from distance and magnitude diff --git a/CODE/cgi-bin/seiscomp2mc3.pl b/CODE/cgi-bin/seiscomp2mc3.pl index 14f6d2ca..75d0ec35 100755 --- a/CODE/cgi-bin/seiscomp2mc3.pl +++ b/CODE/cgi-bin/seiscomp2mc3.pl @@ -238,46 +238,61 @@ =head1 DEPENDENCIES # --- selects first pick # sorting pick:time:value = chronological order - @tab = sort(findvalues('/pick/time/value=',\@event)); - my $evt_pick = $tab[0]; - my @pick = findnode('/pick',"/time/value=$evt_pick",\@event); - my $evt_pickID = findvalue('/\@publicID=',\@pick); - my $evt_sdate = substr($evt_pick,0,10) // ''; - my $evt_stime = substr($evt_pick,11,11) // ''; - $evt_stime =~ s/[A-Z]/0/g; # sometimes time value is "2012-05-07T18:46:53.7Z" - my $NET = findvalue('/waveformID/@networkCode=',\@pick) // ''; - my $STA = findvalue('/waveformID/@stationCode=',\@pick) // ''; - my $LOC = findvalue('/waveformID/@locationCode=',\@pick) // ''; - my $CHA = findvalue('/waveformID/@channelCode=',\@pick) // ''; - my $evt_scode = "$NET.$STA.$LOC.$CHA"; - print "station pickID = $evt_pickID\n"; - print "station time = $evt_pick\n"; - print "station code = $evt_scode\n"; - - - my @arrival = findnode('/arrival',"/pickID=$evt_pickID",\@origin); - - my $evt_pha = ''; + my $evt_sdate = ''; + my $evt_stime = ''; + my $evt_SP = ''; + my $evt_scode = ''; my $evt_dist = ''; my $evt_unique = 0; - my $evt_SP = ''; - if (@arrival) { - # --- unique arrival or not - if (scalar(@arrival) == 1) { - $evt_unique = 1; - } - # --- finds first station phase and distance (using "origin:arrival") - $evt_pha = findvalue('/phase=',\@arrival); - $evt_dist = findvalue('/distance=',\@arrival); - $evt_dist *= 111 if ($evt_dist); - print "station phase = $evt_pha\n"; - print "station distance = ".($evt_dist ? "$evt_dist":"")."\n"; - # --- computes S-P and duration from distance and magnitude - $evt_SP = ($evt_dist ? sprintf("%1.2f",$evt_dist/8):""); - print "station S-P = $evt_SP\n"; - } else { - print "* Warning: no arrivals (phase, distance, S-P)!\n"; + @tab = sort(findvalues('/pick/time/value=',\@event)); + # --- Iterate to find first P phase + foreach my $evt_pick_time (@tab) { + my @pick = findnode('/pick',"/time/value=$evt_pick_time",\@event); + my $phase = findvalue('/phaseHint=',\@pick); + $evt_pick_time =~ s/[A-Z]$/0/g; # sometimes time value is "2012-05-07T18:46:53.7Z" + + if ($phase == 'P') { + my $evt_pickID = findvalue('/\@publicID=',\@pick); + $evt_sdate = substr($evt_pick_time,0,10); + $evt_stime = substr($evt_pick_time,11,11); + my $NET = findvalue('/waveformID/@networkCode=',\@pick) // ''; + my $STA = findvalue('/waveformID/@stationCode=',\@pick) // ''; + my $LOC = findvalue('/waveformID/@locationCode=',\@pick) // ''; + my $CHA = findvalue('/waveformID/@channelCode=',\@pick) // ''; + $evt_scode = "$NET.$STA.$LOC.$CHA"; + print "station pickID = $evt_pickID\n"; + print "station time = $evt_pick_time\n"; + print "station code = $evt_scode\n"; + + my @arrival = findnode('/arrival',"/pickID=$evt_pickID",\@origin); + + my $evt_pha = ''; + if (@arrival) { + # --- unique arrival or not + if (scalar(@arrival) == 1) { + $evt_unique = 1; + } + + # --- finds first station phase and distance (using "origin:arrival") + $evt_pha = findvalue('/phase=',\@arrival); + $evt_dist = findvalue('/distance=',\@arrival); + $evt_dist *= 111 if ($evt_dist); + print "station phase = $evt_pha\n"; + print "station distance = ".($evt_dist ? "$evt_dist":"")."\n"; + } else { + print "* Warning: no arrivals (phase, distance, S-P)!\n"; + } + } + # --- Search matching S phase to compute S-P + if ( ($phase == 'S') && (findvalue('/waveformID/@stationCode=',\@pick) == split('.',$evt_scode)[1]) ) { + # --- convert P and S times as epochs + my $ptime = Time::Piece->strptime($evt_sdate . 'T' . substr($evt_stime,0,9), '%Y-%m-%dT%H:%M:%S') + my $stime = Time::Piece->strptime(substr($evt_pick_time,0,19), '%Y-%m-%dT%H:%M:%S') + $evt_SP = ($stime - $ptime) + (substr($evt_pick_time,19,2) - substr($evt_stime,9,2)) / 100 + print "station S-P = $evt_SP\n"; + last; + } } # --- computes duration from distance and magnitude From cecaa340175c58a6be227e6137e1d37ca625376b Mon Sep 17 00:00:00 2001 From: Jean-Marie Saurel Date: Tue, 5 Jul 2022 14:27:14 +0000 Subject: [PATCH 2/3] Forgotten library --- CODE/cgi-bin/seiscomp2mc3.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/CODE/cgi-bin/seiscomp2mc3.pl b/CODE/cgi-bin/seiscomp2mc3.pl index 75d0ec35..78add5e6 100755 --- a/CODE/cgi-bin/seiscomp2mc3.pl +++ b/CODE/cgi-bin/seiscomp2mc3.pl @@ -41,6 +41,7 @@ =head1 DEPENDENCIES use FindBin; use lib $FindBin::Bin; use POSIX; +use Time::Piece; use WebObs::Config; use QML; From b739c47d8a01f7cd10626a22b11e34917e3c5371 Mon Sep 17 00:00:00 2001 From: Jean-Marie Saurel Date: Wed, 13 Jul 2022 12:11:06 +0000 Subject: [PATCH 3/3] Tested and debugged --- CODE/cgi-bin/fdsnws-event2mc3.pl | 37 ++++++++++++++++++++++++++------ CODE/cgi-bin/seiscomp2mc3.pl | 2 +- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CODE/cgi-bin/fdsnws-event2mc3.pl b/CODE/cgi-bin/fdsnws-event2mc3.pl index d9159c5d..ce599326 100755 --- a/CODE/cgi-bin/fdsnws-event2mc3.pl +++ b/CODE/cgi-bin/fdsnws-event2mc3.pl @@ -311,7 +311,7 @@ =head1 DEPENDENCIES my $phase = findvalue('/phaseHint=',\@pick); $evt_pick_time =~ s/[A-Z]$/0/g; # sometimes time value is "2012-05-07T18:46:53.7Z" - if ($phase == 'P') { + if ($phase eq 'P') { my $evt_pickID = findvalue('/\@publicID=',\@pick); $evt_sdate = substr($evt_pick_time,0,10); $evt_stime = substr($evt_pick_time,11,11); @@ -342,13 +342,38 @@ =head1 DEPENDENCIES } else { print "* Warning: no arrivals (phase, distance, S-P)!\n"; } + last; } - # --- Search matching S phase to compute S-P - if ( ($phase == 'S') && (findvalue('/waveformID/@stationCode=',\@pick) == split('.',$evt_scode)[1]) ) { + } + # --- Search matching S phase to compute S-P + foreach my $evt_pick_time (@tab) { + my @pick = findnode('/pick',"/time/value=$evt_pick_time",\@event); + my $phase = findvalue('/phaseHint=',\@pick); + my ($n,$s,$c,$l) = split(/\./,$evt_scode); + + if ( ($phase eq 'S') && (findvalue('/waveformID/@stationCode=',\@pick) eq $s) ) { + my $evt_pickID = findvalue('/\@publicID=',\@pick); + my $NET = findvalue('/waveformID/@networkCode=',\@pick) // ''; + my $STA = findvalue('/waveformID/@stationCode=',\@pick) // ''; + my $LOC = findvalue('/waveformID/@locationCode=',\@pick) // ''; + my $CHA = findvalue('/waveformID/@channelCode=',\@pick) // ''; + $evt_scode = "$NET.$STA.$LOC.$CHA"; + print "station pickID = $evt_pickID\n"; + print "station time = $evt_pick_time\n"; + print "station code = $evt_scode\n"; + + my @arrival = findnode('/arrival',"/pickID=$evt_pickID",\@origin); + + my $evt_pha = ''; + if (@arrival) { + # --- finds first station phase and distance (using "origin:arrival") + $evt_pha = findvalue('/phase=',\@arrival); + print "station phase = $evt_pha\n"; + } # --- convert P and S times as epochs - my $ptime = Time::Piece->strptime($evt_sdate . 'T' . substr($evt_stime,0,9), '%Y-%m-%dT%H:%M:%S') - my $stime = Time::Piece->strptime(substr($evt_pick_time,0,19), '%Y-%m-%dT%H:%M:%S') - $evt_SP = ($stime - $ptime) + (substr($evt_pick_time,19,2) - substr($evt_stime,9,2)) / 100 + my $ptime = Time::Piece->strptime($evt_sdate . 'T' . substr($evt_stime,0,8), '%Y-%m-%dT%H:%M:%S'); + my $stime = Time::Piece->strptime(substr($evt_pick_time,0,19), '%Y-%m-%dT%H:%M:%S'); + $evt_SP = ($stime - $ptime) + (substr($evt_pick_time,20,2) - substr($evt_stime,9,2)) / 100; print "station S-P = $evt_SP\n"; last; } diff --git a/CODE/cgi-bin/seiscomp2mc3.pl b/CODE/cgi-bin/seiscomp2mc3.pl index 78add5e6..63a9054e 100755 --- a/CODE/cgi-bin/seiscomp2mc3.pl +++ b/CODE/cgi-bin/seiscomp2mc3.pl @@ -290,7 +290,7 @@ =head1 DEPENDENCIES # --- convert P and S times as epochs my $ptime = Time::Piece->strptime($evt_sdate . 'T' . substr($evt_stime,0,9), '%Y-%m-%dT%H:%M:%S') my $stime = Time::Piece->strptime(substr($evt_pick_time,0,19), '%Y-%m-%dT%H:%M:%S') - $evt_SP = ($stime - $ptime) + (substr($evt_pick_time,19,2) - substr($evt_stime,9,2)) / 100 + $evt_SP = ($stime - $ptime) + (substr($evt_pick_time,20,2) - substr($evt_stime,9,2)) / 100 print "station S-P = $evt_SP\n"; last; }