Skip to content
Snippets Groups Projects
Commit 6a68b01b authored by Wilbur, Spencer Franklin's avatar Wilbur, Spencer Franklin
Browse files

I cahnged the call from IRISFactory to FDSNFactory in data.py, updated the...

I cahnged the call from IRISFactory to FDSNFactory in data.py, updated the validator in DataAPIQuery.py to accept Variometer IDs, added a new file called variometers.py so that the ASL_Observatory_index can be used by the webservice, and this includes a change to app.py where I added a router to the new variometers.py script. I opted to not change any of the file names currently, but will give this some more thought. I wanted to commit these chagnes soon so that Nick can begin working on the front end.
parent a0761858
No related branches found
No related tags found
1 merge request!319Variometer API Additions
......@@ -8,7 +8,7 @@ from pydantic import BaseModel, root_validator, validator
from ... import pydantic_utcdatetime
from .Element import ELEMENTS
from .Observatory import OBSERVATORY_INDEX
from .Observatory import OBSERVATORY_INDEX, ASL_OBSERVATORY_INDEX
DEFAULT_ELEMENTS = ["X", "Y", "Z", "F"]
......@@ -100,10 +100,11 @@ class DataApiQuery(BaseModel):
@validator("id")
def validate_id(cls, id: str) -> str:
if id not in OBSERVATORY_INDEX:
complete_observatory_index = {**OBSERVATORY_INDEX, **ASL_OBSERVATORY_INDEX}
if id not in complete_observatory_index:
raise ValueError(
f"Bad observatory id '{id}'."
f" Valid values are: {', '.join(sorted(OBSERVATORY_INDEX.keys()))}."
f" Valid values are: {', '.join(sorted(complete_observatory_index.keys()))}."
)
return id
......
......@@ -5,7 +5,7 @@ from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse, PlainTextResponse, RedirectResponse
from obspy import UTCDateTime
from . import algorithms, data, elements, metadata, observatories
from . import algorithms, data, elements, metadata, observatories, variometers
ERROR_CODE_MESSAGES = {
......@@ -37,6 +37,7 @@ app.include_router(algorithms.router)
app.include_router(data.router)
app.include_router(elements.router)
app.include_router(observatories.router)
app.include_router(variometers.router)
if METADATA_ENDPOINT:
app.include_router(metadata.router)
......
......@@ -6,7 +6,7 @@ from obspy import UTCDateTime, Stream
from starlette.responses import Response
from ... import DerivedTimeseriesFactory, TimeseriesFactory, TimeseriesUtility
from ...edge import EdgeFactory, IRISFactory, MiniSeedFactory
from ...edge import EdgeFactory, FDSNFactory, MiniSeedFactory
from ...iaga2002 import IAGA2002Writer
from ...imfjson import IMFJSONWriter
from .Observatory import ASL_OBSERVATORY_INDEX
......@@ -33,7 +33,7 @@ def get_data_factory(
host = query.data_host or DataHost.DEFAULT
sampling_period = query.sampling_period
if query.id in ASL_OBSERVATORY_INDEX:
factory = IRISFactory(network="IU", locationCode="40")
factory = FDSNFactory(network="IU", locationCode="40")
elif sampling_period in [
SamplingPeriod.TEN_HERTZ,
SamplingPeriod.HOUR,
......
from typing import Dict
from fastapi import APIRouter, Response
from .Observatory import ASL_OBSERVATORY_INDEX
router = APIRouter()
@router.get(
"/observatories/",
description="Information regarding available geomagnetic observatories",
)
def get_observatories() -> Dict:
return {
"type": "FeatureCollection",
"features": [
ASL_OBSERVATORY_INDEX[id].geojson() for id in ASL_OBSERVATORY_INDEX.keys()
],
}
@router.get(
"/observatories/{id}",
description="Search observatories by 3-letter observatory code",
)
async def get_observatory_by_id(id: str) -> Dict:
try:
return ASL_OBSERVATORY_INDEX[id].geojson()
except KeyError:
return Response(status_code=404)
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment