"""
pythonmodule
============

Provides utility functions for working with SHEMAT-Suite output in Python.
"""
import os
import shutil

###############################################################################
#                               Directories                                   #
###############################################################################
python_dir = os.environ['HOME']+'/pyshemkf'
python_scripts_dir = python_dir+'/scripts'
python_output_dir = python_dir+'/output'


###############################################################################
#                                 Output                                      #
###############################################################################
def py_output_dir(tag, ending):
    """
    Generate Python output directory according to tag ending.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_dir : string
        Designated output directory.
    """
    py_output_dir = (python_output_dir + "/"
                     + tag + "/"
                     + ending)

    return py_output_dir


def py_output_filename(tag, filename, spec, ending):
    """
    Generate Python output filename (with specifier)
    according to filename (without ending), tag ending, spec.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    filename : string
        Filename body, without ending.

    spec : string
        Output identifier that will be added to the filename.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """

    py_output_filename = (py_output_dir(tag, ending) + "/"
                          + filename + "_" + spec + "."
                          + ending)

    return py_output_filename


def py_simple_output_filename(filename, tag, ending):
    """
    Generate Python simple output filename (without specifier)
    according to filename (without ending), tag, ending.

    Parameters
    ----------
    filename : string
        Filename body, without ending.

    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_simple_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    filename is used as body of the output-filename, nothing is added.
    """

    py_simple_output_filename = (py_output_dir(tag, ending) + "/"
                                 + filename + "."
                                 + ending)

    return py_simple_output_filename


###############################################################################
#                            Script Backup                                    #
###############################################################################
def py_backup(python_sub_dir, tag, filename, ending, spec):
    """
    Copy a python script to backup directory and add specifier

    Parameters
    ----------
    python_sub_dir : string
        Absolute subdirectory of the script, mostly
        ~/PythonExecDir and ~/pyshemkf/scripts

    tag : string
        Subdirectory name in ~/PythonExecDir or
        ~/pyshemkf/scripts

    filename : string
        Filename body, without ending.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    spec : string
        Output identifier that will be added to the filename.

    Notes
    ----------
    Returns nothing, but copies the file to a possibly generated backup
    directory.

    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    # Script Name
    py_file_name = (python_sub_dir + "/"
                    + tag + "/"
                    + filename + "."
                    + ending)

    # Possibly create backup directory
    if not os.path.exists(python_sub_dir+"/"+tag+"/backup"):
        os.mkdir(python_sub_dir+"/"+tag+"/backup")

    # Backup Script Name
    py_backup_file_name = (python_sub_dir + "/"
                           + tag + "/"
                           + "backup" + "/"
                           + filename + "_"
                           + spec + "."
                           + ending)

    # Exception if file already exists
    if os.path.isfile(py_backup_file_name):
        os.remove(py_backup_file_name)
        print('Removed old file: '+py_backup_file_name)

    shutil.copyfile(py_file_name, py_backup_file_name)
    print('Backup as '+py_backup_file_name)

f81808130624e1e02043f0d177018cee3f734e9a
<mask token>


def py_output_filename(tag, filename, spec, ending):
    """
    Generate Python output filename (with specifier)
    according to filename (without ending), tag ending, spec.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    filename : string
        Filename body, without ending.

    spec : string
        Output identifier that will be added to the filename.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '_' + spec + '.' + ending
    return py_output_filename


def py_simple_output_filename(filename, tag, ending):
    """
    Generate Python simple output filename (without specifier)
    according to filename (without ending), tag, ending.

    Parameters
    ----------
    filename : string
        Filename body, without ending.

    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_simple_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    filename is used as body of the output-filename, nothing is added.
    """
    py_simple_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '.' + ending
    return py_simple_output_filename


def py_backup(python_sub_dir, tag, filename, ending, spec):
    """
    Copy a python script to backup directory and add specifier

    Parameters
    ----------
    python_sub_dir : string
        Absolute subdirectory of the script, mostly
        ~/PythonExecDir and ~/pyshemkf/scripts

    tag : string
        Subdirectory name in ~/PythonExecDir or
        ~/pyshemkf/scripts

    filename : string
        Filename body, without ending.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    spec : string
        Output identifier that will be added to the filename.

    Notes
    ----------
    Returns nothing, but copies the file to a possibly generated backup
    directory.

    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_file_name = python_sub_dir + '/' + tag + '/' + filename + '.' + ending
    if not os.path.exists(python_sub_dir + '/' + tag + '/backup'):
        os.mkdir(python_sub_dir + '/' + tag + '/backup')
    py_backup_file_name = (python_sub_dir + '/' + tag + '/' + 'backup' +
        '/' + filename + '_' + spec + '.' + ending)
    if os.path.isfile(py_backup_file_name):
        os.remove(py_backup_file_name)
        print('Removed old file: ' + py_backup_file_name)
    shutil.copyfile(py_file_name, py_backup_file_name)
    print('Backup as ' + py_backup_file_name)

<mask token>


def py_output_dir(tag, ending):
    """
    Generate Python output directory according to tag ending.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_dir : string
        Designated output directory.
    """
    py_output_dir = python_output_dir + '/' + tag + '/' + ending
    return py_output_dir


def py_output_filename(tag, filename, spec, ending):
    """
    Generate Python output filename (with specifier)
    according to filename (without ending), tag ending, spec.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    filename : string
        Filename body, without ending.

    spec : string
        Output identifier that will be added to the filename.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '_' + spec + '.' + ending
    return py_output_filename


