Skip to content
Draft
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ dmypy.json
# Datafiles
*.xlsx
*.csv


!onsset/data/*.csv
!test/*/*.csv

# VSCode
.vscode
Expand Down
Empty file added onsset/data/.gitkeep
Empty file.
9 changes: 5 additions & 4 deletions onsset/onsset.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
from math import exp, log, pi
from typing import Dict
import scipy.spatial

import numpy as np
import pandas as pd
import scipy.spatial

logging.basicConfig(format='%(asctime)s\t\t%(message)s', level=logging.DEBUG)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1566,7 +1566,7 @@ def do_kdtree(combined_x_y_arrays, points):
dist, indexes = mytree.query(points)
return indexes

def calculate_new_connections(self, year, time_step, start_year):
def calculate_new_connections(self, year: int, time_step: int, start_year: int):
"""this method defines new connections for grid related purposes

Arguments
Expand Down Expand Up @@ -1719,7 +1719,8 @@ def calculate_total_demand_per_settlement(self, year):
self.df.loc[self.df[SET_URBAN] == 2, SET_TOTAL_ENERGY_PER_CELL] = \
self.df[SET_CAPITA_DEMAND] * self.df[SET_POP + "{}".format(year)]

def set_scenario_variables(self, year, num_people_per_hh_rural, num_people_per_hh_urban, time_step, start_year,
def set_scenario_variables(self, year: int, num_people_per_hh_rural, num_people_per_hh_urban,
time_step: int, start_year: int,
urban_tier, rural_tier, end_year_pop, productive_demand):
"""
this method determines some basic parameters required in LCOE calculation
Expand Down Expand Up @@ -1751,7 +1752,7 @@ def set_scenario_variables(self, year, num_people_per_hh_rural, num_people_per_h
self.calculate_total_demand_per_settlement(year)

def calculate_off_grid_lcoes(self, mg_hydro_calc, mg_wind_calc, mg_pv_calc, sa_pv_calc, mg_diesel_calc,
sa_diesel_calc, year, end_year, time_step, diesel_techs=0):
sa_diesel_calc, year: int, end_year: int, time_step: int, diesel_techs=0):
"""
Calculate the LCOEs for all off-grid technologies

Expand Down
473 changes: 249 additions & 224 deletions onsset/runner.py

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

from onsset.runner import read_scenario_data


def test_read_scenario_data():
"""Store the configuration data as a dictionary
"""

path = os.path.join('test', 'test_data', 'config.csv')

data = [
['Country', 'Djibouti'],
['CountryCode', 'dj'],
['StartYear', 2018],
['EndYear', 2030],
['PopStartYear', 971000],
['UrbanRatioStartYear', 0.778],
['PopEndYearHigh', 1179150],
['PopEndYearLow', 1132710],
['UrbanRatioEndYear', 0.8],
['NumPeoplePerHHRural', 7.7],
['NumPeoplePerHHUrban', 6.5],
['GridCapacityInvestmentCost', 4426],
['GridLosses', 0.083],
['BaseToPeak', 0.8],
['ExistingGridCostRatio', 0.1],
['MaxGridExtensionDist', 50],
['NewGridGenerationCapacityAnnualLimitMW', 19],
['ElecActual', 0.6],
['Rural_elec_ratio', 0.26],
['Urban_elec_ratio', 0.7],
]
actual = read_scenario_data(path)
expected = dict(data)

assert actual == expected
26 changes: 26 additions & 0 deletions test/test_data/config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameter,value,description,data_type
Country,Djibouti,,str
CountryCode,dj,,str
StartYear,2018,,int
EndYear,2030,,int
PopStartYear,971000,,int
UrbanRatioStartYear,0.778,,float
PopEndYearHigh,1179150,,int
PopEndYearLow,1132710,,int
UrbanRatioEndYear,0.8,,float
NumPeoplePerHHRural,7.7,,float
NumPeoplePerHHUrban,6.5,,float
GridCapacityInvestmentCost,4426,,float
GridLosses,0.083,,float
BaseToPeak,0.8,,float
ExistingGridCostRatio,0.1,,float
MaxGridExtensionDist,50,,float
NewGridGenerationCapacityAnnualLimitMW,19,,float
ElecActual,0.6,,float
Rural_elec_ratio,0.26,,float
Urban_elec_ratio,0.7,,float
ElecModelled,,,float
urban_elec_ratio_modelled,,,float
rural_elec_ratio_modelled,,,float
UrbanCutOff,,,float
UrbanRatioModelled,,,float
37 changes: 37 additions & 0 deletions test/test_data/template_config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameter;value;description
Country;Benin;Name of country
CountryCode;bj;ISO-2 code of country
StartYear;2020;Start year of analysis
EndYEar;2030;End year of analysis
PopStartYear;12123000;Population in start year
UrbanRatioStartYear;0.484;Urban ratio in start year (0 = all rural, 1 = all urban)
UrbanCutOff;;Cut-off value for urban settlements, all settlements with higher population are urban, else rural.
UrbanRatioModelled;;Urban ratio modelled based on input
PopEndYearHigh;15672000;Population in 2030 (high variant)
PopEndYearLow;15672000;Population in 2030 (low variant)
UrbanRatioEndYear;0.541;Urban ratio in end year (0 = all rural, 1 = all urban)
NumPeoplePerHHRural;3.6;Number of people per housheold in rural setttlements
NumPeoplePerHHUrban;3.1;Number of people per housheold in urban setttlements
GridCapacityInvestmentCost;1982;grid capacity investments costs USD/kW. Weighted average of additions to the grid
GridLosses;0.143;Losses in transmission and distrbution network (%)
DiscountRate;0.08;Discount rate (%)
BaseToPeak;0.8;Base to peak ratio (%)
ExistingGridCostRatio;0.1;
MaxGridExtensionDist;50;Max limit for how far the grid can extend
NewGridGenerationCapacityAnnualLimitMW;70;Annual added capacity limit (MW/year) between start year and the intermediate year (no limit between intermediate and end yaer)
ElecActual;0.42;National electrification rate as reported by country
Rural_elec_ratio;0.18;Rural electrification rate as repoterd by country
Urban_elec_ratio;0.67;Urban electrification rate as repoterd by country
ElecModelled;;National electrification rate modelled by OnSSET
urban_elec_ratio_modelled;;Rural electrification rate modelled by OnSSET
rural_elec_ratio_modelled;;Urban electrification rate modelled by OnSSET
UrbanTargetTier;5;Electricity demand in urban settlements in the end year (1-5 are MTF tiers, 6 is custom demand)
RuralTargetTier;4;Electricity demand in rural settlements in the end year (1-5 are MTF tiers, 6 is custom demand)
5YearTarget;0.71;Electrification rate 5 years from start year of analysis
GridConnectionsLimitThousands;9999;Limit for how many people that can be connected to the grid
GridGenerationCost;0.16;Cost of generating electricity for the centralised grid
PV_Cost_adjust;1.25;Development of PV price
DieselPrice;9999;Diesel price
ProductiveDemand;0;
PrioritizationAlgorithm;2;Determines which settlements to prioritize first (for electrification in the intermediate year).
AutoIntensificationKM;0;
6 changes: 3 additions & 3 deletions test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def run_analysis(tmpdir):
Returns a tuple of bool for whether the summary or full files match

"""

specs_path = os.path.join('test', 'test_data', 'dj-specs-test.xlsx')
specs_path = os.path.join('test', 'test_data', 'config.csv')
scenario_path = os.path.join('test', 'test_data', 'dj-specs-test.xlsx')
csv_path = os.path.join('test', 'test_data', 'dj-test.csv')
calibrated_csv_path = os.path.join(tmpdir, 'dj-calibrated.csv')
specs_path_calib = os.path.join(tmpdir, 'dj-specs-test-calib.xlsx')

calibration(specs_path, csv_path, specs_path_calib, calibrated_csv_path)

scenario(specs_path_calib, calibrated_csv_path, tmpdir, tmpdir)
scenario(specs_path, scenario_path, calibrated_csv_path, tmpdir, tmpdir)

actual = os.path.join(tmpdir, 'dj-1-1_1_1_1_0_0_summary.csv')
expected = os.path.join('test', 'test_results', 'expected_summary.csv')
Expand Down