Python - Convert EPW Data Units

I’m attempting to use the following piece of python code to read an EPW file convert its units to IP, and then pull the dry bulb temperatures…

epw = EPW(selected_epw_file)
db_temps = epw.dry_bulb_temperature
db_temps = db_temps.convert_to_unit('F')
st.write(db_temps)

but streamlit is giving me the following error:

i also tried to convert the entire epw to ip with:

epw = epw.convert_to_ip
db_temps = epw.dry_bulb_temperature

but it seems like once you convert it with “.convert_to_ip” all of the typical EPW functions are gone

any insight is appreciated! thanks

@jakechevrier

For the second problem, you’re missing brackets, so you’re returning the method. Easy fix:

epw = epw.convert_to_ip() # <--- add this
db_temps = epw.dry_bulb_temperature

For the first problem… is the epw there a pandas dataframe? I’m guessing ladybug_pandas isn’t casting the values to floats, possibly due to version conflicts between it and streamlit. You can confirm this by checking the datatype:

print(epw.dry_bulb_temperature.dtype)
# should be float64

If it’s not a float, this should fix you problem:

epw["dry_bulb_temperature"] = epw["dry_bulb_temperature"].astype(float)

If not, then there may be some type conversion bug within the module.

Also, it looks like you’re using python 3.10. That’s fairly new, and most packages haven’t resolved all their bugs on it yet. Consider downgrading to at least 3.9 if you’re still having a lot of issues.

@SaeranVasanthakumar, appreciate the response!

I’m loading the local epw file directly into the EPW()…
This code doesn’t get past the “convert_to_ip()” line without throwing the error, so i believe its something to do with the “convert_to_ip”:

            #selected_epw_file = '/data/location.epw'
            epwfile = EPW(selected_epw_file)
            epwfile = epwfile.convert_to_ip()
            st.write(epwfile)
            
            db_temps = epwfile.dry_bulb_temperature
            st.write(db_temps) #hoping to not convert this to a dataframe, because i eventually want to create a heat map chart with it

TypeError: can’t multiply sequence by non-int of type ‘float’

I was hoping to avoid converting to dataframe because then i’ll loose the heatmap function of the data, and have to add a header and datatype before passing it back to a heat map chart

            #selected_epw_file = '/data/location.epw'
            epwfile = EPW(selected_epw_file)
            db_temps = epwfile.dry_bulb_temperature
            db_temps = db_temps.to_ip()
            st.write(db_temps)
            
            makeannualchart(db_temps,'RdYlBu',False,'drybulbtemp')

gives the following error in streamlit:

TypeError: can’t multiply sequence by non-int of type ‘float’
Traceback:
File “/home/vscode/.local/lib/python3.7/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 565, in _run_script
exec(code, module.dict)
File “/workspaces/pactapp/EPWMap.py”, line 224, in
db_temps.convert_to_ip()
File “/home/vscode/.local/lib/python3.7/site-packages/ladybug/_datacollectionbase.py”, line 164, in convert_to_ip
self._values, self._header.unit)
File “/home/vscode/.local/lib/python3.7/site-packages/ladybug/datatype/temperature.py”, line 38, in to_ip
return self.to_unit(values, ‘F’, from_unit), ‘F’
File “/home/vscode/.local/lib/python3.7/site-packages/ladybug/datatype/temperature.py”, line 31, in to_unit
return self._to_unit_base(‘C’, values, unit, from_unit)
File “/home/vscode/.local/lib/python3.7/site-packages/ladybug_pandas/extension_types/dtype.py”, line 23, in _to_unit_base_hack
values = eval(statement, namespace)
File “”, line 1, in
File “/home/vscode/.local/lib/python3.7/site-packages/ladybug/datatype/temperature.py”, line 18, in _C_to_F
return value * 9. / 5. + 32.

Am I misunderstanding something from this documentation?

No you don’t have to convert the EPW to a dataframe. I thought you were already using dataframe since part of your error is occuring in the ladybug_pandas library, which is only called if the EPW is a dataframe:

If ladybug_pandas is being called without you explicitly making the conversion, I think you may have some sort of namespace collision, either due to ambiguous library imports, or something streamlit is doing on its end.

For the first case, can you share the entire script so we can see the libraries are imported? For the second case, can you try removing all code related to streamlit, and see if the unit conversion works with just the ladybug libraries?