Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't load time-series that consist only of NAN's into the store. #60

Merged
merged 2 commits into from
Oct 26, 2023
Merged
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
22 changes: 12 additions & 10 deletions data-loader/client_knmi_station.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# tested with Python 3.11
import concurrent
import math
import os
import uuid
from multiprocessing import cpu_count
Expand Down Expand Up @@ -45,16 +46,17 @@ def netcdf_file_to_requests(file_path: Path | str) -> Tuple[List, List]:
for time, obs_value in zip(pd.to_datetime(param_file["time"].data).to_pydatetime(), param_file.data):
ts = Timestamp()
ts.FromDatetime(time)
obs_mdata = dstore.ObsMetadata(
id=str(uuid.uuid4()),
geo_point=dstore.Point(lat=latitude, lon=longitude),
obstime_instant=ts,
value=str(obs_value), # TODO: Store float in DB
)
observations.append(dstore.Metadata1(ts_mdata=ts_mdata, obs_mdata=obs_mdata))

# print(len(observations))
observation_request_messages.append(dstore.PutObsRequest(observations=observations))
if not math.isnan(obs_value): # Stations that don't have a parameter give them all as nan
obs_mdata = dstore.ObsMetadata(
id=str(uuid.uuid4()),
geo_point=dstore.Point(lat=latitude, lon=longitude),
obstime_instant=ts,
value=str(obs_value), # TODO: Store float in DB
)
observations.append(dstore.Metadata1(ts_mdata=ts_mdata, obs_mdata=obs_mdata))

if len(observations) > 0:
observation_request_messages.append(dstore.PutObsRequest(observations=observations))

return observation_request_messages

Expand Down
16 changes: 8 additions & 8 deletions integration-test/test_knmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def test_find_series_all_stations_single_parameter(grpc_stub):
request = dstore.GetObsRequest(instruments=["rh"])
response = grpc_stub.GetObservations(request)

assert len(response.observations) == NUMBER_OF_STATIONS
assert len(response.observations) == 46 # Not all station have RH


def test_find_series_single_station_all_parameters(grpc_stub):
request = dstore.GetObsRequest(platforms=["06260"])
response = grpc_stub.GetObservations(request)

assert len(response.observations) == NUMBER_OF_PARAMETERS
assert len(response.observations) == 42 # Station 06260 doesn't have all parameters


def test_get_values_single_station_single_parameters(grpc_stub):
Expand Down Expand Up @@ -108,19 +108,19 @@ def test_get_values_single_station_single_parameters(grpc_stub):
(51.75, 3.68),
),
["rh"],
["06260", "06310", "06323", "06340", "06343", "06348", "06350", "06356"],
["06260", "06310", "06323", "06340", "06348", "06350", "06356"],
),
(
# All stations in the Netherlands
# All stations in the Netherlands which have RH
((56.00, 2.85), (56.00, 7.22), (50.75, 7.22), (50.75, 2.85)),
["rh"],
# fmt: off
[
"06201", "06203", "06204", "06205", "06207", "06208", "06211", "06214", "06215",
"06225", "06229", "06235", "06239", "06240", "06242", "06248", "06249", "06251",
"06252", "06257", "06258", "06260", "06267", "06269", "06270", "06273", "06275",
"06203", "06204", "06205", "06207", "06208", "06211", "06214", "06215",
"06235", "06239", "06240", "06242", "06249", "06251",
"06257", "06260", "06267", "06269", "06270", "06273", "06275",
"06277", "06278", "06279", "06280", "06283", "06286", "06290", "06310", "06317",
"06319", "06320", "06321", "06323", "06330", "06340", "06343", "06344", "06348",
"06319", "06323", "06330", "06340", "06344", "06348",
"06350", "06356", "06370", "06375", "06377", "06380", "06391"
],
# fmt: on
Expand Down