Skip to content

Commit

Permalink
fix tests in test_api_historic and test_api_latest
Browse files Browse the repository at this point in the history
  • Loading branch information
neumann-nico committed Oct 2, 2021
1 parent fe7aaac commit 08c543b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 56 deletions.
84 changes: 59 additions & 25 deletions tests/provider/dwd/radar/test_api_historic.py
Expand Up @@ -165,19 +165,19 @@ def test_radar_request_composite_historic_fx_yesterday():
# Verify number of results.
assert len(results) == 25

buffer = results[0].data

# Verify data.
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)
payload = results[0].data.getvalue()

# TODO: Use wradlib to parse binary format.
# https://docs.wradlib.org/en/stable/notebooks/radolan/radolan_format.html
date_time = request.start_date.strftime("%d%H%M")
month_year = request.start_date.strftime("%m%y")
header = (
f"FX{date_time}10000{month_year}BY.......VS 3SW 2.12.0PR E-01INT 5GP 900x 900VV 000MF 00000002MS " # noqa:E501,B950
f"..<{station_reference_pattern_unsorted}>"
)
attrs = {
}
print(requested_attrs)
assert requested_attrs == attrs

assert re.match(bytes(header, encoding="ascii"), payload[:160])


@pytest.mark.xfail(reason="Out of service", strict=True)
Expand Down Expand Up @@ -247,8 +247,8 @@ def test_radar_request_composite_historic_radolan_rw_yesterday():
'intervalseconds': 3600,
'nrow': 900,
'ncol': 900,
'radarlocations': ['boo', 'ros', 'hnr', 'umd', 'pro', 'ess', 'fld', 'drs', 'neu', 'nhb', 'oft', 'eis', 'tur',
'isn', 'fbg', 'mem'],
'radarlocations': ['asb', 'boo', 'ros', 'hnr', 'umd', 'pro', 'ess', 'fld', 'drs', 'neu', 'nhb', 'oft', 'eis',
'tur', 'isn', 'fbg', 'mem'],
'moduleflag': 1
}
assert requested_attrs == attrs
Expand All @@ -273,7 +273,32 @@ def test_radar_request_composite_historic_radolan_rw_timerange():
# Verify number of results.
assert len(results) == 3

# TODO: Verify data.
buffer = results[0].data

# Verify data.
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)

attrs = {
'producttype': 'RW',
# 'datetime': 'TODO',
'radarid': '10000',
'datasize': 1620000,
'maxrange': '150 km',
'radolanversion': '2.29.1',
'precision': 0.1,
'intervalseconds': 3600,
'nrow': 900,
'ncol': 900,
'radarlocations': ['asb', 'boo', 'ros', 'hnr', 'umd', 'pro', 'ess', 'fld', 'drs', 'neu', 'nhb', 'oft',
'eis', 'tur', 'isn', 'fbg', 'mem'],
'moduleflag': 1
}

# TODO check datetime
del requested_attrs['datetime']

assert requested_attrs == attrs


@pytest.mark.remote
Expand All @@ -300,12 +325,11 @@ def test_radar_request_site_historic_dx_yesterday():

# Verify data.
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)

attrs = {}
print(requested_attrs)
assert requested_attrs == attrs
timestamp_aligned = round_minutes(timestamp, 5)
date_time = timestamp_aligned.strftime("%d%H%M")
month_year = timestamp_aligned.strftime("%m%y")
header = f"DX{date_time}10132{month_year}BY.....VS 2CO0CD4CS0EP0.80.80.80.80.80.80.80.8MS" # noqa:E501,B950
assert re.match(header, requested_header)


@pytest.mark.remote
Expand All @@ -332,7 +356,17 @@ def test_radar_request_site_historic_dx_timerange():

assert len(results) == 6

# TODO: Verify data.
buffer = results[0].data

# Verify data.
requested_header = wrl.io.read_radolan_header(buffer)

timestamp_aligned = round_minutes(timestamp, 5)
date_time = timestamp_aligned.strftime("%d%H%M")
month_year = timestamp_aligned.strftime("%m%y")
header = f"DX{date_time}10132{month_year}BY.....VS 2CO0CD4CS0EP0.80.80.80.80.80.80.80.8MS " # noqa:E501,B950

assert re.match(header, requested_header)


@pytest.mark.remote
Expand Down Expand Up @@ -363,16 +397,16 @@ def test_radar_request_site_historic_pe_binary_yesterday():

# Verify data.
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)

attrs = {}
print(requested_attrs)
assert requested_attrs == attrs
date_time = request.start_date.strftime("%d%H")
month_year = request.start_date.strftime("%m%y")
header = (
f"PE{date_time}..10132{month_year}BY ....?VS 1LV12 1.0 2.0 3.0 4.0 5.0 " # noqa:E501,B950
f"6.0 7.0 8.0 9.0 10.0 11.0 12.0CO0CD0CS0ET 5.0FL....MS"
)

