Skip to content

Commit

Permalink
Merge pull request #28 from EURODEO/rename_proto_fields_temporal_spatial
Browse files Browse the repository at this point in the history
Renamed interval & inside to temporal_interval & spatial_area
  • Loading branch information
jo-asplin-met-no authored Feb 7, 2024
2 parents 85d290b + 486c2ea commit 35e3e80
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
12 changes: 8 additions & 4 deletions api/routers/edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions datastore/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
```

Expand Down
2 changes: 1 addition & 1 deletion datastore/datastore/dsimpl/getobservations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion datastore/datastore/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions datastore/examples/clients/python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions datastore/integration-test/test_knmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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})
Expand Down
8 changes: 5 additions & 3 deletions datastore/load-test/locustfile_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]),
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions protobuf/datastore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 35e3e80

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py584621%23–68
datastore_pb2_grpc.py43430%2–225
dependencies.py22220%1–33
grpc_getter.py880%1–16
locustfile.py15150%1–31
main.py22220%3–51
metadata_endpoints.py19190%1–70
formatters
   \_\_init\_\_.py12650%16–32
   base_formatter.py7186%18
   covjson.py52198%69
routers
   \_\_init\_\_.py00100% 
   edr.py47470%2–126
   records.py00100% 
test
   test_covjson.py600100% 
TOTAL36523037% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
4 0 💤 0 ❌ 0 🔥 0.861s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py584621%23–68
datastore_pb2_grpc.py43430%2–225
dependencies.py22220%1–33
grpc_getter.py880%1–16
locustfile.py15150%1–31
main.py22220%3–51
metadata_endpoints.py19190%1–70
formatters
   \_\_init\_\_.py12650%16–32
   base_formatter.py7186%18
   covjson.py52198%69
routers
   \_\_init\_\_.py00100% 
   edr.py47470%2–126
   records.py00100% 
test
   test_covjson.py600100% 
TOTAL36523037% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
4 0 💤 0 ❌ 0 🔥 0.952s ⏱️

Please sign in to comment.