예제 #1
0
파일: pywrapper.py 프로젝트: jkettleb/cmor
def setup(inpath='.',netcdf_file_action=cmor_const.CMOR_PRESERVE,set_verbosity=cmor_const.CMOR_NORMAL,exit_control=cmor_const.CMOR_NORMAL,logfile=None,create_subdirectories=1):
    """
    Usage cmor_setup(inpath='.',netcdf_file_action=cmor.CMOR_PRESERVE,set_verbosity=cmor.CMOR_NORMAL,exit_control=cmor.CMOR_NORMAL)
    Where:
    path:                  Alternate directory where to find tables if not in current directory
    netcdf_file_action:    What to do when opening the netcdf file, valid options are:
                           CMOR_PRESERVE, CMOR_APPEND, CMOR_REPLACE, CMOR_PRESERVE_4, CMOR_APPEND_4, CMOR_REPLACE_4, CMOR_PRESERVE_3, CMOR_APPEND_3 or CMOR_REPLACE_3
                           The _3 means netcdf will be created in the old NetCDF3 format (no compression nor chunking), _4 means use NetCDF4 classic format. No _ is equivalent to _3

    set_verbosity:         CMOR_QUIET or CMOR_NORMAL
    exit_control:          CMOR_EXIT_ON_WARNING, CMOR_EXIT_ON_MAJOR, CMOR_NORMAL
    create_subdirectories: 1 to create subdirectories structure, 0 to dump files directly where cmor_dataset tells to
"""
    if not isinstance(exit_control,int) or not exit_control in [ cmor_const.CMOR_EXIT_ON_WARNING, cmor_const.CMOR_EXIT_ON_MAJOR, cmor_const.CMOR_NORMAL]:
        raise Exception, "exit_control must an integer valid values are: CMOR_EXIT_ON_WARNING, CMOR_EXIT_ON_MAJOR, CMOR_NORMAL"

    if not isinstance(netcdf_file_action,int) or not netcdf_file_action in [ cmor_const.CMOR_PRESERVE, cmor_const.CMOR_APPEND, cmor_const.CMOR_REPLACE, cmor_const.CMOR_PRESERVE_3, cmor_const.CMOR_APPEND_3, cmor_const.CMOR_REPLACE_3,cmor_const.CMOR_PRESERVE_4, cmor_const.CMOR_APPEND_4, cmor_const.CMOR_REPLACE_4 ]:
        raise Exception, "netcdf_file_action must be an integer. Valid values are: CMOR_PRESERVE, CMOR_APPEND, CMOR_REPLACE, CMOR_PRESERVE_3, CMOR_APPEND_3 or CMOR_REPLACE_3, CMOR_PRESERVE_4, CMOR_APPEND_4 or CMOR_REPLACE_4"

    if not isinstance(set_verbosity,int) or not set_verbosity in [ cmor_const.CMOR_QUIET, cmor_const.CMOR_NORMAL]:
        raise Exception, "set_verbosity must an integer valid values are: CMOR_QUIET, CMOR_NORMAL"

    if not isinstance(inpath,str) and not os.path.exists(inpath):
        raise Exception, "path must be a Valid path"
    if logfile is None:
        logfile = ""

    if not create_subdirectories in [0,1]:
        raise Exception, "create_subdirectories must be 0 or 1"
    return _cmor.setup(inpath,netcdf_file_action,set_verbosity,exit_control,logfile,create_subdirectories)
예제 #2
0
def setup(inpath='.',
          netcdf_file_action=cmor_const.CMOR_PRESERVE,
          set_verbosity=cmor_const.CMOR_NORMAL,
          exit_control=cmor_const.CMOR_NORMAL,
          logfile=None,
          create_subdirectories=1):
    """
    Usage cmor_setup(inpath='.',netcdf_file_action=cmor.CMOR_PRESERVE,set_verbosity=cmor.CMOR_NORMAL,exit_control=cmor.CMOR_NORMAL)
    Where:
    path:                  Alternate directory where to find tables if not in current directory
    netcdf_file_action:    What to do when opening the netcdf file, valid options are:
                           CMOR_PRESERVE, CMOR_APPEND, CMOR_REPLACE, CMOR_PRESERVE_4, CMOR_APPEND_4, CMOR_REPLACE_4, CMOR_PRESERVE_3, CMOR_APPEND_3 or CMOR_REPLACE_3
                           The _3 means netcdf will be created in the old NetCDF3 format (no compression nor chunking), _4 means use NetCDF4 classic format. No _ is equivalent to _3

    set_verbosity:         CMOR_QUIET or CMOR_NORMAL
    exit_control:          CMOR_EXIT_ON_WARNING, CMOR_EXIT_ON_MAJOR, CMOR_NORMAL
    create_subdirectories: 1 to create subdirectories structure, 0 to dump files directly where cmor_dataset tells to
"""
    if not isinstance(exit_control, int) or not exit_control in [
            cmor_const.CMOR_EXIT_ON_WARNING, cmor_const.CMOR_EXIT_ON_MAJOR,
            cmor_const.CMOR_NORMAL
    ]:
        raise Exception(
            "exit_control must an integer valid values are: CMOR_EXIT_ON_WARNING, CMOR_EXIT_ON_MAJOR, CMOR_NORMAL"
        )

    if not isinstance(netcdf_file_action, int) or not netcdf_file_action in [
            cmor_const.CMOR_PRESERVE, cmor_const.CMOR_APPEND,
            cmor_const.CMOR_REPLACE, cmor_const.CMOR_PRESERVE_3,
            cmor_const.CMOR_APPEND_3, cmor_const.CMOR_REPLACE_3,
            cmor_const.CMOR_PRESERVE_4, cmor_const.CMOR_APPEND_4,
            cmor_const.CMOR_REPLACE_4
    ]:
        raise Exception(
            "netcdf_file_action must be an integer. Valid values are: CMOR_PRESERVE, CMOR_APPEND, CMOR_REPLACE, CMOR_PRESERVE_3, CMOR_APPEND_3 or CMOR_REPLACE_3, CMOR_PRESERVE_4, CMOR_APPEND_4 or CMOR_REPLACE_4"
        )

    if not isinstance(set_verbosity, int) or not set_verbosity in [
            cmor_const.CMOR_QUIET, cmor_const.CMOR_NORMAL
    ]:
        raise Exception(
            "set_verbosity must an integer valid values are: CMOR_QUIET, CMOR_NORMAL"
        )

    if not isinstance(inpath, str) and not os.path.exists(inpath):
        raise Exception("path must be a Valid path")
    if logfile is None:
        logfile = ""

    if not create_subdirectories in [0, 1]:
        raise Exception("create_subdirectories must be 0 or 1")
    return _cmor.setup(inpath, netcdf_file_action, set_verbosity, exit_control,
                       logfile, create_subdirectories)