Commit a9f941de authored by Alice Donini's avatar Alice Donini
Browse files

restructure argparse

parent 44a1c0a2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -14,8 +14,9 @@ from utils import (

# Argument parser
args = parse_arguments(description="DL1 to DL2 converter",
                       add_run=True,
                       add_dl2=True,
                       add_job=True,
                       add_common=True,
                       )

config_file = get_config(args.config)
+2 −2
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ from utils import (
# Argument parsera
args = parse_arguments(description="DL2 to DL3 converter",
                       add_job=True,
                       add_run=True,
                       add_dl3=True)
                       add_dl3=True,
                       add_common=True)

config_file = get_config(args.config)

+2 −2
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ from utils import (parse_arguments,

# Argument parser
args = parse_arguments(description="DL3 index maker",
                       add_job=True,
                       add_run=True)
                       add_common=True,
                       add_job=False)

config_file = get_config(args.config)

+47 −28
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from operator import attrgetter
from astropy.coordinates import SkyCoord
from glob import glob
from argparse import HelpFormatter
from datetime import datetime


class SortingHelpFormatter(HelpFormatter):
@@ -15,29 +16,41 @@ class SortingHelpFormatter(HelpFormatter):
        super(SortingHelpFormatter, self).add_arguments(actions)


def parse_arguments(description, add_run=False, add_irf=False, add_job=False, add_dl3=False):
def parse_arguments(description, add_dl2=False, add_irf=False, add_job=False, add_dl3=False, create_runlist=False, add_common=False):
    parser = argparse.ArgumentParser(description=description, formatter_class=SortingHelpFormatter)

    parser.add_argument('--prod', '-p',
                        dest='prod', required=False, type=str, default='v0.9.4',
                        help='Prod to use (default: %(default)s)')
    parser.add_argument('--outdir', '-o',
                        dest='outdir', required=False, type=str, default=None,
                        help='Directory to store the output')
    parser.add_argument('--config', '-c',
                        type=str, default=None, dest='config',
                        help='Specify a personal config file for the analysis')
    parser.add_argument('--config-analysis',
                        type=str, default=None, dest='config_analysis',
                        help='Specify a config file which describes analysis profile to use')
    # parser.add_argument('--config-analysis',
    #                     type=str, default=None, dest='config_analysis',
    #                     help='Specify a config file which describes analysis profile to use')
    parser.add_argument('--verbose', '-v',
                        action='store_true', dest='verbose',
                        help='Increase output verbosity')

    if add_run:
    if create_runlist:
        parser.add_argument('--source_name', '-n', required=True, default=None,
                            dest='source_name', type=str,
                            help='Name of the source')
        parser.add_argument('--ra', type=float, dest='ra',
                            help='RA coordinate of the target. To add if you want to use custom position')
        parser.add_argument('--dec', type=float, dest='dec',
                            help='Dec coordinate of the target. To add if you want to use custom position')
        parser.add_argument('--night', type=str, dest='night',
                            nargs='+', required=False,
                            help='Night of the observation in the format YYYYMMDD. More nights can be specified')

    if add_common:
        parser.add_argument('--source_name', '-n', required=True,
                            default=None, dest='source_name', type=str,
                            help='Name of the source')
        parser.add_argument('--config', '-c', type=str, default=None,
                            required=True, dest='config', help='Specify a personal config file for the analysis')
        parser.add_argument('--dry',
                            default=False, required=False, action='store_true', dest='dry',
                            help='Make a dry run, no true submission')
        
    if add_dl2:
        parser.add_argument('--outdir', '-o', dest='outdir', required=False,
                            type=str, default=None, help='Directory to store the output')
        parser.add_argument('--tcuname',
                            default=None, dest='tcuname', type=str,
                            help='Apply run selection based on TCU source name')
@@ -46,9 +59,7 @@ def parse_arguments(description, add_run=False, add_irf=False, add_job=False, ad
                            help='File with a list of run and the associated night to be analysed')
        parser.add_argument('--distance', '-dis',
                            type=float, dest='distance', default=-1,
                            help='Max distance in degrees between the target position and the run pointing \
                                  position for the run selection, negative value means no selection using \
                                  this parameter (default: %(default)s).')
                            help='Max distance in degrees between the target position and the run pointing position for the run selection. Negative value means no selection using this parameter (default: %(default)s).')
        parser.add_argument('--ra',
                            type=float, dest='ra', default=-1,
                            help='RA coordinate of the target. To add if you want to use custom position')
@@ -56,17 +67,6 @@ def parse_arguments(description, add_run=False, add_irf=False, add_job=False, ad
                            type=float, dest='dec', default=-91,
                            help='Dec coordinate of the target. To add if you want to use custom position')

    if add_job:
        parser.add_argument('--submit',
                            default=False, dest='submit', action='store_true', required=False,
                            help='Submit the cmd to slurm on site')
        parser.add_argument('--dry',
                            default=False, required=False, action='store_true', dest='dry',
                            help='Make a dry run, no true submission')
        parser.add_argument('--globber', '-g',
                            dest='globber', action='store_true', required=False, default=False,
                            help='If True, overwrites existing output file without asking')

    if add_irf:
        parser.add_argument('--gh_cut',
                            required=False, type=float, dest='gh_cut',
@@ -79,6 +79,17 @@ def parse_arguments(description, add_run=False, add_irf=False, add_job=False, ad
                            help='Observation time for IRF in hours')

    if add_dl3:
        parser.add_argument('--outdir', '-o', dest='outdir', type=str,
                            default=None, help='Directory to store the output')
        parser.add_argument('--runlist', '-rl',
                            default=None, dest='runlist', type=str,
                            help='File with a list of run and the associated night to be analysed')
        parser.add_argument('--ra',
                            type=float, dest='ra', default=-1,
                            help='RA coordinate of the target. To add if you want to use custom position')
        parser.add_argument('--dec',
                            type=float, dest='dec', default=-91,
                            help='Dec coordinate of the target. To add if you want to use custom position')
        parser.add_argument('--cut_file', '-cut',
                            default=None, dest='cut_file', type=str,
                            help='Cut file')
@@ -88,6 +99,14 @@ def parse_arguments(description, add_run=False, add_irf=False, add_job=False, ad
        parser.add_argument('--theta_cut',
                            required=False, type=float, dest='theta_cut',
                            help='Fixed selection cut for theta')

    if add_job:
        parser.add_argument('--submit', default=False, dest='submit',
                            action='store_true', required=False, help='Submit the cmd to slurm on site')
        parser.add_argument('--globber', '-g',
                            dest='globber', action='store_true', required=False, default=False,
                            help='If True, overwrites existing output file without asking (default: %(default)s).')

    args = parser.parse_args()
    return args