assert re.match(header, requested_header)


@pytest.mark.xfail
@pytest.mark.remote
Expand Down Expand Up @@ -882,12 +916,12 @@ def test_radar_request_radvor_re_yesterday():
'radarid': '10000',
'datasize': 1620000,
'maxrange': '150 km',
'radolanversion': 'P200002H',
'radolanversion': 'P200003H',
'precision': 0.001,
'intervalseconds': 3600,
'nrow': 900,
'ncol': 900,
'radarlocations': ['deboo', 'dedrs', 'deeis', 'deess', 'defbg', 'defld', 'dehnr', 'deisn', 'demem',
'radarlocations': ['deasb', 'deboo', 'dedrs', 'deeis', 'deess', 'defbg', 'defld', 'dehnr', 'deisn', 'demem',
'deneu', 'denhb', 'deoft', 'depro', 'deros', 'detur', 'deumd'],
'predictiontime': 0,
'moduleflag': 8,
Expand Down Expand Up @@ -968,8 +1002,8 @@ def test_radar_request_radvor_rq_yesterday():
'intervalseconds': 3600,
'nrow': 900,
'ncol': 900,
'radarlocations': ['boo', 'drs', 'eis', 'ess', 'fbg', 'fld', 'hnr', 'isn', 'mem', 'neu', 'nhb', 'oft', 'pro',
'ros', 'tur', 'umd'],
'radarlocations': ['asb', 'boo', 'drs', 'eis', 'ess', 'fbg', 'fld', 'hnr', 'isn', 'mem', 'neu', 'nhb', 'oft',
'pro', 'ros', 'tur', 'umd'],
'predictiontime': 0,
'moduleflag': 8,
'quantification': 1
Expand Down
40 changes: 9 additions & 31 deletions tests/provider/dwd/radar/test_api_latest.py
Expand Up @@ -27,32 +27,23 @@ def test_radar_request_composite_latest_rx_reflectivity():
)

buffer = next(request.query())[1]
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)

# Verify data.
attrs = {
payload = buffer.getvalue()

}
print(requested_attrs)
assert requested_attrs == attrs
month_year = datetime.utcnow().strftime("%m%y")
header = (
f"RX......10000{month_year}BY 8101..VS 3SW ......PR E\\+00INT 5GP 900x 900MS " # noqa:E501,B950
f"..<{station_reference_pattern_unsorted}>" # noqa:E501,B950
)

assert re.match(bytes(header, encoding="ascii"), payload[:160])


@pytest.mark.remote
def test_radar_request_composite_latest_rw_reflectivity():
"""
Example for testing radar COMPOSITES (RADOLAN) latest.
"""

timestamp_aligned = round_minutes(datetime.utcnow(), 5)
print(timestamp_aligned)
timestamp = datetime.utcnow() - timedelta(days=1)
print(timestamp)

request = DwdRadarValues(
parameter=DwdRadarParameter.RW_REFLECTIVITY,
start_date=DwdRadarDate.LATEST,
Expand All @@ -66,12 +57,11 @@ def test_radar_request_composite_latest_rw_reflectivity():
buffer = results[0][1]
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)
print(requested_attrs)
print(datetime.utcnow().strftime('%m%y'))

# Verify data.
attrs = {
'producttype': 'RW',
'datetime': 'TODO',
# 'datetime': 'TODO',
'radarid': '10000',
'datasize': 1620000,
'maxrange': '150 km',
Expand All @@ -85,15 +75,10 @@ def test_radar_request_composite_latest_rw_reflectivity():
'moduleflag': 1
}

#for key in ['datetime', 'radolanversion']:
# del requested_attrs[key]
# TODO check datetime
del requested_attrs['datetime']

assert requested_attrs == attrs
header = (
f"RW......10000{month_year}"
f"BY16201..VS 3SW ......PR E-01INT 60GP 900x 900MF 00000001MS "
f"..<{station_reference_pattern_unsorted}>"
)


@pytest.mark.remote
Expand All @@ -110,17 +95,10 @@ def test_radar_request_site_latest_dx_reflectivity():

buffer = next(request.query())[1]
requested_header = wrl.io.read_radolan_header(buffer)
requested_attrs = wrl.io.parse_dwd_composite_header(requested_header)
print(requested_attrs)

timestamp_aligned = round_minutes(datetime.utcnow(), 5)
month_year = timestamp_aligned.strftime("%m%y")

# Verify data.
attrs = {

}

assert requested_attrs == attrs

header = f"DX......10132{month_year}BY.....VS 2CO0CD4CS0EP0.80.80.80.80.80.80.80.8MS" # noqa:E501,B950
assert re.match(header, requested_header)

0 comments on commit 08c543b

Please sign in to comment.