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

Exit when there is no valid imagery for any point #136

Merged
merged 1 commit into from
Jan 9, 2024
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
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",
ejm714 marked this conversation as resolved.
Show resolved Hide resolved
"--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