diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 15c4ef4..dd12b95 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,12 @@ repos: - id: check-yaml - id: check-added-large-files - id: flake8 + args: ['--max-line-length=120'] # default of Black - id: requirements-txt-fixer - id: check-merge-conflict - id: name-tests-test args: ['--django'] +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.4 + hooks: + - id: isort diff --git a/onsset/onsset.py b/onsset/onsset.py index 1622c1a..ae064b8 100644 --- a/onsset/onsset.py +++ b/onsset/onsset.py @@ -1,15 +1,12 @@ import logging -import pandas as pd -from math import ceil, pi, exp, log, sqrt, radians, cos, sin, asin +from math import asin, ceil, cos, exp, log, pi, radians, sin, sqrt + # from pyproj import Proj import numpy as np +import pandas as pd logging.basicConfig(format='%(asctime)s\t\t%(message)s', level=logging.DEBUG) -# General -LHV_DIESEL = 9.9445485 # (kWh/l) lower heating value -HOURS_PER_YEAR = 8760 - # Columns in settlements file must match these exactly SET_COUNTRY = 'Country' # This cannot be changed, lots of code will break SET_X_DEG = 'X_deg' # Coordinates in degrees @@ -100,43 +97,9 @@ SET_SA_DIESEL_FUEL = 'SADieselFuelCost' SET_MG_DIESEL_FUEL = 'MGDieselFuelCost' -# Columns in the specs file must match these exactly -SPE_COUNTRY = 'Country' -SPE_POP = 'PopStartYear' # The actual population in the base year -SPE_URBAN = 'UrbanRatioStartYear' # The ratio of urban population (range 0 - 1) in base year -SPE_POP_FUTURE = 'PopEndYear' -SPE_URBAN_FUTURE = 'UrbanRatioEndYear' -SPE_URBAN_MODELLED = 'UrbanRatioModelled' # The urban ratio in the model after calibration (for comparison) -SPE_URBAN_CUTOFF = 'UrbanCutOff' # The urban cutoff population calirated by the model, in people per km2 -SPE_URBAN_GROWTH = 'UrbanGrowth' # The urban growth rate as a simple multplier (urban pop future / urban pop present) -SPE_RURAL_GROWTH = 'RuralGrowth' # Same as for urban -SPE_NUM_PEOPLE_PER_HH_RURAL = 'NumPeoplePerHHRural' -SPE_NUM_PEOPLE_PER_HH_URBAN = 'NumPeoplePerHHUrban' -SPE_DIESEL_PRICE_LOW = 'DieselPriceLow' # Diesel price in USD/litre -SPE_DIESEL_PRICE_HIGH = 'DieselPriceHigh' # Same, with a high forecast var -SPE_GRID_PRICE = 'GridPrice' # Grid price of electricity in USD/kWh -SPE_GRID_CAPACITY_INVESTMENT = 'GridCapacityInvestmentCost' # grid capacity investments costs from TEMBA USD/kW -SPE_GRID_LOSSES = 'GridLosses' # As a ratio (0 - 1) -SPE_BASE_TO_PEAK = 'BaseToPeak' # As a ratio (0 - 1) -SPE_EXISTING_GRID_COST_RATIO = 'ExistingGridCostRatio' -SPE_MAX_GRID_DIST = 'MaxGridDist' -SPE_ELEC = 'ElecActual' # Actual current percentage electrified population (0 - 1) -SPE_ELEC_MODELLED = 'ElecModelled' # The modelled version after calibration (for comparison) -SPE_ELEC_URBAN = 'Urban_elec_ratio' # Actual electrification for urban areas -SPE_ELEC_RURAL = 'Rural_elec_ratio' # Actual electrification for rural areas -SPE_MIN_NIGHT_LIGHTS = 'MinNightLights' -SPE_MAX_GRID_EXTENSION_DIST = 'MaxGridExtensionDist' -SPE_MAX_ROAD_DIST = 'MaxRoadDist' -SPE_POP_CUTOFF1 = 'PopCutOffRoundOne' -SPE_POP_CUTOFF2 = 'PopCutOffRoundTwo' -SPE_ELEC_LIMIT = "ElecLimit" -SPE_INVEST_LIMIT = "InvestmentLimit" -SPE_DIST_TO_TRANS = "DistToTrans" - -SPE_START_YEAR = "StartYear" -SPE_END_YEAR = "EndYEar" -SPE_TIMESTEP = "TimeStep" - +# General +LHV_DIESEL = 9.9445485 # (kWh/l) lower heating value +HOURS_PER_YEAR = 8760 class Technology: """ diff --git a/onsset/runner.py b/onsset/runner.py index 987d42a..c0de752 100644 --- a/onsset/runner.py +++ b/onsset/runner.py @@ -1,10 +1,23 @@ # Defines the modules +import logging import os -from onsset import * + import pandas as pd +from onsset import (SET_ELEC_ORDER, SET_LCOE_GRID, SET_MIN_GRID_DIST, + SET_MV_CONNECT_DIST, SettlementProcessor, Technology) +from onsset.specs import (SPE_COUNTRY, SPE_ELEC, SPE_ELEC_MODELLED, + SPE_ELEC_RURAL, SPE_ELEC_URBAN, SPE_END_YEAR, + SPE_EXISTING_GRID_COST_RATIO, + SPE_GRID_CAPACITY_INVESTMENT, SPE_GRID_LOSSES, + SPE_MAX_GRID_EXTENSION_DIST, + SPE_NUM_PEOPLE_PER_HH_RURAL, + SPE_NUM_PEOPLE_PER_HH_URBAN, SPE_POP, SPE_POP_FUTURE, + SPE_START_YEAR, SPE_URBAN, SPE_URBAN_FUTURE, + SPE_URBAN_MODELLED) from openpyxl import load_workbook + def calibration(specs_path, csv_path, specs_path_calib, calibrated_csv_path): diff --git a/onsset/specs.py b/onsset/specs.py new file mode 100644 index 0000000..9fbed25 --- /dev/null +++ b/onsset/specs.py @@ -0,0 +1,37 @@ +"""Columns in the specs file must match these exactly +""" +SPE_COUNTRY = 'Country' +SPE_POP = 'PopStartYear' # The actual population in the base year +SPE_URBAN = 'UrbanRatioStartYear' # The ratio of urban population (range 0 - 1) in base year +SPE_POP_FUTURE = 'PopEndYear' +SPE_URBAN_FUTURE = 'UrbanRatioEndYear' +SPE_URBAN_MODELLED = 'UrbanRatioModelled' # The urban ratio in the model after calibration (for comparison) +SPE_URBAN_CUTOFF = 'UrbanCutOff' # The urban cutoff population calirated by the model, in people per km2 +SPE_URBAN_GROWTH = 'UrbanGrowth' # The urban growth rate as a simple multplier (urban pop future / urban pop present) +SPE_RURAL_GROWTH = 'RuralGrowth' # Same as for urban +SPE_NUM_PEOPLE_PER_HH_RURAL = 'NumPeoplePerHHRural' +SPE_NUM_PEOPLE_PER_HH_URBAN = 'NumPeoplePerHHUrban' +SPE_DIESEL_PRICE_LOW = 'DieselPriceLow' # Diesel price in USD/litre +SPE_DIESEL_PRICE_HIGH = 'DieselPriceHigh' # Same, with a high forecast var +SPE_GRID_PRICE = 'GridPrice' # Grid price of electricity in USD/kWh +SPE_GRID_CAPACITY_INVESTMENT = 'GridCapacityInvestmentCost' # grid capacity investments costs from TEMBA USD/kW +SPE_GRID_LOSSES = 'GridLosses' # As a ratio (0 - 1) +SPE_BASE_TO_PEAK = 'BaseToPeak' # As a ratio (0 - 1) +SPE_EXISTING_GRID_COST_RATIO = 'ExistingGridCostRatio' +SPE_MAX_GRID_DIST = 'MaxGridDist' +SPE_ELEC = 'ElecActual' # Actual current percentage electrified population (0 - 1) +SPE_ELEC_MODELLED = 'ElecModelled' # The modelled version after calibration (for comparison) +SPE_ELEC_URBAN = 'Urban_elec_ratio' # Actual electrification for urban areas +SPE_ELEC_RURAL = 'Rural_elec_ratio' # Actual electrification for rural areas +SPE_MIN_NIGHT_LIGHTS = 'MinNightLights' +SPE_MAX_GRID_EXTENSION_DIST = 'MaxGridExtensionDist' +SPE_MAX_ROAD_DIST = 'MaxRoadDist' +SPE_POP_CUTOFF1 = 'PopCutOffRoundOne' +SPE_POP_CUTOFF2 = 'PopCutOffRoundTwo' +SPE_ELEC_LIMIT = "ElecLimit" +SPE_INVEST_LIMIT = "InvestmentLimit" +SPE_DIST_TO_TRANS = "DistToTrans" + +SPE_START_YEAR = "StartYear" +SPE_END_YEAR = "EndYEar" +SPE_TIMESTEP = "TimeStep"