Skip to content

Commit

Permalink
Add ecoinvent migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Jul 23, 2024
1 parent e48bf81 commit 6c17d28
Show file tree
Hide file tree
Showing 10 changed files with 6,199 additions and 42 deletions.
345 changes: 307 additions & 38 deletions dev/Generate SimaPro mappings.ipynb

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions dev/Generate ecoinvent mappings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "03251142-6347-4c3b-9dab-ca61b3b8a552",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import randonneur as rd\n",
"from pathlib import Path\n",
"import randonneur_data as rdata"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3065cefd-ec8a-4d69-bc76-b45973abeba7",
"metadata": {},
"outputs": [],
"source": [
"registry = rdata.Registry()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8b1cda58-092e-4897-b1bd-821ce19649f3",
"metadata": {},
"outputs": [],
"source": [
"def write_for_version(version, base_path, filename, sheet_name, combined):\n",
" df = pd.read_excel(\n",
" base_path / filename,\n",
" sheet_name\n",
" ) \n",
" data = [\n",
" {\n",
" 'source': {\n",
" 'identifier': row['Simapro Process Identifier'],\n",
" 'name': row['Simapro Process Name'],\n",
" 'platform_id': row['PlatformID'],\n",
" },\n",
" 'target': {\n",
" 'filename': row[combined].lower() + \".spold\",\n",
" 'name': row['Activity Name'],\n",
" 'location': row['Geography'],\n",
" 'reference product': row['Reference Product Name'],\n",
" 'unit': row['Unit'],\n",
" }\n",
" } \n",
" for row in df.to_dict(orient='records')\n",
" ]\n",
" dp = rd.Datapackage(\n",
" name=f\"simapro-ecoinvent-{version}-cutoff\",\n",
" description=f\"Data migration file from SimaPro 9 to ecoinvent-{version}-cutoff generated by PRé and provided via request at https://support.simapro.com/s/contactsupport\",\n",
" contributors=[\n",
" {\"title\": \"PRé\", \"path\": \"https://pre-sustainability.com/\", \"role\": \"author\"},\n",
" {\"title\": \"Chris Mutel\", \"path\": \"https://chris.mutel.org/\", \"role\": \"wrangler\"},\n",
" ],\n",
" mapping_source=rd.MappingConstants.SIMAPRO_CSV,\n",
" mapping_target=rd.MappingConstants.ECOSPOLD2,\n",
" version=\"2.0.0\",\n",
" source_id=\"SimaPro-9\",\n",
" target_id=f\"ecoinvent-{version}-cutoff\"\n",
" )\n",
" dp.add_data(\"replace\", data)\n",
" return registry.add_file(dp.to_json(Path(f\"simapro-ecoinvent-{version}-cutoff.json\")), replace=True)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9afb0067-7343-46b4-beed-1fe7491281d9",
"metadata": {},
"outputs": [],
"source": [
"base_path = Path('/Users/cmutel/Projects/SimaPro - ecoinvent mapping/')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8c30c0c9-9296-4527-aa74-c81fa0c9e12f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"PosixPath('/Users/cmutel/Code/randonneur_data/randonneur_data/data/simapro-ecoinvent-3.10-cutoff.xz')"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"write_for_version(\n",
" version=\"3.10\", \n",
" base_path=base_path, \n",
" filename=\"ecoinvent 3.10 Cut-off - SimaPro mapping.xlsx\", \n",
" sheet_name=\"Mapping_Results_2024-04-25\", \n",
" combined='Activity_UUID_Product_UUID',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dbd86fa4-6142-461f-aa90-0aa650a44e0d",
"metadata": {},
"outputs": [],
"source": [
"write_for_version(\n",
" version=\"3.8\", \n",
" base_path=base_path, \n",
" filename='ecoinvent cut-off 3.8 - SimaPro mapping file.xlsx', \n",
" sheet_name=\"ecoinventCut-off38-SimaPro\", \n",
" combined='Activity UUID & Product UUID'\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08b41875-d606-4320-961d-15ce1bd94124",
"metadata": {},
"outputs": [],
"source": [
"write_for_version(\n",
" version=\"3.9.1\", \n",
" base_path=base_path, \n",
" filename='Ecoinvent_391_SimaPro_Mapping_Results_2023-10-03.xlsx', \n",
" sheet_name=\"Mapping_Results_2023-10-03\", \n",
" combined='Activity_UUID_Product_UUID'\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "66d21bb6-14f5-41d2-9e80-f9fd8256fe0d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"`randonneur_data` registry with 3 files:\n",
"\tsimapro-ecoinvent-3.10-cutoff\n",
"\tsimapro-ecoinvent-3.8-cutoff\n",
"\tsimapro-ecoinvent-3.9.1-cutoff"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"registry"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion randonneur_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Registry",
)

__version__ = "0.0.1"
__version__ = "0.0.2"


import json
Expand Down
Loading

0 comments on commit 6c17d28

Please sign in to comment.