Skip to content

Commit

Permalink
add coord check
Browse files Browse the repository at this point in the history
  • Loading branch information
griembauer committed Jan 22, 2024
1 parent 2123bf4 commit 9604cc0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
# type=float, help='Northern boundary of AOI in decimal degrees'
north: 46.6

# type=float, help='Southern boundary of AOI in decimal degrees'
# type=float, help='Southern boundary of AOI in decimal degrees. Must be smaller than north'
south: 45.67

# type=float, help='Eastern boundary of AOI in decimal degrees'
east: 11.97

# type=float, help='Western boundary of AOI in decimal degrees'
# type=float, help='Western boundary of AOI in decimal degrees. Must be smaller than east'
west: 10.44

# type=str, help='Start date of temporal extent in ISO format (YYYY-MM-DD)'
Expand Down
55 changes: 55 additions & 0 deletions sadasadam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
############################################################################

import argparse
from datetime import datetime
import os
import shutil
import yaml
Expand All @@ -29,6 +30,52 @@
from sadasadam.download import download_and_extract


def check_filter(start, end, north, south, east, west):
"""
Helper function that checks whether the date and coordinate fields
from the config file make sense.
"""
north_f = float(north)
south_f = float(south)
east_f = float(east)
west_f = float(west)
start_date = datetime.strptime(start, "%Y-%m-%d")
end_date = datetime.strptime(end, "%Y-%m-%d")
if north_f < -90 or north_f > 90:
raise Exception(
f"The value for north {north} is outside the valid"
" -90 to 90 degree range."
)
if south_f < -90 or south_f > 90:
raise Exception(
f"The value for south {south} is outside the valid"
" -90 to 90 degree range."
)
if south_f > north_f:
raise Exception(
f"The value for south {south} is larger " f"than for north {north}"
)
if east_f < -360 or east_f > 360:
# best would be -180 to 180 but -350 etc. should also be understood
raise Exception(
f"The value for east {east} is outside the valid"
" -360 to 360 degree range."
)
if west_f < -360 or west_f > 360:
# best would be -180 to 180 but -350 etc. should also be understood
raise Exception(
f"The value for west {west} is outside the valid"
" -360 to 360 degree range."
)
if west_f > east_f:
raise Exception(
f"The value for west {west} is " f"larger than for east {east}."
)

if start_date > end_date:
raise Exception(f"Start date {start} is later than end date {end}.")


def check_bool(variable):
"""
Helper function that checks whether a variable is of type bool and raises
Expand Down Expand Up @@ -81,6 +128,14 @@ def main():
raise Exception(
"Please provide an end date for the temporal extent"
)
check_filter(
start=start,
end=end,
north=north,
south=south,
east=east,
west=west,
)
cloud_cover = config.get("cloud_cover")
if not cloud_cover:
raise Exception("Please provide a maximum cloud cover")
Expand Down

0 comments on commit 9604cc0

Please sign in to comment.