Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandra-kim committed Jun 16, 2022
1 parent 42ad7a5 commit 871bbff
Show file tree
Hide file tree
Showing 17 changed files with 764 additions and 500 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ MANIFEST
dev/write_files/
dev/archived/implicit_markets/
dev/archived/*.pickle
dev/archived/.ipynb_checkpoints/
data/
4 changes: 2 additions & 2 deletions akula/combustion.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ def generate_validation_datapackage(mask_tech, mask_bio, num_samples=SAMPLES, se


if __name__ == "__main__":
random_seeds = [51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
num_samples = SAMPLES
random_seeds = [85, 86]
num_samples = 15000
for random_seed in random_seeds:
print(f"Random seed {random_seed}")
generate_liquid_fuels_combustion_correlated_samples(num_samples, random_seed)
Expand Down
12 changes: 6 additions & 6 deletions akula/electricity/create_datapackages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .entso_data_converter import ENTSODataConverter
from .add_residual_mix import add_swiss_residual_mix
from entso_data_converter import ENTSODataConverter
from add_residual_mix import add_swiss_residual_mix
import bw2data as bd
import bw_processing as bwp
from fs.zipfs import ZipFS
Expand Down Expand Up @@ -141,20 +141,21 @@ def create_timeseries_entso_datapackages():

ndata = data.shape[1]

random_seeds = np.arange(61, 71)
random_seeds = [85, 86]
num_samples = 15000

for random_seed in random_seeds:

print(f"Random seed {random_seed}")

np.random.seed(random_seed)
choice = np.random.choice(np.arange(ndata), SAMPLES)
choice = np.random.choice(np.arange(ndata), num_samples)

data_current = data[:, choice]

# Create datapackage
dp = bwp.create_datapackage(
fs=ZipFS(str(DATA_DIR / f"{name}-{random_seed}.zip"), write=True),
fs=ZipFS(str(DATA_DIR / "xgboost" / f"{name}-{random_seed}.zip"), write=True),
name='timeseries ENTSO electricity values',
seed=random_seed,
sequential=True,
Expand All @@ -169,5 +170,4 @@ def create_timeseries_entso_datapackages():
)
dp.finalize_serialization()

print(dp.data[1])
print("")
2 changes: 1 addition & 1 deletion akula/electricity/entso_data_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bentso import CachingDataClient as CDC
from bentso.constants import ENTSO_COUNTRIES, TRADE_PAIRS
from pathlib import Path
from .config import ENTSO_MAPPING
from config import ENTSO_MAPPING

assert bd.__version__ >= (4, 0, "DEV11")
# assert bentso.__version__ >= (0, 4)
Expand Down
25 changes: 13 additions & 12 deletions akula/markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,19 @@ def generate_validation_datapackages(indices, mask, num_samples, seed=42):

if __name__ == "__main__":

random_seeds = [48, 49, 50]
for random_seed in random_seeds:
print(f"Random seed {random_seed}")
generate_markets_datapackage(
similar_fuzzy,
get_dirichlet_scales,
"implicit-markets",
SAMPLES,
random_seed,
)

# im = bwp.load_datapackage(ZipFS(str(DATA_DIR / "implicit-markets-43.zip")))
# random_seeds = [85, 86]
# num_samples = 15000
# for random_seed in random_seeds:
# print(f"Random seed {random_seed}")
# generate_markets_datapackage(
# similar_fuzzy,
# get_dirichlet_scales,
# "implicit-markets",
# num_samples,
# random_seed,
# )

im = bwp.load_datapackage(ZipFS(str(DATA_DIR / "implicit-markets-91.zip")))
# im_data = im.get_resource('implicit-markets.data')[0]
# im_indices = im.get_resource('implicit-markets.indices')[0]

Expand Down
5 changes: 3 additions & 2 deletions akula/parameterized_exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,12 @@ def generate_validation_datapackages(indices, mask, num_samples, seed=42):
bd.projects.set_current("GSA for archetypes")

# Generate datapackages for high-dimensional screening
random_seeds = [51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
random_seeds = [85, 86]
num_samples = 15000
for random_seed in random_seeds:
print(f"Random seed {random_seed}")
parameters_dp, exchanges_dp = generate_parameterized_exchanges_datapackage(
"ecoinvent-parameterization", SAMPLES, random_seed
"ecoinvent-parameterization", num_samples, random_seed
)
parameters_dp.finalize_serialization()
exchanges_dp.finalize_serialization()
Expand Down
2 changes: 1 addition & 1 deletion akula/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = (0, 1, "DEV2")
version = (0, 1, "DEV3")
142 changes: 107 additions & 35 deletions dev/GSA project master definition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "63711f04",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"env: ENTSOE_API_TOKEN=98eb7887-8d16-43f4-b75c-1e8a80be520e\n",
"env: BENTSO_DATA_DIR=/Users/akim/Documents/LCA_files/entso-data-cache\n"
]
}
],
"source": [
"import bw2data as bd\n",
"import bw2calc as bc\n",
Expand Down Expand Up @@ -37,27 +46,89 @@
"\n",
"import sys\n",
"sys.path.append('/Users/akim/PycharmProjects/akula')\n",
"from akula.electricity import replace_ei_with_entso, add_swiss_residual_mix"
"# from akula.electricity import replace_ei_with_entso, add_swiss_residual_mix"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72c66e53",
"metadata": {},
"outputs": [],
"source": [
"bd.projects.delete_project(\"GSA for archetypes\", True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "b155e53b-688d-40f2-8bb2-4e58e55c0925",
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"Impacts WITH exiobase\n",
"---------------------\n",
"Biosphere database already present!!! No setup is needed\n",
"ecoinvent 3.3 cutoff database already present!!! No import is needed\n",
"--> Consumption_db.xlsx already exists, reading it\n",
"Created consumption_db.xlsx file in BW format in 1.21 seconds\n",
"Extracted 1 worksheets in 1.28 seconds\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n",
"Applying strategy: migrate_datasets\n",
"Applying strategy: migrate_exchanges\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/akim/PycharmProjects/consumption_model_ch/consumption_model_ch/strategies/consumption_db.py:248: DtypeWarning: Columns (2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344) have mixed types. Specify dtype option on import or set low_memory=False.\n",
" df = pd.read_table(filepath)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Applying strategy: link_iterable_by_fields\n",
"Applying strategy: link_iterable_by_fields\n",
"Applying strategy: link_iterable_by_fields\n",
"Applying strategy: link_iterable_by_fields\n",
"Applied 0 strategies in 0.00 seconds\n",
"207 datasets\n",
"6676 exchanges\n",
"0 unlinked exchanges\n",
" \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Writing activities to SQLite3 database:\n",
"0% [##############################] 100% | ETA: 00:00:00\n",
"Total time elapsed: 00:00:00\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Title: Writing activities to SQLite3 database:\n",
" Started: 05/28/2022 22:27:11\n",
" Finished: 05/28/2022 22:27:12\n",
" Total time elapsed: 00:00:00\n",
" CPU %: 99.90\n",
" Memory %: 2.07\n",
"Created database: swiss consumption 1.0\n",
"1756.551 ch hh average consumption aggregated, years 151617\n"
]
}
],
"source": [
"def import_all_databases(use_exiobase, year='091011', add_activities=True, add_archetypes=False):\n",
"\n",
Expand Down Expand Up @@ -111,8 +182,8 @@
" )\n",
" \n",
" # Modify electricity mixes\n",
" add_swiss_residual_mix()\n",
" replace_ei_with_entso()\n",
"# add_swiss_residual_mix()\n",
"# replace_ei_with_entso()\n",
"\n",
" # Add uncertainties to GWP values\n",
" method = (\"IPCC 2013\", \"climate change\", \"GWP 100a\", \"uncertain\")\n",
Expand All @@ -139,13 +210,13 @@
" lca.lcia()\n",
" print(\"{:8.3f} {}\".format(lca.score, demand_act['name']))\n",
"\n",
" # LCIA for all Swiss consumption sectors\n",
" sectors = sorted([act for act in co if \"sector\" in act['name'].lower() and str(year) in act['name']])\n",
" for demand_act in sectors:\n",
" lca = bc.LCA({demand_act: 1}, method)\n",
" lca.lci()\n",
" lca.lcia()\n",
" print(\"{:8.3f} {}\".format(lca.score, demand_act['name']))\n",
"# # LCIA for all Swiss consumption sectors\n",
"# sectors = sorted([act for act in co if \"sector\" in act['name'].lower() and str(year) in act['name']])\n",
"# for demand_act in sectors:\n",
"# lca = bc.LCA({demand_act: 1}, method)\n",
"# lca.lci()\n",
"# lca.lcia()\n",
"# print(\"{:8.3f} {}\".format(lca.score, demand_act['name']))\n",
" \n",
"\n",
"def plot_archetypes(use_exiobase, year):\n",
Expand Down Expand Up @@ -184,18 +255,19 @@
"\n",
"if __name__ == \"__main__\":\n",
"\n",
" print(\"Impacts WITHOUT exiobase\")\n",
" print(\"------------------------\")\n",
" use_ex = False\n",
" year = '151617'\n",
" import_all_databases(use_ex, year, True, False)\n",
"# print(\"Impacts WITHOUT exiobase\")\n",
"# print(\"------------------------\")\n",
"# use_ex = False\n",
"# year = '151617'\n",
"# import_all_databases(use_ex, year, True, False)\n",
"# plot_archetypes(use_ex, year)\n",
"\n",
"# print(\"\\n\")\n",
"# print(\"Impacts WITH exiobase\")\n",
"# print(\"---------------------\")\n",
"# use_ex = True\n",
"# import_all_databases(use_ex, year, True, False)\n",
" print(\"\\n\")\n",
" print(\"Impacts WITH exiobase\")\n",
" print(\"---------------------\")\n",
" use_ex = True\n",
" year = '151617'\n",
" import_all_databases(use_ex, year, True, False)\n",
"# plot_archetypes(use_ex, year)\n"
]
},
Expand All @@ -219,7 +291,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f50e7877",
"id": "e2726174",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit 871bbff

Please sign in to comment.