Exemple #1
0
def validate_param(param_uwg):
    """Validate a .uwg parameter file.
    \n
    Args:\n
        param_uwg: Full path to a .uwg parameter file.
    """
    try:
        # validate the Model JSON
        click.echo('Validating .uwg parameter file ...')
        UWG.from_param_file(param_uwg)
        click.echo('Congratulations! Your .uwg parameter file is valid!')
    except Exception as e:
        print('The .uwg parameter file validation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Exemple #2
0
def validate_param(param_uwg):
    """Validate a .uwg parameter file.

    \b
    Args:
        param_uwg: Full path to a .uwg parameter file.
    """
    try:
        try:
            schema_model
        except Exception:
            raise ImportError(
                'uwg_schema is not installed. Try `pip install . [cli]` command.')

        # validate the Model JSON
        click.echo('Validating .uwg parameter file ...')
        UWG.from_param_file(param_uwg)
        click.echo('Congratulations! Your .uwg parameter file is valid!')
    except Exception as e:
        _logger.exception('The .uwg parameter file validation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Exemple #3
0
def simulate_uwg_param_model(param_uwg, epw_path, new_epw_dir, new_epw_name):
    """Simulate a UWG model from a .uwg parameter file.

    \b
    Args:
        param_uwg: Full path to a .uwg param file.
        epw_path: Full path of the rural .epw file that will be morphed.
    """
    try:
        uwg_model = UWG.from_param_file(
            param_uwg, epw_path, new_epw_dir, new_epw_name)
        uwg_model.generate()
        uwg_model.simulate()
        uwg_model.write_epw()
    except Exception as e:
        _logger.exception('UWG model simulation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Exemple #4
0
def auto_setup_uwg(epw_path=DEFAULT_EPW_PATH,
                   param_path=DEFAULT_PARAM_PATH,
                   log_file_name=None,
                   log_level=None,
                   uwg_param_dir=None):
    """Set up uwg object from initialize.uwg."""
    if log_file_name and log_level:
        setup_log_file(log_file_name, log_level)

    if param_path:
        model = UWG.from_param_file(param_path,
                                    epw_path=epw_path,
                                    new_epw_dir=NEW_DIR)
    else:
        model = UWG(epw_path, new_epw_dir=NEW_DIR)

    # Increase precision for testing
    model.epw_precision = 16

    return model
Exemple #5
0
def test_init():
    """Test initialization methods."""

    test_dir = os.path.abspath(os.path.dirname(__file__))
    param_path = os.path.join(test_dir, 'parameters',
                              'initialize_singapore.uwg')
    epw_path = os.path.join(test_dir, 'epw', 'SGP_Singapore.486980_IWEC.epw')

    refBEM, refSch = UWG.load_refDOE()
    refBEM[0][2][0].building.shgc = 0.9
    ref_bem_vec = [refBEM[0][2][0], refBEM[2][2][0]]
    ref_sch_vec = [refSch[0][2][0], refSch[2][2][0]]

    # base init
    UWG(epw_path)

    # from param_file
    UWG.from_param_file(param_path, epw_path)

    # from args
    UWG.from_param_args(bldheight=10.0,
                        blddensity=0.5,
                        vertohor=0.5,
                        zone='1A',
                        treecover=0.1,
                        grasscover=0.1,
                        epw_path=epw_path)
    model = UWG.from_param_args(10.0,
                                0.5,
                                0.5,
                                treecover=0.1,
                                grasscover=0.1,
                                zone='1A',
                                ref_bem_vector=[],
                                ref_sch_vector=[],
                                epw_path=epw_path)
    model.generate()
    assert model.ref_bem_vector == []
    assert model.ref_sch_vector == []

    UWG.from_param_args(10.0,
                        0.5,
                        0.5,
                        0.1,
                        0.1,
                        '1A',
                        ref_bem_vector=ref_bem_vec,
                        ref_sch_vector=ref_sch_vec,
                        epw_path=epw_path)
    with pytest.raises(AssertionError):
        UWG.from_param_args(10.0,
                            0.5,
                            0.5,
                            0.1,
                            0.1,
                            '1A',
                            ref_bem_vector=ref_bem_vec,
                            ref_sch_vector=ref_sch_vec[:1])
    with pytest.raises(AssertionError):
        UWG.from_param_args(10.0,
                            0.5,
                            0.5,
                            0.1,
                            0.1,
                            '1A',
                            ref_bem_vector=None,
                            ref_sch_vector=ref_sch_vec)
    with pytest.raises(Exception):
        # No epw_path
        model = UWG.from_param_args(bldheight=10.0,
                                    blddensity=0.5,
                                    vertohor=0.5,
                                    grasscover=0.1,
                                    treecover=0.1,
                                    zone='1A')
        model.generate()

    # from dict
    data = UWG.from_param_args(10.0, 0.5, 0.5, 0.1, 0.1,
                               '1A').to_dict(include_refDOE=False)
    UWG.from_dict(data)
    model1 = UWG.from_param_args(10.0,
                                 0.5,
                                 0.5,
                                 0.1,
                                 0.1,
                                 '1A',
                                 ref_bem_vector=ref_bem_vec,
                                 ref_sch_vector=ref_sch_vec)
    data = model1.to_dict(include_refDOE=True)
    model2 = UWG.from_dict(data, epw_path=epw_path)
    model2.generate()
    assert model2.ref_bem_vector[0].building.shgc == pytest.approx(0.9,
                                                                   abs=1e-10)
    assert model2.refBEM[0][2][0].building.shgc == pytest.approx(0.9,
                                                                 abs=1e-10)