-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable user to import weather file as .dat #3713
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -74,6 +74,31 @@ def copy_weather_file(source_weather_file, locator): | |||||||||||||||||||||||||||||||||||||||||||
source_weather_file=source_weather_file | ||||||||||||||||||||||||||||||||||||||||||||
)) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
def parse_dat_weather_file(source_dat_file, output_epw_file): | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
convert a DWD .dat-file to a epw-file | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you be able to add the header definitions of the .dat file in english in the function's docstring as well. I think this would help others understand the provided columns when debugging this in the future.
|
||||||||||||||||||||||||||||||||||||||||||||
:param string source_dat_file: source .dat | ||||||||||||||||||||||||||||||||||||||||||||
:param string output_epw_file: output EPW | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
import pandas as pd | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
print(f"Parsing .dat file: {source_dat_file}") | ||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||
weather_data = pd.read_csv(source_dat_file, sep="\s+", skiprows=6, header=None) | ||||||||||||||||||||||||||||||||||||||||||||
weather_data.columns = ['Year', 'Month', 'Day', 'Hour', 'Temperature', 'Radiation', 'WindSpeed', '...'] | ||||||||||||||||||||||||||||||||||||||||||||
reyery marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
# from dat to epw | ||||||||||||||||||||||||||||||||||||||||||||
with open(output_epw_file, 'w') as epw_file: | ||||||||||||||||||||||||||||||||||||||||||||
# add EPW-Header | ||||||||||||||||||||||||||||||||||||||||||||
epw_file.write("LOCATION,Example,DEU,,,0,0,0\n") | ||||||||||||||||||||||||||||||||||||||||||||
epw_file.write("DESIGN CONDITIONS,0\n") | ||||||||||||||||||||||||||||||||||||||||||||
reyery marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
for _, row in weather_data.iterrows(): | ||||||||||||||||||||||||||||||||||||||||||||
epw_line = f"{row['Year']},{row['Month']},{row['Day']},{row['Hour']},...,{row['Temperature']},...\n" | ||||||||||||||||||||||||||||||||||||||||||||
epw_file.write(epw_line) | ||||||||||||||||||||||||||||||||||||||||||||
reyery marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||
raise ValueError(f"Error parsing .dat-Datei: {e}") | ||||||||||||||||||||||||||||||||||||||||||||
reyery marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
def main(config): | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -85,7 +110,13 @@ def main(config): | |||||||||||||||||||||||||||||||||||||||||||
locator = cea.inputlocator.InputLocator(config.scenario) | ||||||||||||||||||||||||||||||||||||||||||||
weather = config.weather_helper.weather | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if config.weather_helper.weather == 'climate.onebuilding.org': | ||||||||||||||||||||||||||||||||||||||||||||
if weather.endswith('.dat'): | ||||||||||||||||||||||||||||||||||||||||||||
print(f"Detected .dat file: {weather}") | ||||||||||||||||||||||||||||||||||||||||||||
# convert .dat in .epw | ||||||||||||||||||||||||||||||||||||||||||||
dat_weather_file = weather | ||||||||||||||||||||||||||||||||||||||||||||
epw_weather_file = locator.get_weather_file() | ||||||||||||||||||||||||||||||||||||||||||||
parse_dat_weather_file(dat_weather_file, epw_weather_file) | ||||||||||||||||||||||||||||||||||||||||||||
elif config.weather_helper.weather == 'climate.onebuilding.org': | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+129
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add file validation and error handling The .dat file handling needs additional validation and cleanup. if weather.endswith('.dat'):
+ if not os.path.exists(weather):
+ raise ValueError(f"Weather file not found: {weather}")
print(f"Detected .dat file: {weather}")
- # convert .dat in .epw
dat_weather_file = weather
epw_weather_file = locator.get_weather_file()
+ try:
parse_dat_weather_file(dat_weather_file, epw_weather_file)
+ except Exception as e:
+ # Clean up any partially written EPW file
+ if os.path.exists(epw_weather_file):
+ os.remove(epw_weather_file)
+ raise 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
print("No weather provided, fetching from online sources.") | ||||||||||||||||||||||||||||||||||||||||||||
fetch_weather_data(locator.get_weather_file(), locator.get_zone_geometry()) | ||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||
|
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mar-Ges we should only return the path of the file when parsing the weather path parameter in the config. The conversion would be done inside the weather-helper instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.