Skip to content

Commit

Permalink
Make following changes
Browse files Browse the repository at this point in the history
 - Catch error being raised due to corrupted files
 - Remove existing data directory for product id
 - Retry downloading, and processing for the product id
  • Loading branch information
plant99 committed Jul 26, 2020
1 parent 8384811 commit 3447b78
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions felicette/cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import click
import sys
from rasterio.errors import RasterioIOError

from felicette.utils.geo_utils import geocoder_util
from felicette.utils.file_manager import check_sat_path
from felicette.utils.file_manager import check_sat_path, file_paths_wrt_id
from felicette.sat_downloader import (
download_landsat_data,
search_landsat_data,
preview_landsat_image,
)
from felicette.utils.sys_utils import exit_cli
from felicette.utils.sys_utils import exit_cli, remove_dir
from felicette.sat_processor import process_landsat_data

def trigger_download_and_processing(landsat_item, bands):
# download data
data_id = download_landsat_data(landsat_item, bands)
# process data
process_landsat_data(data_id, bands)

@click.command()
@click.option(
Expand Down Expand Up @@ -68,10 +74,19 @@ def main(coordinates, location_name, pan_enhancement, no_preview, vegetation):

# NB: can't enable pan-enhancement with vegetation

# download data
data_id = download_landsat_data(landsat_item, bands)
# process data
process_landsat_data(data_id, bands)
try:
trigger_download_and_processing(landsat_item, bands)
except RasterioIOError:
response = input("Local data for this location is corrupted, felicette will remove existing data to proceed, are you sure? [Y/n]")
if response in ["y", "Y", ""]:
# remove file dir
file_paths = file_paths_wrt_id(landsat_item._data["id"])
remove_dir(file_paths["base"])
# retry downloading and processing image with a clean directory
trigger_download_and_processing(landsat_item, bands)
elif response in ["n", "N"]:
exit_cli(print, "")



if __name__ == "__main__":
Expand Down

0 comments on commit 3447b78

Please sign in to comment.