Skip to content

Commit

Permalink
Merge pull request #250 from GeoNet/sc13
Browse files Browse the repository at this point in the history
Update for SeisComPML schema0.6, 0.12 0.13
  • Loading branch information
sue-h-gns authored May 14, 2024
2 parents c18af72 + 665acd7 commit 8941dfe
Show file tree
Hide file tree
Showing 573 changed files with 70,663 additions and 27,056 deletions.
729 changes: 729 additions & 0 deletions cmd/fdsn-quake-consumer/assets/sc3ml_0.12__quakeml_1.2.xsl

Large diffs are not rendered by default.

743 changes: 743 additions & 0 deletions cmd/fdsn-quake-consumer/assets/sc3ml_0.13__quakeml_1.2.xsl

Large diffs are not rendered by default.

685 changes: 685 additions & 0 deletions cmd/fdsn-quake-consumer/assets/sc3ml_0.6__quakeml_1.2.xsl

Large diffs are not rendered by default.

965 changes: 965 additions & 0 deletions cmd/fdsn-quake-consumer/etc/2024p344188_0.12.xml

Large diffs are not rendered by default.

965 changes: 965 additions & 0 deletions cmd/fdsn-quake-consumer/etc/2024p344188_0.13.xml

Large diffs are not rendered by default.

4,092 changes: 4,092 additions & 0 deletions cmd/fdsn-quake-consumer/etc/2801727_0.6.xml

Large diffs are not rendered by default.

