Beispiel #1
0
import cdp
import cdtime
import cdutil
import genutil
import numpy

from pcmdi_metrics.driver.pmp_parser import PMPParser

try:
    import cmor

    hasCMOR = True
except Exception:
    hasCMOR = False

parser = PMPParser(description="Generates Climatologies from files")

cmor_xtra_args = [
    "contact",
    "references",
    "model_id",
    "institute_id",
    "forcing",
    "parent_experiment_id",
    "parent_experiment_rip",
    "realization",
    "comment",
    "history",
    "branch_time",
    "physics_version",
    "initialization_method",
Beispiel #2
0
        self.fileName = filename
        self.args = args
        self.monthname = monthname_d[args.month]
        self.varname = varname
        self.template = filename_template


def populateStringConstructor(template, args):
    template = genutil.StringConstructor(template)
    for k in list(template.keys()):
        if hasattr(args, k):
            setattr(template, k, str(getattr(args, k)))
    return template


P = PMPParser()
P.use("--modpath")
P.use("--results_dir")
P.use("--num_workers")

P.add_argument(
    "-m",
    "--month",
    type=int,
    default=7,
    help="Month to be processed, given as 2-char month number",
)
P.add_argument("-f",
               "--firstyear",
               type=int,
               default=1999,
Beispiel #3
0
def AddParserArgument():

    P = PMPParser()  # Includes all default options

    P.add_argument("--mip",
                   type=str,
                   default="cmip5",
                   help="A WCRP MIP project such as CMIP3 and CMIP5")
    P.add_argument("--exp",
                   type=str,
                   default="historical",
                   help="An experiment such as AMIP, historical or pi-contorl")
    P.use("--modpath")
    P.add_argument("--modpath_lf",
                   type=str,
                   dest='modpath_lf',
                   help="Directory path to model land fraction field")
    P.add_argument("--modnames",
                   type=str,
                   nargs='+',
                   default=None,
                   help="List of models")
    P.add_argument("-r",
                   "--realization",
                   type=str,
                   default="r1i1p1",
                   help="Consider all accessible realizations as idividual\n"
                   "- r1i1p1: default, consider only 'r1i1p1' member\n"
                   "          Or, specify realization, e.g, r3i1p1'\n"
                   "- *: consider all available realizations")
    P.use("--reference_data_path")
    P.add_argument("--reference_data_lf_path",
                   type=str,
                   dest='reference_data_lf_path',
                   help="Data path to land fraction of reference dataset")
    P.add_argument(
        "--metricsCollection",
        type=str,
        dest='metricsCollection',
        default="ENSO_perf",
        help="Metrics Collection e.g. ENSO_perf, ENSO_tel, or ENSO_proc")
    P.add_argument("--json_name",
                   type=str,
                   dest='json_name',
                   help="File name for output JSON")
    P.add_argument("--netcdf_name",
                   type=str,
                   dest='netcdf_name',
                   help="File name for output NetCDF")
    P.use("--results_dir")
    P.add_argument("--case_id",
                   type=str,
                   dest="case_id",
                   default="{:v%Y%m%d}".format(datetime.datetime.now()),
                   help="version as date, e.g., v20191116 (yyyy-mm-dd)")
    P.add_argument(
        "--obs_catalogue",
        type=str,
        default=None,
        dest='obs_catalogue',
        help="obs_catalogue JSON file for CMORized observation, default is None"
    )
    P.add_argument(
        "--obs_cmor_path",
        type=str,
        default=None,
        dest='obs_cmor_path',
        help="Directory path for CMORized observation dataset, default is None"
    )
    # Switches
    P.add_argument("-d",
                   "--debug",
                   nargs='?',
                   const=True,
                   default=False,
                   type=bool,
                   help="Option for debug: True / False (defualt)")
    P.add_argument(
        "--obs_cmor",
        nargs='?',
        const=True,
        default=False,
        type=bool,
        help="Use CMORized reference database?: True / False (defualt)")
    P.add_argument(
        "--nc_out",
        nargs='?',
        const=True,
        default=True,
        type=bool,
        help="Option for generate netCDF file output: True (default) / False")

    param = P.get_parameter()

    return param
from __future__ import print_function
import os
import tempfile
import cdms2
import cdutil
import numpy
import cdtime
from pcmdi_metrics.driver.pmp_parser import PMPParser

try:
    import cmor
    hasCMOR = True
except Exception:
    hasCMOR = False

parser = PMPParser(description='Generates Climatologies from files')

p = parser.add_argument_group('processing')
p.add_argument("--verbose",
               action="store_true",
               dest="verbose",
               help="verbose output",
               default=True)
p.add_argument("--quiet",
               action="store_false",
               dest="verbose",
               help="quiet output")
p.add_argument(
    "-v",
    "--var",
    dest="var",
def ReadOptions():

    P = PMPParser()  # Includes all default options

    #P.use("--mip")
    #P.use("--exp")

    P.add_argument("--mip",
                   type=str,
                   default="cmip5",
                   help="A WCRP MIP project such as CMIP3 and CMIP5")
    P.add_argument("--exp",
                   type=str,
                   default="historical",
                   help="An experiment such as AMIP, historical or pi-contorl")
    P.use("--modpath")
    P.add_argument("--modpath_lf",
                   type=str,
                   dest='modpath_lf',
                   help="Directory path to model land fraction field")
    P.add_argument("--modnames",
                   type=str,
                   nargs='+',
                   default=None,
                   help="List of models")
    P.add_argument("-r",
                   "--realization",
                   type=str,
                   default="r1i1p1",
                   help="Consider all accessible realizations as idividual\n"
                   "- r1i1p1: default, consider only 'r1i1p1' member\n"
                   "          Or, specify realization, e.g, r3i1p1'\n"
                   "- *: consider all available realizations")
    P.use("--reference_data_path")
    P.add_argument("--reference_data_lf_path",
                   type=str,
                   dest='reference_data_lf_path',
                   help="Data path to land fraction of reference dataset")
    P.add_argument("--metricsCollection",
                   type=str,
                   dest='metricsCollection',
                   help="Metrics Collection e.g. MC1, ENSO_perf, or ENSO_tel")
    P.add_argument("--json_name",
                   type=str,
                   dest='json_name',
                   help="File name for output JSON")
    P.add_argument("--netcdf_name",
                   type=str,
                   dest='netcdf_name',
                   help="File name for output NetCDF")
    P.use("--results_dir")

    # Switches
    P.add_argument("-d",
                   "--debug",
                   nargs='?',
                   const=True,
                   default=False,
                   type=bool,
                   help="Option for debug: True / False (defualt)")
    P.add_argument(
        "--nc_out",
        nargs='?',
        const=True,
        default=True,
        type=bool,
        help="Option for generate netCDF file output: True (default) / False")

    param = P.get_parameter()

    return param
Beispiel #6
0
    def testProcessTemplatedArgument(self):
        parser = PMPParser(description='Test')

        parser.add_argument("--something", default="something")
        parser.add_argument("--someone", default="someone")
        parser.add_argument("--template", default="%(something)/abc/%(someone)")
        parser.add_argument("-s")  # for nosetest

        parser.add_argument("--with-coverage", default=False, action="store_true",
                            help="run test with code coverage")
        parser.add_argument("--cover-packages", help="package name to get code coverage on")

        A = parser.get_parameter()

        self.assertEqual(A.process_templated_argument("template")(),"something/abc/someone")
        self.assertEqual(A.process_templated_argument("%(someone)/cba/%(something)")(),"someone/cba/something")
Beispiel #7
0
#!/usr/bin/env python

import glob
import os

from genutil import StringConstructor

from pcmdi_metrics.driver.pmp_parser import PMPParser
from pcmdi_metrics.precip_variability.lib import (
    AddParserArgument,
    precip_variability_across_timescale,
)

# Read parameters
P = PMPParser()
P = AddParserArgument(P)
param = P.get_parameter()
mip = param.mip
mod = param.mod
var = param.var
dfrq = param.frq
modpath = param.modpath
prd = param.prd
fac = param.fac
nperseg = param.nperseg
noverlap = param.noverlap
print(modpath)
print(mod)
print(prd)
print(nperseg, noverlap)
Beispiel #8
0
import copy
import distutils.spawn
import importlib
import inspect
import os
import shlex
import stat
import subprocess
import sys
import tempfile

import cdp

from pcmdi_metrics.driver.pmp_parser import PMPParser

parser = PMPParser(description="Parallelize a driver over some arguments")
parser.add_argument("--driver", help="driver to prallelize")
parser.add_argument(
    "--bash",
    help="generate a bash script rather than running in parallel",
    action="store_true",
)
parser.use("num_workers")
parser.add_argument("--granularize")
p = parser.get_parameter()

param_name = parser.view_args().parameters
pth = os.path.dirname(os.path.abspath(param_name))
sys.path.insert(0, pth)
nm = os.path.basename(param_name)[:-3]
parameters = importlib.import_module(nm)
Beispiel #9
0
import cdat_info
import requests

from pcmdi_metrics.driver.pmp_parser import PMPParser


def download_file(download_url_root, name, local_filename):
    r = requests.get("%s/%s" % (download_url_root, name), stream=True)
    with open(local_filename, "wb") as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:  # filter local_filename keep-alive new chunks
                f.write(chunk)


parser = PMPParser(description="Get sample data")
parser.add_argument(
    "--dataset",
    help="Download observation or sample data or both",
    default="all",
    choices=["all", "obs", "sample"],
)
parser.add_argument("--version", help="which version to use", default="latest")
parser.add_argument(
    "--server",
    help="which server to use",
    default="https://pcmdiweb.llnl.gov/pss/pmpdata",
)
parser.add_argument(
    "--version_in_path",
    action="store_true",
Beispiel #10
0
        self.fileName = filename
        self.args = args
        self.monthname = monthname_d[args.month]
        self.varname = varname
        self.template = filename_template


def populateStringConstructor(template, args):
    template = genutil.StringConstructor(template)
    for k in template.keys():
        if hasattr(args, k):
            setattr(template, k, str(getattr(args, k)))
    return template


P = PMPParser()
P.add_argument("-i",
               "--modroot",
               default='data',
               help="Root directory for model (or observed) 3-hourly data")
P.add_argument("-m",
               "--month",
               type=int,
               default=7,
               help="Month to be processed, given as 2-char month number")
P.add_argument("-f",
               "--firstyear",
               type=int,
               default=1999,
               help="First year of data processing")
P.add_argument("-l",
Beispiel #11
0
from pcmdi_metrics.driver.pmp_parser import PMPParser
import tempfile
import requests
import os
import cdat_info


def download_file(download_url_root, name, local_filename):
    r = requests.get("%s/%s" % (download_url_root, name), stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:  # filter local_filename keep-alive new chunks
                f.write(chunk)


parser = PMPParser(description='Get sample data')
parser.add_argument("--dataset", help="Download observation or sample data or both",
                    default="all", choices=["all", "obs", "sample"])
parser.add_argument("--version", help="which version to use", default="latest")
parser.add_argument("--server", help="which server to use",
                    default="https://pcmdiweb.llnl.gov/pss/pmpdata")
parser.add_argument("--version_in_path", action="store_true", default=False,
                    help="Append version in root path, avoids clobbering versions")
parser.add_argument(
    "--output-path", help="directory where to download", default=None)
# parser.use("num_workers")
p = parser.get_parameter()

# Step1 prepare the paths to get the sample datafiles
pth = tempfile.mkdtemp()
files = []
Beispiel #12
0
        self.fileName = filename
        self.args = args
        self.monthname = monthname_d[args.month]
        self.varname = varname
        self.template = filename_template


def populateStringConstructor(template, args):
    template = genutil.StringConstructor(template)
    for k in list(template.keys()):
        if hasattr(args, k):
            setattr(template, k, str(getattr(args, k)))
    return template


P = PMPParser()
P.use("--modpath")
P.use("--results_dir")
P.use("--num_workers")

P.add_argument("-m", "--month",
               type=int,
               default=7,
               help="Month to be processed, given as 2-char month number")
P.add_argument("-f", "--firstyear",
               type=int,
               default=1999,
               help="First year of data processing")
P.add_argument("-l", "--lastyear",
               type=int,
               default=2005,
#!/usr/bin/env python
from __future__ import print_function
from pcmdi_metrics.driver.pmp_parser import PMPParser
import subprocess
import os
import importlib
import sys
import inspect
import tempfile
import cdp
import shlex
import copy
import distutils.spawn
import stat

parser = PMPParser(description='Parallelize a driver over some arguments')
parser.add_argument("--driver", help="driver to prallelize")
parser.add_argument("--bash", help="generate a bash script rather than running in parallel", action="store_true")
parser.use("num_workers")
parser.add_argument("--granularize")
p = parser.get_parameter()

param_name = parser.view_args().parameters
pth = os.path.dirname(os.path.abspath(param_name))
sys.path.insert(0, pth)
nm = os.path.basename(param_name)[:-3]
parameters = importlib.import_module(nm)


def build(variables, parameters, params=[{}]):
    if len(variables) == 0:
    def testProcessTemplatedArgument(self):
        parser = PMPParser(description='Test')

        parser.add_argument("--something", default="something")
        parser.add_argument("--someone", default="someone")
        parser.add_argument("--template",
                            default="%(something)/abc/%(someone)")
        parser.add_argument("-s")  # for nosetest

        A = parser.get_parameter()

        self.assertEqual(
            A.process_templated_argument("template")(),
            "something/abc/someone")
        self.assertEqual(
            A.process_templated_argument("%(someone)/cba/%(something)")(),
            "someone/cba/something")