diff --git a/src/asli/asli.py b/src/asli/asli.py index 383e167..f0183d2 100644 --- a/src/asli/asli.py +++ b/src/asli/asli.py @@ -4,6 +4,7 @@ import datetime import logging import os +import matplotlib.pyplot as plt from pathlib import Path from typing import Mapping, Union @@ -435,7 +436,7 @@ def _cli_common_args(parser: argparse.ArgumentParser) -> argparse.ArgumentParser "-o", "--output", type=str, - help="Output file path for CSV, relative to .", + help="Output file path for file, relative to .", ) parser.add_argument( "msl_files", @@ -461,6 +462,13 @@ def _get_cli_plot_args(): type=str, help="Input CSV file, relative to .", ) + parser.add_argument( + "-y", + "--year", + nargs="?", + type=int, + help="When present, plot only the year specified" + ) parser = _cli_common_args(parser) return parser.parse_args() @@ -499,8 +507,18 @@ def _cli_plot(): a = ASLICalculator(args.datadir, args.mask, args.msl_files[0]) a.read_mask_data() a.read_msl_data() - a.import_from_csv(args.input) - a.plot_region_all() + # Perform the calculation if no input file is provided + if args.input: + a.import_from_csv(args.input) + else: + a.calculate() + # Plot all if no specific year is provided + if args.year: + a.plot_region_year(args.year) + else: + a.plot_region_all() + if args.output: + plt.savefig(os.path.join(args.datadir, args.output)) def _cli_calc(): """Command-line interface to ASL calculation.""" @@ -517,4 +535,4 @@ def _cli_calc(): if __name__ == "__main__": - _cli_calc() + _cli_calc() \ No newline at end of file diff --git a/src/asli/plot.py b/src/asli/plot.py index e51b4d3..d4da690 100644 --- a/src/asli/plot.py +++ b/src/asli/plot.py @@ -110,4 +110,4 @@ def plot_lows( if regionbox: draw_regional_box(regionbox) - return ax + return ax \ No newline at end of file