Python usage examples - BHoM/LadybugTools_Toolkit GitHub Wiki

This page contains some assorted examples of capability and usage of the Python scripts contained within the toolkit.

EPW file

Open and read

from ladybug.epw import EPW
epw_path = r"C:\path\to\your_weather_file.epw"
epw = EPW(epw_path)

print(epw.dry_bulb_temperature)

This exposes an 'Hourly Continuous Data Collection' object, which contains the array of dry bulb temperatures as well as metadata (contained in the header).

To access a list of the dry bulb temperatures themselves, use: epw.dry_bulb_temperature.values

To access the metadata, use: epw.dry_bulb_temperature.header

An EPW file usually contains many data elements. In Jupyter, these can be viewed by typing epw. then hitting the tab key.

image

Tabbing also exposes a lot of additional functionality that can be applied to the epw object. Refer to the Ladybug documentation for more guidance.

Edit

Values in an EPW file can be edited, and the file saved. It is good practice to create a new copy of the file when saving.

import numpy as np
from ladybug.epw import EPW

epw_path = r"C:\path\to\your_weather_file.epw" # epw path goes here
epw = EPW(epw_path)

new_vals = [i for i in np.arange(8760)] # new values go here
epw.wind_speed.values = new_vals
new_path = epw_path.parent / f"{epw_path.stem}_EDIT.epw"
epw.save(new_path)

Typologies

A number of typologies have been pre-defined and can be accessed by:

from ladybugtools_toolkit.external_comfort.typology import Typologies
my_typology = Typologies.OPENFIELD.value

Tip: don't forget the .value when using pre-defined typologies.

The following script creates a custom typology that contains two shelters:

from ladybugtools_toolkit.external_comfort.typology import Typology, Shelter
my_custom_typology = Typology(
    name="Typ1",
    evaporative_cooling_effectiveness=0,
    shelters=[
        Shelter(
            altitude_range=[10, 80],
            azimuth_range=[100,280],
            wind_porosity=0.5,
            radiation_porosity=0.1,
        ),
        Shelter(
            altitude_range=[0, 10],
            azimuth_range=[100,280],
            wind_porosity=0.8,
            radiation_porosity=0.5,
        )
    ],
    wind_speed_adjustment=1,
)