Unit Conversion from SI to IP

Hi @mostapha and @chriswmackey,

I have been trying to convert an hourlycontinouscollection to ip unit using both convert_to_ip() and to_ip() functions but it doesnt work per below which is because it seems the datacollection is not returned as numbers.

_wea_data = global_epw.import_data_by_field(fields[hourly_selected])
a = _wea_data.convert_to_ip()
a

Can you please advise on this?

Thanks
AT

Hi @amirtabadkani,

Can you provide the rest of the code who we can recreate the issue? What’s the field that you are trying to convert to IP?

its DBT - but that shouldn’t be the case based on the GH component which seems to be working for all the fields -

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)}

hourly_selected = st.selectbox('Which variable to plot?',options=fields.keys())
_wea_data = global_epw.import_data_by_field(fields[hourly_selected])
a = _wea_data.convert_to_ip()
a

That function should basically do the same in GH but it comes with an error when using the same function.

When I simplify your code, everything works as expected.

from ladybug.epw import EPW, EPWFields

epw_file = r"C:\Program Files\ladybug_tools\resources\weather\AUS_NSW_Sydney.Intl.AP.947670_TMYx.2004-2018\AUS_NSW_Sydney.Intl.AP.947670_TMYx.2004-2018.epw"
global_epw = EPW(epw_file)
fields = {EPWFields._fields[i]['name'].name: i for i in range(6, 34)}
_wea_data = global_epw.import_data_by_field(6)
_wea_data.convert_to_ip()
print(_wea_data)

:point_down:

Hourly Continuous Data Collection
1/1 to 12/31 between 0 and 23 @1
Dry Bulb Temperature (F)
...8760 values...

It works as a Streamlit app too.

import streamlit as st
from ladybug.epw import EPW, EPWFields

epw_file = r"C:\Program Files\ladybug_tools\resources\weather\AUS_NSW_Sydney.Intl.AP.947670_TMYx.2004-2018\AUS_NSW_Sydney.Intl.AP.947670_TMYx.2004-2018.epw"
global_epw = EPW(epw_file)
fields = {EPWFields._fields[i]['name'].name: i for i in range(6, 34)}
hourly_selected = st.selectbox(
    'Which variable to plot?', options=fields.keys())
_wea_data = global_epw.import_data_by_field(fields[hourly_selected])
_wea_data.convert_to_ip()

st.write(_wea_data)

Something must be happening with the input weather file.

That is weird - it runs ok when I test the code on Jupyter Notebook - but it still shows me the same error for IP conversion when I run the code on Streamlit - do you have any clues what might be the issue? I downgraded Numpy version but still didnt work -

It’s hard to tell without being able to debug the code. Can you share the weather file with us?

You can also try to print the fields and see what you get. Here is a modified code that should help with debugging.

import streamlit as st
from ladybug.epw import EPW, EPWFields

epw_file = r"C:\Program Files\ladybug_tools\resources\weather\AUS_NSW_Sydney.Intl.AP.947670_TMYx.2004-2018\AUS_NSW_Sydney.Intl.AP.947670_TMYx.2004-2018.epw"
global_epw = EPW(epw_file)
fields = {EPWFields._fields[i]['name'].name: i for i in range(6, 34)}
hourly_selected = st.selectbox(
    'Which variable to plot?', options=fields.keys())

selected_field = fields[hourly_selected]
st.write(selected_field)

wea_data = global_epw.import_data_by_field(selected_field)
wea_data.convert_to_ip()

st.write(_wea_data)

I can retrieve the field name correctly and even I can get the hourly data collection in the right format per below but I just cant convert to IP units through that function. The code works with no issues when using SI units with any epw files.

image

Thinking if thats a versioning issue of any of the libraries which might be incompatible -

Hi @mostapha - can you tell me which is your python version? thanks

Hi @amirtabadkani, we currently use Python 3.10 for all the Ladybug Tools and Pollination development. We still test against 3.7 to ensure the libraries are compatible with 3.7 too.

Sorry @mostapha, can you also let me know which is your Streamlit version? It works when I do the coding inside Jupiter Notebook - I think there might be sth wrong with Streamlit

Thanks
AT

Hi @amirtabadkani, no worries. I use the latest version of streamlit.