Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 2022 data #322

Merged
merged 16 commits into from
Dec 27, 2023
354 changes: 354 additions & 0 deletions notebooks/explore_methods/test_allocate_gen_fuel.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### About\n",
"This notebook can be used to explore the processing steps in `pudl.analysis.allocate_gen_fuel`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"import oge.load_data as load_data\n",
"\n",
"from pudl.analysis import allocate_gen_fuel\n",
"\n",
"year = 2022"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# pick a plant to investigate\n",
"plant_to_investigate = 47"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gf = load_data.load_pudl_table(\"denorm_generation_fuel_combined_eia923\", year)\n",
"bf = load_data.load_pudl_table(\"denorm_boiler_fuel_eia923\", year)\n",
"gen = load_data.load_pudl_table(\"denorm_generation_eia923\", year)\n",
"gens = load_data.load_pudl_table(\"denorm_generators_eia\", year)\n",
"bga = load_data.load_pudl_table(\"boiler_generator_assn_eia860\", year)\n",
"\n",
"gf, bf, gen, bga, gens = allocate_gen_fuel.select_input_data(\n",
" gf=gf, bf=bf, gen=gen, bga=bga, gens=gens\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bf[bf[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gen[gen[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gf[gf[\"plant_id_eia\"] == plant_to_investigate][[\"fuel_consumed_mmbtu\"]].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gf[gf[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"freq = \"MS\"\n",
"bf, gens_at_freq, gen = allocate_gen_fuel.standardize_input_frequency(\n",
" bf, gens, gen, freq\n",
")\n",
"# Add any startup energy source codes to the list of energy source codes\n",
"gens_at_freq = allocate_gen_fuel.adjust_msw_energy_source_codes(gens_at_freq, gf, bf)\n",
"gens_at_freq = allocate_gen_fuel.add_missing_energy_source_codes_to_gens(\n",
" gens_at_freq, gf, bf\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gens_at_freq[gens_at_freq[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gen_assoc = allocate_gen_fuel.associate_generator_tables(\n",
" gens=gens_at_freq, gf=gf, gen=gen, bf=bf, bga=bga\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gen_assoc[gen_assoc[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Generate a fraction to use to allocate net generation and fuel consumption by.\n",
"# These two methods create a column called `frac`, which will be a fraction\n",
"# to allocate net generation from the gf table for each `IDX_PM_ESC` group\n",
"gen_pm_fuel = allocate_gen_fuel.prep_alloction_fraction(gen_assoc)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gen_pm_fuel[gen_pm_fuel[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Net gen allocation\n",
"net_gen_alloc = allocate_gen_fuel.allocate_gen_fuel_by_gen_esc(gen_pm_fuel).pipe(\n",
" allocate_gen_fuel._test_gen_pm_fuel_output, gf=gf, gen=gen\n",
")\n",
"allocate_gen_fuel.test_gen_fuel_allocation(gen, net_gen_alloc)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"net_gen_alloc[net_gen_alloc[\"plant_id_eia\"] == plant_to_investigate][\n",
" [\"net_generation_mwh\"]\n",
"].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gf[gf[\"plant_id_eia\"] == plant_to_investigate][[\"net_generation_mwh\"]].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gf_923 = load_data.load_pudl_table(\"generation_fuel_eia923\", year)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gf_923[gf_923[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"net_gen_alloc[net_gen_alloc[\"plant_id_eia\"] == plant_to_investigate].groupby(\n",
" [\n",
" \"report_date\",\n",
" \"plant_id_eia\",\n",
" \"prime_mover_code\",\n",
" \"energy_source_code\",\n",
" ]\n",
")[\"net_generation_mwh\"].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(\n",
" net_gen_alloc[net_gen_alloc[\"plant_id_eia\"] == plant_to_investigate]\n",
" .groupby(\n",
" [\n",
" \"report_date\",\n",
" \"plant_id_eia\",\n",
" \"prime_mover_code\",\n",
" \"energy_source_code\",\n",
" ]\n",
" )[\"net_generation_mwh\"]\n",
" .sum()\n",
" - gf[gf[\"plant_id_eia\"] == plant_to_investigate]\n",
" .groupby(\n",
" [\n",
" \"report_date\",\n",
" \"plant_id_eia\",\n",
" \"prime_mover_code\",\n",
" \"energy_source_code\",\n",
" ]\n",
" )[\"net_generation_mwh\"]\n",
" .sum()\n",
").head(50)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# fuel allocation\n",
"fuel_alloc = allocate_gen_fuel.allocate_fuel_by_gen_esc(gen_pm_fuel)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# check total fuel after allocation\n",
"fuel_alloc[fuel_alloc[\"plant_id_eia\"] == plant_to_investigate][\n",
" [\"fuel_consumed_mmbtu\"]\n",
"].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fuel_alloc[fuel_alloc[\"plant_id_eia\"] == plant_to_investigate]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# check that allocation fractions sum to 1\n",
"fuel_alloc[fuel_alloc[\"plant_id_eia\"] == plant_to_investigate].groupby(\n",
" [\n",
" \"report_date\",\n",
" \"plant_id_eia\",\n",
" \"prime_mover_code\",\n",
" \"energy_source_code\",\n",
" ]\n",
")[\"frac\"].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# see where tehre is a difference between inputs and outputs\n",
"(\n",
" fuel_alloc[fuel_alloc[\"plant_id_eia\"] == plant_to_investigate]\n",
" .groupby(\n",
" [\n",
" \"report_date\",\n",
" \"plant_id_eia\",\n",
" \"prime_mover_code\",\n",
" \"energy_source_code\",\n",
" ]\n",
" )[\"fuel_consumed_mmbtu\"]\n",
" .sum()\n",
" - gf[gf[\"plant_id_eia\"] == plant_to_investigate]\n",
" .groupby(\n",
" [\n",
" \"report_date\",\n",
" \"plant_id_eia\",\n",
" \"prime_mover_code\",\n",
" \"energy_source_code\",\n",
" ]\n",
" )[\"fuel_consumed_mmbtu\"]\n",
" .sum()\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "open-grid-emissions-QkuIZ37I",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion notebooks/manual_data/default_fuel_sulfur_content.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.11.4"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
Loading
Loading