Exemplo n.º 1
0
                floor_srf.Zone_Name, len(analysis_points)))

    # Write the analysis grids to a directory for processing
    for hb_analysis_grid in hb_analysis_grids:
        analysis_grid_path = "{0:}/AnalysisGrids/{1:}.json".format(
            output_directory, hb_analysis_grid.name)
        # print(analysis_grid_path)
        with open(analysis_grid_path, "w") as f:
            json.dump({"analysis_grids": [hb_analysis_grid.to_json()]}, f)
        print("Analysis grid_file for {0:} written to {1:}".format(
            hb_analysis_grid.name, os.path.normpath(analysis_grid_path)))

    # Generate sky matrix for annual analysis
    sky_matrix = SkyMatrix.from_epw_file(input_weatherfile_path,
                                         sky_density=2,
                                         north=north_angle_deg,
                                         hoys=range(0, 8760),
                                         mode=0,
                                         suffix="")
    print("Sky matrix ({0:}) generated".format(sky_matrix))

    # Write the sky matrix for annual simulation to file
    sky_matrix_path = "{0:}/sky_mtx.json".format(output_directory)
    with open(sky_matrix_path, "w") as f:
        json.dump({"sky_mtx": sky_matrix.to_json()}, f)
    print("Sky matrix written to {0:}".format(
        os.path.normpath(sky_matrix_path)))

    # Write the context geometry (surfaces) around the analysis grids
    surfaces_path = "{0:}/surfaces.json".format(
        os.path.normpath(output_directory))
    with open(surfaces_path, "w") as f:
    Args:
        name_: An optional suffix for sky name. The suffix will be added at the
            end of the standard name. Use this input to customize the new and
            avoid sky being overwritten by other skymatrix components.
        north_: An angle in degrees between 0-360 to indicate north direction
            (Default: 0).
        _wea: Ladybug Wea object.
        _density_: A positive intger for sky density. [1] Tregenza Sky,
            [2] Reinhart Sky, etc. (Default: 1)
        hoys_: Optional list of hours for generating the sky matrix (Default: 0..8759)
    Returns:
        readMe!: Reports, errors, warnings, etc.
        skyMTX: Sky matrix for multi-phase daylight analysis.
"""

ghenv.Component.Name = "HoneybeePlus_Sky Matrix"
ghenv.Component.NickName = 'skyMatrix'
ghenv.Component.Message = 'VER 0.0.04\nFEB_07_2018'
ghenv.Component.Category = "HoneybeePlus"
ghenv.Component.SubCategory = '02 :: Daylight :: Light Sources'
ghenv.Component.AdditionalHelpFromDocStrings = "2"

try:
    from honeybee.radiance.sky.skymatrix import SkyMatrix
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

if _wea:
    skymtx = SkyMatrix(_wea, _density_, north_, hoys_, suffix=name_)
            (Default: 0).
        _wea: Ladybug Wea object.
        _skyDensity_: A positive intger for sky density. [1] Tregenza Sky,
            [2] Reinhart Sky, etc. (Default: 1)
        hoys_: Optional list of hours for generating the sky matrix (Default: 0..8759)
    Returns:
        readMe!: Reports, errors, warnings, etc.
        skyMTX: Sky matrix for multi-phase daylight analysis.
"""

ghenv.Component.Name = "HoneybeePlus_Sky Matrix"
ghenv.Component.NickName = 'skyMatrix'
ghenv.Component.Message = 'VER 0.0.01\nDEC_05_2016'
ghenv.Component.Category = "HoneybeePlus"
ghenv.Component.SubCategory = '02 :: Daylight :: Light Sources'
ghenv.Component.AdditionalHelpFromDocStrings = "1"

try:
    from honeybee.radiance.sky.skymatrix import SkyMatrix
except ImportError as e:
    msg = '\nFailed to import honeybee. Did you install honeybee on your machine?' + \
            '\nYou can download the installer file from github: ' + \
            'https://github.com/ladybug-analysis-tools/honeybee-plus/tree/master/plugin/grasshopper/samplefiles' + \
            '\nOpen an issue on github if you think this is a bug:' + \
            ' https://github.com/ladybug-analysis-tools/honeybee-plus/issues'

    raise ImportError('{}\n\t{}'.format(msg, e))

if _wea:
    skyMTX = SkyMatrix(_wea, _skyDensity_, north_, hoys_)
Exemplo n.º 4
0
# assign inputs
north_, _wea, _density_, hoys_ = IN
skymtx = None

try:
    from honeybee.radiance.sky.skymatrix import SkyMatrix
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

if _wea:
    skymtx = SkyMatrix(_wea, _density_, north_, hoys_)

