diff --git a/data/notebooks/Lab/Updates_in_stored_procedures_LG_v2_0_09_23.ipynb b/data/notebooks/Lab/Updates_in_stored_procedures_LG_v2_0_09_23.ipynb
index 29cd959ca5..035d763a1e 100644
--- a/data/notebooks/Lab/Updates_in_stored_procedures_LG_v2_0_09_23.ipynb
+++ b/data/notebooks/Lab/Updates_in_stored_procedures_LG_v2_0_09_23.ipynb
@@ -80,7 +80,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 4,
"id": "ec6f1dba",
"metadata": {},
"outputs": [],
@@ -94,7 +94,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 5,
"id": "a1fcf162",
"metadata": {},
"outputs": [],
@@ -129,7 +129,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 6,
"id": "bc136206",
"metadata": {},
"outputs": [],
@@ -145,7 +145,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 7,
"id": "1f72adc5",
"metadata": {},
"outputs": [],
@@ -365,7 +365,86 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 13,
+ "id": "e16128ce",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "## Write query for new GHG emissions farm indicator\n",
+ "\n",
+ "SQL_GET_H3_TABLE_COLUMN_FOR_MATERIAL_INDICATORS = \"\"\"\n",
+ "CREATE OR REPLACE FUNCTION get_h3_table_column_for_material_indicators(nameCode text, \n",
+ "materialId uuid)\n",
+ "RETURNS TABLE (h3_table_name varchar, h3_column_name varchar, h3_resolution int) AS\n",
+ "$$\n",
+ " SELECT h3_data.\"h3tableName\", h3_data.\"h3columnName\", h3_data.\"h3resolution\"\n",
+ " FROM h3_data\n",
+ " INNER JOIN \"material_indicator_to_h3\" mith ON mith.\"h3DataId\" = h3_data.\"id\"\n",
+ " INNER JOIN \"indicator\" i ON i.\"id\" = mith.\"indicatorId\"\n",
+ " WHERE i.\"nameCode\" = nameCode \n",
+ " AND mith.\"materialId\" = materialId\n",
+ " LIMIT 1;\n",
+ "$$\n",
+ "LANGUAGE SQL;\n",
+ "\"\"\"\n",
+ "\n",
+ "## UPDATED DEFORESTATION, CLIMATE RISK FORMULAS/CARBON, NATURAL CONVERSION:\n",
+ "## This query is also used for the TARGET INDICATORS:\n",
+ "##UNSUSTAINABLE WATER USE AND NUTRIENT LOAD REDUCTION\n",
+ "SQL_GET_ANNUAL_COMMODITY_WEIGHTED_MATERIAL_IMPACT_OVER_GEO_REGION = (\n",
+ " SQL_GET_H3_TABLE_COLUMN_FOR_MATERIAL_INDICATORS\n",
+ " + SQL_GET_H3_TABLE_COLUMN_FOR_MATERIAL\n",
+ " + \"\"\"\n",
+ "CREATE OR REPLACE FUNCTION get_annual_commodity_weighted_material_impact_over_georegion(\n",
+ " geo_region_id uuid,\n",
+ " nameCode text,\n",
+ " material_id uuid,\n",
+ " h3_data_type material_to_h3_type_enum\n",
+ ")\n",
+ "RETURNS float AS\n",
+ "$$\n",
+ " DECLARE\n",
+ " h3_resolution integer;\n",
+ " indicator_h3_table_name varchar;\n",
+ " indicator_h3_column_name varchar;\n",
+ " h3_indicator_resolution varchar;\n",
+ " material_h3_table_name varchar;\n",
+ " material_h3_column_name varchar;\n",
+ " sum float;\n",
+ " BEGIN\n",
+ " \n",
+ " -- Get h3data table name, column for material indicator\n",
+ " SELECT * INTO indicator_h3_table_name, indicator_h3_column_name, h3_indicator_resolution\n",
+ " FROM get_h3_table_column_for_material_indicators(nameCode, material_id);\n",
+ " \n",
+ " -- Get h3data table name, column and resolution for the material production\n",
+ " SELECT * INTO material_h3_table_name, material_h3_column_name, h3_resolution\n",
+ " FROM get_h3_table_column_for_material(material_id, h3_data_type);\n",
+ " \n",
+ " -- Sum commodity weighted impact values\n",
+ " EXECUTE format(\n",
+ " 'SELECT sum(h3ind.%I * h3prod.%I )\n",
+ " FROM\n",
+ " get_h3_uncompact_geo_region($1, $2) geo_region\n",
+ " INNER JOIN %I h3ind ON h3ind.h3index = geo_region.h3index\n",
+ " INNER JOIN %I h3prod ON h3ind.h3index = h3prod.h3index;\n",
+ " ', indicator_h3_column_name,\n",
+ " material_h3_column_name,\n",
+ " indicator_h3_table_name,\n",
+ " material_h3_table_name)\n",
+ " USING geo_region_id, h3_resolution\n",
+ " INTO sum;\n",
+ " RETURN sum;\n",
+ " END;\n",
+ "$$\n",
+ "LANGUAGE plpgsql;\n",
+ "\"\"\"\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
"id": "0235fafe",
"metadata": {},
"outputs": [
@@ -373,7 +452,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
- "/tmp/ipykernel_35166/4203819147.py:1: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
+ "/tmp/ipykernel_17293/4203819147.py:1: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
" pd.read_sql_query(\"\"\"SELECT * FROM indicator\"\"\", conn)\n"
]
},
@@ -411,6 +490,17 @@
"
\n",
" \n",
" 0 | \n",
+ " 936d0a9f-fe48-42b4-9433-63282d4dada5 | \n",
+ " Deforestation footprint (sLUC) | \n",
+ " Deforestation footprint (sLUC) | \n",
+ " DF_SLUC | \n",
+ " The deforestation footprint (sLUC) indicator q... | \n",
+ " active | \n",
+ " {'name': 'Deforestation footprint (sLUC)', 'un... | \n",
+ " 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
" 157b5f22-916b-4981-84c7-f6607ec65445 | \n",
" GHG emissions from deforestation (sLUC) | \n",
" GHGs (deforestation, sLUC) | \n",
@@ -421,7 +511,18 @@
" a0e8110c-fbde-4c8c-ac19-f0f69078b96b | \n",
"
\n",
" \n",
- " 1 | \n",
+ " 2 | \n",
+ " 3a718205-10c1-4e11-81b3-cb8965e378c7 | \n",
+ " Biodiversity importance of natural ecosystems ... | \n",
+ " Forest landscape integrity loss | \n",
+ " FLIL | \n",
+ " The biodiversity importance of natural ecosyst... | \n",
+ " active | \n",
+ " {'name': 'Biodiversity importance of natural e... | \n",
+ " 1129394b-6baa-41dd-9409-80d808dbc32e | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
" 1994e7bf-5442-4061-ba48-6320574263ad | \n",
" GHG emissions from farm management | \n",
" GHGs (farm management) | \n",
@@ -432,18 +533,18 @@
" a0e8110c-fbde-4c8c-ac19-f0f69078b96b | \n",
"
\n",
" \n",
- " 2 | \n",
- " 9c2124c7-5df0-40d5-962e-d35480d48cd3 | \n",
- " Surface or groundwater use | \n",
- " Water use | \n",
- " WU | \n",
- " The surface or groundwater use indicator estim... | \n",
+ " 4 | \n",
+ " 5c595ac7-f144-485f-9f32-601f6faae9fe | \n",
+ " Land use footprint for production | \n",
+ " Land footprint | \n",
+ " LF | \n",
+ " The land use footprint for production indicato... | \n",
" active | \n",
- " {'name': 'Surface or groundwater use', 'units'... | \n",
- " 9c0da38a-6371-4c79-879b-218fc39c4700 | \n",
+ " {'name': 'Land use footprint for production', ... | \n",
+ " 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 | \n",
"
\n",
" \n",
- " 3 | \n",
+ " 5 | \n",
" ffdd6f19-6737-4a10-9d36-5243d3f14b45 | \n",
" Excess surface or groundwater use | \n",
" Unsustainable water use | \n",
@@ -454,18 +555,7 @@
" 9c0da38a-6371-4c79-879b-218fc39c4700 | \n",
"
\n",
" \n",
- " 4 | \n",
- " 3a718205-10c1-4e11-81b3-cb8965e378c7 | \n",
- " Biodiversity importance of natural ecosystems ... | \n",
- " Forest landscape integrity loss | \n",
- " FLIL | \n",
- " The biodiversity importance of natural ecosyst... | \n",
- " active | \n",
- " {'name': 'Biodiversity importance of natural e... | \n",
- " 1129394b-6baa-41dd-9409-80d808dbc32e | \n",
- "
\n",
- " \n",
- " 5 | \n",
+ " 6 | \n",
" a39394be-ad57-41bc-9c2c-be0949ec6193 | \n",
" Excess freshwater nutrient load assimilation v... | \n",
" Excess nutrient load | \n",
@@ -476,29 +566,29 @@
" 9c0da38a-6371-4c79-879b-218fc39c4700 | \n",
"
\n",
" \n",
- " 6 | \n",
- " 936d0a9f-fe48-42b4-9433-63282d4dada5 | \n",
- " Deforestation footprint (sLUC) | \n",
- " Deforestation footprint (sLUC) | \n",
- " DF_SLUC | \n",
- " The deforestation footprint (sLUC) indicator q... | \n",
+ " 7 | \n",
+ " 5c133ba4-da24-46db-9c6c-ece7520f01b0 | \n",
+ " Cropland expansion in natural ecosystems | \n",
+ " Net cropland expansion | \n",
+ " NCE | \n",
+ " The annual average area of cropland expansion ... | \n",
" active | \n",
- " {'name': 'Deforestation footprint (sLUC)', 'un... | \n",
+ " {'name': 'Cropland expansion in natural ecosys... | \n",
" 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 | \n",
"
\n",
" \n",
- " 7 | \n",
- " 5c595ac7-f144-485f-9f32-601f6faae9fe | \n",
- " Land use footprint for production | \n",
- " Land footprint | \n",
- " LF | \n",
- " The land use footprint for production indicato... | \n",
+ " 8 | \n",
+ " 9c2124c7-5df0-40d5-962e-d35480d48cd3 | \n",
+ " Surface or groundwater use | \n",
+ " Water use | \n",
+ " WU | \n",
+ " The surface or groundwater use indicator estim... | \n",
" active | \n",
- " {'name': 'Land use footprint for production', ... | \n",
- " 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 | \n",
+ " {'name': 'Surface or groundwater use', 'units'... | \n",
+ " 9c0da38a-6371-4c79-879b-218fc39c4700 | \n",
"
\n",
" \n",
- " 8 | \n",
+ " 9 | \n",
" d5f945c9-8636-45a2-a7c9-67a1dc8e687a | \n",
" Freshwater nutrient load assimilation volume | \n",
" Nutrient load | \n",
@@ -508,96 +598,85 @@
" {'name': 'Freshwater nutrient load assimilatio... | \n",
" 9c0da38a-6371-4c79-879b-218fc39c4700 | \n",
"
\n",
- " \n",
- " 9 | \n",
- " 5c133ba4-da24-46db-9c6c-ece7520f01b0 | \n",
- " Cropland expansion in natural ecosystems | \n",
- " Net cropland expansion | \n",
- " NCE | \n",
- " The annual average area of cropland expansion ... | \n",
- " active | \n",
- " {'name': 'Cropland expansion in natural ecosys... | \n",
- " 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 | \n",
- "
\n",
" \n",
"\n",
""
],
"text/plain": [
" id \\\n",
- "0 157b5f22-916b-4981-84c7-f6607ec65445 \n",
- "1 1994e7bf-5442-4061-ba48-6320574263ad \n",
- "2 9c2124c7-5df0-40d5-962e-d35480d48cd3 \n",
- "3 ffdd6f19-6737-4a10-9d36-5243d3f14b45 \n",
- "4 3a718205-10c1-4e11-81b3-cb8965e378c7 \n",
- "5 a39394be-ad57-41bc-9c2c-be0949ec6193 \n",
- "6 936d0a9f-fe48-42b4-9433-63282d4dada5 \n",
- "7 5c595ac7-f144-485f-9f32-601f6faae9fe \n",
- "8 d5f945c9-8636-45a2-a7c9-67a1dc8e687a \n",
- "9 5c133ba4-da24-46db-9c6c-ece7520f01b0 \n",
+ "0 936d0a9f-fe48-42b4-9433-63282d4dada5 \n",
+ "1 157b5f22-916b-4981-84c7-f6607ec65445 \n",
+ "2 3a718205-10c1-4e11-81b3-cb8965e378c7 \n",
+ "3 1994e7bf-5442-4061-ba48-6320574263ad \n",
+ "4 5c595ac7-f144-485f-9f32-601f6faae9fe \n",
+ "5 ffdd6f19-6737-4a10-9d36-5243d3f14b45 \n",
+ "6 a39394be-ad57-41bc-9c2c-be0949ec6193 \n",
+ "7 5c133ba4-da24-46db-9c6c-ece7520f01b0 \n",
+ "8 9c2124c7-5df0-40d5-962e-d35480d48cd3 \n",
+ "9 d5f945c9-8636-45a2-a7c9-67a1dc8e687a \n",
"\n",
" name \\\n",
- "0 GHG emissions from deforestation (sLUC) \n",
- "1 GHG emissions from farm management \n",
- "2 Surface or groundwater use \n",
- "3 Excess surface or groundwater use \n",
- "4 Biodiversity importance of natural ecosystems ... \n",
- "5 Excess freshwater nutrient load assimilation v... \n",
- "6 Deforestation footprint (sLUC) \n",
- "7 Land use footprint for production \n",
- "8 Freshwater nutrient load assimilation volume \n",
- "9 Cropland expansion in natural ecosystems \n",
+ "0 Deforestation footprint (sLUC) \n",
+ "1 GHG emissions from deforestation (sLUC) \n",
+ "2 Biodiversity importance of natural ecosystems ... \n",
+ "3 GHG emissions from farm management \n",
+ "4 Land use footprint for production \n",
+ "5 Excess surface or groundwater use \n",
+ "6 Excess freshwater nutrient load assimilation v... \n",
+ "7 Cropland expansion in natural ecosystems \n",
+ "8 Surface or groundwater use \n",
+ "9 Freshwater nutrient load assimilation volume \n",
"\n",
" shortName nameCode \\\n",
- "0 GHGs (deforestation, sLUC) GHG_DEF_SLUC \n",
- "1 GHGs (farm management) GHG_FARM \n",
- "2 Water use WU \n",
- "3 Unsustainable water use UWU \n",
- "4 Forest landscape integrity loss FLIL \n",
- "5 Excess nutrient load ENL \n",
- "6 Deforestation footprint (sLUC) DF_SLUC \n",
- "7 Land footprint LF \n",
- "8 Nutrient load NL \n",
- "9 Net cropland expansion NCE \n",
+ "0 Deforestation footprint (sLUC) DF_SLUC \n",
+ "1 GHGs (deforestation, sLUC) GHG_DEF_SLUC \n",
+ "2 Forest landscape integrity loss FLIL \n",
+ "3 GHGs (farm management) GHG_FARM \n",
+ "4 Land footprint LF \n",
+ "5 Unsustainable water use UWU \n",
+ "6 Excess nutrient load ENL \n",
+ "7 Net cropland expansion NCE \n",
+ "8 Water use WU \n",
+ "9 Nutrient load NL \n",
"\n",
" description status \\\n",
- "0 The GHG emissions from deforestation (sLUC) in... active \n",
- "1 The GHG emissions from farm management indicat... inactive \n",
- "2 The surface or groundwater use indicator estim... active \n",
- "3 The excess surface or groundwater use indicato... active \n",
- "4 The biodiversity importance of natural ecosyst... active \n",
- "5 The excess freshwater nutrient load assimilati... active \n",
- "6 The deforestation footprint (sLUC) indicator q... active \n",
- "7 The land use footprint for production indicato... active \n",
- "8 The freshwater nutrient load assimilation volu... active \n",
- "9 The annual average area of cropland expansion ... active \n",
+ "0 The deforestation footprint (sLUC) indicator q... active \n",
+ "1 The GHG emissions from deforestation (sLUC) in... active \n",
+ "2 The biodiversity importance of natural ecosyst... active \n",
+ "3 The GHG emissions from farm management indicat... inactive \n",
+ "4 The land use footprint for production indicato... active \n",
+ "5 The excess surface or groundwater use indicato... active \n",
+ "6 The excess freshwater nutrient load assimilati... active \n",
+ "7 The annual average area of cropland expansion ... active \n",
+ "8 The surface or groundwater use indicator estim... active \n",
+ "9 The freshwater nutrient load assimilation volu... active \n",
"\n",
" metadata \\\n",
- "0 {'name': 'GHG emissions from deforestation (sL... \n",
- "1 {'name': 'GHG emissions from farm management',... \n",
- "2 {'name': 'Surface or groundwater use', 'units'... \n",
- "3 {'name': 'Excess surface or groundwater use', ... \n",
- "4 {'name': 'Biodiversity importance of natural e... \n",
- "5 {'name': 'Excess freshwater nutrient load assi... \n",
- "6 {'name': 'Deforestation footprint (sLUC)', 'un... \n",
- "7 {'name': 'Land use footprint for production', ... \n",
- "8 {'name': 'Freshwater nutrient load assimilatio... \n",
- "9 {'name': 'Cropland expansion in natural ecosys... \n",
+ "0 {'name': 'Deforestation footprint (sLUC)', 'un... \n",
+ "1 {'name': 'GHG emissions from deforestation (sL... \n",
+ "2 {'name': 'Biodiversity importance of natural e... \n",
+ "3 {'name': 'GHG emissions from farm management',... \n",
+ "4 {'name': 'Land use footprint for production', ... \n",
+ "5 {'name': 'Excess surface or groundwater use', ... \n",
+ "6 {'name': 'Excess freshwater nutrient load assi... \n",
+ "7 {'name': 'Cropland expansion in natural ecosys... \n",
+ "8 {'name': 'Surface or groundwater use', 'units'... \n",
+ "9 {'name': 'Freshwater nutrient load assimilatio... \n",
"\n",
" unitId \n",
- "0 a0e8110c-fbde-4c8c-ac19-f0f69078b96b \n",
+ "0 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 \n",
"1 a0e8110c-fbde-4c8c-ac19-f0f69078b96b \n",
- "2 9c0da38a-6371-4c79-879b-218fc39c4700 \n",
- "3 9c0da38a-6371-4c79-879b-218fc39c4700 \n",
- "4 1129394b-6baa-41dd-9409-80d808dbc32e \n",
+ "2 1129394b-6baa-41dd-9409-80d808dbc32e \n",
+ "3 a0e8110c-fbde-4c8c-ac19-f0f69078b96b \n",
+ "4 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 \n",
"5 9c0da38a-6371-4c79-879b-218fc39c4700 \n",
- "6 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 \n",
+ "6 9c0da38a-6371-4c79-879b-218fc39c4700 \n",
"7 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 \n",
"8 9c0da38a-6371-4c79-879b-218fc39c4700 \n",
- "9 6970f9b8-eba0-4fee-b6ee-2723ce6604d4 "
+ "9 9c0da38a-6371-4c79-879b-218fc39c4700 "
]
},
- "execution_count": 5,
+ "execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
@@ -608,7 +687,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 16,
"id": "d189912f",
"metadata": {},
"outputs": [
@@ -616,8 +695,8 @@
"name": "stderr",
"output_type": "stream",
"text": [
- "/tmp/ipykernel_35166/981770809.py:1: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
- " sourcing_records = pd.read_sql_query(\"\"\"\n"
+ "/tmp/ipykernel_17293/2847287075.py:1: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
+ " sourcing_records = pd.read_sql_query( SQL_GET_ANNUAL_COMMODITY_WEIGHTED_MATERIAL_IMPACT_OVER_GEO_REGION +\n"
]
},
{
@@ -658,8 +737,8 @@
" \n",
" \n",
" 0 | \n",
- " efee8975-84fb-4aec-94e7-938da662f17d | \n",
- " 3234.0 | \n",
+ " cd61b61e-bed0-47a7-8ae4-b129a3929c2f | \n",
+ " 1101.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -673,8 +752,8 @@
"
\n",
" \n",
" 1 | \n",
- " 5c830838-d035-437d-859d-5d8a34399bc4 | \n",
- " 4328.0 | \n",
+ " cc9c4e0c-3bdb-4bc0-8c21-7841f2879819 | \n",
+ " 7298.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -688,8 +767,8 @@
"
\n",
" \n",
" 2 | \n",
- " f8887f90-f675-42bb-b0be-f176c0358862 | \n",
- " 2260.0 | \n",
+ " ced1f2ce-76ce-43af-b31d-61a34d3cc04c | \n",
+ " 7807.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -703,8 +782,8 @@
"
\n",
" \n",
" 3 | \n",
- " aa7416c7-3f6a-4da3-a2ac-11e7faef960c | \n",
- " 2191.0 | \n",
+ " 732104e5-65df-4635-8581-4e601bf3618c | \n",
+ " 9480.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -718,8 +797,8 @@
"
\n",
" \n",
" 4 | \n",
- " 530bf195-a3db-42c0-a3f4-a0a7d490cb3f | \n",
- " 2344.0 | \n",
+ " 7085e20c-6351-48e7-bb36-3c54303d105d | \n",
+ " 2696.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -737,11 +816,11 @@
],
"text/plain": [
" id tonnage production harvest \\\n",
- "0 efee8975-84fb-4aec-94e7-938da662f17d 3234.0 0.0 0.0 \n",
- "1 5c830838-d035-437d-859d-5d8a34399bc4 4328.0 0.0 0.0 \n",
- "2 f8887f90-f675-42bb-b0be-f176c0358862 2260.0 0.0 0.0 \n",
- "3 aa7416c7-3f6a-4da3-a2ac-11e7faef960c 2191.0 0.0 0.0 \n",
- "4 530bf195-a3db-42c0-a3f4-a0a7d490cb3f 2344.0 0.0 0.0 \n",
+ "0 cd61b61e-bed0-47a7-8ae4-b129a3929c2f 1101.0 0.0 0.0 \n",
+ "1 cc9c4e0c-3bdb-4bc0-8c21-7841f2879819 7298.0 0.0 0.0 \n",
+ "2 ced1f2ce-76ce-43af-b31d-61a34d3cc04c 7807.0 0.0 0.0 \n",
+ "3 732104e5-65df-4635-8581-4e601bf3618c 9480.0 0.0 0.0 \n",
+ "4 7085e20c-6351-48e7-bb36-3c54303d105d 2696.0 0.0 0.0 \n",
"\n",
" raw_def_footprint_per_tonne_annual \\\n",
"0 0.0 \n",
@@ -779,14 +858,15 @@
"4 0.0 "
]
},
- "execution_count": 6,
+ "execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sourcing_records = pd.read_sql_query(\n",
- " \"\"\"\n",
+ " SQL_GET_ANNUAL_COMMODITY_WEIGHTED_MATERIAL_IMPACT_OVER_GEO_REGION\n",
+ " + \"\"\"\n",
" SELECT \n",
" sr.id,\n",
" sr.tonnage,\n",
@@ -800,6 +880,7 @@
" sl.raw_uwu_per_tonne_annual,\n",
" sl.raw_nutrient_load,\n",
" sl.raw_enl_per_tonne_annual\n",
+ " --sl.raw_ghg_emissions_farm_per_tonne_annual\n",
" FROM \n",
" sourcing_records sr\n",
" INNER JOIN\n",
@@ -838,6 +919,9 @@
" get_indicator_coefficient_impact(\n",
" 'NL', \"adminRegionId\", \"materialId\"\n",
" ) raw_nutrient_load\n",
+ " --get_annual_commodity_weighted_material_impact_over_georegion(\n",
+ " -- \"geoRegionId\",'GHG_FARM', \"materialId\", 'producer'\n",
+ " --) raw_ghg_emissions_farm_per_tonne_annual\n",
" FROM\n",
" sourcing_location\n",
" ) AS sl\n",
@@ -851,7 +935,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 17,
"id": "8bfca8a5",
"metadata": {},
"outputs": [
@@ -893,8 +977,8 @@
"
\n",
" \n",
" 0 | \n",
- " efee8975-84fb-4aec-94e7-938da662f17d | \n",
- " 3234.0 | \n",
+ " cd61b61e-bed0-47a7-8ae4-b129a3929c2f | \n",
+ " 1101.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -908,8 +992,8 @@
"
\n",
" \n",
" 1 | \n",
- " 5c830838-d035-437d-859d-5d8a34399bc4 | \n",
- " 4328.0 | \n",
+ " cc9c4e0c-3bdb-4bc0-8c21-7841f2879819 | \n",
+ " 7298.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -923,8 +1007,8 @@
"
\n",
" \n",
" 2 | \n",
- " f8887f90-f675-42bb-b0be-f176c0358862 | \n",
- " 2260.0 | \n",
+ " ced1f2ce-76ce-43af-b31d-61a34d3cc04c | \n",
+ " 7807.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -938,8 +1022,8 @@
"
\n",
" \n",
" 3 | \n",
- " aa7416c7-3f6a-4da3-a2ac-11e7faef960c | \n",
- " 2191.0 | \n",
+ " 732104e5-65df-4635-8581-4e601bf3618c | \n",
+ " 9480.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -953,8 +1037,8 @@
"
\n",
" \n",
" 4 | \n",
- " 530bf195-a3db-42c0-a3f4-a0a7d490cb3f | \n",
- " 2344.0 | \n",
+ " 7085e20c-6351-48e7-bb36-3c54303d105d | \n",
+ " 2696.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -972,11 +1056,11 @@
],
"text/plain": [
" id tonnage production harvest \\\n",
- "0 efee8975-84fb-4aec-94e7-938da662f17d 3234.0 0.0 0.0 \n",
- "1 5c830838-d035-437d-859d-5d8a34399bc4 4328.0 0.0 0.0 \n",
- "2 f8887f90-f675-42bb-b0be-f176c0358862 2260.0 0.0 0.0 \n",
- "3 aa7416c7-3f6a-4da3-a2ac-11e7faef960c 2191.0 0.0 0.0 \n",
- "4 530bf195-a3db-42c0-a3f4-a0a7d490cb3f 2344.0 0.0 0.0 \n",
+ "0 cd61b61e-bed0-47a7-8ae4-b129a3929c2f 1101.0 0.0 0.0 \n",
+ "1 cc9c4e0c-3bdb-4bc0-8c21-7841f2879819 7298.0 0.0 0.0 \n",
+ "2 ced1f2ce-76ce-43af-b31d-61a34d3cc04c 7807.0 0.0 0.0 \n",
+ "3 732104e5-65df-4635-8581-4e601bf3618c 9480.0 0.0 0.0 \n",
+ "4 7085e20c-6351-48e7-bb36-3c54303d105d 2696.0 0.0 0.0 \n",
"\n",
" raw_def_footprint_per_tonne_annual \\\n",
"0 0.0 \n",
@@ -1014,7 +1098,7 @@
"4 0.0 "
]
},
- "execution_count": 7,
+ "execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
@@ -1025,7 +1109,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 18,
"id": "88a48719",
"metadata": {},
"outputs": [
@@ -1076,8 +1160,8 @@
"
\n",
" \n",
" 0 | \n",
- " efee8975-84fb-4aec-94e7-938da662f17d | \n",
- " 3234.0 | \n",
+ " cd61b61e-bed0-47a7-8ae4-b129a3929c2f | \n",
+ " 1101.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -1100,8 +1184,8 @@
"
\n",
" \n",
" 1 | \n",
- " 5c830838-d035-437d-859d-5d8a34399bc4 | \n",
- " 4328.0 | \n",
+ " cc9c4e0c-3bdb-4bc0-8c21-7841f2879819 | \n",
+ " 7298.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -1124,8 +1208,8 @@
"
\n",
" \n",
" 2 | \n",
- " f8887f90-f675-42bb-b0be-f176c0358862 | \n",
- " 2260.0 | \n",
+ " ced1f2ce-76ce-43af-b31d-61a34d3cc04c | \n",
+ " 7807.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -1148,8 +1232,8 @@
"
\n",
" \n",
" 3 | \n",
- " aa7416c7-3f6a-4da3-a2ac-11e7faef960c | \n",
- " 2191.0 | \n",
+ " 732104e5-65df-4635-8581-4e601bf3618c | \n",
+ " 9480.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -1172,8 +1256,8 @@
"
\n",
" \n",
" 4 | \n",
- " 530bf195-a3db-42c0-a3f4-a0a7d490cb3f | \n",
- " 2344.0 | \n",
+ " 7085e20c-6351-48e7-bb36-3c54303d105d | \n",
+ " 2696.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
@@ -1201,11 +1285,11 @@
],
"text/plain": [
" id tonnage production harvest \\\n",
- "0 efee8975-84fb-4aec-94e7-938da662f17d 3234.0 0.0 0.0 \n",
- "1 5c830838-d035-437d-859d-5d8a34399bc4 4328.0 0.0 0.0 \n",
- "2 f8887f90-f675-42bb-b0be-f176c0358862 2260.0 0.0 0.0 \n",
- "3 aa7416c7-3f6a-4da3-a2ac-11e7faef960c 2191.0 0.0 0.0 \n",
- "4 530bf195-a3db-42c0-a3f4-a0a7d490cb3f 2344.0 0.0 0.0 \n",
+ "0 cd61b61e-bed0-47a7-8ae4-b129a3929c2f 1101.0 0.0 0.0 \n",
+ "1 cc9c4e0c-3bdb-4bc0-8c21-7841f2879819 7298.0 0.0 0.0 \n",
+ "2 ced1f2ce-76ce-43af-b31d-61a34d3cc04c 7807.0 0.0 0.0 \n",
+ "3 732104e5-65df-4635-8581-4e601bf3618c 9480.0 0.0 0.0 \n",
+ "4 7085e20c-6351-48e7-bb36-3c54303d105d 2696.0 0.0 0.0 \n",
"\n",
" raw_def_footprint_per_tonne_annual \\\n",
"0 0.0 \n",
@@ -1259,7 +1343,7 @@
"[5 rows x 26 columns]"
]
},
- "execution_count": 14,
+ "execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
@@ -1291,6 +1375,18 @@
" sourcing_records[\"raw_emissions\"] * sourcing_records[\"land_footprint\"]\n",
")\n",
"\n",
+ "# GHG EMISSIONS FARM:\n",
+ "# 1. Calculate the total carbon emissions in georegion\n",
+ "# 2. Multiply the carbon emissions by the commodity production\n",
+ "# 3. Multiply that by the land footprint impact\n",
+ "# sourcing_records[\"raw_emissions_farm\"] = (\n",
+ "# sourcing_records[\"raw_ghg_emissions_farm_per_tonne_annual\"] / sourcing_records[\"production\"]\n",
+ "# )\n",
+ "# sourcing_records[\"ghg_emissions_farm\"] = (\n",
+ "# sourcing_records[\"raw_emissions_farm\"] * sourcing_records[\"tonnage\"]\n",
+ "# )\n",
+ "\n",
+ "\n",
"# NET CROPLAND EXPANAION\n",
"# 1. Calculate the total net cropland expansion by hectare of human land use\n",
"# 2. Multiply the net cropland expansion by the commodity production\n",