diff --git a/powersimdata/scenario/scenario_info.py b/powersimdata/scenario/scenario_info.py index 180adccbf..6fa87474e 100644 --- a/powersimdata/scenario/scenario_info.py +++ b/powersimdata/scenario/scenario_info.py @@ -1,3 +1,5 @@ +import warnings + from prereise.gather.constants import abv2state, state2loadzone, \ interconnect2loadzone @@ -36,10 +38,10 @@ def area_to_loadzone(self, area): elif area in {'Texas', 'Western', 'Eastern'}: loadzone_set = interconnect2loadzone[area] elif area == 'all': - loadzone_set = list(self.grid.zone2id.keys()) + loadzone_set = set(self.grid.zone2id.keys()) else: print("%s is incorrect." % area) - raise Exception('Invalid area') + raise ValueError('Invalid area') return loadzone_set def check_time_range(self, start_time, end_time): @@ -58,12 +60,12 @@ def check_time_range(self, start_time, end_time): (end_time not in self.pg.index): print('Available time range [%s, %s]' % (str(self.pg.index[0]), str(self.pg.index[-1]))) - raise Exception('Invalid time range') + raise ValueError('Time range out of scope!') start_i = self.pg.index.get_loc(start_time) end_i = self.pg.index.get_loc(end_time) if start_i > end_i: - print('start_time falls behind end_time!') - raise Exception('Invalid time range') + raise ValueError('Invalid time range: ' + 'start_time falls behind end_time!') return start_i, end_i def get_capacity(self, gentype, area): @@ -81,7 +83,7 @@ def get_capacity(self, gentype, area): (self.grid.plant['type'] == gentype) & (self.grid.plant['zone_name'].isin(loadzone_set))]['Pmax'].sum() if total_capacity == 0: - print('Warning: no such type of generator in the area specified!') + warnings.warn('No such type of generator in the area specified!') return float(total_capacity) def get_generation(self, gentype, area, start_time, end_time): @@ -129,7 +131,7 @@ def get_profile_resource(self, gentype, area, start_time, end_time): (self.grid.plant['zone_name']. isin(loadzone_set))].index) if gentype not in self.profile: - raise Exception('Invalid resource type') + raise ValueError('Invalid resource type') query_profile_df = self.profile[gentype][plant_id_list] self.check_time_range(start_time, end_time) total_resource = query_profile_df.loc[start_time:end_time].sum().sum() @@ -176,7 +178,8 @@ def get_capacity_factor(self, gentype, area, start_time, end_time): total_hours = end_i - start_i + 1 total_capacity = self.get_capacity(gentype, area) if total_capacity == 0: - raise ZeroDivisionError('Division by zero') + raise ZeroDivisionError('No such type of generator in the area ' + 'specified. Division by zero.') total_generation = self.get_generation(gentype, area, start_time, end_time) cf = round(total_generation / (total_hours * total_capacity), 4)