-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inspired by the copernicusmarine CLI !
- Loading branch information
Showing
9 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='vfrecovery', | ||
version='2.0', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
install_requires=[ | ||
'Click', | ||
], | ||
entry_points={ | ||
'console_scripts': [ | ||
'vfrecovery = vfrecovery.command_line_interface.virtualfleet_recovery:base_command_line_interface', | ||
], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# from importlib.metadata import version | ||
# __version__ = version("vfrecovery") | ||
from importlib.metadata import version | ||
__version__ = version("vfrecovery") | ||
|
||
from vfrecovery.python_interface.predict import predict |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import click | ||
|
||
|
||
@click.group() | ||
def cli_group_describe() -> None: | ||
pass | ||
|
||
@cli_group_describe.command( | ||
"describe", | ||
short_help="Describe VirtualFleet-Recovery predictions", | ||
help=""" | ||
Returns data about an existing VirtualFleet-Recovery prediction | ||
Data could be a JSON file, specific metrics or images | ||
""", | ||
epilog=""" | ||
Examples: | ||
\b | ||
vfrecovery describe 6903091 112 | ||
""", # noqa | ||
) | ||
@click.argument('WMO') | ||
@click.argument('CYC') | ||
def describe( | ||
wmo: int, | ||
cyc: int): | ||
click.echo(f"Return description for {wmo} {cyc}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import click | ||
from typing import Union, List | ||
from vfrecovery.core_functions.predict import predict_function | ||
|
||
@click.group() | ||
def cli_group_predict() -> None: | ||
pass | ||
|
||
@cli_group_predict.command( | ||
"predict", | ||
short_help="Execute VirtualFleet-Recovery predictions", | ||
help=""" | ||
Execute VirtualFleet-Recovery predictor and return results as a JSON string | ||
""", | ||
epilog=""" | ||
Examples: | ||
\b | ||
vfrecovery predict 6903091 112 | ||
""", # noqa | ||
) | ||
@click.option( | ||
"-n", "--n_predictions", | ||
type=int, | ||
required=False, | ||
default=1, | ||
show_default=True, | ||
is_flag=False, | ||
help="Number of profiles to simulate", | ||
) | ||
@click.argument('WMO') | ||
@click.argument('CYC', nargs=-1) | ||
def predict( | ||
wmo: int, | ||
cyc: Union[int, List], | ||
n_predictions) -> None: | ||
# click.echo(f"Prediction for {wmo} {cyc}") | ||
results = predict_function(wmo, cyc, n_predictions=n_predictions) | ||
click.echo(results) |
24 changes: 24 additions & 0 deletions
24
vfrecovery/command_line_interface/virtualfleet_recovery.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import click | ||
|
||
from vfrecovery.command_line_interface.group_describe import cli_group_describe | ||
from vfrecovery.command_line_interface.group_predict import cli_group_predict | ||
|
||
@click.command( | ||
cls=click.CommandCollection, | ||
sources=[ | ||
cli_group_describe, | ||
cli_group_predict, | ||
], | ||
context_settings=dict(help_option_names=["-h", "--help"]), | ||
) | ||
@click.version_option(None, "-V", "--version", package_name="vfrecovery") | ||
def base_command_line_interface(): | ||
pass | ||
|
||
|
||
def command_line_interface(): | ||
base_command_line_interface(windows_expand_args=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
command_line_interface() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
def predict_function( | ||
wmo: int, | ||
cyc: int, | ||
n_predictions: int = 1, | ||
): | ||
""" | ||
Execute VirtualFleet-Recovery predictor and return results as a JSON string | ||
Inputs | ||
------ | ||
wmo | ||
cyc | ||
n_predictions | ||
Returns | ||
------- | ||
data | ||
""" # noqa | ||
return {'wmo': wmo, 'cyc': cyc} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
from vfrecovery.core_functions.predict import predict_function | ||
|
||
|
||
def predict( | ||
wmo: int, | ||
cyc: int, | ||
n_predictions, | ||
): | ||
""" | ||
Execute VirtualFleet-Recovery predictor and return results as a JSON string | ||
Inputs | ||
------ | ||
wmo | ||
cyc | ||
n_predictions | ||
Returns | ||
------- | ||
data | ||
""" # noqa | ||
results_json = predict_function( | ||
wmo, cyc, | ||
n_predictions=n_predictions, | ||
) | ||
results = json.loads(results_json) | ||
return results |