From d61005d497cfa9e81fb28e8a18316046aec854fd Mon Sep 17 00:00:00 2001 From: bendnorman Date: Wed, 4 Oct 2023 08:37:45 +0200 Subject: [PATCH 1/6] Rename heat_rate_mmbtu_mwh -> heat_rate_mmbtu_mwh_by_unit --- ...ename_heat_rate_mmbtu_mwh_to_heat_rate_.py | 121 ++++++++++++++++++ src/pudl/analysis/eia_ferc1_record_linkage.py | 24 +++- src/pudl/analysis/eia_ferc1_train.py | 2 +- src/pudl/analysis/mcoe.py | 25 ++-- src/pudl/analysis/plant_parts_eia.py | 2 +- src/pudl/metadata/fields.py | 2 +- src/pudl/metadata/resources/eia.py | 4 +- src/pudl/metadata/resources/mcoe.py | 10 +- src/pudl/validate.py | 12 +- test/unit/analysis/plant_parts_eia_test.py | 4 +- 10 files changed, 172 insertions(+), 34 deletions(-) create mode 100644 migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py diff --git a/migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py b/migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py new file mode 100644 index 0000000000..e5e2f9d299 --- /dev/null +++ b/migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py @@ -0,0 +1,121 @@ +"""Rename heat_rate_mmbtu_mwh to heat_rate_mmbtu_mwh_by_unit + +Revision ID: c415b55c4dcf +Revises: ab0540a6484c +Create Date: 2023-10-04 08:08:23.744433 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'c415b55c4dcf' +down_revision = 'ab0540a6484c' +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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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__plant_parts', schema=None) as batch_op: + batch_op.add_column(sa.Column('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + with op.batch_alter_table('out_eia__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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + 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('heat_rate_mmbtu_mwh_by_unit') + + # ### end Alembic commands ### diff --git a/src/pudl/analysis/eia_ferc1_record_linkage.py b/src/pudl/analysis/eia_ferc1_record_linkage.py index 874342202f..786e19d047 100644 --- a/src/pudl/analysis/eia_ferc1_record_linkage.py +++ b/src/pudl/analysis/eia_ferc1_record_linkage.py @@ -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), + heat_rate_mmbtu_mwh_by_unit=lambda x: ( + x.fuel_mmbtu / x.net_generation_mwh + ), ) .rename( columns={ @@ -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", + "heat_rate_mmbtu_mwh_by_unit", + "heat_rate_mmbtu_mwh_by_unit", + label="heat_rate_mmbtu_mwh_by_unit", ), Exact( "fuel_type_code_pudl", @@ -816,6 +818,20 @@ def prettyify_best_matches( and FERC plant data. This removes the comparison vectors (the floats between 0 and 1 that compare the two columns from each dataset). """ + # if utility_id_pudl is not in the `PPE_COLS`, we need to include it + ppe_cols_to_grab = pudl.analysis.plant_parts_eia.PPE_COLS + [ + "plant_id_pudl", + "total_fuel_cost", + "fuel_cost_per_mmbtu", + "net_generation_mwh", + "capacity_mw", + "capacity_factor", + "total_mmbtu", + "heat_rate_mmbtu_mwh_by_unit", + "fuel_type_code_pudl", + "installation_year", + "plant_part_id_eia", + ] connects_ferc1_eia = ( # first merge in the EIA plant-parts pd.merge( diff --git a/src/pudl/analysis/eia_ferc1_train.py b/src/pudl/analysis/eia_ferc1_train.py index f441219b3f..0a9911a0cb 100644 --- a/src/pudl/analysis/eia_ferc1_train.py +++ b/src/pudl/analysis/eia_ferc1_train.py @@ -103,7 +103,7 @@ "total_fuel_cost", "total_mmbtu", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", ] # -------------------------------------------------------------------------------------- diff --git a/src/pudl/analysis/mcoe.py b/src/pudl/analysis/mcoe.py index 8522d6abca..6b3f7b1bab 100644 --- a/src/pudl/analysis/mcoe.py +++ b/src/pudl/analysis/mcoe.py @@ -258,7 +258,7 @@ def heat_rate_by_unit(gen_fuel_by_energy_source: pd.DataFrame, bga: pd.DataFrame - unit_id_pudl - net_generation_mwh - fuel_consumed_for_electricity_mmbtu - - heat_rate_mmbtu_mwh + - heat_rate_mmbtu_mwh_by_unit """ gen_fuel_by_unit = pudl.helpers.date_merge( left=gen_fuel_by_energy_source, @@ -274,7 +274,7 @@ def heat_rate_by_unit(gen_fuel_by_energy_source: pd.DataFrame, bga: pd.DataFrame .sum() .convert_dtypes() .assign( - heat_rate_mmbtu_mwh=lambda x: x.fuel_consumed_for_electricity_mmbtu + heat_rate_mmbtu_mwh_by_unit=lambda x: x.fuel_consumed_for_electricity_mmbtu / x.net_generation_mwh ) ) @@ -299,7 +299,7 @@ def heat_rate_by_gen( Returns: DataFrame with columns report_date, plant_id_eia, unit_id_pudl, generator_id, - heat_rate_mmbtu_mwh, fuel_type_code_pudl, fuel_type_count, prime_mover_code. + heat_rate_mmbtu_mwh_by_unit, fuel_type_code_pudl, fuel_type_count, prime_mover_code. The output will have a time frequency corresponding to that of the input pudl_out. Output data types are set to their canonical values before returning. """ @@ -312,7 +312,7 @@ def heat_rate_by_gen( "report_date", "plant_id_eia", "unit_id_pudl", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", ], ] @@ -377,7 +377,7 @@ def fuel_cost( "generator_id", "unit_id_pudl", "report_date", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", ], ] gens = gens.loc[ @@ -488,7 +488,7 @@ def fuel_cost( "plant_id_eia", "report_date", "generator_id", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "fuel_cost_from_eiaapi", ] ], @@ -505,7 +505,7 @@ def fuel_cost( "report_date", "generator_id", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "fuel_cost_from_eiaapi", ] ] @@ -513,13 +513,14 @@ def fuel_cost( fc = ( pd.concat([one_fuel, multi_fuel], sort=True) .assign( - fuel_cost_per_mwh=lambda x: x.fuel_cost_per_mmbtu * x.heat_rate_mmbtu_mwh + fuel_cost_per_mwh=lambda x: x.fuel_cost_per_mmbtu + * x.heat_rate_mmbtu_mwh_by_unit ) .sort_values(["report_date", "plant_id_eia", "generator_id"]) ) out_df = ( - gen_w_ft.drop("heat_rate_mmbtu_mwh", axis=1) + gen_w_ft.drop("heat_rate_mmbtu_mwh_by_unit", axis=1) .drop_duplicates() .merge(fc, on=["report_date", "plant_id_eia", "generator_id"]) ) @@ -606,7 +607,7 @@ def mcoe( "unit_id_pudl", "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "fuel_cost_per_mwh", ], ], @@ -618,12 +619,12 @@ def mcoe( ) # Calculate a couple more derived values: .assign( - total_mmbtu=lambda x: x.net_generation_mwh * x.heat_rate_mmbtu_mwh, + total_mmbtu=lambda x: x.net_generation_mwh * x.heat_rate_mmbtu_mwh_by_unit, total_fuel_cost=lambda x: x.total_mmbtu * x.fuel_cost_per_mmbtu, ) .pipe( pudl.helpers.oob_to_nan_with_dependent_cols, - cols=["heat_rate_mmbtu_mwh"], + cols=["heat_rate_mmbtu_mwh_by_unit"], dependent_cols=["total_mmbtu", "fuel_cost_per_mwh"], lb=min_heat_rate, ub=None, diff --git a/src/pudl/analysis/plant_parts_eia.py b/src/pudl/analysis/plant_parts_eia.py index ff0a93d759..62c56bcc49 100644 --- a/src/pudl/analysis/plant_parts_eia.py +++ b/src/pudl/analysis/plant_parts_eia.py @@ -281,7 +281,7 @@ WTAVG_DICT = { "fuel_cost_per_mwh": "capacity_mw", - "heat_rate_mmbtu_mwh": "capacity_mw", + "heat_rate_mmbtu_mwh_by_unit": "capacity_mw", "fuel_cost_per_mmbtu": "capacity_mw", } """Dict: a dictionary of columns (keys) to perform weighted averages on and the weight diff --git a/src/pudl/metadata/fields.py b/src/pudl/metadata/fields.py index 56d1fb3bce..7cdf63577b 100644 --- a/src/pudl/metadata/fields.py +++ b/src/pudl/metadata/fields.py @@ -1231,7 +1231,7 @@ "description": "The energy contained in fuel burned, measured in million BTU.", "unit": "MMBtu", }, - "heat_rate_mmbtu_mwh": { + "heat_rate_mmbtu_mwh_by_unit": { "type": "number", "description": "Fuel content per unit of electricity generated. Coming from MCOE calculation.", "unit": "MMBtu_MWh", diff --git a/src/pudl/metadata/resources/eia.py b/src/pudl/metadata/resources/eia.py index d67edc40b8..976746061c 100644 --- a/src/pudl/metadata/resources/eia.py +++ b/src/pudl/metadata/resources/eia.py @@ -551,7 +551,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", @@ -651,7 +651,7 @@ "fuel_cost_per_mwh", "fuel_type_code_pudl", "generator_retirement_date", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "installation_year", "net_generation_mwh", "generator_operating_year", diff --git a/src/pudl/metadata/resources/mcoe.py b/src/pudl/metadata/resources/mcoe.py index 2b738a3e3d..1525960f0b 100644 --- a/src/pudl/metadata/resources/mcoe.py +++ b/src/pudl/metadata/resources/mcoe.py @@ -24,7 +24,7 @@ "unit_id_pudl", "net_generation_mwh", "fuel_consumed_for_electricity_mmbtu", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", ], "primary_key": [ "report_date", @@ -53,7 +53,7 @@ "plant_id_eia", "unit_id_pudl", "generator_id", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "fuel_type_code_pudl", "fuel_type_count", "prime_mover_code", @@ -126,7 +126,7 @@ "fuel_type_code_pudl", "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "fuel_cost_per_mwh", ], "primary_key": [ @@ -165,7 +165,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", @@ -212,7 +212,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh", + "heat_rate_mmbtu_mwh_by_unit", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", diff --git a/src/pudl/validate.py b/src/pudl/validate.py index 8a7278fe8e..d7b1e1a998 100644 --- a/src/pudl/validate.py +++ b/src/pudl/validate.py @@ -2661,7 +2661,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 7.0, "hi_q": 0.50, "hi_bound": 7.5, - "data_col": "heat_rate_mmbtu_mwh", + "data_col": "heat_rate_mmbtu_mwh_by_unit", "weight_col": "net_generation_mwh", }, { # EIA natural gas reporting really only becomes usable in 2015. @@ -2671,7 +2671,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 6.4, "hi_q": 0.95, "hi_bound": 13.0, - "data_col": "heat_rate_mmbtu_mwh", + "data_col": "heat_rate_mmbtu_mwh_by_unit", "weight_col": "net_generation_mwh", }, ] @@ -2685,7 +2685,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 10.0, "hi_q": 0.50, "hi_bound": 11.0, - "data_col": "heat_rate_mmbtu_mwh", + "data_col": "heat_rate_mmbtu_mwh_by_unit", "weight_col": "net_generation_mwh", }, { @@ -2695,7 +2695,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 9.0, "hi_q": 0.95, "hi_bound": 12.5, - "data_col": "heat_rate_mmbtu_mwh", + "data_col": "heat_rate_mmbtu_mwh_by_unit", "weight_col": "net_generation_mwh", }, ] @@ -2861,7 +2861,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_q": 0.05, "mid_q": 0.50, "hi_q": 0.95, - "data_col": "heat_rate_mmbtu_mwh", + "data_col": "heat_rate_mmbtu_mwh_by_unit", "weight_col": "net_generation_mwh", }, { @@ -2870,7 +2870,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_q": 0.05, "mid_q": 0.50, "hi_q": 0.95, - "data_col": "heat_rate_mmbtu_mwh", + "data_col": "heat_rate_mmbtu_mwh_by_unit", "weight_col": "net_generation_mwh", }, ] diff --git a/test/unit/analysis/plant_parts_eia_test.py b/test/unit/analysis/plant_parts_eia_test.py index 202822c442..fb9f14fd65 100644 --- a/test/unit/analysis/plant_parts_eia_test.py +++ b/test/unit/analysis/plant_parts_eia_test.py @@ -534,7 +534,7 @@ def test_one_to_many(): "net_generation_mwh": [100] * 8, "total_fuel_cost": [100] * 8, "fuel_cost_per_mwh": [1] * 8, - "heat_rate_mmbtu_mwh": [1] * 8, + "heat_rate_mmbtu_mwh_by_unit": [1] * 8, "fuel_cost_per_mmbtu": [1] * 8, "fuel_type_code_pudl": ["test"] * 8, "planned_generator_retirement_date": [2076] * 8, @@ -621,7 +621,7 @@ def test_one_to_many(): "net_generation_mwh": [100, 100, 100, 100, 100, 100, 100, 100, 200], "total_fuel_cost": [100, 100, 100, 100, 100, 100, 100, 100, 200], "fuel_cost_per_mwh": [1] * 9, - "heat_rate_mmbtu_mwh": [1] * 9, + "heat_rate_mmbtu_mwh_by_unit": [1] * 9, "fuel_cost_per_mmbtu": [1] * 9, "fuel_type_code_pudl": ["test"] * 9, "planned_generator_retirement_date": [2076] * 9, From 53e2f2d2849c146a523f713361791b5506037c9b Mon Sep 17 00:00:00 2001 From: bendnorman Date: Wed, 4 Oct 2023 20:02:31 +0200 Subject: [PATCH 2/6] Rename heat rate mmbtu mwh to follow existing naming convention --- ...41cf_rename_heat_rate_column_to_follow_.py | 121 ++++++++++++++++++ src/pudl/analysis/eia_ferc1_record_linkage.py | 10 +- src/pudl/analysis/eia_ferc1_train.py | 2 +- src/pudl/analysis/mcoe.py | 24 ++-- src/pudl/analysis/plant_parts_eia.py | 2 +- src/pudl/metadata/fields.py | 2 +- src/pudl/metadata/resources/eia.py | 4 +- src/pudl/metadata/resources/mcoe.py | 10 +- src/pudl/validate.py | 12 +- test/unit/analysis/plant_parts_eia_test.py | 4 +- 10 files changed, 156 insertions(+), 35 deletions(-) create mode 100644 migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py diff --git a/migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py b/migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py new file mode 100644 index 0000000000..7428946be9 --- /dev/null +++ b/migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py @@ -0,0 +1,121 @@ +"""Rename heat rate column to follow column naming convention + +Revision ID: 1e4356aa41cf +Revises: c415b55c4dcf +Create Date: 2023-10-04 20:00:29.217602 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = '1e4356aa41cf' +down_revision = 'c415b55c4dcf' +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_by_unit') + + 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_by_unit') + + 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_by_unit') + + 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_by_unit') + + 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_by_unit') + + 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_by_unit') + + 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_by_unit') + + 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_by_unit') + + 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_by_unit') + + with op.batch_alter_table('out_eia__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_by_unit') + + 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_by_unit') + + 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_by_unit') + + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + 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_by_unit', 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_by_unit', sa.FLOAT(), nullable=True)) + batch_op.drop_column('unit_heat_rate_mmbtu_per_mwh') + + with op.batch_alter_table('out_eia__plant_parts', schema=None) as batch_op: + batch_op.add_column(sa.Column('heat_rate_mmbtu_mwh_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', sa.FLOAT(), nullable=True)) + batch_op.drop_column('unit_heat_rate_mmbtu_per_mwh') + + # ### end Alembic commands ### diff --git a/src/pudl/analysis/eia_ferc1_record_linkage.py b/src/pudl/analysis/eia_ferc1_record_linkage.py index 786e19d047..73776960b3 100644 --- a/src/pudl/analysis/eia_ferc1_record_linkage.py +++ b/src/pudl/analysis/eia_ferc1_record_linkage.py @@ -209,7 +209,7 @@ 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_by_unit=lambda x: ( + unit_heat_rate_mmbtu_per_mwh=lambda x: ( x.fuel_mmbtu / x.net_generation_mwh ), ) @@ -421,9 +421,9 @@ def make_features( label="fuel_cost_per_mmbtu", ), Numeric( - "heat_rate_mmbtu_mwh_by_unit", - "heat_rate_mmbtu_mwh_by_unit", - label="heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", + "unit_heat_rate_mmbtu_per_mwh", + label="unit_heat_rate_mmbtu_per_mwh", ), Exact( "fuel_type_code_pudl", @@ -827,7 +827,7 @@ def prettyify_best_matches( "capacity_mw", "capacity_factor", "total_mmbtu", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "fuel_type_code_pudl", "installation_year", "plant_part_id_eia", diff --git a/src/pudl/analysis/eia_ferc1_train.py b/src/pudl/analysis/eia_ferc1_train.py index 0a9911a0cb..61b7ae3c81 100644 --- a/src/pudl/analysis/eia_ferc1_train.py +++ b/src/pudl/analysis/eia_ferc1_train.py @@ -103,7 +103,7 @@ "total_fuel_cost", "total_mmbtu", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", ] # -------------------------------------------------------------------------------------- diff --git a/src/pudl/analysis/mcoe.py b/src/pudl/analysis/mcoe.py index 6b3f7b1bab..245b9b6b77 100644 --- a/src/pudl/analysis/mcoe.py +++ b/src/pudl/analysis/mcoe.py @@ -258,7 +258,7 @@ def heat_rate_by_unit(gen_fuel_by_energy_source: pd.DataFrame, bga: pd.DataFrame - unit_id_pudl - net_generation_mwh - fuel_consumed_for_electricity_mmbtu - - heat_rate_mmbtu_mwh_by_unit + - unit_heat_rate_mmbtu_per_mwh """ gen_fuel_by_unit = pudl.helpers.date_merge( left=gen_fuel_by_energy_source, @@ -274,7 +274,7 @@ def heat_rate_by_unit(gen_fuel_by_energy_source: pd.DataFrame, bga: pd.DataFrame .sum() .convert_dtypes() .assign( - heat_rate_mmbtu_mwh_by_unit=lambda x: x.fuel_consumed_for_electricity_mmbtu + unit_heat_rate_mmbtu_per_mwh=lambda x: x.fuel_consumed_for_electricity_mmbtu / x.net_generation_mwh ) ) @@ -299,7 +299,7 @@ def heat_rate_by_gen( Returns: DataFrame with columns report_date, plant_id_eia, unit_id_pudl, generator_id, - heat_rate_mmbtu_mwh_by_unit, fuel_type_code_pudl, fuel_type_count, prime_mover_code. + unit_heat_rate_mmbtu_per_mwh, fuel_type_code_pudl, fuel_type_count, prime_mover_code. The output will have a time frequency corresponding to that of the input pudl_out. Output data types are set to their canonical values before returning. """ @@ -312,7 +312,7 @@ def heat_rate_by_gen( "report_date", "plant_id_eia", "unit_id_pudl", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", ], ] @@ -377,7 +377,7 @@ def fuel_cost( "generator_id", "unit_id_pudl", "report_date", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", ], ] gens = gens.loc[ @@ -488,7 +488,7 @@ def fuel_cost( "plant_id_eia", "report_date", "generator_id", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "fuel_cost_from_eiaapi", ] ], @@ -505,7 +505,7 @@ def fuel_cost( "report_date", "generator_id", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "fuel_cost_from_eiaapi", ] ] @@ -514,13 +514,13 @@ def fuel_cost( pd.concat([one_fuel, multi_fuel], sort=True) .assign( fuel_cost_per_mwh=lambda x: x.fuel_cost_per_mmbtu - * x.heat_rate_mmbtu_mwh_by_unit + * x.unit_heat_rate_mmbtu_per_mwh ) .sort_values(["report_date", "plant_id_eia", "generator_id"]) ) out_df = ( - gen_w_ft.drop("heat_rate_mmbtu_mwh_by_unit", axis=1) + gen_w_ft.drop("unit_heat_rate_mmbtu_per_mwh", axis=1) .drop_duplicates() .merge(fc, on=["report_date", "plant_id_eia", "generator_id"]) ) @@ -607,7 +607,7 @@ def mcoe( "unit_id_pudl", "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "fuel_cost_per_mwh", ], ], @@ -619,12 +619,12 @@ def mcoe( ) # Calculate a couple more derived values: .assign( - total_mmbtu=lambda x: x.net_generation_mwh * x.heat_rate_mmbtu_mwh_by_unit, + total_mmbtu=lambda x: x.net_generation_mwh * x.unit_heat_rate_mmbtu_per_mwh, total_fuel_cost=lambda x: x.total_mmbtu * x.fuel_cost_per_mmbtu, ) .pipe( pudl.helpers.oob_to_nan_with_dependent_cols, - cols=["heat_rate_mmbtu_mwh_by_unit"], + cols=["unit_heat_rate_mmbtu_per_mwh"], dependent_cols=["total_mmbtu", "fuel_cost_per_mwh"], lb=min_heat_rate, ub=None, diff --git a/src/pudl/analysis/plant_parts_eia.py b/src/pudl/analysis/plant_parts_eia.py index 62c56bcc49..fcea7d5370 100644 --- a/src/pudl/analysis/plant_parts_eia.py +++ b/src/pudl/analysis/plant_parts_eia.py @@ -281,7 +281,7 @@ WTAVG_DICT = { "fuel_cost_per_mwh": "capacity_mw", - "heat_rate_mmbtu_mwh_by_unit": "capacity_mw", + "unit_heat_rate_mmbtu_per_mwh": "capacity_mw", "fuel_cost_per_mmbtu": "capacity_mw", } """Dict: a dictionary of columns (keys) to perform weighted averages on and the weight diff --git a/src/pudl/metadata/fields.py b/src/pudl/metadata/fields.py index 7cdf63577b..7c38305386 100644 --- a/src/pudl/metadata/fields.py +++ b/src/pudl/metadata/fields.py @@ -1231,7 +1231,7 @@ "description": "The energy contained in fuel burned, measured in million BTU.", "unit": "MMBtu", }, - "heat_rate_mmbtu_mwh_by_unit": { + "unit_heat_rate_mmbtu_per_mwh": { "type": "number", "description": "Fuel content per unit of electricity generated. Coming from MCOE calculation.", "unit": "MMBtu_MWh", diff --git a/src/pudl/metadata/resources/eia.py b/src/pudl/metadata/resources/eia.py index 976746061c..bdba2b3c7e 100644 --- a/src/pudl/metadata/resources/eia.py +++ b/src/pudl/metadata/resources/eia.py @@ -551,7 +551,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", @@ -651,7 +651,7 @@ "fuel_cost_per_mwh", "fuel_type_code_pudl", "generator_retirement_date", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "installation_year", "net_generation_mwh", "generator_operating_year", diff --git a/src/pudl/metadata/resources/mcoe.py b/src/pudl/metadata/resources/mcoe.py index 1525960f0b..740506d7fd 100644 --- a/src/pudl/metadata/resources/mcoe.py +++ b/src/pudl/metadata/resources/mcoe.py @@ -24,7 +24,7 @@ "unit_id_pudl", "net_generation_mwh", "fuel_consumed_for_electricity_mmbtu", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", ], "primary_key": [ "report_date", @@ -53,7 +53,7 @@ "plant_id_eia", "unit_id_pudl", "generator_id", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "fuel_type_code_pudl", "fuel_type_count", "prime_mover_code", @@ -126,7 +126,7 @@ "fuel_type_code_pudl", "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "fuel_cost_per_mwh", ], "primary_key": [ @@ -165,7 +165,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", @@ -212,7 +212,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh_by_unit", + "unit_heat_rate_mmbtu_per_mwh", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", diff --git a/src/pudl/validate.py b/src/pudl/validate.py index d7b1e1a998..d226f88420 100644 --- a/src/pudl/validate.py +++ b/src/pudl/validate.py @@ -2661,7 +2661,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 7.0, "hi_q": 0.50, "hi_bound": 7.5, - "data_col": "heat_rate_mmbtu_mwh_by_unit", + "data_col": "unit_heat_rate_mmbtu_per_mwh", "weight_col": "net_generation_mwh", }, { # EIA natural gas reporting really only becomes usable in 2015. @@ -2671,7 +2671,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 6.4, "hi_q": 0.95, "hi_bound": 13.0, - "data_col": "heat_rate_mmbtu_mwh_by_unit", + "data_col": "unit_heat_rate_mmbtu_per_mwh", "weight_col": "net_generation_mwh", }, ] @@ -2685,7 +2685,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 10.0, "hi_q": 0.50, "hi_bound": 11.0, - "data_col": "heat_rate_mmbtu_mwh_by_unit", + "data_col": "unit_heat_rate_mmbtu_per_mwh", "weight_col": "net_generation_mwh", }, { @@ -2695,7 +2695,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_bound": 9.0, "hi_q": 0.95, "hi_bound": 12.5, - "data_col": "heat_rate_mmbtu_mwh_by_unit", + "data_col": "unit_heat_rate_mmbtu_per_mwh", "weight_col": "net_generation_mwh", }, ] @@ -2861,7 +2861,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_q": 0.05, "mid_q": 0.50, "hi_q": 0.95, - "data_col": "heat_rate_mmbtu_mwh_by_unit", + "data_col": "unit_heat_rate_mmbtu_per_mwh", "weight_col": "net_generation_mwh", }, { @@ -2870,7 +2870,7 @@ def plot_vs_agg(orig_df, agg_df, validation_cases): "low_q": 0.05, "mid_q": 0.50, "hi_q": 0.95, - "data_col": "heat_rate_mmbtu_mwh_by_unit", + "data_col": "unit_heat_rate_mmbtu_per_mwh", "weight_col": "net_generation_mwh", }, ] diff --git a/test/unit/analysis/plant_parts_eia_test.py b/test/unit/analysis/plant_parts_eia_test.py index fb9f14fd65..9b234464bf 100644 --- a/test/unit/analysis/plant_parts_eia_test.py +++ b/test/unit/analysis/plant_parts_eia_test.py @@ -534,7 +534,7 @@ def test_one_to_many(): "net_generation_mwh": [100] * 8, "total_fuel_cost": [100] * 8, "fuel_cost_per_mwh": [1] * 8, - "heat_rate_mmbtu_mwh_by_unit": [1] * 8, + "unit_heat_rate_mmbtu_per_mwh": [1] * 8, "fuel_cost_per_mmbtu": [1] * 8, "fuel_type_code_pudl": ["test"] * 8, "planned_generator_retirement_date": [2076] * 8, @@ -621,7 +621,7 @@ def test_one_to_many(): "net_generation_mwh": [100, 100, 100, 100, 100, 100, 100, 100, 200], "total_fuel_cost": [100, 100, 100, 100, 100, 100, 100, 100, 200], "fuel_cost_per_mwh": [1] * 9, - "heat_rate_mmbtu_mwh_by_unit": [1] * 9, + "unit_heat_rate_mmbtu_per_mwh": [1] * 9, "fuel_cost_per_mmbtu": [1] * 9, "fuel_type_code_pudl": ["test"] * 9, "planned_generator_retirement_date": [2076] * 9, From d8c01da01237dbe518214d2924c81c82fee1c7c5 Mon Sep 17 00:00:00 2001 From: bendnorman Date: Wed, 8 Nov 2023 12:40:20 -0900 Subject: [PATCH 3/6] Rename heat_rate_mmbtu_mwh_eia/ferc1 columns to unit_heat_rate_mmbtu_per_mwh_eia/ferc1 --- ...d34_add_data_maturity_to_eia923m_tables.py | 113 --------- ...41cf_rename_heat_rate_column_to_follow_.py | 121 --------- ...b_wipe_schema_and_ferc1_name_transition.py | 4 +- ...e_demand_hourly_pa_ferc714_report_date_.py | 35 --- ...4_rename_heat_rate_mmbtu_mwh_unit_heat_.py | 235 ++++++++++++++++++ ...ename_heat_rate_mmbtu_mwh_to_heat_rate_.py | 121 --------- ...4_add_unit__to_ferc1_and_eia_heat_rate_.py | 37 +++ src/pudl/metadata/fields.py | 4 +- .../resources/ferc1_eia_record_linkage.py | 8 +- 9 files changed, 280 insertions(+), 398 deletions(-) delete mode 100644 migrations/versions/1ceb9897fd34_add_data_maturity_to_eia923m_tables.py delete mode 100644 migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py delete mode 100644 migrations/versions/3313ca078f4e_demand_hourly_pa_ferc714_report_date_.py create mode 100644 migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py delete mode 100644 migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py create mode 100644 migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py diff --git a/migrations/versions/1ceb9897fd34_add_data_maturity_to_eia923m_tables.py b/migrations/versions/1ceb9897fd34_add_data_maturity_to_eia923m_tables.py deleted file mode 100644 index ec582b8c97..0000000000 --- a/migrations/versions/1ceb9897fd34_add_data_maturity_to_eia923m_tables.py +++ /dev/null @@ -1,113 +0,0 @@ -"""add data_maturity to eia923m tables - -Revision ID: 1ceb9897fd34 -Revises: f11241c9292d -Create Date: 2023-10-26 16:30:33.771381 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = '1ceb9897fd34' -down_revision = 'f11241c9292d' -branch_labels = None -depends_on = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('boiler_fuel_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_boiler_fuel_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_boiler_fuel_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_boiler_fuel_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_boiler_fuel_monthly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_boiler_fuel_monthly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_boiler_fuel_yearly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_boiler_fuel_yearly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_fuel_receipts_costs_monthly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_fuel_receipts_costs_monthly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_fuel_receipts_costs_yearly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_fuel_receipts_costs_yearly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_generation_fuel_combined_monthly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_generation_fuel_combined_monthly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_generation_fuel_combined_yearly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_generation_fuel_combined_yearly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_generation_monthly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_generation_monthly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_generation_yearly_eia923', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_generation_yearly_eia923_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('denorm_plants_utilities_eia', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_denorm_plants_utilities_eia_data_maturity_data_maturities'), 'data_maturities', ['data_maturity'], ['code']) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('denorm_plants_utilities_eia', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_plants_utilities_eia_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_generation_yearly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_generation_yearly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_generation_monthly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_generation_monthly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_generation_fuel_combined_yearly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_generation_fuel_combined_yearly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_generation_fuel_combined_monthly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_generation_fuel_combined_monthly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_fuel_receipts_costs_yearly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_fuel_receipts_costs_yearly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_fuel_receipts_costs_monthly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_fuel_receipts_costs_monthly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_boiler_fuel_yearly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_boiler_fuel_yearly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_boiler_fuel_monthly_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_boiler_fuel_monthly_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('denorm_boiler_fuel_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_denorm_boiler_fuel_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('boiler_fuel_eia923', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_boiler_fuel_eia923_data_maturity_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - # ### end Alembic commands ### diff --git a/migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py b/migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py deleted file mode 100644 index 7428946be9..0000000000 --- a/migrations/versions/1e4356aa41cf_rename_heat_rate_column_to_follow_.py +++ /dev/null @@ -1,121 +0,0 @@ -"""Rename heat rate column to follow column naming convention - -Revision ID: 1e4356aa41cf -Revises: c415b55c4dcf -Create Date: 2023-10-04 20:00:29.217602 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = '1e4356aa41cf' -down_revision = 'c415b55c4dcf' -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_by_unit') - - 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_by_unit') - - 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_by_unit') - - 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_by_unit') - - 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_by_unit') - - 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_by_unit') - - 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_by_unit') - - 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_by_unit') - - 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_by_unit') - - with op.batch_alter_table('out_eia__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_by_unit') - - 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_by_unit') - - 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_by_unit') - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - 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_by_unit', 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_by_unit', sa.FLOAT(), nullable=True)) - batch_op.drop_column('unit_heat_rate_mmbtu_per_mwh') - - with op.batch_alter_table('out_eia__plant_parts', schema=None) as batch_op: - batch_op.add_column(sa.Column('heat_rate_mmbtu_mwh_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', 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_by_unit', sa.FLOAT(), nullable=True)) - batch_op.drop_column('unit_heat_rate_mmbtu_per_mwh') - - # ### end Alembic commands ### diff --git a/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py b/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py index d43a703aa4..80e88b2943 100644 --- a/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py +++ b/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py @@ -21309,7 +21309,7 @@ def upgrade() -> None: comment="Total annual heat content of fuel consumed by a plant part record in the plant parts list.", ), sa.Column( - "heat_rate_mmbtu_mwh_eia", + "unit_heat_rate_mmbtu_per_mwh_eia", sa.Float(), nullable=True, comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.", @@ -21802,7 +21802,7 @@ def upgrade() -> None: comment="Simplified fuel type code used in PUDL", ), sa.Column( - "heat_rate_mmbtu_mwh_ferc1", + "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.", diff --git a/migrations/versions/3313ca078f4e_demand_hourly_pa_ferc714_report_date_.py b/migrations/versions/3313ca078f4e_demand_hourly_pa_ferc714_report_date_.py deleted file mode 100644 index 61acfd18cf..0000000000 --- a/migrations/versions/3313ca078f4e_demand_hourly_pa_ferc714_report_date_.py +++ /dev/null @@ -1,35 +0,0 @@ -"""demand_hourly_pa_ferc714.report_date can't be null - -Revision ID: 3313ca078f4e -Revises: 1ceb9897fd34 -Create Date: 2023-11-02 15:48:50.477585 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = '3313ca078f4e' -down_revision = '1ceb9897fd34' -branch_labels = None -depends_on = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('demand_hourly_pa_ferc714', schema=None) as batch_op: - batch_op.alter_column('report_date', - existing_type=sa.DATE(), - nullable=False) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('demand_hourly_pa_ferc714', schema=None) as batch_op: - batch_op.alter_column('report_date', - existing_type=sa.DATE(), - nullable=True) - - # ### end Alembic commands ### diff --git a/migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py b/migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py new file mode 100644 index 0000000000..f66e808f39 --- /dev/null +++ b/migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py @@ -0,0 +1,235 @@ +"""Rename heat_rate_mmbtu_mwh -> unit_heat_rate_mmbtu_per_mwh + +Revision ID: c22d59125ab4 +Revises: 1fef7b82e48b +Create Date: 2023-11-08 11:48:55.310396 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'c22d59125ab4' +down_revision = '1fef7b82e48b' +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__plants_utilities', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk__out_eia__plants_utilities_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + 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('core_eia923__monthly_boiler_fuel', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_core_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('core_ferc714__hourly_demand_pa', schema=None) as batch_op: + batch_op.alter_column('report_date', + existing_type=sa.DATE(), + nullable=False) + + 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_eia923__boiler_fuel', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__monthly_boiler_fuel', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__monthly_fuel_receipts_costs', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__monthly_generation', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_generation_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__monthly_generation_fuel_combined', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__yearly_boiler_fuel', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__yearly_fuel_receipts_costs', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__yearly_generation', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_generation_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + with op.batch_alter_table('out_eia923__yearly_generation_fuel_combined', schema=None) as batch_op: + batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) + batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) + + 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('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_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('out_eia923__yearly_generation_fuel_combined', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__yearly_generation', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_generation_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__yearly_fuel_receipts_costs', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__yearly_boiler_fuel', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__monthly_generation_fuel_combined', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__monthly_generation', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_generation_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__monthly_fuel_receipts_costs', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__monthly_boiler_fuel', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + with op.batch_alter_table('out_eia923__boiler_fuel', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_out_eia923__boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + 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('core_ferc714__hourly_demand_pa', schema=None) as batch_op: + batch_op.alter_column('report_date', + existing_type=sa.DATE(), + nullable=True) + + with op.batch_alter_table('core_eia923__monthly_boiler_fuel', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk_core_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + 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__plants_utilities', schema=None) as batch_op: + batch_op.drop_constraint(batch_op.f('fk__out_eia__plants_utilities_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') + batch_op.drop_column('data_maturity') + + 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 ### diff --git a/migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py b/migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py deleted file mode 100644 index e5e2f9d299..0000000000 --- a/migrations/versions/c415b55c4dcf_rename_heat_rate_mmbtu_mwh_to_heat_rate_.py +++ /dev/null @@ -1,121 +0,0 @@ -"""Rename heat_rate_mmbtu_mwh to heat_rate_mmbtu_mwh_by_unit - -Revision ID: c415b55c4dcf -Revises: ab0540a6484c -Create Date: 2023-10-04 08:08:23.744433 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = 'c415b55c4dcf' -down_revision = 'ab0540a6484c' -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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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__plant_parts', schema=None) as batch_op: - batch_op.add_column(sa.Column('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('heat_rate_mmbtu_mwh_by_unit', 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('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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - with op.batch_alter_table('out_eia__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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - 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('heat_rate_mmbtu_mwh_by_unit') - - # ### end Alembic commands ### diff --git a/migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py b/migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py new file mode 100644 index 0000000000..e6a5b0a89c --- /dev/null +++ b/migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py @@ -0,0 +1,37 @@ +"""Add unit_ to ferc1 and eia heat rate columns + +Revision ID: f5a33d973154 +Revises: c22d59125ab4 +Create Date: 2023-11-08 12:34:10.536814 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'f5a33d973154' +down_revision = 'c22d59125ab4' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + 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_ferc1') + batch_op.drop_column('heat_rate_mmbtu_mwh_eia') + + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + 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_eia', sa.FLOAT(), nullable=True)) + batch_op.add_column(sa.Column('heat_rate_mmbtu_mwh_ferc1', 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') + + # ### end Alembic commands ### diff --git a/src/pudl/metadata/fields.py b/src/pudl/metadata/fields.py index 7c38305386..7bd14e5652 100644 --- a/src/pudl/metadata/fields.py +++ b/src/pudl/metadata/fields.py @@ -1236,12 +1236,12 @@ "description": "Fuel content per unit of electricity generated. Coming from MCOE calculation.", "unit": "MMBtu_MWh", }, - "heat_rate_mmbtu_mwh_eia": { + "unit_heat_rate_mmbtu_per_mwh_eia": { "type": "number", "description": "Fuel content per unit of electricity generated. Coming from MCOE calculation.", "unit": "MMBtu_MWh", }, - "heat_rate_mmbtu_mwh_ferc1": { + "unit_heat_rate_mmbtu_per_mwh_ferc1": { "type": "number", "description": "Fuel content per unit of electricity generated. Calculated from FERC reported fuel consumption and net generation.", "unit": "MMBtu_MWh", diff --git a/src/pudl/metadata/resources/ferc1_eia_record_linkage.py b/src/pudl/metadata/resources/ferc1_eia_record_linkage.py index 3c04c82ab0..1e338352d7 100644 --- a/src/pudl/metadata/resources/ferc1_eia_record_linkage.py +++ b/src/pudl/metadata/resources/ferc1_eia_record_linkage.py @@ -55,7 +55,7 @@ "fuel_cost_per_mwh", "fuel_type_code_pudl", "generator_retirement_date", - "heat_rate_mmbtu_mwh", + "unit_heat_rate_mmbtu_per_mwh", "installation_year", "net_generation_mwh", "generator_operating_year", @@ -107,7 +107,7 @@ "fuel_cost_from_eiaapi", "fuel_cost_per_mmbtu", "fuel_cost_per_mwh", - "heat_rate_mmbtu_mwh", + "unit_heat_rate_mmbtu_per_mwh", "net_generation_mwh", "total_fuel_cost", "total_mmbtu", @@ -175,7 +175,7 @@ "capacity_mw_eia", "capacity_factor_eia", "total_mmbtu_eia", - "heat_rate_mmbtu_mwh_eia", + "unit_heat_rate_mmbtu_per_mwh_eia", "fuel_type_code_pudl_eia", "installation_year_eia", "plant_part_id_eia", @@ -258,7 +258,7 @@ "total_fuel_cost_ferc1", "total_mmbtu_ferc1", "fuel_type_code_pudl_ferc1", - "heat_rate_mmbtu_mwh_ferc1", + "unit_heat_rate_mmbtu_per_mwh_ferc1", ], "primary_key": ["record_id_ferc1"], }, From afaa449c7509ffc290bdff22423960030c6e3497 Mon Sep 17 00:00:00 2001 From: bendnorman Date: Wed, 8 Nov 2023 12:48:43 -0900 Subject: [PATCH 4/6] Remove unused ppe_cols_to_grab variable --- src/pudl/analysis/eia_ferc1_record_linkage.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/pudl/analysis/eia_ferc1_record_linkage.py b/src/pudl/analysis/eia_ferc1_record_linkage.py index 73776960b3..808c9146ea 100644 --- a/src/pudl/analysis/eia_ferc1_record_linkage.py +++ b/src/pudl/analysis/eia_ferc1_record_linkage.py @@ -818,20 +818,6 @@ def prettyify_best_matches( and FERC plant data. This removes the comparison vectors (the floats between 0 and 1 that compare the two columns from each dataset). """ - # if utility_id_pudl is not in the `PPE_COLS`, we need to include it - ppe_cols_to_grab = pudl.analysis.plant_parts_eia.PPE_COLS + [ - "plant_id_pudl", - "total_fuel_cost", - "fuel_cost_per_mmbtu", - "net_generation_mwh", - "capacity_mw", - "capacity_factor", - "total_mmbtu", - "unit_heat_rate_mmbtu_per_mwh", - "fuel_type_code_pudl", - "installation_year", - "plant_part_id_eia", - ] connects_ferc1_eia = ( # first merge in the EIA plant-parts pd.merge( From 0f90efa3bbb66353251ecaba23d1f40035a37a1b Mon Sep 17 00:00:00 2001 From: bendnorman Date: Wed, 15 Nov 2023 11:10:49 -0900 Subject: [PATCH 5/6] Resolve migration issues with unit heat rate column --- ...b_wipe_schema_and_ferc1_name_transition.py | 4 +- ...3_add_unit__to_heat_rate_mmbtu_per_mwh.py} | 20 ++++++++-- ...4_add_unit__to_ferc1_and_eia_heat_rate_.py | 37 ------------------- 3 files changed, 18 insertions(+), 43 deletions(-) rename migrations/versions/{c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py => 9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py} (93%) delete mode 100644 migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py diff --git a/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py b/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py index 80e88b2943..d43a703aa4 100644 --- a/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py +++ b/migrations/versions/1fef7b82e48b_wipe_schema_and_ferc1_name_transition.py @@ -21309,7 +21309,7 @@ def upgrade() -> None: comment="Total annual heat content of fuel consumed by a plant part record in the plant parts list.", ), sa.Column( - "unit_heat_rate_mmbtu_per_mwh_eia", + "heat_rate_mmbtu_mwh_eia", sa.Float(), nullable=True, comment="Fuel content per unit of electricity generated. Coming from MCOE calculation.", @@ -21802,7 +21802,7 @@ def upgrade() -> None: comment="Simplified fuel type code used in PUDL", ), sa.Column( - "unit_heat_rate_mmbtu_per_mwh_ferc1", + "heat_rate_mmbtu_mwh_ferc1", sa.Float(), nullable=True, comment="Fuel content per unit of electricity generated. Calculated from FERC reported fuel consumption and net generation.", diff --git a/migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py b/migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py similarity index 93% rename from migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py rename to migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py index f66e808f39..710a4eb2e0 100644 --- a/migrations/versions/c22d59125ab4_rename_heat_rate_mmbtu_mwh_unit_heat_.py +++ b/migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py @@ -1,15 +1,15 @@ -"""Rename heat_rate_mmbtu_mwh -> unit_heat_rate_mmbtu_per_mwh +"""Add unit_ to heat_rate_mmbtu_per_mwh -Revision ID: c22d59125ab4 +Revision ID: 9ccfb2eb8d23 Revises: 1fef7b82e48b -Create Date: 2023-11-08 11:48:55.310396 +Create Date: 2023-11-15 10:27:27.709921 """ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = 'c22d59125ab4' +revision = '9ccfb2eb8d23' down_revision = '1fef7b82e48b' branch_labels = None depends_on = None @@ -118,6 +118,12 @@ def upgrade() -> None: 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') @@ -131,6 +137,12 @@ def downgrade() -> None: 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') diff --git a/migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py b/migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py deleted file mode 100644 index e6a5b0a89c..0000000000 --- a/migrations/versions/f5a33d973154_add_unit__to_ferc1_and_eia_heat_rate_.py +++ /dev/null @@ -1,37 +0,0 @@ -"""Add unit_ to ferc1 and eia heat rate columns - -Revision ID: f5a33d973154 -Revises: c22d59125ab4 -Create Date: 2023-11-08 12:34:10.536814 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = 'f5a33d973154' -down_revision = 'c22d59125ab4' -branch_labels = None -depends_on = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - 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_ferc1') - batch_op.drop_column('heat_rate_mmbtu_mwh_eia') - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - 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_eia', sa.FLOAT(), nullable=True)) - batch_op.add_column(sa.Column('heat_rate_mmbtu_mwh_ferc1', 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') - - # ### end Alembic commands ### From 7ef9c70274b9ad7f7e1f8553fe7f0d480df3f577 Mon Sep 17 00:00:00 2001 From: bendnorman Date: Wed, 15 Nov 2023 14:11:53 -0900 Subject: [PATCH 6/6] Recreate heat rate migration revision --- ...23_add_unit__to_heat_rate_mmbtu_per_mwh.py | 247 -------------- ...bd_add_unit__to_heat_rate_mmbtu_per_mwh.py | 305 ++++++++++++++++++ 2 files changed, 305 insertions(+), 247 deletions(-) delete mode 100644 migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py create mode 100644 migrations/versions/ccdf68a30cbd_add_unit__to_heat_rate_mmbtu_per_mwh.py diff --git a/migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py b/migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py deleted file mode 100644 index 710a4eb2e0..0000000000 --- a/migrations/versions/9ccfb2eb8d23_add_unit__to_heat_rate_mmbtu_per_mwh.py +++ /dev/null @@ -1,247 +0,0 @@ -"""Add unit_ to heat_rate_mmbtu_per_mwh - -Revision ID: 9ccfb2eb8d23 -Revises: 1fef7b82e48b -Create Date: 2023-11-15 10:27:27.709921 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = '9ccfb2eb8d23' -down_revision = '1fef7b82e48b' -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__plants_utilities', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk__out_eia__plants_utilities_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - 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('core_eia923__monthly_boiler_fuel', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_core_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('core_ferc714__hourly_demand_pa', schema=None) as batch_op: - batch_op.alter_column('report_date', - existing_type=sa.DATE(), - nullable=False) - - 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_eia923__boiler_fuel', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__monthly_boiler_fuel', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__monthly_fuel_receipts_costs', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__monthly_generation', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_generation_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__monthly_generation_fuel_combined', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__monthly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__yearly_boiler_fuel', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__yearly_fuel_receipts_costs', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__yearly_generation', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_generation_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - with op.batch_alter_table('out_eia923__yearly_generation_fuel_combined', schema=None) as batch_op: - batch_op.add_column(sa.Column('data_maturity', sa.Text(), nullable=True, comment='Level of maturity of the data record. Some data sources report less-than-final data. PUDL sometimes includes this data, but use at your own risk.')) - batch_op.create_foreign_key(batch_op.f('fk_out_eia923__yearly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), 'core_pudl__codes_data_maturities', ['data_maturity'], ['code']) - - 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('out_eia923__yearly_generation_fuel_combined', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__yearly_generation', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_generation_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__yearly_fuel_receipts_costs', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__yearly_boiler_fuel', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__yearly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__monthly_generation_fuel_combined', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_generation_fuel_combined_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__monthly_generation', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_generation_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__monthly_fuel_receipts_costs', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_fuel_receipts_costs_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__monthly_boiler_fuel', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - with op.batch_alter_table('out_eia923__boiler_fuel', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_out_eia923__boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - 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('core_ferc714__hourly_demand_pa', schema=None) as batch_op: - batch_op.alter_column('report_date', - existing_type=sa.DATE(), - nullable=True) - - with op.batch_alter_table('core_eia923__monthly_boiler_fuel', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk_core_eia923__monthly_boiler_fuel_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - 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__plants_utilities', schema=None) as batch_op: - batch_op.drop_constraint(batch_op.f('fk__out_eia__plants_utilities_data_maturity_core_pudl__codes_data_maturities'), type_='foreignkey') - batch_op.drop_column('data_maturity') - - 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 ### diff --git a/migrations/versions/ccdf68a30cbd_add_unit__to_heat_rate_mmbtu_per_mwh.py b/migrations/versions/ccdf68a30cbd_add_unit__to_heat_rate_mmbtu_per_mwh.py new file mode 100644 index 0000000000..ffd41d29eb --- /dev/null +++ b/migrations/versions/ccdf68a30cbd_add_unit__to_heat_rate_mmbtu_per_mwh.py @@ -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 ###