1313import argparse
1414import sys
1515from abc import ABC , abstractmethod
16+ from pathlib import Path
1617
17- from imap_processing import instruments , processing_levels
18+ import imap_processing
1819
1920
2021def _parse_args ():
@@ -28,15 +29,25 @@ def _parse_args():
2829 description = (
2930 "This command line program invokes the processing pipeline "
3031 "for a specific instrument and data level. Example usage: "
31- '"python run_processing swe l1a".'
32+ '"python run_processing --instrument swe --level l1a".'
33+ )
34+ data_dir_help = (
35+ "Directory to use for reading and writing IMAP data. "
36+ "The default is an 'imap-data/' folder in the "
37+ "current working directory. This can also be "
38+ "set using the IMAP_DATA_DIR environment variable."
39+ )
40+ instrument_help = (
41+ "The instrument to process. Acceptable values are: "
42+ f"{ imap_processing .INSTRUMENTS } "
3243 )
33-
34- instrument_help = f"The instrument to process. Acceptable values are: { instruments } "
3544 level_help = (
36- f"The data level to process. Acceptable values are: { processing_levels } "
45+ "The data level to process. Acceptable values are: "
46+ f"{ imap_processing .PROCESSING_LEVELS } "
3747 )
3848
3949 parser = argparse .ArgumentParser (prog = "imap_cli" , description = description )
50+ parser .add_argument ("--data-dir" , type = str , required = False , help = data_dir_help )
4051 parser .add_argument ("--instrument" , type = str , required = True , help = instrument_help )
4152 parser .add_argument ("--level" , type = str , required = True , help = level_help )
4253 args = parser .parse_args ()
@@ -52,15 +63,23 @@ def _validate_args(args):
5263 args : argparse.Namespace
5364 An object containing the parsed arguments and their values
5465 """
55- if args .instrument not in instruments :
66+ if args .instrument not in imap_processing . INSTRUMENTS :
5667 raise ValueError (
57- f"{ args .instrument } is not in the supported instrument list: { instruments } "
68+ f"{ args .instrument } is not in the supported instrument list: "
69+ f"{ imap_processing .INSTRUMENTS } "
5870 )
59- if args .level not in processing_levels [args .instrument ]:
71+ if args .level not in imap_processing . PROCESSING_LEVELS [args .instrument ]:
6072 raise ValueError (
6173 f"{ args .level } is not a supported data level for the { args .instrument } "
62- f" instrument, valid levels are: { processing_levels [args .instrument ]} "
74+ " instrument, valid levels are: "
75+ f"{ imap_processing .PROCESSING_LEVELS [args .instrument ]} "
6376 )
77+ if args .data_dir :
78+ data_path = Path (args .data_dir )
79+ if not data_path .exists ():
80+ raise ValueError (f"Data directory { args .data_dir } does not exist" )
81+ # Set the data directory to the user-supplied value
82+ imap_processing .config ["DATA_DIR" ] = data_path
6483
6584
6685class ProcessInstrument (ABC ):
@@ -162,7 +181,13 @@ def process(self):
162181
163182
164183def main ():
165- """Create CLI entrypoint."""
184+ """Run the processing for a specific instrument & data level.
185+
186+ Set up the command line arguments, parse them, and then invoke the
187+ appropriate instrument processing function.
188+ """
189+ # NOTE: This is to allow the cli script to be installed and reference
190+ # this function for an entrypoint.
166191 args = _parse_args ()
167192
168193 _validate_args (args )
0 commit comments