Skip to content

Commit

Permalink
Merge pull request #168 from GeoNet/sc6
Browse files Browse the repository at this point in the history
add support for seiscomp3-schema/0.6, 0.12
  • Loading branch information
sue-h-gns committed May 14, 2024
2 parents 0a0f3e4 + d4e1051 commit 1a968ac
Show file tree
Hide file tree
Showing 6 changed files with 7,573 additions and 4 deletions.
6 changes: 5 additions & 1 deletion sc3ml/sc3ml.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
)

const (
sc3ml06 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.6`
sc3ml07 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.7`
sc3ml08 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.8`
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`
sc3ml12 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.12`
sc3ml13 = `http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.13`
)

Expand Down Expand Up @@ -144,19 +146,21 @@ type Amplitude struct {
// the objects referenced by ID in the SeisComPML e.g., PreferredOrigin,
// PreferredMagnitude etc.
//
// Supported SC3ML versions are 0.7, 0.8, 0.9, 0.10, 0.11
// Supported SC3ML versions are 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13
// Any other versions will result in a error.
func Unmarshal(b []byte, s *Seiscomp) error {
if err := xml.Unmarshal(b, s); err != nil {
return err
}

switch s.XMLns {
case sc3ml06:
case sc3ml07:
case sc3ml08:
case sc3ml09:
case sc3ml10:
case sc3ml11:
case sc3ml12:
case sc3ml13:
default:
return errors.New("unsupported SC3ML version")
Expand Down
89 changes: 86 additions & 3 deletions sc3ml/sc3ml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ 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.6.xsd 2801727_0.6.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.12.xsd 2024p344188_0.12.xml
xmllint --noout --schema sc3ml_0.13.xsd 2024p344188_0.13.xml
*/
func TestUnmarshal(t *testing.T) {
Expand Down Expand Up @@ -388,8 +390,89 @@ func TestDecodeSC3ML07CMT(t *testing.T) {
}
}

func TestUnmarshall13(t *testing.T) {
for _, input := range []string{"2024p344188_0.13.xml"} {
func TestUnmarshall06(t *testing.T) {
for _, input := range []string{"2801727_0.6.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 != "2801727" {
t.Errorf("%s: expected publicID 2801727 got %s", input, e.PublicID)
}

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

if e.PreferredOrigin.Time.Value.Format(time.RFC3339Nano) != "2007-10-01T13:35:26.69Z" {
t.Errorf("%s: expected 2007-10-01T13:35:26.69Z, got %s", input, e.PreferredOrigin.Time.Value.Format(time.RFC3339Nano))
}

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

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

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

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

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

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

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

if e.PreferredOrigin.Quality.UsedPhaseCount != 14 {
t.Errorf("%s: UsedPhaseCount expected 14 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 e.PreferredMagnitude.Magnitude.Value != 4.9 {
t.Errorf("%s: Magnitude expected 4.9 got %f", input, e.PreferredMagnitude.Magnitude.Value)
}

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

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

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

0 comments on commit 1a968ac

Please sign in to comment.