Exemple #1
0
def tget(filename=None):
    """Load processing parameters from a parameter save file.

    A file name may be given (e.g., "tget 'savefile.sav'"), in which case the
    parameters are loaded from the file specified. If no file name is given,
    the parameters are loaded from the file 'pybdsm.last' if it exists.

    Normally, the save file is created by the tput command (try "help tput"
    for more info).

    The save file is a "pickled" python dictionary which can be loaded into
    python and edited by hand. See the pickle module for more information.
    Below is an example of how to edit a save file by hand:

      BDSM [1]: import pickle
      BDSM [2]: savefile = open('savefile.sav', 'w')
      BDSM [3]: pars = pickle.load(savefile)
      BDSM [4]: pars['rms_box'] = (80, 20)  --> change rms_box parameter
      BDSM [5]: pickle.dump(pars, savefile) --> save changes

    """
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    import os

    global _session

    # Check whether user has given a task name as input (as done in casapy).
    # If so, reset filename to None but set the current_cmd.
    if isinstance(filename, Task):
        _set_current_cmd(filename)
        filename = None

    if filename == None or filename == '':
        if os.path.isfile('mpip.last'):
            filename = 'mpip.last'
        else:
            mylog.error('No file name given and '\
                  '"mpip.last" not found.\n Please specify a file to load.')
            return

    if os.path.isfile(filename):
        try:
            pkl_file = open(filename, 'rb')
            pars = pickle.load(pkl_file)
            pkl_file.close()
            _session.opts.set_opts(pars)
            _replace_vals_in_namespace()
            mylogger.userinfo(
                mylog, "Loaded parameters from file '" + filename + "'.")
        except Exception, e:
            mylog.exception("Could not read file '" + filename + "'.\n")
Exemple #2
0
def tget(filename=None):
    """Load processing parameters from a parameter save file.

    A file name may be given (e.g., "tget 'savefile.sav'"), in which case the
    parameters are loaded from the file specified. If no file name is given,
    the parameters are loaded from the file 'pybdsm.last' if it exists.

    Normally, the save file is created by the tput command (try "help tput"
    for more info).

    The save file is a "pickled" python dictionary which can be loaded into
    python and edited by hand. See the pickle module for more information.
    Below is an example of how to edit a save file by hand:

      BDSM [1]: import pickle
      BDSM [2]: savefile = open('savefile.sav', 'w')
      BDSM [3]: pars = pickle.load(savefile)
      BDSM [4]: pars['rms_box'] = (80, 20)  --> change rms_box parameter
      BDSM [5]: pickle.dump(pars, savefile) --> save changes

    """
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    import os

    global _session

    # Check whether user has given a task name as input (as done in casapy).
    # If so, reset filename to None but set the current_cmd.
    if isinstance(filename, Task):
        _set_current_cmd(filename)
        filename = None

    if filename == None or filename == '':
        if os.path.isfile('mpip.last'):
            filename = 'mpip.last'
        else:
            mylog.error('No file name given and '\
                  '"mpip.last" not found.\n Please specify a file to load.')
            return

    if os.path.isfile(filename):
        try:
            pkl_file = open(filename, 'rb')
            pars = pickle.load(pkl_file)
            pkl_file.close()
            _session.opts.set_opts(pars)
            _replace_vals_in_namespace()
            mylogger.userinfo(mylog,"Loaded parameters from file '" + filename + "'.")
        except Exception, e:
	    mylog.exception("Could not read file '" + filename + "'.\n")
Exemple #3
0
def tput(filename=None, quiet=False):
    """Save processing parameters to a file.

    A file name may be given (e.g., "tput 'savefile.sav'"), in which case the
    parameters are saved to the file specified. If no file name is given, the
    parameters are saved to the file 'pybdsm.last'. The saved parameters can
    be loaded using the tget command (try "help tget" for more info).

    The save file is a "pickled" python dictionary which can be loaded into
    python and edited by hand. See the pickle module for more information.
    Below is an example of how to edit a save file by hand:

      BDSM [1]: import pickle
      BDSM [2]: savefile = open('savefile.sav', 'w')
      BDSM [3]: pars = pickle.load(savefile)
      BDSM [4]: pars['rms_box'] = (80, 20)  --> change rms_box parameter
      BDSM [5]: pickle.dump(pars, savefile) --> save changes

    """
    try:
        import cPickle as pickle
    except ImportError:
        import pickle

    global _session
    success = _set_pars_from_prompt()
    if not success:
        return
    if filename == None or filename == '':
        filename = 'mpip.last'

    # convert opts to dictionary
    pars = _session.opts.to_dict()
    output = open(filename, 'wb')
    pickle.dump(pars, output)
    output.close()
    if not quiet:
        mylogger.userinfo(mylog,
                          "Saved parameters to file '" + filename + "'.")
Exemple #4
0
def tput(filename=None, quiet=False):
    """Save processing parameters to a file.

    A file name may be given (e.g., "tput 'savefile.sav'"), in which case the
    parameters are saved to the file specified. If no file name is given, the
    parameters are saved to the file 'pybdsm.last'. The saved parameters can
    be loaded using the tget command (try "help tget" for more info).

    The save file is a "pickled" python dictionary which can be loaded into
    python and edited by hand. See the pickle module for more information.
    Below is an example of how to edit a save file by hand:

      BDSM [1]: import pickle
      BDSM [2]: savefile = open('savefile.sav', 'w')
      BDSM [3]: pars = pickle.load(savefile)
      BDSM [4]: pars['rms_box'] = (80, 20)  --> change rms_box parameter
      BDSM [5]: pickle.dump(pars, savefile) --> save changes

    """
    try:
        import cPickle as pickle
    except ImportError:
        import pickle

    global _session
    success = _set_pars_from_prompt()
    if not success:
        return
    if filename == None or filename == '':
        filename = 'mpip.last'

    # convert opts to dictionary
    pars = _session.opts.to_dict()
    output = open(filename, 'wb')
    pickle.dump(pars, output)
    output.close()
    if not quiet:
        mylogger.userinfo(mylog, "Saved parameters to file '" + filename + "'.")