Windrose legend issue

There is also another issue with LegendParameters - the minimum and maximum functions do not work - this can be a new topic though -

with st.expander('Windrose'):
    
        windrose_st_month = st.number_input(
            'Start month', min_value=1, max_value=12, value=1, key='windrose_st_month')
        windrose_end_month = st.number_input(
            'End month', min_value=1, max_value=12, value=12, key='windrose_end_month')

        windrose_st_day = st.number_input(
            'Start day', min_value=1, max_value=31, value=1, key='windrose_st_day')
        windrose_end_day = st.number_input(
            'End day', min_value=1, max_value=31, value=31, key='windrose_end_day')

        windrose_st_hour = st.number_input(
            'Start hour', min_value=0, max_value=23, value=0, key='windrose_st_hour')
        windrose_end_hour = st.number_input(
            'End hour', min_value=0, max_value=23, value=23, key='windrose_end_hour')

def get_windrose_figure_temp(st_month: int, st_day: int, st_hour: int, end_month: int,
                    end_day: int, end_hour: int, _epw, global_colorset) -> Figure:
    
    """Create windrose figure.
    Args:
        st_month: A number representing the start month.
        st_day: A number representing the start day.
        st_hour: A number representing the start hour.
        end_month: A number representing the end month.
        end_day: A number representing the end day.
        end_hour: A number representing the end hour.
        epw: An EPW object.
        global_colorset: A string representing the name of a Colorset.
    Returns:
        A plotly figure.
    """
    
    lb_ap = AnalysisPeriod(st_month, st_day, st_hour, end_month, end_day, end_hour)        
    
    fields = get_fields()
        
    windrose_data = SI_IP_Check(_epw.import_data_by_field(fields['Dry Bulb Temperature']))
    
    wind_dir = _epw.wind_direction.filter_by_analysis_period(lb_ap)
    windrose_dbt_ = windrose_data.filter_by_analysis_period(lb_ap)
    
    lb_lp = LegendParameters(colors=colorsets[global_colorset], max = 60)
    
    lb_windrose_temp = WindRose(wind_dir,windrose_dbt_)
    lb_windrose_temp.legend_parameters = lb_lp
    
    return lb_windrose_temp.plot(title='Wind Direction vs. Dry Bulb Temperature', show_title=True)

windrose_figure_temp = get_windrose_figure_temp(windrose_st_month, windrose_st_day, windrose_st_hour, windrose_end_month,
                                              windrose_end_day, windrose_end_hour, global_epw, global_colorset)

st.plotly_chart(windrose_figure_temp, use_container_width=True,
                        config=get_figure_config(f'Windrose_{global_epw.location.city}'))
    

image

Can you please share a minimum complete script that I can use to re-produce the issue. A minimum complete script will have all the necessary libraries and functions imported.

What you shared seems like a snippet from your Streamlit app. I could not get it to work right away.

Thanks @devang - I hope this helps

from ladybug.windrose import WindRose
from ladybug.analysisperiod import AnalysisPeriod
from ladybug.legend import LegendParameters
from ladybug.epw import EPWFields
from ladybug.color import Colorset, Color
from ladybug.datacollection import HourlyContinuousCollection

epw_file = './assets/sample.epw'

global_epw = EPW(epw_file)

@st.cache_data(ttl=2)
def get_windrose_figure_temp(st_month: int, st_day: int, st_hour: int, end_month: int,
                    end_day: int, end_hour: int, _epw, global_colorset) -> Figure:
    
    """Create windrose figure.
    Args:
        st_month: A number representing the start month.
        st_day: A number representing the start day.
        st_hour: A number representing the start hour.
        end_month: A number representing the end month.
        end_day: A number representing the end day.
        end_hour: A number representing the end hour.
        epw: An EPW object.
        global_colorset: A string representing the name of a Colorset.
    Returns:
        A plotly figure.
    """
    
    lb_ap = AnalysisPeriod(st_month, st_day, st_hour, end_month, end_day, end_hour)        
    
    fields = get_fields()
        
    windrose_data = _epw.import_data_by_field(fields['Dry Bulb Temperature'])
    
    wind_dir = _epw.wind_direction.filter_by_analysis_period(lb_ap)
    windrose_dbt_ = windrose_data.filter_by_analysis_period(lb_ap)
    
    lb_lp = LegendParameters(colors=colorsets[global_colorset], max = 60)
    
    lb_windrose_temp = WindRose(wind_dir,windrose_dbt_)
    lb_windrose_temp.legend_parameters = lb_lp
    
    return lb_windrose_temp.plot(title='Wind Direction vs. Dry Bulb Temperature', show_title=True)

windrose_figure_temp = get_windrose_figure_temp(windrose_st_month, windrose_st_day, windrose_st_hour, windrose_end_month,
                                              windrose_end_day, windrose_end_hour, global_epw, global_colorset)
    
        st.plotly_chart(windrose_figure_temp, use_container_width=True,
                        config=get_figure_config(f'Windrose_{global_epw.location.city}'))

Not. It wasn’t a complete minimum script that someone can use right away. Fortunately, I knew that you had used functions from the Weather-report app. So I could get the functions.

Following is an example of a complete minimum script that anyone can just use.

import streamlit as st
from ladybug.windrose import WindRose
from ladybug.analysisperiod import AnalysisPeriod
from ladybug.legend import LegendParameters
from ladybug.epw import EPWFields
from ladybug.epw import EPW
from ladybug.color import Colorset
from plotly.graph_objs import Figure

