Skip to content

Instantly share code, notes, and snippets.

@sariths
Created February 26, 2019 14:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sariths/53805279212b55dc2dea6c8673f9511b to your computer and use it in GitHub Desktop.
Save sariths/53805279212b55dc2dea6c8673f9511b to your computer and use it in GitHub Desktop.
def changeEPWData(oldEpwFilePath,newEpwFilePath,dataIndex,dataList):
"""
:param oldEpwFilePath: Path of the original epw file.
:param newEpwFilePath: Path to which the new file should be written to.
:param dataIndex: Index of the data which is to be changed. Refer notes below.
:param dataList: A list of 8760 values that will replace the original data.
:return:
Notes: dataIndex refers to the position of specific data in EPW columns. For example, index for Dry Bulb Temperature
is 6. Refer this link for all the data indices:
https://github.com/ladybug-tools/ladybug/blob/f35d7dc0b4c83d9ed8a6d2f3fb49b216b1c357a8/ladybug/epw.py#L274-L309
"""
with open(oldEpwFilePath) as oldStream,open(newEpwFilePath,"w") as newStream:
numCount=0
for idx,lines in enumerate(oldStream):
if lines.strip():
try:
lineSplit=lines.strip().split(",")
dataTest=float(lineSplit[0])
lineSplit[dataIndex]=str(dataList[numCount])
data=",".join(lineSplit)
newStream.write(data+"\n")
numCount+=1
except ValueError:
newStream.write(lines.strip()+"\n")
else:
newStream.write(lines)
return newEpwFilePath
if __name__ == "__main__":
newTempData=[20000000000]*8760
changeEPWData(r"D:\nyc.epw",r"D:\new.epw",dataIndex=6,dataList=newTempData)
#Testing (optional). Requires ladybug library to be installed.
from ladybug.epw import EPW
#Test old file
old=EPW(r"D:\nyc.epw")
print(min(old.dry_bulb_temperature),max(old.dry_bulb_temperature))
#Test new file.
new=EPW(r"D:\new.epw")
print(min(new.dry_bulb_temperature),max(new.dry_bulb_temperature))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment