Skip to content

Commit

Permalink
restore args and cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Apr 30, 2024
1 parent 00a4de5 commit b7ae87b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
7 changes: 4 additions & 3 deletions podaac/forge_py/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def create_parser():
"""Create a argparse parser for the backfill cli"""

parser = ArgumentParser()
parser.add_argument("--config")
parser.add_argument("-g", "--granule")
parser.add_argument("-c", "--config", required=True)
parser.add_argument("-g", "--granule", required=True)
parser.add_argument("-o", "--output_file")
parser.add_argument("--log-file")
parser.add_argument("--log-level")

Expand All @@ -52,4 +53,4 @@ def parse_args(args=None):
args = vars(args)
merged_dict = merge_dicts(default_config, config, args)
merged_config = Namespace(**merged_dict)
return merged_config
return merged_config
27 changes: 25 additions & 2 deletions podaac/forge_py/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script to run forge as a cli command"""
# pylint: disable=R0801, E1101

import logging
import sys
Expand Down Expand Up @@ -54,10 +55,32 @@ def main(args=None):

safe_log_args(logger, args)

print('forge main here again')
config_file = args.config
local_file = args.granule

with open(config_file) as config_f:
read_config = json.load(config_f)

longitude_var = read_config.get('lonVar')
latitude_var = read_config.get('latVar')
is360 = read_config.get('is360', False)

# Generate footprint
with xr.open_dataset(local_file, decode_times=False) as ds:
lon_data = ds[longitude_var]
lat_data = ds[latitude_var]
alpha_shape = forge.fit_footprint(lon_data, lat_data, is360=is360)

wkt_representation = dumps(alpha_shape)

if args.output_file:
with open(args.output_file, "w") as json_file:
json.dump(wkt_representation, json_file)

print(wkt_representation)

logger.info(f"Finished forge-py: {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S %Z')}") # pylint: disable=W1203


if __name__ == "__main__":
main()
main()

0 comments on commit b7ae87b

Please sign in to comment.