# assign outputs to OUT
OUT = (skymtx, )
Exemplo n.º 5
0
def run_radiance(epw_file: str,
                 ground: Ground,
                 shades: Shade = None,
                 case_name: str = "openfield",
                 output_directory: str = pathlib.Path(tempfile.gettempdir()),
                 run: bool = False):
    """ Run Radiance for a point in an open-field (with or without shade)

    Parameters
    ----------
    epw_file : str
        Path to EPW file
    ground : Ground
        Ground object to simulate
    ground : Ground
        Ground object to simulate
    case_name : str
        Name of case being simulated
    output_directory : str
        Directory where simulation results will be stored
    run : bool
        Run the simulation

    Returns
    -------
    [direct_radiation, diffuse_radiation] : float
        Annual hourly direct and diffuse radiation

    """
    # Construct case output directory and process variables
    epw_file = pathlib.Path(epw_file)

    # Create ground and shade (if included) context geometry and materials
    context_geometry = []
    context_geometry.append(ground.to_hb())

    if shades is not None:
        for shd in shades:
            context_geometry.append(shd.to_hb())

    # Flatten objects
    context_geometry = flatten(context_geometry)

    with _HiddenPrints():

        # Prepare Radiance case for radiation incident on exposed test-point
        sky_matrix = SkyMatrix.from_epw_file(epw_file)
        analysis_grid = AnalysisGrid.from_points_and_vectors([[0, 0, 1.2]],
                                                             name="openfield")
        recipe = GridBased(sky_mtx=sky_matrix,
                           analysis_grids=[analysis_grid],
                           simulation_type=1,
                           hb_objects=context_geometry,
                           reuse_daylight_mtx=True)

    # Run annual irradiance simulation
    command_file = recipe.write(target_folder=output_directory,
                                project_name=case_name)

    if run:
        with _HiddenPrints():
            recipe.run(command_file=command_file)

        print("Direct and diffuse solar radiation simulation completed")

        # Read Radiance results
        radiation_direct, radiation_diffuse = load_radiance_results(
            output_directory / case_name / "gridbased_annual" / "result")

        return radiation_direct, radiation_diffuse
    else:
        print("Radiance case written to {}".format(
            str(output_directory / case_name / "gridbased_annual")))
        return None
Exemplo n.º 6
0
# assign inputs
north_, _wea, _density_, _month_, _day_, _hour_ = IN
skyVec = None

try:
    from honeybee.radiance.sky.skymatrix import SkyMatrix
    from ladybug.dt import DateTime
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))
        
    raise ImportError('{}\n\t{}'.format(msg, e))

if _wea:
    north_ = north_ or 0
    _month_ = _month_ or 6
    _day_ = _day_ or 21
    _hour_ = _hour_ or 12
    dt = DateTime(_month_, _day_, _hour_)
    _density_ = _density_ or 1
    
    skyVec = SkyMatrix(_wea, _density_, north_, (int(dt.hoy),),
                       suffix=str(int(dt.hoy)))
    

# assign outputs to OUT
OUT = (skyVec,)
Exemplo n.º 7
0
def run(epw_file: str, case_name: str = None, output_directory: str = None):
    """
    Calculate the open-field irradiation from the sky, split into direct-from-sun, and diffuse-from-sky-dome components
    :param epw_file: Weather-file with location and climatic conditions for simulation
    :param case_name: Name of case being simulated
    :param output_directory: Location of generated outputs
    :return DirectHorizontalIrradiance, DiffuseHorizontalIrradiance:
    """

    case_name = "openfield" if case_name is None else case_name
    output_directory = pathlib.Path(tempfile.gettempdir(
    )) if output_directory is None else output_directory

    # Preparation
    epw_file = pathlib.Path(epw_file)
    output_directory = pathlib.Path(output_directory)

    # Prepare Radiance case for radiation incident on exposed test-point
    smx = SkyMatrix.from_epw_file(epw_file)
    ag = AnalysisGrid.from_points_and_vectors([[0, 0, 1.2]], name="OpenField")
    recipe = GridBased(sky_mtx=smx, analysis_grids=[ag], simulation_type=1)

    # Run annual irradiance simulation
    command_file = recipe.write(target_folder=output_directory,
                                project_name=case_name)
    recipe.run(command_file=command_file)

    # Read Radiance results
    total = pd.read_csv(
        output_directory / case_name / "gridbased_annual" / "result" /
        "total..scene..default.ill",
        skiprows=6,
        sep="\t",
        header=None,
    ).T.dropna() / 179
    direct = pd.read_csv(
        output_directory / case_name / "gridbased_annual" / "result" /
        "direct..scene..default.ill",
        skiprows=6,
        sep="\t",
        header=None,
    ).T.dropna() / 179
    diffuse = (total - direct)[0].values
    sun = (pd.read_csv(
        output_directory / case_name / "gridbased_annual" / "result" /
        "sun..scene..default.ill",
        skiprows=6,
        sep="\t",
        header=None,
    ).T.dropna() / 179)[0].values

    sun = HourlyContinuousCollection(header=Header(
        DirectHorizontalIrradiance(),
        unit="W/m2",
        analysis_period=AnalysisPeriod()),
                                     values=sun)
    diffuse = HourlyContinuousCollection(header=Header(
        DiffuseHorizontalIrradiance(),
        unit="W/m2",
        analysis_period=AnalysisPeriod()),
                                         values=diffuse)

    print("Direct and diffuse solar radiation simulation completed")

    return sun, diffuse
Exemplo n.º 8
0
# assign inputs
north_, _wea, _density_, _month_, _day_, _hour_ = IN
skyVec = None

try:
    from honeybee.radiance.sky.skymatrix import SkyMatrix
    from ladybug.dt import DateTime
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

    raise ImportError('{}\n\t{}'.format(msg, e))

if _wea:
    north_ = north_ or 0
    _month_ = _month_ or 6
    _day_ = _day_ or 21
    _hour_ = _hour_ or 12
    dt = DateTime(_month_, _day_, _hour_)
    _density_ = _density_ or 1

    skyVec = SkyMatrix(_wea, _density_, north_, (int(dt.hoy), ))

# assign outputs to OUT
OUT = (skyVec, )