Skip to content

Commit

Permalink
fix(command): Enable local EPW path to be used in place of directory
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Oct 29, 2024
1 parent 0852262 commit 41e5122
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions ladybug_rhino/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def _download_weather(weather_URL):
"""Download a weather URL with a check if it's already in the default folder."""
# first check wether the url is actually a local path
if not weather_URL.lower().startswith('http'):
if weather_URL.lower().endswith('.epw') and os.path.isfile(weather_URL):
return weather_URL
assert os.path.isdir(weather_URL), 'Input weather URL is not a web ' \
'address nor a local folder directory.'
for fp in os.listdir(weather_URL):
Expand Down
44 changes: 28 additions & 16 deletions ladybug_rhino/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,34 @@ def extract_project_info(project_info_json):

# first check wether the url is actually a local path
if not weather_url.lower().startswith('http'):
assert os.path.isdir(weather_url), 'Input weather URL is not a web ' \
'address nor a local folder directory.'
file_checklist = ['.epw', '.stat', '.ddy']
for f in os.listdir(weather_url):
for i, f_check in enumerate(file_checklist):
if f.lower().endswith(f_check): # file type found
file_checklist.pop(i)
if f_check == '.epw':
epw_path = os.path.join(weather_url, f)
elif f_check == '.stat':
stat_path = os.path.join(weather_url, f)
break
if len(file_checklist) != 0:
msg = 'The following directory does not contain these files '\
'({}):\n{}'.format(', '.join(file_checklist), weather_url)
raise ValueError(msg)
assert os.path.isdir(weather_url) or os.path.isfile(weather_url), \
'Input weather URL is not a web address nor a local folder directory.'
if os.path.isfile(weather_url):
assert weather_url.endswith('.epw'), \
'Input weather URL is not an EPW file.'
epw_path = weather_url
weather_url, file_name = os.path.split(weather_url)
stat_path = os.path.join(weather_url, file_name.replace('.epw', '.stat'))
ddy_path = os.path.join(weather_url, file_name.replace('.epw', '.ddy'))
assert os.path.isfile(stat_path), \
'No STAT file was found at: {}.'.format(stat_path)
assert os.path.isfile(stat_path), \
'No DDY file was found at: {}.'.format(ddy_path)
else:
file_checklist = ['.epw', '.stat', '.ddy']
for f in os.listdir(weather_url):
for i, f_check in enumerate(file_checklist):
if f.lower().endswith(f_check): # file type found
file_checklist.pop(i)
if f_check == '.epw':
epw_path = os.path.join(weather_url, f)
elif f_check == '.stat':
stat_path = os.path.join(weather_url, f)
break
if len(file_checklist) != 0:
msg = 'The following directory does not contain these files '\
'({}):\n{}'.format(', '.join(file_checklist), weather_url)
raise ValueError(msg)
else: # download the EPW file to the user folder
_def_folder = folders.default_epw_folder
if weather_url.lower().endswith('.zip'): # onebuilding URL type
Expand Down

0 comments on commit 41e5122

Please sign in to comment.