59 changes: 35 additions & 24 deletions cmd/fdsn-quake-consumer/sc3ml.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import (

const deleted = `not existing`

var sc3ml06 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.6" version="0.6">`)
var sc3ml07 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.7" version="0.7">`)
var sc3ml08 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.8" version="0.8">`)
var sc3ml09 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.9" version="0.9">`)
var sc3ml10 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.10" version="0.10">`)
var sc3ml11 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.11" version="0.11">`)
var sc3ml12 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.12" version="0.12">`)
var sc3ml13 = []byte(`<seiscomp xmlns="http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.13" version="0.13">`)

// event is for saving information to the db.
// field names must match the column names in fdsn.event and the field names must be exported.
Expand Down Expand Up @@ -55,39 +58,43 @@ type event struct {
toQuakeMLEvent converts seisComPML to a QuakeML event fragment using an XSLT.
Supported versions of SC3ML are
* 0.7
* 0.8
* 0.9
* 0.10
* 0.11
- 0.6
- 0.7
- 0.8
- 0.9
- 0.10
- 0.11
- 0.12
- 0.13
The xslt source is from http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.7/sc3ml_0.7__quakeml_1.2.xsl
It has been edited to output only an Event fragment without the parent elements and namespaces. e.g.,
129d128
< xmlns="http://quakeml.org/xmlns/bed/1.2"
132c131
< <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
---
> <xsl:output method="xml" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>
138c137
< <xsl:variable name="ID_PREFIX" select="'smi:org.gfz-potsdam.de/geofon/'"/>
---
> <xsl:variable name="ID_PREFIX" select="'smi:nz.org.geonet/'"/>
145d143
< <q:quakeml>
147d144
< <eventParameters>
156d152
< </eventParameters>
158d153
< </q:quakeml>
129d128
< xmlns="http://quakeml.org/xmlns/bed/1.2"
132c131
< <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
---
> <xsl:output method="xml" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>
138c137
< <xsl:variable name="ID_PREFIX" select="'smi:org.gfz-potsdam.de/geofon/'"/>
---
> <xsl:variable name="ID_PREFIX" select="'smi:nz.org.geonet/'"/>
145d143
< <q:quakeml>
147d144
< <eventParameters>
156d152
< </eventParameters>
158d153
< </q:quakeml>
*/
func toQuakeMLEvent(seisComPML []byte) (string, error) {
cmd := exec.Command("/usr/bin/xsltproc")

switch {
case bytes.Contains(seisComPML, sc3ml06):
cmd.Args = append(cmd.Args, "assets/sc3ml_0.6__quakeml_1.2.xsl")
case bytes.Contains(seisComPML, sc3ml07):
cmd.Args = append(cmd.Args, "assets/sc3ml_0.7__quakeml_1.2.xsl")
case bytes.Contains(seisComPML, sc3ml08):
Expand All @@ -98,6 +105,10 @@ func toQuakeMLEvent(seisComPML []byte) (string, error) {
cmd.Args = append(cmd.Args, "assets/sc3ml_0.10__quakeml_1.2.xsl")
case bytes.Contains(seisComPML, sc3ml11):
cmd.Args = append(cmd.Args, "assets/sc3ml_0.11__quakeml_1.2.xsl")
case bytes.Contains(seisComPML, sc3ml12):
cmd.Args = append(cmd.Args, "assets/sc3ml_0.12__quakeml_1.2.xsl")
case bytes.Contains(seisComPML, sc3ml13):
cmd.Args = append(cmd.Args, "assets/sc3ml_0.13__quakeml_1.2.xsl")

default:
return "", fmt.Errorf("found no %s", "XSLT")
Expand Down
112 changes: 112 additions & 0 deletions cmd/fdsn-quake-consumer/sc3ml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,118 @@ func TestEventUnmarshal(t *testing.T) {
}
}

func TestEventUnmarshalSC06(t *testing.T) {
for _, input := range []string{"2801727_0.6.xml"} {
b, err := os.ReadFile("etc/" + input)
if err != nil {
t.Fatal(err)
}

var e event
if err = unmarshal(b, &e); err != nil {
t.Error(err)
}
if !strings.HasPrefix(e.Quakeml12Event, `<event publicID="smi:nz.org.geonet/2801727">`) {
t.Errorf("%s: quakeml fragment should start with <event...", input)
}

if !strings.HasSuffix(e.Quakeml12Event, `</event>`) {
t.Errorf("%s: quakeml fragment should end with </event>", input)
}

c := event{
PublicID: "2801727",
EventType: "outside of network interest",
Longitude: 164.175,
Latitude: -49.10301,
Depth: 10,
DepthType: "operator assigned",
EvaluationMethod: "GROPE",
EarthModel: "nz1dr",
EvaluationMode: "",
EvaluationStatus: "reviewed",
UsedPhaseCount: 14,
UsedStationCount: 10,
OriginError: 0.29521,
AzimuthalGap: 334,
MinimumDistance: 3.39,
Magnitude: 4.9,
MagnitudeUncertainty: 0,
MagnitudeType: "Mw",
MagnitudeStationCount: 0,
Deleted: false,
Sc3ml: string(b),
}

c.ModificationTime, _ = time.Parse(time.RFC3339Nano, "2012-05-21T16:04:00Z")
c.OriginTime, _ = time.Parse(time.RFC3339Nano, "2007-10-01T13:35:26.69Z")

if c.Quakeml12Event, err = toQuakeMLEvent(b); err != nil {
t.Error(err)
}

if !reflect.DeepEqual(e, c) {
t.Errorf("c not equal to e, expected: %+v", e)
}
}
}

func TestEventUnmarshalSC12_13(t *testing.T) {
for _, input := range []string{"2024p344188_0.12.xml", "2024p344188_0.13.xml"} {
b, err := os.ReadFile("etc/" + input)
if err != nil {
t.Fatal(err)
}

var e event

if err = unmarshal(b, &e); err != nil {
t.Error(err)
}
if !strings.HasPrefix(e.Quakeml12Event, `<event publicID="smi:nz.org.geonet/2024p344188">`) {
t.Errorf("%s: quakeml fragment should start with <event...", input)
}

if !strings.HasSuffix(e.Quakeml12Event, `</event>`) {
t.Errorf("%s: quakeml fragment should end with </event>", input)
}

c := event{
PublicID: "2024p344188",
EventType: "other",
Longitude: 176.2128674424493,
Latitude: -38.62063477317881,
Depth: 5.1162109375,
EvaluationMethod: "NonLinLoc",
EarthModel: "nz3drx",
EvaluationMode: "automatic",
EvaluationStatus: "",
UsedPhaseCount: 10,
UsedStationCount: 10,
OriginError: 0.13178423630674604,
AzimuthalGap: 76.05025526639076,
MinimumDistance: 0.0752301603770797,
Magnitude: 1.4089917745797527,
MagnitudeUncertainty: 0,
MagnitudeType: "M",
MagnitudeStationCount: 5,
Deleted: false,
Sc3ml: string(b),
}

c.ModificationTime, _ = time.Parse(time.RFC3339Nano, "2024-05-07T22:58:22.37962Z")
c.OriginTime, _ = time.Parse(time.RFC3339Nano, "2024-05-07T08:24:09.853066Z")

if c.Quakeml12Event, err = toQuakeMLEvent(b); err != nil {
t.Error(err)
}

if !reflect.DeepEqual(e, c) {
t.Errorf("c not equal to e, expected: %+v", e)
}
}
}

// TestEventType tests that the remapping of SC3ML event type to QuakeML is correct.
// The bug in the sc3ml_*_quakeml_1.2.xsl conversion (inserting "other" instead of "other event"
// has been fixed locally and reported upstream. GMC 12 Sept 2017
Expand Down
4 changes: 2 additions & 2 deletions cmd/fdsn-ws/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type fdsnError struct {
timestamp time.Time
}

func fdsnErrorHandler(err error, h http.Header, b *bytes.Buffer) error {
func fdsnErrorHandler(err error, h http.Header, b *bytes.Buffer, nounce string) error {
switch e := err.(type) {
case fdsnError:
var ver string
Expand Down Expand Up @@ -109,5 +109,5 @@ func fdsnErrorHandler(err error, h http.Header, b *bytes.Buffer) error {
return nil
}

return weft.TextError(err, h, b)
return weft.TextError(err, h, b, nounce)
}
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ module github.com/GeoNet/fdsn
go 1.21

require (
github.com/GeoNet/kit v0.0.0-20220629232654-4b4c51b3443f
github.com/GeoNet/kit v0.0.0-20240512234353-4d4493144f60
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/gorilla/schema v1.2.0
github.com/lib/pq v1.10.3
)

require (
github.com/aws/aws-sdk-go-v2 v1.16.2 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.15.3 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.18.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 // indirect
github.com/aws/smithy-go v1.11.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.3 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.52.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.31.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.4 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit 8941dfe

Please sign in to comment.