Skip to content

Commit

Permalink
Prepare to revert
Browse files Browse the repository at this point in the history
  • Loading branch information
invisibleroads committed Oct 8, 2016
1 parent ad5e4ed commit 658a79f
Show file tree
Hide file tree
Showing 12 changed files with 652 additions and 530 deletions.
584 changes: 112 additions & 472 deletions estimate_electricity_cost_by_technology_from_population.py

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions estimate_grid_mv_line_budget_in_meters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
from invisibleroads_macros.configuration import TerseArgumentParser

# coding: utf-8
from infrastructure_planning.macros import load_and_run

# In[1]:
"""
from infrastructure_planning.demography.exponential import estimate_population
"""

print('whee')

def add_arguments_for_estimate_population(x):
x.add('demand_point_table_path')
x.add('population_year')
x.add('population_growth_as_percent_of_population_per_year')
x.add('financing_year')
x.add('time_horizon_in_years')


if __name__ == '__main__':
x = TerseArgumentParser()
add_arguments_for_estimate_population(x)
load_and_run(x)
6 changes: 2 additions & 4 deletions forecast_electricity_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def estimate_electricity_consumption_per_capita(target_year, country_name):
t = ELECTRICITY_CONSUMPTION_PER_CAPITA_BY_YEAR_TABLE
country_t = _get_country_table(t, 'Country Name', country_name)
if not len(country_t):
raise InvalidData(
'missing electricity_consumption_per_capita country_name')
raise InvalidData('missing country_name')
year_packs = []
for column_name in country_t.columns:
try:
Expand All @@ -133,8 +132,7 @@ def estimate_electricity_consumption_per_capita(target_year, country_name):
continue
year_packs.append((year, value))
if not year_packs:
raise InvalidData(
'missing electricity_consumption_per_capita year_value')
raise InvalidData('missing year_value')
estimate_electricity_consumption_per_capita = \
get_interpolated_spline_extrapolated_linear_function(year_packs)
return estimate_electricity_consumption_per_capita(target_year)
Expand Down
13 changes: 3 additions & 10 deletions infrastructure_planning/demography/exponential.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from pandas import Series

from ..exceptions import InfrastructurePlanningError


M = {
'bad_financing_year':
'financing year (%s) must be greater than or equal to '
'population year (%s)',
}
from ..exceptions import ValidationError


def estimate_population(
Expand All @@ -17,8 +10,8 @@ def estimate_population(
financing_year,
time_horizon_in_years):
if financing_year < population_year:
raise InfrastructurePlanningError('financing_year', M[
'bad_financing_year'] % (financing_year, population_year))
raise ValidationError(
'financing_year', 'cannot be less than population_year')
# Compute the population at financing_year
base_population = _grow_exponentially(
population, population_growth_as_percent_of_population_per_year,
Expand Down
9 changes: 4 additions & 5 deletions infrastructure_planning/electricity/cost/grid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from geopy.distance import vincenty as get_distance
from invisibleroads_macros.math import divide_safely

from ...exceptions import ExpectedPositive, InfrastructurePlanningError
from ...exceptions import ExpectedPositive, ValidationError
from ...finance.valuation import compute_discounted_cash_flow
from ...production import adjust_for_losses, prepare_system_cost
from .mini_grid import estimate_lv_connection_cost, estimate_lv_line_cost
Expand Down Expand Up @@ -56,10 +56,9 @@ def estimate_electricity_production_cost(
grid_mv_transformer_load_power_factor,
grid_electricity_production_cost_per_kwh):
if not -1 <= grid_mv_transformer_load_power_factor <= 1:
raise InfrastructurePlanningError(
'grid_mv_transformer_load_power_factor', (
'power factor (%s) must be between '
'-1 and 1' % grid_mv_transformer_load_power_factor))
raise ValidationError(
'grid_mv_transformer_load_power_factor',
'must be between -1 and +1')
production_in_kwh_by_year = adjust_for_losses(
consumption_in_kwh_by_year,
grid_system_loss_as_percent_of_total_production / 100.,
Expand Down
18 changes: 15 additions & 3 deletions infrastructure_planning/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ class InvalidData(InfrastructurePlanningError):
pass


class ExpectedPositive(InvalidData):
class UnsupportedFormat(InfrastructurePlanningError):
pass


class UnsupportedFormat(InfrastructurePlanningError):
pass
class ValidationError(InfrastructurePlanningError):

def __init__(self, argument_name, error_message):
self.argument_name = argument_name
self.error_message = error_message
text = '%s.error = %s' % (argument_name, error_message)
self.args = (text,)


class ExpectedPositive(ValidationError):

def __init__(self, argument_name):
super(ExpectedPositive, self).__init__(
argument_name, 'must be greater than or equal to zero')
Loading

0 comments on commit 658a79f

Please sign in to comment.