Skip to content

Commit

Permalink
exit when there is no satellite imagery; add test (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejm714 authored Jan 9, 2024
1 parent 0c3a28b commit e737715
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cyfi/data/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ def generate_all_features(
satellite_features = calculate_satellite_features(satellite_meta, config, cache_dir)

ct_with_satellite = satellite_features.index.nunique()
if ct_with_satellite < samples.shape[0]:
if ct_with_satellite == 0:
logger.error(
"Relevant satellite data is not available for any of the provided sample points. Please try a different location or date."
)
exit(1)
elif ct_with_satellite < samples.shape[0]:
logger.warning(
f"Relevant satellite data is not available for all sample points. Features will only be generated for {ct_with_satellite:,} sample points with valid satellite imagery ({(ct_with_satellite / samples.shape[0]):.0%} of sample points)"
)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@ def test_cli_predict_point_crs(mocker, local_model_path): # noqa: F811
assert "Invalid value for '--crs" in result.stdout


def test_graceful_exit_when_no_satellite_data():
# use location and date in SF where it was cloudy all month and there is no valid imagery
result = runner.invoke(
app,
[
"predict-point",
"--date",
"2024-01-04",
"--lat",
"37.753",
"--lon",
"-122.364",
],
)
assert result.exit_code == 1
assert (
"Relevant satellite data is not available for any of the provided sample points. Please try a different location or date"
in result.stdout
)


def test_cli_evaluate(tmp_path, evaluate_data_path):
df = pd.read_csv(evaluate_data_path)
df = add_unique_identifier(df)
Expand Down

0 comments on commit e737715

Please sign in to comment.