Beispiel #1
0
def test_copy_files_to_folder():
    """Test the copy file to folder capability"""
    existing_file = "./tests/fixtures/ddy/chicago.ddy"
    target_dir = "./tests/zip"
    futil.copy_files_to_folder([existing_file], target_dir)
    final_file = os.path.join(target_dir, "chicago.ddy")
    assert os.path.isfile(final_file)
    assert 20000 < os.stat(final_file).st_size < 30000
    os.remove(final_file)
def prepare_idf_for_simulation(idf_file_path, epw_file_path):
    """Prepare an IDF file to be run through EnergyPlus.

    This includes copying the Energy+.idd to the directory of the IDF, copying the EPW
    file to the directory, renaming the EPW to in.epw and renaming the IDF to in.idf
    (if it is not already names so).

    A check is also performed to be sure that a valid EnergyPlus installation
    was found.

    Args:
        idf_file_path: The full path to an IDF file.
        epw_file_path: The full path to an EPW file.

    Returns:
        directory -- The folder in which the IDF exists and out of which the EnergyPlus
        simulation will be run.
    """
    # check the energyplus directory
    if not folders.energyplus_path:
        raise OSError('No EnergyPlus installation was found on this machine.\n'
                      'Install EnergyPlus to run energy simulations.')

    # check the input files
    assert os.path.isfile(idf_file_path), \
        'No IDF file found at {}.'.format(idf_file_path)
    assert os.path.isfile(epw_file_path), \
        'No EPW file found at {}.'.format(epw_file_path)

    # copy all files needed for simulation to the folder
    directory = os.path.split(idf_file_path)[0]
    idd_path = os.path.join(folders.energyplus_path, 'Energy+.idd')
    copy_files_to_folder([idd_path, epw_file_path], directory, True)

    # rename the weather file to in.epw (what energyplus is expecting)
    epw_file_name = os.path.split(epw_file_path)[-1]
    if epw_file_name != 'in.epw':
        old_file_name = os.path.join(directory, epw_file_name)
        new_file_name = os.path.join(directory, 'in.epw')
        # ensure that there isn't an in.epw file there already
        if os.path.isfile(new_file_name):
            os.remove(new_file_name)
        os.rename(old_file_name, new_file_name)

    # rename the idf file to in.idf if it isn't named that already
    idf_file_name = os.path.split(idf_file_path)[-1]
    if idf_file_name != 'in.idf':
        old_file_name = os.path.join(directory, epw_file_name)
        new_file_name = os.path.join(directory, 'in.idf')
        # ensure that there isn't an in.idf file there already
        if os.path.isfile(new_file_name):
            os.remove(new_file_name)
        os.rename(old_file_name, new_file_name)

    return directory