def py_simple_output_filename(filename, tag, ending):
    """
    Generate Python simple output filename (without specifier)
    according to filename (without ending), tag, ending.

    Parameters
    ----------
    filename : string
        Filename body, without ending.

    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_simple_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    filename is used as body of the output-filename, nothing is added.
    """
    py_simple_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '.' + ending
    return py_simple_output_filename


def py_backup(python_sub_dir, tag, filename, ending, spec):
    """
    Copy a python script to backup directory and add specifier

    Parameters
    ----------
    python_sub_dir : string
        Absolute subdirectory of the script, mostly
        ~/PythonExecDir and ~/pyshemkf/scripts

    tag : string
        Subdirectory name in ~/PythonExecDir or
        ~/pyshemkf/scripts

    filename : string
        Filename body, without ending.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    spec : string
        Output identifier that will be added to the filename.

    Notes
    ----------
    Returns nothing, but copies the file to a possibly generated backup
    directory.

    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_file_name = python_sub_dir + '/' + tag + '/' + filename + '.' + ending
    if not os.path.exists(python_sub_dir + '/' + tag + '/backup'):
        os.mkdir(python_sub_dir + '/' + tag + '/backup')
    py_backup_file_name = (python_sub_dir + '/' + tag + '/' + 'backup' +
        '/' + filename + '_' + spec + '.' + ending)
    if os.path.isfile(py_backup_file_name):
        os.remove(py_backup_file_name)
        print('Removed old file: ' + py_backup_file_name)
    shutil.copyfile(py_file_name, py_backup_file_name)
    print('Backup as ' + py_backup_file_name)

<mask token>
python_dir = os.environ['HOME'] + '/pyshemkf'
python_scripts_dir = python_dir + '/scripts'
python_output_dir = python_dir + '/output'


def py_output_dir(tag, ending):
    """
    Generate Python output directory according to tag ending.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_dir : string
        Designated output directory.
    """
    py_output_dir = python_output_dir + '/' + tag + '/' + ending
    return py_output_dir


def py_output_filename(tag, filename, spec, ending):
    """
    Generate Python output filename (with specifier)
    according to filename (without ending), tag ending, spec.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    filename : string
        Filename body, without ending.

    spec : string
        Output identifier that will be added to the filename.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '_' + spec + '.' + ending
    return py_output_filename


def py_simple_output_filename(filename, tag, ending):
    """
    Generate Python simple output filename (without specifier)
    according to filename (without ending), tag, ending.

    Parameters
    ----------
    filename : string
        Filename body, without ending.

    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_simple_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    filename is used as body of the output-filename, nothing is added.
    """
    py_simple_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '.' + ending
    return py_simple_output_filename


def py_backup(python_sub_dir, tag, filename, ending, spec):
    """
    Copy a python script to backup directory and add specifier

    Parameters
    ----------
    python_sub_dir : string
        Absolute subdirectory of the script, mostly
        ~/PythonExecDir and ~/pyshemkf/scripts

    tag : string
        Subdirectory name in ~/PythonExecDir or
        ~/pyshemkf/scripts

    filename : string
        Filename body, without ending.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    spec : string
        Output identifier that will be added to the filename.

    Notes
    ----------
    Returns nothing, but copies the file to a possibly generated backup
    directory.

    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_file_name = python_sub_dir + '/' + tag + '/' + filename + '.' + ending
    if not os.path.exists(python_sub_dir + '/' + tag + '/backup'):
        os.mkdir(python_sub_dir + '/' + tag + '/backup')
    py_backup_file_name = (python_sub_dir + '/' + tag + '/' + 'backup' +
        '/' + filename + '_' + spec + '.' + ending)
    if os.path.isfile(py_backup_file_name):
        os.remove(py_backup_file_name)
        print('Removed old file: ' + py_backup_file_name)
    shutil.copyfile(py_file_name, py_backup_file_name)
    print('Backup as ' + py_backup_file_name)

<mask token>
import os
import shutil
python_dir = os.environ['HOME'] + '/pyshemkf'
python_scripts_dir = python_dir + '/scripts'
python_output_dir = python_dir + '/output'


def py_output_dir(tag, ending):
    """
    Generate Python output directory according to tag ending.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_dir : string
        Designated output directory.
    """
    py_output_dir = python_output_dir + '/' + tag + '/' + ending
    return py_output_dir


def py_output_filename(tag, filename, spec, ending):
    """
    Generate Python output filename (with specifier)
    according to filename (without ending), tag ending, spec.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    filename : string
        Filename body, without ending.

    spec : string
        Output identifier that will be added to the filename.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '_' + spec + '.' + ending
    return py_output_filename


