Skip to content

Commit

Permalink
Merge pull request #3029 from catalyst-cooperative/rename-heat-rate-m…
Browse files Browse the repository at this point in the history
…mbtu-mwh-column

Rename `heat_rate_mmbtu_mwh -> unit_heat_rate_mmbtu_per_mwh`... again
  • Loading branch information
bendnorman committed Nov 16, 2023
2 parents 4a2be6a + 7ef9c70 commit 1396ad8
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
"""Add unit_ to heat_rate_mmbtu_per_mwh
Revision ID: ccdf68a30cbd
Revises: 9edc4a11c809
Create Date: 2023-11-15 14:09:59.541894
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "ccdf68a30cbd"
down_revision = "9edc4a11c809"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table(
"_out_eia__monthly_derived_generator_attributes", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__monthly_fuel_cost_by_generator", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__monthly_heat_rate_by_generator", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__monthly_heat_rate_by_unit", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__yearly_derived_generator_attributes", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__yearly_fuel_cost_by_generator", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__yearly_heat_rate_by_generator", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"_out_eia__yearly_heat_rate_by_unit", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table("mega_generators_eia", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table("out_eia__monthly_generators", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table("out_eia__yearly_generators", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"out_eia__yearly_generators_by_ownership", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table("out_eia__yearly_plant_parts", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

with op.batch_alter_table(
"out_pudl__yearly_assn_eia_ferc1_plant_parts", schema=None
) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh_eia",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh_ferc1",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Calculated from FERC reported fuel consumption and net generation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh_eia")
batch_op.drop_column("heat_rate_mmbtu_mwh_ferc1")

with op.batch_alter_table("plant_parts_eia", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"unit_heat_rate_mmbtu_per_mwh",
sa.Float(),
nullable=True,
comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.",
)
)
batch_op.drop_column("heat_rate_mmbtu_mwh")

# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("plant_parts_eia", schema=None) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"out_pudl__yearly_assn_eia_ferc1_plant_parts", schema=None
) as batch_op:
batch_op.add_column(
sa.Column("heat_rate_mmbtu_mwh_ferc1", sa.FLOAT(), nullable=True)
)
batch_op.add_column(
sa.Column("heat_rate_mmbtu_mwh_eia", sa.FLOAT(), nullable=True)
)
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh_ferc1")
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh_eia")

with op.batch_alter_table("out_eia__yearly_plant_parts", schema=None) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"out_eia__yearly_generators_by_ownership", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table("out_eia__yearly_generators", schema=None) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table("out_eia__monthly_generators", schema=None) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table("mega_generators_eia", schema=None) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__yearly_heat_rate_by_unit", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__yearly_heat_rate_by_generator", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__yearly_fuel_cost_by_generator", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__yearly_derived_generator_attributes", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__monthly_heat_rate_by_unit", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__monthly_heat_rate_by_generator", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__monthly_fuel_cost_by_generator", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

with op.batch_alter_table(
"_out_eia__monthly_derived_generator_attributes", schema=None
) as batch_op:
batch_op.add_column(sa.Column("heat_rate_mmbtu_mwh", sa.FLOAT(), nullable=True))
batch_op.drop_column("unit_heat_rate_mmbtu_per_mwh")

# ### end Alembic commands ###
10 changes: 6 additions & 4 deletions src/pudl/analysis/eia_ferc1_record_linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def get_plants_ferc1(self, clobber: bool = False) -> pd.DataFrame:
x.plant_id_report_year + "_" + x.utility_id_pudl.map(str)
),
fuel_cost_per_mmbtu=lambda x: (x.fuel_cost / x.fuel_mmbtu),
heat_rate_mmbtu_mwh=lambda x: (x.fuel_mmbtu / x.net_generation_mwh),
unit_heat_rate_mmbtu_per_mwh=lambda x: (
x.fuel_mmbtu / x.net_generation_mwh
),
)
.rename(
columns={
Expand Down Expand Up @@ -419,9 +421,9 @@ def make_features(
label="fuel_cost_per_mmbtu",
),
Numeric(
"heat_rate_mmbtu_mwh",
"heat_rate_mmbtu_mwh",
label="heat_rate_mmbtu_mwh",
"unit_heat_rate_mmbtu_per_mwh",
"unit_heat_rate_mmbtu_per_mwh",
label="unit_heat_rate_mmbtu_per_mwh",
),
Exact(
"fuel_type_code_pudl",
Expand Down
2 changes: 1 addition & 1 deletion src/pudl/analysis/eia_ferc1_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"total_fuel_cost",
"total_mmbtu",
"fuel_cost_per_mmbtu",
"heat_rate_mmbtu_mwh",
"unit_heat_rate_mmbtu_per_mwh",
]

# --------------------------------------------------------------------------------------
Expand Down

0 comments on commit 1396ad8

Please sign in to comment.