|
1 | 1 | import click |
| 2 | +import json |
2 | 3 |
|
3 | | -from aef_export.embeddings import export_image |
| 4 | +from aef_export.embeddings import export_image, export_aoi |
4 | 5 | from aef_export.coverage import export_image_collection |
5 | 6 | from aef_export.settings import get_settings |
| 7 | +from aef_export.task_tracking import update_db_state, get_task_summary, BillingTier |
6 | 8 | from aef_export.utils import initialize_ee |
7 | 9 |
|
8 | 10 |
|
@@ -54,3 +56,56 @@ def image( |
54 | 56 | initialize_ee(settings.google_cloud_project) |
55 | 57 | task_id = export_image(image_id, gcs_bucket_name, gcs_key_prefix, quantize) |
56 | 58 | click.echo(f"Task id: {task_id}") |
| 59 | + |
| 60 | + |
| 61 | +@app.command() |
| 62 | +@click.argument( |
| 63 | + "geojson_filepath", type=click.Path(exists=True, file_okay=True, dir_okay=False) |
| 64 | +) |
| 65 | +@click.argument("bq_dataset_name") |
| 66 | +@click.argument("bq_table_name") |
| 67 | +@click.argument("gcs_bucket_name") |
| 68 | +@click.option("--limit", type=int, required=False, default=None) |
| 69 | +def aoi( |
| 70 | + geojson_filepath: str, |
| 71 | + bq_dataset_name: str, |
| 72 | + bq_table_name: str, |
| 73 | + gcs_bucket_name: str, |
| 74 | + limit: int | None = None, |
| 75 | +): |
| 76 | + settings = get_settings() |
| 77 | + initialize_ee(settings.google_cloud_project) |
| 78 | + |
| 79 | + with open(geojson_filepath) as f: |
| 80 | + data = json.load(f) |
| 81 | + |
| 82 | + if data["type"] == "Feature": |
| 83 | + polygon = data["geometry"] |
| 84 | + elif data["type"] == "Polygon": |
| 85 | + polygon = data |
| 86 | + else: |
| 87 | + raise ValueError( |
| 88 | + "Input file must be a geojson polygon, either geometry or feature" |
| 89 | + ) |
| 90 | + |
| 91 | + export_aoi(polygon, bq_dataset_name, bq_table_name, gcs_bucket_name, limit) |
| 92 | + |
| 93 | + |
| 94 | +@app.group() |
| 95 | +def db(): |
| 96 | + pass |
| 97 | + |
| 98 | + |
| 99 | +@db.command() |
| 100 | +def update_task_status(): |
| 101 | + settings = get_settings() |
| 102 | + initialize_ee(settings.google_cloud_project) |
| 103 | + update_db_state() |
| 104 | + |
| 105 | + |
| 106 | +@db.command() |
| 107 | +@click.option( |
| 108 | + "--billing-tier", type=click.Choice(BillingTier), default=BillingTier.tier1 |
| 109 | +) |
| 110 | +def summarize(billing_tier: BillingTier = BillingTier.tier1): |
| 111 | + click.echo(json.dumps(get_task_summary(billing_tier))) |
0 commit comments