Skip to content

Commit

Permalink
update scml version 0.13 as per #15614
Browse files Browse the repository at this point in the history
  • Loading branch information
bpeng committed May 8, 2024
1 parent e45c2a7 commit b677a50
Show file tree
Hide file tree
Showing 4 changed files with 2,365 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sc3ml/sc3ml.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
sc3ml09 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.9`
sc3ml10 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.10`
sc3ml11 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.11`
sc3ml13 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.13`
)

type Seiscomp struct {
Expand Down Expand Up @@ -156,6 +157,7 @@ func Unmarshal(b []byte, s *Seiscomp) error {
case sc3ml09:
case sc3ml10:
case sc3ml11:
case sc3ml13:
default:
return errors.New("unsupported SC3ML version")
}
Expand Down
99 changes: 94 additions & 5 deletions sc3ml/sc3ml_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sc3ml_test

import (
"math"
"os"
"testing"
"time"
Expand All @@ -12,11 +13,12 @@ import (
Versions of the input files are created by editing the source file and changing
the version. The validating them using the XSDs:
xmllint --noout --schema sc3ml_0.7.xsd 2015p768477_0.7.xml
xmllint --noout --schema sc3ml_0.8.xsd 2015p768477_0.8.xml
xmllint --noout --schema sc3ml_0.9.xsd 2015p768477_0.9.xml
xmllint --noout --schema sc3ml_0.10.xsd 2015p768477_0.10.xml
xmllint --noout --schema sc3ml_0.11.xsd 2015p768477_0.11.xml
xmllint --noout --schema sc3ml_0.7.xsd 2015p768477_0.7.xml
xmllint --noout --schema sc3ml_0.8.xsd 2015p768477_0.8.xml
xmllint --noout --schema sc3ml_0.9.xsd 2015p768477_0.9.xml
xmllint --noout --schema sc3ml_0.10.xsd 2015p768477_0.10.xml
xmllint --noout --schema sc3ml_0.11.xsd 2015p768477_0.11.xml
xmllint --noout --schema sc3ml_0.13.xsd 2024p344188_0.13.xml
*/
func TestUnmarshal(t *testing.T) {
for _, input := range []string{"2015p768477_0.7.xml", "2015p768477_0.8.xml", "2015p768477_0.9.xml", "2015p768477_0.10.xml", "2015p768477_0.11.xml"} {
Expand Down Expand Up @@ -387,6 +389,87 @@ func TestDecodeSC3ML07CMT(t *testing.T) {
}
}

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

var s sc3ml.Seiscomp

if err = sc3ml.Unmarshal(b, &s); err != nil {
t.Errorf("%s: %s", input, err.Error())
}

if len(s.EventParameters.Events) != 1 {
t.Errorf("should have found 1 event for %s.", input)
}

e := s.EventParameters.Events[0]

if e.PublicID != "2024p344188" {
t.Errorf("%s: expected publicID 2024p344188 got %s", input, e.PublicID)
}

if e.Type != "other" {
t.Errorf("%s: expected type other got %s", input, e.Type)
}

if e.PreferredOrigin.Time.Value.Format(time.RFC3339Nano) != "2024-05-07T08:24:09.853066Z" {
t.Errorf("%s: expected 2024-05-07T08:24:09.853066Z, got %s", input, e.PreferredOrigin.Time.Value.Format(time.RFC3339Nano))
}

if !valueEqual(e.PreferredOrigin.Latitude.Value, -38.620635) {
t.Errorf("%s: Latitude expected -38.620635 got %f", input, e.PreferredOrigin.Latitude.Value)
}

if !valueEqual(e.PreferredOrigin.Longitude.Value, 176.212867) {
t.Errorf("%s: Longitude expected 176.212867 got %f", input, e.PreferredOrigin.Longitude.Value)
}

if !valueEqual(e.PreferredOrigin.Depth.Value, 5.116211) {
t.Errorf("%s: Depth expected 5.116211 got %f", input, e.PreferredOrigin.Depth.Value)
}

if e.PreferredOrigin.MethodID != "NonLinLoc" {
t.Errorf("%s: MethodID expected NonLinLoc got %s", input, e.PreferredOrigin.MethodID)
}

if e.PreferredOrigin.EarthModelID != "nz3drx" {
t.Errorf("%s: EarthModelID expected nz3drx got %s", input, e.PreferredOrigin.EarthModelID)
}

if !valueEqual(e.PreferredOrigin.Quality.AzimuthalGap, 76.050255) {
t.Errorf("%s: AzimuthalGap expected 76.050255 got %f", input, e.PreferredOrigin.Quality.AzimuthalGap)
}

if !valueEqual(e.PreferredOrigin.Quality.MinimumDistance, 0.075230) {
t.Errorf("%s: MinimumDistance expected 0.075230 got %f", input, e.PreferredOrigin.Quality.MinimumDistance)
}

if e.PreferredOrigin.Quality.UsedPhaseCount != 10 {
t.Errorf("%s: UsedPhaseCount expected 10 got %d", input, e.PreferredOrigin.Quality.UsedPhaseCount)
}

if e.PreferredOrigin.Quality.UsedStationCount != 10 {
t.Errorf("%s: UsedStationCount expected 10 got %d", input, e.PreferredOrigin.Quality.UsedStationCount)
}

if !valueEqual(e.PreferredMagnitude.Magnitude.Value, 1.408992) {
t.Errorf("%s: Magnitude expected 1.408992 got %f", input, e.PreferredMagnitude.Magnitude.Value)
}

if e.PreferredMagnitude.Type != "M" {
t.Errorf("%s: Magnitude type expected M got %s", input, e.PreferredMagnitude.Type)
}

if e.PreferredMagnitude.StationCount != 5 {
t.Errorf("%s: Expected StationCount 5 gor %d", input, e.PreferredMagnitude.StationCount)
}
}
}

func TestUnmarshalUnsupported(t *testing.T) {
for _, input := range []string{"2015p768477_0.4.xml"} {
b, err := os.ReadFile("testdata/" + input)
Expand Down Expand Up @@ -416,3 +499,9 @@ func BenchmarkUnmarshalSeiscompml(b *testing.B) {
_ = sc3ml.Unmarshal(by, &s)
}
}

// check if two float values are equal
func valueEqual(value1, value2 float64) bool {
tolerance := 0.000001
return math.Abs(value1-value2) < tolerance
}

0 comments on commit b677a50

Please sign in to comment.