def py_simple_output_filename(filename, tag, ending):
    """
    Generate Python simple output filename (without specifier)
    according to filename (without ending), tag, ending.

    Parameters
    ----------
    filename : string
        Filename body, without ending.

    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_simple_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    filename is used as body of the output-filename, nothing is added.
    """
    py_simple_output_filename = py_output_dir(tag, ending
        ) + '/' + filename + '.' + ending
    return py_simple_output_filename


def py_backup(python_sub_dir, tag, filename, ending, spec):
    """
    Copy a python script to backup directory and add specifier

    Parameters
    ----------
    python_sub_dir : string
        Absolute subdirectory of the script, mostly
        ~/PythonExecDir and ~/pyshemkf/scripts

    tag : string
        Subdirectory name in ~/PythonExecDir or
        ~/pyshemkf/scripts

    filename : string
        Filename body, without ending.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    spec : string
        Output identifier that will be added to the filename.

    Notes
    ----------
    Returns nothing, but copies the file to a possibly generated backup
    directory.

    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    py_file_name = python_sub_dir + '/' + tag + '/' + filename + '.' + ending
    if not os.path.exists(python_sub_dir + '/' + tag + '/backup'):
        os.mkdir(python_sub_dir + '/' + tag + '/backup')
    py_backup_file_name = (python_sub_dir + '/' + tag + '/' + 'backup' +
        '/' + filename + '_' + spec + '.' + ending)
    if os.path.isfile(py_backup_file_name):
        os.remove(py_backup_file_name)
        print('Removed old file: ' + py_backup_file_name)
    shutil.copyfile(py_file_name, py_backup_file_name)
    print('Backup as ' + py_backup_file_name)

"""
pythonmodule
============

Provides utility functions for working with SHEMAT-Suite output in Python.
"""
import os
import shutil

###############################################################################
#                               Directories                                   #
###############################################################################
python_dir = os.environ['HOME']+'/pyshemkf'
python_scripts_dir = python_dir+'/scripts'
python_output_dir = python_dir+'/output'


###############################################################################
#                                 Output                                      #
###############################################################################
def py_output_dir(tag, ending):
    """
    Generate Python output directory according to tag ending.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_dir : string
        Designated output directory.
    """
    py_output_dir = (python_output_dir + "/"
                     + tag + "/"
                     + ending)

    return py_output_dir


def py_output_filename(tag, filename, spec, ending):
    """
    Generate Python output filename (with specifier)
    according to filename (without ending), tag ending, spec.

    Parameters
    ----------
    tag : string
        Subdirectory name in ~/pyshemkf/output

    filename : string
        Filename body, without ending.

    spec : string
        Output identifier that will be added to the filename.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """

    py_output_filename = (py_output_dir(tag, ending) + "/"
                          + filename + "_" + spec + "."
                          + ending)

    return py_output_filename


def py_simple_output_filename(filename, tag, ending):
    """
    Generate Python simple output filename (without specifier)
    according to filename (without ending), tag, ending.

    Parameters
    ----------
    filename : string
        Filename body, without ending.

    tag : string
        Subdirectory name in ~/pyshemkf/output

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    Returns
    ----------
    py_simple_output_filename : string
        Absolute filename for output file.

    Notes
    ----------
    filename is used as body of the output-filename, nothing is added.
    """

    py_simple_output_filename = (py_output_dir(tag, ending) + "/"
                                 + filename + "."
                                 + ending)

    return py_simple_output_filename


###############################################################################
#                            Script Backup                                    #
###############################################################################
def py_backup(python_sub_dir, tag, filename, ending, spec):
    """
    Copy a python script to backup directory and add specifier

    Parameters
    ----------
    python_sub_dir : string
        Absolute subdirectory of the script, mostly
        ~/PythonExecDir and ~/pyshemkf/scripts

    tag : string
        Subdirectory name in ~/PythonExecDir or
        ~/pyshemkf/scripts

    filename : string
        Filename body, without ending.

    ending : string
        File ending of output.
        Examples: npy, png, jpg, eps, pdf

    spec : string
        Output identifier that will be added to the filename.

    Notes
    ----------
    Returns nothing, but copies the file to a possibly generated backup
    directory.

    spec is added to filename to form the body filename body.

    The format-convention for spec is of the following form
    (see pskf.tools.plot.spec.specl()):
        'model_2018_01_01_b'
    In principle any string can be used as spec.
    """
    # Script Name
    py_file_name = (python_sub_dir + "/"
                    + tag + "/"
                    + filename + "."
                    + ending)

    # Possibly create backup directory
    if not os.path.exists(python_sub_dir+"/"+tag+"/backup"):
        os.mkdir(python_sub_dir+"/"+tag+"/backup")

    # Backup Script Name
    py_backup_file_name = (python_sub_dir + "/"
                           + tag + "/"
                           + "backup" + "/"
                           + filename + "_"
                           + spec + "."
                           + ending)

    # Exception if file already exists
    if os.path.isfile(py_backup_file_name):
        os.remove(py_backup_file_name)
        print('Removed old file: '+py_backup_file_name)

    shutil.copyfile(py_file_name, py_backup_file_name)
    print('Backup as '+py_backup_file_name)
