예제 #1
0
def test_default_diag_parser():
    from om4labs.om4parser import default_diag_parser
    from om4labs.om4parser import DefaultDictParser

    parser = default_diag_parser(template=True)
    args = parser.parse_args([])
    args = args.__dict__
    num_default_options = len(list(args.keys()))
    assert isinstance(args, dict), "unable to obtain dict of options"
    assert num_default_options > 0, "no options are present"

    parser = default_diag_parser(template=False)
    args = parser.parse_args(["foo"])
    _num_keys = len(list(args.__dict__.keys()))
    assert (_num_keys == num_default_options
            ), "argparse object does not have the same number of keys"

    parser = default_diag_parser(template=False, exclude="gridspec")
    args = parser.parse_args(["foo"])
    _num_keys = len(list(args.__dict__.keys()))
    assert _num_keys == (num_default_options -
                         1), "excluding a single string failed"

    parser = default_diag_parser(template=False, exclude=["gridspec", "basin"])
    args = parser.parse_args(["foo"])
    _num_keys = len(list(args.__dict__.keys()))
    assert _num_keys == (num_default_options - 2), "excluding a list failed"
예제 #2
0
def parse(cliargs=None, template=False):
    """Function to capture the user-specified command line options

    Parameters
    ----------
    cliargs : argparse, optional
        Command line options from argparse, by default None
    template : bool, optional
        Return dictionary instead of parser, by default False

    Returns
    -------
        parsed command line arguments
    """

    description = " "

    exclude = ["basin", "hgrid", "topog", "gridspec", "config"]

    parser = default_diag_parser(description=description,
                                 template=template,
                                 exclude=exclude)

    parser.add_argument(
        "--varname",
        type=str,
        default="tos",
        help="Variable to analyze. Default is tos.",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #3
0
def parse(cliargs=None, template=False):
    description = """Plot sea ice vs. NSIDC"""

    parser = default_diag_parser(
        description=description, template=template, exclude=["basin", "topog"]
    )

    parser.add_argument(
        "--month",
        type=str,
        default="March",
        help="Month to analyze. Deafult is March",
    )

    parser.add_argument(
        "--region",
        type=str,
        default="nh",
        help="Region for analysis. Default is nh. Options are nh and sh",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #4
0
def parse(cliargs=None, template=False):
    """
    Function to capture the user-specified command line options
    """
    description = """Driver script for plotting all OM4 section transports"""

    exclude = [
        "basin",
        "config",
        "gridspec",
        "hgrid",
        "infile",
        "obsfile",
        "platform",
        "static",
        "suptitle",
        "topog",
    ]

    parser = default_diag_parser(description=description,
                                 template=template,
                                 exclude=exclude)

    parser.add_argument(
        "ppdir",
        metavar="PPDIR",
        type=str,
        nargs="+",
        help="Path to root post-processing directory (<...>/pp)",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #5
0
def parse(cliargs=None, template=False):
    """
    Function to capture the user-specified command line options
    """
    description = """ """

    parser = default_diag_parser(
        description=description,
        template=template,
        exclude=["obsfile", "topog", "config", "platform", "basin"],
    )

    parser.add_argument(
        "--bins",
        type=str,
        default="20,30,0.1",
        help=
        "Density bins at which to evaluate transformation, provided as start, stop, increment.",
    )

    parser.add_argument(
        "--group_tend",
        dest="group_tend",
        action="store_true",
        help=
        "Group heat and salt tendencies together, i.e. only return the total transformation. Not passing this could lead to a performance cost.",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #6
0
def parse(cliargs=None, template=False):
    description = """Plot annual volume transport through the Drake Passage"""

    parser = default_diag_parser(description=description, template=template)

    parser.add_argument("--dataset", type=str, required=False)

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
def parse(cliargs=None, template=False):
    """Function to capture the user-specified command line options

    Parameters
    ----------
    cliargs : argparse, optional
        Command line options from argparse, by default None
    template : bool, optional
        Return dictionary instead of parser, by default False

    Returns
    -------
        parsed command line arguments
    """

    description = "Diagnostic for layer mean potential temperature drift"

    parser = default_diag_parser(
        description=description,
        template=template,
        exclude=["gridspec", "static", "basin", "obsfile", "hgrid", "topog"],
    )

    parser.add_argument(
        "--description",
        type=str,
        required=False,
        default="Layer-average temperature drift [degC] vs. time",
        help="description string in subtitle",
    )
    parser.add_argument(
        "--varname",
        type=str,
        required=False,
        default="thetao_xyave",
        help="variable name to plot",
    )
    parser.add_argument(
        "--range",
        type=float,
        required=False,
        default=1.0,
        help="min/max data range for contouring",
    )
    parser.add_argument("--interval",
                        type=float,
                        required=False,
                        default=0.1,
                        help="contour interval")

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #8
0
def parse(cliargs=None, template=False):
    """
    Function to capture the user-specified command line options
    """
    description = """ """

    parser = default_diag_parser(description=description,
                                 template=template,
                                 exclude=["obsfile", "topog"])

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #9
0
def parse(cliargs=None, template=False):
    """
    Function to capture the user-specified command line options
    """
    description = """Generic routine for plotting section transports"""

    exclude = [
        "basin",
        "config",
        "gridspec",
        "hgrid",
        "obsfile",
        "platform",
        "static",
        "suptitle",
        "topog",
    ]

    parser = default_diag_parser(description=description,
                                 template=template,
                                 exclude=exclude)

    parser.add_argument(
        "--passage_label",
        type=str,
        default="",
        help="Text to use for the name of the passage being plotted",
    )

    parser.add_argument(
        "--obsrange",
        type=str,
        default=None,
        help=
        "Comma-separated tuple of min and max observed ranges (e.g. -20,20)",
    )

    parser.add_argument(
        "--outfile",
        type=str,
        default="section",
        help=
        "Name of output file name with path (--outdir) and extension (--format)",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #10
0
def parse(cliargs=None, template=False):
    """Function to capture the user-specified command line options

    Parameters
    ----------
    cliargs : argparse, optional
        Command line options from argparse, by default None
    template : bool, optional
        Return dictionary instead of parser, by default False

    Returns
    -------
        parsed command line arguments

    example usage:
    om4labs stress_curl -s fname_static.nc --dataset OM4_windstress --period 1999-2018 fname_model_taux.nc fname_model_tauy.nc
    """

    description = " "

    exclude = ["basin", "hgrid", "topog", "gridspec", "config"]

    parser = default_diag_parser(description=description,
                                 template=template,
                                 exclude=exclude)

    parser.add_argument(
        "--dataset",
        type=str,
        required=False,
        default="OM4_windstress",
        help="Name of the observational dataset, \
              as provided in intake catalog",
    )

    parser.add_argument(
        "--period",
        type=str,
        required=False,
        default="1959-1978",
        help=
        "Time period for OMIP2 dataset, available are 1959-1978 and 1999-2018",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #11
0
def parse(cliargs=None, template=False):
    """Function to capture the user-specified command line options

    Parameters
    ----------
    cliargs : argparse, optional
        Command line options from argparse, by default None
    template : bool, optional
        Return dictionary instead of parser, by default False

    Returns
    -------
        parsed command line arguments
    """

    description = " "

    parser = default_diag_parser(description=description, template=template)

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
def parse(cliargs=None, template=False):
    """ parse the command line arguments """

    description = "Script for plotting annual-average bias to obs"
    parser = default_diag_parser(description=description,
                                 template=template,
                                 exclude=["basin", "topog"])

    parser.add_argument(
        "--depth",
        type=float,
        default=None,
        required=False,
        help="depth of field compared to obs",
    )

    parser.add_argument(
        "--dataset",
        type=str,
        required=False,
        default="WOA13_annual_TS",
        help="Name of the observational dataset, \
              as provided in intake catalog",
    )

    parser.add_argument(
        "--style",
        type=str,
        required=False,
        default="diff",
        help="output plot style (diff/compare)",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)
예제 #13
0
def parse(cliargs=None, template=False):
    """Function to capture the user-specified command line options

    Parameters
    ----------
    cliargs : argparse, optional
        Command line options from argparse, by default None
    template : bool, optional
        Return dictionary instead of parser, by default False

    Returns
    -------
        parsed command line arguments
    """

    description = " "

    parser = default_diag_parser(description=description, template=template)

    parser.add_argument(
        "--dataset",
        type=str,
        required=False,
        default="WOA13_annual_TS",
        help="Name of the observational dataset, \
              as provided in intake catalog",
    )

    parser.add_argument(
        "--argo_file",
        type=str,
        required=False,
        default=None,
        help="Name of the Argo climatology file "
        + "(in-situ temp and practical salinity)",
    )

    parser.add_argument(
        "--model_xcoord",
        type=str,
        required=False,
        default="lon",
        help="Name of x-coordinate in the model data",
    )

    parser.add_argument(
        "--model_ycoord",
        type=str,
        required=False,
        default="lat",
        help="Name of y-coordinate in the model data",
    )

    parser.add_argument(
        "--model_zcoord",
        type=str,
        required=False,
        default="z_l",
        help="Name of z-coordinate in the model data",
    )

    if template is True:
        return parser.parse_args(None).__dict__
    else:
        return parser.parse_args(cliargs)