Skip to content

Commit

Permalink
Format with black
Browse files Browse the repository at this point in the history
  • Loading branch information
plant99 committed Jul 23, 2020
1 parent 7df0b7e commit b2eb15d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
8 changes: 6 additions & 2 deletions felicette/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

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


@click.command()
@click.option(
"-c",
Expand Down Expand Up @@ -47,7 +52,6 @@ def main(coordinates, location_name, pan_enhancement, preview_image, vegetation)
# unless specified, cloud_cover_lt is 10
landsat_item = search_landsat_data(coordinates, 10)


# check if directory exists to save the data for this product id
check_sat_path(landsat_item._data["id"])

Expand Down
27 changes: 18 additions & 9 deletions felicette/sat_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
from felicette.utils.geo_utils import get_tiny_bbox
from felicette.utils.sys_utils import exit_cli
from felicette.constants import band_tag_map
from felicette.utils.file_manager import save_to_file, data_file_exists, file_paths_wrt_id
from felicette.utils.file_manager import (
save_to_file,
data_file_exists,
file_paths_wrt_id,
)


def handle_prompt_response(response):
if response in ["n", "N"]:
exit_cli("Why not try a different location next time? I'd suggest [link=https://en.wikipedia.org/wiki/Svalbard]Svalbard[/link] :)")
exit_cli(
"Why not try a different location next time? I'd suggest [link=https://en.wikipedia.org/wiki/Svalbard]Svalbard[/link] :)"
)
elif response in ["y", "Y", ""]:
return None
else:
Expand All @@ -35,6 +42,7 @@ def search_landsat_data(coordinates, cloud_cover_lt):
landsat_item = search_items[0]
return landsat_item


def preview_landsat_image(landsat_item):
paths = file_paths_wrt_id(landsat_item._data["id"])
# download image and save it in directory
Expand All @@ -43,20 +51,20 @@ def preview_landsat_image(landsat_item):
landsat_item.assets["thumbnail"]["href"],
paths["preview"],
landsat_item._data["id"],
"✗ preview data doesn't exist, downloading image"
"✗ preview data doesn't exist, downloading image",
)
else:
rprint(
"[green] ✓ ",
"required data exists for preview image"
)
rprint("[green] ✓ ", "required data exists for preview image")
# print success info
rprint("[blue]Preview image saved at:[/blue]")
print(paths["preview"])
# prompt a confirm option
response = input("Are you sure you want to see an enhanced version of the image at the path shown above? [Y/n]")
response = input(
"Are you sure you want to see an enhanced version of the image at the path shown above? [Y/n]"
)
return handle_prompt_response(response)


def download_landsat_data(landsat_item, bands):

# get paths w.r.t. id
Expand All @@ -69,7 +77,8 @@ def download_landsat_data(landsat_item, bands):
landsat_item.assets["B{}".format(band)]["href"],
band_filename,
landsat_item._data["id"],
"✗ required data doesn't exist, downloading %s %s" % (band_tag_map["b" + str(band)], "band")
"✗ required data doesn't exist, downloading %s %s"
% (band_tag_map["b" + str(band)], "band"),
)
else:
rprint(
Expand Down
3 changes: 2 additions & 1 deletion felicette/sat_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def process_landsat_vegetation(id, bands):
rprint("[blue]JPEG image saved at:[/blue]")
print(paths["vegetation_path_jpeg"])


def process_landsat_rgb(id, bands):
# get paths of files related to this id
paths = file_paths_wrt_id(id)
Expand Down Expand Up @@ -164,4 +165,4 @@ def process_landsat_data(id, bands):
if bands == [2, 3, 4]:
process_landsat_rgb(id, bands)
elif bands == [3, 4, 5]:
process_landsat_vegetation(id, bands)
process_landsat_vegetation(id, bands)
4 changes: 1 addition & 3 deletions felicette/utils/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,5 @@ def file_paths_wrt_id(id):
home_path_id, "%s-color-processed.jpeg" % (id)
),
"vegetation_path": os.path.join(home_path_id, "%s-vegetation.tiff" % (id)),
"vegetation_path_jpeg": os.path.join(
home_path_id, "%s-vegetation.jpeg" % (id)
),
"vegetation_path_jpeg": os.path.join(home_path_id, "%s-vegetation.jpeg" % (id)),
}
6 changes: 4 additions & 2 deletions felicette/utils/sys_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
from rich import print as rprint


def exit_cli(message):
rprint("%s" % message)
sys.exit(0)
rprint("%s" % message)
sys.exit(0)

0 comments on commit b2eb15d

Please sign in to comment.