Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions pollination_handlers/inputs/wea.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,47 @@ def _wea_file_name(wea_obj):
dts = (DateTime(1, 1, 0), DateTime(12, 11, 23))
wea_obj.location.city = ''.join(i for i in wea_obj.location.city if ord(i) < 128)
return '{}_{}_{}'.format(wea_obj.location.city, dts[0].int_hoy, dts[-1].int_hoy)


def epw_or_wea_handler_timestep_annual_check(wea_obj):
"""Translate an EPW or Wea object to check annual/timestep criteria,
but return the original input object/path, e.g., if the input is a path to
an epw file, return that path after checking the criteria.

Args:
wea_obj: Either a Wea python object, an EPW object, or the path to a
wea or an epw file.

Returns:
Either a EPW or Wea file.
"""
if isinstance(wea_obj, str):
if not os.path.isfile(wea_obj):
raise ValueError('Invalid file path: %s' % wea_obj)
if wea_obj.lower().endswith('.wea'):
check_wea = Wea.from_file(wea_obj)
result = wea_obj
elif wea_obj.lower().endswith('.epw'):
check_wea = Wea.from_epw_file(wea_obj)
result = wea_obj
else:
raise ValueError(
'File path should end with wea or epw not %s' % wea_obj.split('.')[-1]
)
elif isinstance(wea_obj, EPW):
check_wea = wea_obj.to_wea()
result = wea_obj
elif isinstance(wea_obj, Wea):
check_wea = wea_obj
file_path = get_tempfile('wea', _wea_file_name(wea_obj))
result = wea_obj.write(file_path)
else:
raise ValueError(
'Wea input should be a string, a Wea object, or an EPW object. '
'Not {}.'.format(type(wea_obj))
)

assert check_wea.timestep == 1, 'Wea timestep must be 1 for this recipe.'
assert check_wea.is_annual, 'Wea must be annual for this recipe.'

return result
16 changes: 16 additions & 0 deletions pollination_handlers/outputs/daylight.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,19 @@ def read_hourly_continuous_collection_from_json(json_path):
data = json.load(json_file)
datacollection = HourlyContinuousCollection.from_dict(data)
return datacollection


def read_csv_summary_formatted(summary_csv):
"""Read a CSV file and return a list of formatted summary lists."""
if not os.path.isfile(summary_csv):
raise ValueError('Invalid file path: %s' % summary_csv)

results = []
with open(summary_csv) as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
row_results = []
for key, value in row.items():
row_results.append('{}: {}'.format(key, value))
results.append(row_results)
return results
Loading