# Unit Conversion from SI to IP

**URL:** <https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422>\
**Category:** Scripting\
**Tags:** question\
**Created:** [December 12, 2023, 2:12am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422 "2023-12-12T02:12:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [December 12, 2023, 2:12am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/1 "2023-12-12T02:12:16Z")

</div>

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.

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

```

 ![image](https://discourse.pollination.cloud/uploads/default/original/2X/a/a1cddb3e6c7aa3653788be4ab9ca4f08b1dd8557.png)

Can you please advise on this?

Thanks  
AT

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/mostapha/32/5761_2.png) [@mostapha](https://discourse.pollination.solutions/u/mostapha)\
**Post date:** [December 12, 2023, 2:28am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/2 "2023-12-12T02:28:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [December 12, 2023, 2:40am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/3 "2023-12-12T02:40:03Z")

</div>

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

```auto
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.

 ![image](https://discourse.pollination.cloud/uploads/default/original/2X/c/c6c4fe2e920083dae970b73db4aa5ebe0b8d9459.png)

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/mostapha/32/5761_2.png) [@mostapha](https://discourse.pollination.solutions/u/mostapha)\
**Post date:** [December 12, 2023, 3:10pm UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/4 "2023-12-12T15:10:37Z")

</div>

When I simplify your code, everything works as expected.

```py
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)

```

👇

```log
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.

 ![image](https://discourse.pollination.cloud/uploads/default/original/2X/f/f0215121beb63511087d5f4b7c508abeacfa3990.png)

```py
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.

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [December 13, 2023, 1:27am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/5 "2023-12-13T01:27:32Z")

</div>

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 -

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/mostapha/32/5761_2.png) [@mostapha](https://discourse.pollination.solutions/u/mostapha)\
**Post date:** [December 13, 2023, 2:55pm UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/6 "2023-12-13T14:55:29Z")

</div>

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.

```py
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)

```

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [December 14, 2023, 12:26am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/7 "2023-12-14T00:26:03Z")

</div>

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](https://discourse.pollination.cloud/uploads/default/original/2X/f/fdf3ac633bbdc565033af5b6e7edda5454b87fe9.png)

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

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [January 11, 2024, 6:41am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/8 "2024-01-11T06:41:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/mostapha/32/5761_2.png) [@mostapha](https://discourse.pollination.solutions/u/mostapha)\
**Post date:** [January 11, 2024, 2:11pm UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/9 "2024-01-11T14:11:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [January 17, 2024, 5:22am UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/11 "2024-01-17T05:22:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/mostapha/32/5761_2.png) [@mostapha](https://discourse.pollination.solutions/u/mostapha)\
**Post date:** [January 17, 2024, 1:49pm UTC](https://discourse.pollination.solutions/t/unit-conversion-from-si-to-ip/3422/12 "2024-01-17T13:49:18Z")

</div>

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