Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file output to cli plotting #35

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/asli/asli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import logging
import os
import matplotlib.pyplot as plt
from pathlib import Path
from typing import Mapping, Union

Expand Down Expand Up @@ -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 <datadir>.",
help="Output file path for file, relative to <datadir>.",
)
parser.add_argument(
"msl_files",
Expand All @@ -461,6 +462,13 @@ def _get_cli_plot_args():
type=str,
help="Input CSV file, relative to <datadir>.",
)
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()
Expand Down Expand Up @@ -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."""
Expand All @@ -517,4 +535,4 @@ def _cli_calc():


if __name__ == "__main__":
_cli_calc()
_cli_calc()
2 changes: 1 addition & 1 deletion src/asli/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ def plot_lows(
if regionbox:
draw_regional_box(regionbox)

return ax
return ax
Loading