Skip to content

Commit

Permalink
Add plotting capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Feb 1, 2025
1 parent d454ca3 commit fc8ced8
Show file tree
Hide file tree
Showing 10 changed files with 1,078 additions and 47 deletions.
81 changes: 76 additions & 5 deletions tests/ui/cli/test_cli_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.mark.remote
def test_cli_interpolate():
def test_cli_interpolate_no_metadata_no_stations():
runner = CliRunner()
result = runner.invoke(
cli,
Expand All @@ -20,6 +20,8 @@ def test_cli_interpolate():
"--station=00071",
"--date=1986-10-31/1986-11-01",
"--format=json",
"--with_metadata=false",
"--with_stations=false",
],
)
if result.exit_code != 0:
Expand Down Expand Up @@ -61,8 +63,6 @@ def test_cli_interpolate_with_metadata_with_stations(metadata):
"--station=00071",
"--date=1986-10-31/1986-11-01",
"--format=json",
"--with_metadata=true",
"--with_stations=true",
],
)
if result.exit_code != 0:
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_cli_interpolate_with_metadata_with_stations(metadata):


@pytest.mark.remote
def test_cli_interpolate_geojson():
def test_cli_interpolate_geojson(metadata):
runner = CliRunner()
result = runner.invoke(
cli,
Expand All @@ -142,7 +142,8 @@ def test_cli_interpolate_geojson():
if result.exit_code != 0:
raise ChildProcessError(result.stderr)
response = json.loads(result.stdout)
assert response.keys() == {"data"}
assert response.keys() == {"metadata", "data"}
assert response["metadata"] == metadata
assert response["data"] == {
"type": "FeatureCollection",
"features": [
Expand Down Expand Up @@ -241,6 +242,8 @@ def test_cli_interpolate_interpolation_station_distance():
"--date=1986-10-31/1986-11-01",
"--format=json",
'--interpolation_station_distance={"temperature_air_mean_2m": 10}',
"--with_metadata=false",
"--with_stations=false",
],
)
if result.exit_code != 0:
Expand Down Expand Up @@ -283,6 +286,8 @@ def test_cli_interpolate_dont_use_nearby_station():
"--date=1986-10-31/1986-11-01",
"--format=json",
"--use_nearby_station_distance=0",
"--with_metadata=false",
"--with_stations=false",
],
)
if result.exit_code != 0:
Expand Down Expand Up @@ -325,6 +330,8 @@ def test_cli_interpolate_custom_units():
"--date=1986-10-31/1986-11-01",
"--format=json",
'--unit_targets={"temperature": "degree_fahrenheit"}',
"--with_metadata=false",
"--with_stations=false",
],
)
if result.exit_code != 0:
Expand All @@ -351,3 +358,67 @@ def test_cli_interpolate_custom_units():
"taken_station_ids": ["00071"],
},
]


@pytest.mark.parametrize(
"fmt",
[
"png",
"jpg",
"webp",
"svg",
],
)
def test_cli_interpolate_image(fmt):
runner = CliRunner()
result = runner.invoke(
cli,
[
"interpolate",
"--provider=dwd",
"--network=observation",
"--parameters=daily/climate_summary/temperature_air_mean_2m",
"--station=00071",
"--date=1986-10-31/1986-11-01",
"--format=json",
f"--format={fmt}",
],
)
assert result.exit_code == 0


@pytest.mark.remote
def test_cli_interpolate_image_html():
runner = CliRunner()
result = runner.invoke(
cli,
[
"interpolate",
"--provider=dwd",
"--network=observation",
"--parameters=daily/climate_summary/temperature_air_mean_2m",
"--date=2020-06-30",
"--station=01048",
"--format=html",
],
)
assert result.exit_code == 0
assert "html" in result.output


@pytest.mark.remote
def test_cli_interpolate_image_pdf():
runner = CliRunner()
result = runner.invoke(
cli,
[
"interpolate",
"--provider=dwd",
"--network=observation",
"--parameters=daily/climate_summary/temperature_air_mean_2m",
"--date=2020-06-30",
"--station=01048",
"--format=pdf",
],
)
assert result.exit_code == 0
47 changes: 47 additions & 0 deletions tests/ui/cli/test_cli_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def invoke_wetterdienst_stations_static(provider, network, setting, station, fmt
f"--network={network}",
f"--station={station}",
f"--format={fmt}",
"--with_metadata=false",
]
+ setting
+ (additional or []),
Expand Down Expand Up @@ -360,3 +361,49 @@ def test_cli_stations_geojson_pretty_true(json_dumps_mock):
additional=["--pretty=true"],
)
assert json_dumps_mock.call_args.kwargs["indent"] == 4


