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

Rename heat_rate_mmbtu_mwh -> unit_heat_rate_mmbtu_per_mwh... again #3029

Merged
merged 7 commits into from
Nov 16, 2023
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
Loading
Loading