Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Format and Lint existing python files #317

Merged
merged 8 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint

on:
push:
pull_request:
branches:
- development
- main

jobs:
formatting:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- run: python -m pip install --upgrade ruff
- run: ruff check . --diff
- run: ruff format . --diff
68 changes: 34 additions & 34 deletions notebooks/explore_data/compare_data_sources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"# Depending on how your jupyter handles working directories, this may not be needed.\n",
"import sys\n",
"\n",
"sys.path.append(\"../../../open-grid-emissions/\")\n"
"sys.path.append(\"../../../open-grid-emissions/\")"
]
},
{
Expand Down Expand Up @@ -57,7 +57,7 @@
"metadata": {},
"outputs": [],
"source": [
"year = 2019\n"
"year = 2019"
]
},
{
Expand Down Expand Up @@ -142,7 +142,7 @@
" col.replace(\"Net Generation (MW) from \", \"\") for col in eia_930.columns\n",
"]\n",
"\n",
"eia_930.head(3)\n"
"eia_930.head(3)"
]
},
{
Expand Down Expand Up @@ -171,7 +171,7 @@
" \"Natural Gas\",\n",
" \"All Petroleum Products\",\n",
" \"Other Fuel Sources\",\n",
"]\n"
"]"
]
},
{
Expand All @@ -185,7 +185,7 @@
"\n",
"# replace negative values with NaN\n",
"for col in emitting_gen_columns:\n",
" eia_930.loc[eia_930[col] < 0, col] = np.nan\n"
" eia_930.loc[eia_930[col] < 0, col] = np.nan"
]
},
{
Expand All @@ -201,7 +201,7 @@
"# Calculate hourly EIA-930 non-renewable generation\n",
"eia_930[\"total_net_generation\"] = eia_930[net_gen_columns].sum(axis=1)\n",
"\n",
"eia_930.head(3)\n"
"eia_930.head(3)"
]
},
{
Expand All @@ -215,7 +215,7 @@
" eia_930.groupby(\"Balancing Authority\").sum()[\"emitting_net_generation\"]\n",
")\n",
"annual_930 = annual_930.rename(columns={\"emitting_net_generation\": \"EIA-930\"})\n",
"annual_930.head()\n"
"annual_930.head()"
]
},
{
Expand Down Expand Up @@ -247,7 +247,7 @@
" AND report_date <= '{year}-12-30'\",\n",
" pudl_engine,\n",
")\n",
"gen_fuel_923.head()\n"
"gen_fuel_923.head()"
]
},
{
Expand All @@ -264,7 +264,7 @@
"fuel_code_dict_pudl = pd.Series(\n",
" fuel_code_dict_pudl.fuel_type_code_pudl.values,\n",
" index=fuel_code_dict_pudl.energy_source_code,\n",
").to_dict()\n"
").to_dict()"
]
},
{
Expand Down Expand Up @@ -336,7 +336,7 @@
"# Add ba code to generation_fuel_eia923\n",
"gen_fuel_923 = gen_fuel_923.merge(plants_ba, how=\"left\", on=\"plant_id_eia\")\n",
"\n",
"gen_fuel_923.head()\n"
"gen_fuel_923.head()"
]
},
{
Expand All @@ -350,7 +350,7 @@
" gen_fuel_923.groupby(\"balancing_authority_code_eia\").sum()[\"net_generation_mwh\"]\n",
")\n",
"annual_923 = annual_923.rename(columns={\"net_generation_mwh\": \"EIA-923\"})\n",
"annual_923.head()\n"
"annual_923.head()"
]
},
{
Expand All @@ -362,7 +362,7 @@
"source": [
"compare_annual_923_930 = annual_923.merge(\n",
" annual_930, how=\"outer\", left_index=True, right_index=True\n",
")\n"
")"
]
},
{
Expand All @@ -373,7 +373,7 @@
"outputs": [],
"source": [
"# identify which BAs are missing from one or another dataset\n",
"compare_annual_923_930[compare_annual_923_930.isna().any(axis=1)]\n"
"compare_annual_923_930[compare_annual_923_930.isna().any(axis=1)]"
]
},
{
Expand All @@ -384,7 +384,7 @@
"outputs": [],
"source": [
"# let's compare each BA\n",
"px.scatter(compare_annual_923_930)\n"
"px.scatter(compare_annual_923_930)"
]
},
{
Expand All @@ -404,7 +404,7 @@
" percent_diff_923_930,\n",
" title=\"percent difference between emitting net generation in EIA-930 and EIA-923\",\n",
" labels={\"value\": \"% change from EIA-923\"},\n",
")\n"
")"
]
},
{
Expand All @@ -430,7 +430,7 @@
"annual_923_by_fuel = annual_923_by_fuel.rename(\n",
" columns={\"net_generation_mwh\": \"EIA-923\"}\n",
")\n",
"annual_923_by_fuel.head(3)\n"
"annual_923_by_fuel.head(3)"
]
},
{
Expand All @@ -457,7 +457,7 @@
"annual_930_by_fuel = annual_930_by_fuel.rename(\n",
" columns={\"Balancing Authority\": \"balancing_authority_code_eia\"}\n",
")\n",
"annual_930_by_fuel\n"
"annual_930_by_fuel"
]
},
{
Expand All @@ -481,7 +481,7 @@
" facet_col_wrap=1,\n",
" height=1000,\n",
" title=\"comparison of net generation by fuel type for each BA\",\n",
")\n"
")"
]
},
{
Expand All @@ -498,7 +498,7 @@
"percent_error[\"percent_error\"] = (\n",
" percent_error[\"EIA-930\"] - percent_error[\"EIA-923\"]\n",
") / percent_error[\"EIA-923\"]\n",
"percent_error\n"
"percent_error"
]
},
{
Expand Down Expand Up @@ -548,7 +548,7 @@
"hourly_net_emissions = pd.read_csv(\n",
" \"../data/outputs/hourly_net_emission.csv\", index_col=0, parse_dates=True\n",
")\n",
"hourly_emission_rate.head()\n"
"hourly_emission_rate.head()"
]
},
{
Expand All @@ -558,7 +558,7 @@
"metadata": {},
"outputs": [],
"source": [
"eia_930.head()\n"
"eia_930.head()"
]
},
{
Expand Down Expand Up @@ -589,7 +589,7 @@
")\n",
"ax2.set_title(ba)\n",
"ax2.legend()\n",
"ax2.set_xlim(parse_dt(\"2019-08-01\"), parse_dt(\"2019-08-10\"))\n"
"ax2.set_xlim(parse_dt(\"2019-08-01\"), parse_dt(\"2019-08-10\"))"
]
},
{
Expand All @@ -610,7 +610,7 @@
")\n",
"data_for_plot = data_for_plot.rename(columns={ba: \"CEMS\"})\n",
"\n",
"px.line(data_for_plot, title=f\"Net generation in {ba} EIA-930 vs CEMS\")\n"
"px.line(data_for_plot, title=f\"Net generation in {ba} EIA-930 vs CEMS\")"
]
},
{
Expand All @@ -632,7 +632,7 @@
"source": [
"# For annual comparison graphs, see below with eGRID\n",
"annual_eia_930 = eia_930.groupby(\"Balancing Authority\").sum()[\"emitting_net_generation\"]\n",
"annual_eia_930.head()\n"
"annual_eia_930.head()"
]
},
{
Expand Down Expand Up @@ -663,7 +663,7 @@
" AND report_date <= '{year}-12-30'\",\n",
" pudl_engine,\n",
")\n",
"gen_923.head()\n"
"gen_923.head()"
]
},
{
Expand All @@ -682,7 +682,7 @@
"otherway = np.setdiff1d(\n",
" gen_fuel_923[\"plant_id_eia\"].unique(), gen_923[\"plant_id_eia\"].unique()\n",
")\n",
"print(f\"{len(oneway)} plants in generation_fuel_eia923 are not in generation_eia923\")\n"
"print(f\"{len(oneway)} plants in generation_fuel_eia923 are not in generation_eia923\")"
]
},
{
Expand Down Expand Up @@ -731,7 +731,7 @@
" header=1,\n",
" index_col=\"BACODE\",\n",
")\n",
"egrid.head()\n"
"egrid.head()"
]
},
{
Expand All @@ -753,7 +753,7 @@
" (egrid_data_code_to_name.loc[0, name], name)\n",
" for name in egrid_data_code_to_name.columns\n",
" ]\n",
")\n"
")"
]
},
{
Expand All @@ -767,7 +767,7 @@
"annual_generation = hourly_net_generation.sum(axis=0).rename(\"hourly\")\n",
"annual_generation = egrid.merge(\n",
" annual_generation, how=\"right\", left_index=True, right_index=True\n",
").loc[:, [\"hourly\", \"BAGENACY\"]]\n"
").loc[:, [\"hourly\", \"BAGENACY\"]]"
]
},
{
Expand All @@ -783,7 +783,7 @@
")\n",
"annual_generation = annual_generation.merge(\n",
" annual_923, how=\"left\", left_index=True, right_index=True\n",
")\n"
")"
]
},
{
Expand All @@ -793,7 +793,7 @@
"metadata": {},
"outputs": [],
"source": [
"annual_generation.head()\n"
"annual_generation.head()"
]
},
{
Expand Down Expand Up @@ -860,7 +860,7 @@
"ax3.hlines([1.0], -0.5, len(annual_generation) - 0.5, color=\"r\")\n",
"ax3.set_ylabel(\"Fraction of 930 generation captured by CEMS\")\n",
"ax3.set_ylim(0, 2)\n",
"ax3.set_title(\"EIA-930 vs OGEI\")\n"
"ax3.set_title(\"EIA-930 vs OGEI\")"
]
},
{
Expand All @@ -872,7 +872,7 @@
"source": [
"# Many small BAs have terrible coverage of EIA-930 data, resulting in low annually aggregated 930 numbers.\n",
"# The worst discrepencies between 930 and eGRID:\n",
"annual_generation.loc[[\"FPL\", \"IPCO\", \"NEVP\", \"SC\", \"TEC\", \"TVA\"], :]\n"
"annual_generation.loc[[\"FPL\", \"IPCO\", \"NEVP\", \"SC\", \"TEC\", \"TVA\"], :]"
]
},
{
Expand Down Expand Up @@ -900,7 +900,7 @@
"ax.set_xticklabels(labels=annual_generation.index, rotation=90)\n",
"ax.hlines([1.0], -0.5, len(annual_generation) - 0.5, color=\"r\")\n",
"ax.set_ylabel(\"Fraction of eGRID non-renewable generation captured by 923\")\n",
"ax.set_title(\"923 vs eGRID\")\n"
"ax.set_title(\"923 vs eGRID\")"
]
},
{
Expand Down
Loading
Loading