@pytest.mark.remote
@pytest.mark.parametrize(
"fmt",
[
"png",
"jpg",
"webp",
"svg",
],
)
def test_cli_stations_image(fmt):
result = invoke_wetterdienst_stations_static(
provider="dwd",
network="observation",
setting=["--parameters=daily/kl", "--periods=recent"],
station="01048",
fmt=fmt,
)
assert "ERROR" not in result.output
assert result.exit_code == 0


def test_cli_stations_image_html():
result = invoke_wetterdienst_stations_static(
provider="dwd",
network="observation",
setting=["--parameters=daily/kl", "--periods=recent"],
station="01048",
fmt="html",
)
assert "ERROR" not in result.output
assert result.exit_code == 0


def test_cli_stations_image_pdf():
result = invoke_wetterdienst_stations_static(
provider="dwd",
network="observation",
setting=["--parameters=daily/kl", "--periods=recent"],
station="01048",
fmt="pdf",
)
assert "ERROR" not in result.output
assert result.exit_code == 0
76 changes: 73 additions & 3 deletions tests/ui/cli/test_cli_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.mark.remote
def test_cli_summarize():
def test_cli_summarize_no_metadata_no_stations():
runner = CliRunner()
result = runner.invoke(
cli,
Expand All @@ -19,6 +19,8 @@ def test_cli_summarize():
"--station=00071",
"--date=1986-10-31/1986-11-01",
"--format=json",
"--with_metadata=false",
"--with_stations=false",
],
)
if result.exit_code != 0:
Expand Down Expand Up @@ -48,7 +50,7 @@ def test_cli_summarize():


@pytest.mark.remote
def test_cli_summarize_geojson():
def test_cli_summarize_geojson(metadata):
runner = CliRunner()
result = runner.invoke(
cli,
Expand All @@ -65,7 +67,8 @@ def test_cli_summarize_geojson():
if result.exit_code != 0:
raise ChildProcessError(result.stderr)
response = json.loads(result.stdout)
assert response.keys() == {"data"}
assert response.keys() == {"metadata", "data"}
assert response["metadata"] == metadata
assert response["data"] == {
"type": "FeatureCollection",
"features": [
Expand Down Expand Up @@ -134,6 +137,8 @@ def test_cli_summarize_custom_units():
"--date=1986-10-31/1986-11-01",
"--format=json",
'--unit_targets={"temperature": "degree_fahrenheit"}',
"--with_metadata=false",
"--with_stations=false",
],
)
if result.exit_code != 0:
Expand All @@ -160,3 +165,68 @@ def test_cli_summarize_custom_units():
"taken_station_id": "00071",
},
]


@pytest.mark.parametrize(
"fmt",
[
"png",
"jpg",
"webp",
"svg",
],
)
def test_cli_summarize_image(fmt):
runner = CliRunner()
result = runner.invoke(
cli,
[
"summarize",
"--provider=dwd",
"--network=observation",
"--parameters=daily/climate_summary/temperature_air_mean_2m",
"--station=00071",
"--date=1986-10-31/1986-11-01",
"--format=json",
f"--format={fmt}",
],
)
assert "Error" not in result.output
assert result.exit_code == 0


@pytest.mark.remote
def test_cli_summarize_image_html():
runner = CliRunner()
result = runner.invoke(
cli,
[
"summarize",
"--provider=dwd",
"--network=observation",
"--parameters=daily/climate_summary/temperature_air_mean_2m",
"--date=2020-06-30",
"--station=01048",
"--format=html",
],
)
assert result.exit_code == 0
assert "html" in result.output


@pytest.mark.remote
def test_cli_summarize_image_pdf():
runner = CliRunner()
result = runner.invoke(
cli,
[
"summarize",
"--provider=dwd",
"--network=observation",
"--parameters=daily/climate_summary/temperature_air_mean_2m",
"--date=2020-06-30",
"--station=01048",
"--format=pdf",
],
)
assert result.exit_code == 0
Loading

0 comments on commit fc8ced8

Please sign in to comment.