diff --git a/api/routers/edr.py b/api/routers/edr.py index 1194f8f2..6445298a 100644 --- a/api/routers/edr.py +++ b/api/routers/edr.py @@ -34,7 +34,9 @@ async def get_locations(bbox: str = Query(..., example="5.0,52.0,6.0,52.1")) -> poly = geometry.Polygon([(left, bottom), (right, bottom), (right, top), (left, top)]) ts_request = dstore.GetObsRequest( filter=dict(instrument=dstore.Strings(values=["tn"])), # Hack - inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]), + spatial_area=dstore.Polygon( + points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords] + ), ) ts_response = await getObsRequest(ts_request) @@ -73,7 +75,7 @@ async def get_data_location_id( platform=dstore.Strings(values=[location_id]), instrument=dstore.Strings(values=list(map(str.strip, parameter_name.split(",")))), ), - interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None, + temporal_interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None, ) response = await getObsRequest(get_obs_request) return edr_formatter[f].convert(response) @@ -114,8 +116,10 @@ async def get_data_area( range = get_datetime_range(datetime) get_obs_request = dstore.GetObsRequest( filter=dict(instrument=dstore.Strings(values=list(map(str.strip, parameter_name.split(","))))), - inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]), - interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None, + spatial_area=dstore.Polygon( + points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords] + ), + temporal_interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None, ) coverages = await getObsRequest(get_obs_request) coverages = edr_formatter[f].convert(coverages) diff --git a/datastore/datastore/README.md b/datastore/datastore/README.md index ee628f30..85dedfd7 100644 --- a/datastore/datastore/README.md +++ b/datastore/datastore/README.md @@ -217,27 +217,27 @@ $ grpcurl -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.D ### Retrieve observations in a time range ```text -$ grpcurl -d '{"interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations +$ grpcurl -d '{"temporal_interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations ... ``` ### Retrieve observations in a polygon ```text -$ grpcurl -d '{"inside": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations +$ grpcurl -d '{"spatial_area": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations ... ``` ### Retrieve observations in both a time range and a polygon ```text -$ grpcurl -d '{"interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}, "inside": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations +$ grpcurl -d '{"temporal_interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}, "spatial_area": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations ... ``` ### Retrieve wind speed and air temperature observations in a time range and a polygon ```text -$ grpcurl -d '{"filter": {"standard_name": {"values": ["wind_speed", "air_temperature"]}}, "interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}, "inside": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations +$ grpcurl -d '{"filter": {"standard_name": {"values": ["wind_speed", "air_temperature"]}}, "temporal_interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}, "spatial_area": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations ... ``` diff --git a/datastore/datastore/dsimpl/getobservations.go b/datastore/datastore/dsimpl/getobservations.go index 5aea6fae..fbefd06d 100644 --- a/datastore/datastore/dsimpl/getobservations.go +++ b/datastore/datastore/dsimpl/getobservations.go @@ -12,7 +12,7 @@ func (svcInfo *ServiceInfo) GetObservations( *datastore.GetObsResponse, error) { // do general validation of any obs time interval - if ti := request.Interval; ti != nil { + if ti := request.GetTemporalInterval(); ti != nil { if ti.Start != nil && ti.End != nil { if ti.End.AsTime().Before(ti.Start.AsTime()) { return nil, fmt.Errorf("end(%v) < start(%v)", ti.End, ti.Start) diff --git a/datastore/datastore/go.mod b/datastore/datastore/go.mod index 25de7865..91f0cdf6 100644 --- a/datastore/datastore/go.mod +++ b/datastore/datastore/go.mod @@ -10,7 +10,7 @@ require ( ) require ( - github.com/golang/protobuf v1.5.3 + github.com/golang/protobuf v1.5.3 // indirect github.com/lib/pq v1.10.0 golang.org/x/net v0.11.0 // indirect golang.org/x/sys v0.9.0 // indirect diff --git a/datastore/datastore/storagebackend/postgresql/getobservations.go b/datastore/datastore/storagebackend/postgresql/getobservations.go index cef48ac5..b10de184 100644 --- a/datastore/datastore/storagebackend/postgresql/getobservations.go +++ b/datastore/datastore/storagebackend/postgresql/getobservations.go @@ -316,9 +316,9 @@ func getStringMdataFilter( func createObsQueryVals( request *datastore.GetObsRequest, phVals *[]interface{}) (string, string, string, error) { - timeFilter := getTimeFilter(request.GetInterval()) + timeFilter := getTimeFilter(request.GetTemporalInterval()) - geoFilter, err := getGeoFilter(request.Inside, phVals) + geoFilter, err := getGeoFilter(request.GetSpatialArea(), phVals) if err != nil { return "", "", "", fmt.Errorf("getGeoFilter() failed: %v", err) } diff --git a/datastore/examples/clients/python/client.py b/datastore/examples/clients/python/client.py index 427cf6c1..0e718ac5 100755 --- a/datastore/examples/clients/python/client.py +++ b/datastore/examples/clients/python/client.py @@ -58,7 +58,7 @@ def call_put_obs(stub, version, type, standard_name, unit, value): # obs time range. def call_get_obs_in_time_range(stub): request = dstore.GetObsRequest( - interval=dstore.TimeInterval( + temporal_interval=dstore.TimeInterval( start=dtime2tstamp(datetime(2023, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc)), end=dtime2tstamp(datetime(2023, 1, 2, 0, 0, 0, 0, tzinfo=timezone.utc)), ) @@ -77,7 +77,7 @@ def call_get_obs_in_polygon(stub): points.append(dstore.Point(lat=60, lon=10.80)) points.append(dstore.Point(lat=60, lon=10.70)) - request = dstore.GetObsRequest(inside=dstore.Polygon(points=points)) + request = dstore.GetObsRequest(spatial_area=dstore.Polygon(points=points)) response = stub.GetObservations(request) return response diff --git a/datastore/integration-test/test_knmi.py b/datastore/integration-test/test_knmi.py index 64aa5f3b..9e836b57 100644 --- a/datastore/integration-test/test_knmi.py +++ b/datastore/integration-test/test_knmi.py @@ -64,7 +64,7 @@ def test_get_values_single_station_single_parameter_one_hour(grpc_stub): ts_request = dstore.GetObsRequest( filter=dict(platform=dstore.Strings(values=["06260"]), instrument=dstore.Strings(values=["rh"])), - interval=dstore.TimeInterval(start=start_datetime, end=end_datetime), + temporal_interval=dstore.TimeInterval(start=start_datetime, end=end_datetime), ) response = grpc_stub.GetObservations(ts_request) @@ -152,7 +152,9 @@ def test_get_values_single_station_single_parameter_one_hour(grpc_stub): @pytest.mark.parametrize("coords,param_ids,expected_station_ids", input_params_polygon) def test_get_observations_with_polygon(grpc_stub, coords, param_ids, expected_station_ids): polygon = dstore.Polygon(points=[dstore.Point(lat=lat, lon=lon) for lat, lon in coords]) - get_obs_request = dstore.GetObsRequest(inside=polygon, filter=dict(instrument=dstore.Strings(values=param_ids))) + get_obs_request = dstore.GetObsRequest( + spatial_area=polygon, filter=dict(instrument=dstore.Strings(values=param_ids)) + ) get_obs_response = grpc_stub.GetObservations(get_obs_request) actual_station_ids = sorted({ts.ts_mdata.platform for ts in get_obs_response.observations}) diff --git a/datastore/load-test/locustfile_read.py b/datastore/load-test/locustfile_read.py index 76d46ea2..057da8ef 100644 --- a/datastore/load-test/locustfile_read.py +++ b/datastore/load-test/locustfile_read.py @@ -43,7 +43,7 @@ def get_data_for_single_timeserie(self): to_time.FromDatetime(datetime(2023, 1, 1)) request = dstore.GetObsRequest( - interval=dstore.TimeInterval(start=from_time, end=to_time), + temporal_interval=dstore.TimeInterval(start=from_time, end=to_time), filter=dict( platform=dstore.Strings(values=[random.choice(stations)]), instrument=dstore.Strings(values=[random.choice(parameters)]), @@ -64,9 +64,11 @@ def get_data_single_station_through_bbox(self): poly = buffer(point, 0.0001, quad_segs=1) # Roughly 10 meters around the point request = dstore.GetObsRequest( - interval=dstore.TimeInterval(start=from_time, end=to_time), + temporal_interval=dstore.TimeInterval(start=from_time, end=to_time), filter=dict(instrument=dstore.Strings(values=[random.choice(parameters)])), - inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]), + spatial_area=dstore.Polygon( + points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords] + ), ) response = self.stub.GetObservations(request) assert len(response.observations) == 1 diff --git a/protobuf/datastore.proto b/protobuf/datastore.proto index 4198e680..4608398e 100644 --- a/protobuf/datastore.proto +++ b/protobuf/datastore.proto @@ -159,10 +159,10 @@ message GetObsRequest { // --- BEGIN non-string metadata ------------------------- // temporal filter - TimeInterval interval = 1; // only observations in this time range may be returned + TimeInterval temporal_interval = 1; // only observations in this time range may be returned // spatial filter - Polygon inside = 2; // if specified, only observations in this area may be returned + Polygon spatial_area = 2; // if specified, only observations in this area may be returned // search wrt. TSMetadata.links // TODO - needs special handling