epw_file = 'path to EPW file'
global_epw = EPW(epw_file)

def get_fields() -> dict:
    # A dictionary of EPW variable name to its corresponding field number
    return {EPWFields._fields[i]['name'].name: i for i in range(6, 34)}

colorsets = {
    'original': Colorset.original(),
    'nuanced': Colorset.nuanced(),
    'annual_comfort': Colorset.annual_comfort(),
    'benefit': Colorset.benefit(),
    'benefit_harm': Colorset.benefit_harm(),
    'black_to_white': Colorset.black_to_white(),
    'blue_green_red': Colorset.blue_green_red(),
    'cloud_cover': Colorset.cloud_cover(),
    'cold_sensation': Colorset.cold_sensation(),
    'ecotect': Colorset.ecotect(),
    'energy_balance': Colorset.energy_balance(),
    'energy_balance_storage': Colorset.energy_balance_storage(),
    'glare_study': Colorset.glare_study(),
    'harm': Colorset.harm(),
    'heat_sensation': Colorset.heat_sensation(),
    'multi_colored': Colorset.multi_colored(),
    'multicolored_2': Colorset.multicolored_2(),
    'multicolored_3': Colorset.multicolored_3(),
    'openstudio_palette': Colorset.openstudio_palette(),
    'peak_load_balance': Colorset.peak_load_balance(),
    'shade_benefit': Colorset.shade_benefit(),
    'shade_benefit_harm': Colorset.shade_benefit_harm(),
    'shade_harm': Colorset.shade_harm(),
    'shadow_study': Colorset.shadow_study(),
    'therm': Colorset.therm(),
    'thermal_comfort': Colorset.thermal_comfort(),
    'view_study': Colorset.view_study()
}

def get_figure_config(title: str) -> dict:
    """Set figure config so that a figure can be downloaded as SVG."""

    return {
        'toImageButtonOptions': {
            'format': 'svg',  # one of png, svg, jpeg, webp
            'filename': title,
            'height': 350,
            'width': 700,
            'scale': 1  # Multiply title/legend/axis/canvas sizes by this factor
        }
    }

global_colorset = colorsets['original']

with st.expander('Windrose'):
    windrose_st_month = st.number_input(
        'Start month', min_value=1, max_value=12, value=1, key='windrose_st_month')
    windrose_end_month = st.number_input(
        'End month', min_value=1, max_value=12, value=12, key='windrose_end_month')

    windrose_st_day = st.number_input(
        'Start day', min_value=1, max_value=31, value=1, key='windrose_st_day')
    windrose_end_day = st.number_input(
        'End day', min_value=1, max_value=31, value=31, key='windrose_end_day')

    windrose_st_hour = st.number_input(
        'Start hour', min_value=0, max_value=23, value=0, key='windrose_st_hour')
    windrose_end_hour = st.number_input(
        'End hour', min_value=0, max_value=23, value=23, key='windrose_end_hour')


def get_windrose_figure_temp(st_month: int, st_day: int, st_hour: int, end_month: int,
                    end_day: int, end_hour: int, _epw, global_colorset) -> Figure:

    """Create windrose figure.
    Args:
        st_month: A number representing the start month.
        st_day: A number representing the start day.
        st_hour: A number representing the start hour.
        end_month: A number representing the end month.
        end_day: A number representing the end day.
        end_hour: A number representing the end hour.
        epw: An EPW object.
        global_colorset: A string representing the name of a Colorset.
    Returns:
        A plotly figure.
    """

    lb_ap = AnalysisPeriod(st_month, st_day, st_hour, end_month, end_day, end_hour)        

    fields = get_fields()

    windrose_data = _epw.import_data_by_field(fields['Dry Bulb Temperature'])

    wind_dir = _epw.wind_direction.filter_by_analysis_period(lb_ap)
    windrose_dbt_ = windrose_data.filter_by_analysis_period(lb_ap)

    lb_lp = LegendParameters(colors=global_colorset, max = 60)

    lb_windrose_temp = WindRose(wind_dir,windrose_dbt_)
    lb_windrose_temp.legend_parameters = lb_lp

    return lb_windrose_temp.plot(title='Wind Direction vs. Dry Bulb Temperature',
                                 show_title=True)

windrose_figure_temp = get_windrose_figure_temp(windrose_st_month, windrose_st_day,
                                                windrose_st_hour, windrose_end_month,
                                              windrose_end_day, windrose_end_hour,
                                              global_epw, global_colorset)

st.plotly_chart(windrose_figure_temp, use_container_width=True,
                config=get_figure_config(f'Windrose_{global_epw.location.city}'))

I understand what you are trying to achieve here. I am sorry to report that, we have not added the capability to load other data on top of Windrose chart yet.

Sorry @devang - I have a very messy script which I might have missed some of the functions but yes, you’re re right the basis is the one you provided before -

To make it clearer, the issue is not about the Windrose itself, it’s about the LegendParameters minimum and maximum values - I can plot DBT on top of Windrose and it works in C - but when I change the units to F, I have to adjust the min/max values accordingly for LP which doesnt work -

below is based on C unit which works fine -

image

or maybe this is sth that is not related to ladybug_charts, and @chriswmackey might be able to help as it sits under ladybug core module - not too sure -

This is a limitation of ladybug-charts. I will look into this.

1 Like

Pushed a fix. Will share once merged. Thank you for your patience.

1 Like

Try with version 1.19.3

2 Likes

it works perfectly fine now - thanks a lot @devang