Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions fdsn-station-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
}
},
"definitions": {
"fdsn-complex": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "number"
}
},
"fdsn-date-time": {
"type": "string",
"format": "date-time",
Expand Down Expand Up @@ -91,6 +99,10 @@
}
}
},
"fdsn-responseStages": {
"type": "array",
"items": { "$ref": "#/definitions/fdsn-responseStage" }
},
"fdsn-responseStage": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -162,17 +174,13 @@
"normalizationFrequency": {
"type": "number"
},
"zero": {
"zeros": {
"type": "array",
"items": {
"type": { "$ref": "#/definitions/fdsn-floatNoUnit" }
}
"items": { "$ref": "#/definitions/fdsn-complex" }
},
"pole": {
"poles": {
"type": "array",
"items": {
"type": { "$ref": "#/definitions/fdsn-floatNoUnit" }
}
"items": { "$ref": "#/definitions/fdsn-complex" }
}
}
}
Expand Down Expand Up @@ -238,7 +246,7 @@
"additionalProperties": false,
"properties": {
"inputSampleRate": {"type": "number"},
"factor": {"type": "number"},
"factor": {"type": "integer"},
"offset": {"type": "number"},
"delay": {"type": "number"},
"correction": {"type": "number"}
Expand Down Expand Up @@ -387,6 +395,10 @@
"type": "string",
"description": "Short site location description"
},
"country": {
"type": "string",
"description": "Country of site location"
},
"description": {
"type": "string",
"description": "Longer description of the site location"
Expand Down Expand Up @@ -496,6 +508,9 @@
"type": "number",
"description": "Frequency in Hertz at which scale is valid"
},
"responseStages": {
"$ref": "#/definitions/fdsn-responseStages"
},
"restrictedStatus": {
"$ref": "#/definitions/fdsn-restrictedStatus"
},
Expand Down
12 changes: 8 additions & 4 deletions tools/StationXML2StationJSON.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StationXML2StationJSON():
"""

NAMESPACE = "{http://www.fdsn.org/xml/station/1}"
MODULE = None
MODULE = "StationXML2StationJSON"
SCHEMA_VERSION = "1.0"

def __init__(self):
Expand Down Expand Up @@ -89,7 +89,7 @@ def extractPolesZeros(self, stage):
"type": "paz",
"inputUnits": self.findElementText(stage, ["InputUnits", "Name"]),
"outputUnits": self.findElementText(stage, ["OutputUnits", "Name"]),
"transferFunctionType": self.findElementText(stage, "PzTransferFunctionType"),
"pzTransferFunctionType": self.findElementText(stage, "PzTransferFunctionType"),
"normalizationFactor": self.findElementText(stage, "NormalizationFactor", float),
"normalizationFrequency": self.findElementText(stage, "NormalizationFrequency", float),
"zeros": map(self.extractComplex, stage.findall(self.NAMESPACE + "Zero")),
Expand All @@ -103,7 +103,11 @@ def extractCoefficient(self, x):
Returns float representation of an element
"""

return float(x.text)
return {
"value": float(x.text),
"plusError": 0,
"minError": 0
}


def extractDecimation(self, decimation):
Expand Down Expand Up @@ -205,7 +209,7 @@ def extractStage(self, stage):
"""

stageDict = {
"gain": self.findElementText(stage, ["StageGain", "Value"], float),
"stageGain": self.findElementText(stage, ["StageGain", "Value"], float),
"gainFrequency": self.findElementText(stage, ["StageGain", "Frequency"], float)
}

Expand Down
10 changes: 9 additions & 1 deletion tools/convert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import requests
import os
import json
import jsonschema

from StationXML2StationJSON import StationXML2StationJSON

Expand All @@ -10,11 +12,17 @@
FDSNStationXML and StationJSON
"""

URL = "https://www.orfeus-eu.org/fdsnws/station/1/query?net=NL&sta=*&cha=HHN&level=response"
URL = "https://www.orfeus-eu.org/fdsnws/station/1/query?net=NL&sta=HGN&cha=BHZ&level=response"

Convertor = StationXML2StationJSON()

# Parse & print
output = Convertor.convert(requests.get(URL).content)

# Validate against the schema
schemaPath = os.path.join(os.path.dirname(__file__), "..", "fdsn-station-schema.json");
with open(schemaPath, "rt") as filehandle:
schema = json.load(filehandle)
jsonschema.validate(output, schema)

print json.dumps(output, indent=4)