Skip to content

Commit

Permalink
Check if GetTSAGRequest provides enough information.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey-Vervoort-KNMI committed Feb 8, 2024
1 parent 943fce5 commit 0d5d41b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions api/grpc_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ async def getObsRequest(get_obs_request):
response = await grpc_stub.GetObservations(get_obs_request)

return response


async def getTSAttrGroupsRequest(get_attr_groups_request):
channel = grpc.aio.insecure_channel(f"{os.getenv('DSHOST', 'localhost')}:{os.getenv('DSPORT', '50050')}")
grpc_stub = dstore_grpc.DatastoreStub(channel)
response = await grpc_stub.GetTSAttrGroups(get_attr_groups_request)

return response
24 changes: 14 additions & 10 deletions api/routers/edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from geojson_pydantic import Feature
from geojson_pydantic import Point
from grpc_getter import getObsRequest
from grpc_getter import getTSAttrGroupsRequest
from shapely import buffer
from shapely import geometry
from shapely import wkt
Expand All @@ -36,27 +37,29 @@ async def get_locations(
left, bottom, right, top = map(str.strip, bbox.split(","))
poly = geometry.Polygon([(left, bottom), (right, bottom), (right, top), (left, top)])

# fmt: off
all_parameters = [
"D1H", "R12H", "R1H", "R24H", "R6H", "Tgn12", "Tgn14", "Tgn6", "Tn12", "Tn14", "Tn6", "Tx12", "Tx24", "Tx6",
"dd", "dr", "ff", "gff", "hc", "hc1", "hc2", "hc3", "nc", "nc1", "nc2", "nc3", "pg", "pp", "pr", "pwc", "qg",
"rg", "rh", "ss", "ta", "td", "tgn", "tn", "tx", "ww", "ww-10", "zm"
]
# fmt: on

# ts_ag_request = dstore.GetTSAGRequest(
# attrs=["instrument", "platform", "standard_name", "title"], # "geo_point_id"],
# # instrument=dstore.Strings(values=all_parameters),
# # spatial_area=dstore.Polygon(
# # points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]
# # ),
# include_instances=False,
# )
ts_request = dstore.GetObsRequest(
filter=dict(instrument=dstore.Strings(values=all_parameters)), # Hack
spatial_area=dstore.Polygon(
points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]
),
)
# TODO: It is not possible to request all of the locations, because the request is too large for gRPC.
# Thus it is necessary to update the datastore.

# TODO: Add flag to protobuf so that it only retrieves the latest observations from the datastore.
# TODO: Simulate retrieval of last obs by setting a recent timestamp
ts_response = await getObsRequest(ts_request)

platform_standard_names = defaultdict(set)
for obs in sorted(ts_response.observations, key=lambda obs: obs.ts_mdata.platform):
platform_standard_names[obs.ts_mdata.platform].add(obs.ts_mdata.standard_name)
platform_standard_names[obs.ts_mdata.platform].add(obs.ts_mdata.instrument)

features = [
Feature(
Expand Down Expand Up @@ -92,6 +95,7 @@ async def get_locations(
# feature_collection = FeatureCollection(features=features, type="FeatureCollection")
# return dict(feature_collection.model_dump(), **{"parameters": parameters})
return EDRFeatureCollection(features=features, type="FeatureCollection", parameters=parameters)
# return


@router.get(
Expand Down

0 comments on commit 0d5d41b

Please sign in to comment.