From 8d78fe83be4e044865505cdb0f7dd7b1c1a57b08 Mon Sep 17 00:00:00 2001 From: Lukas Trippe Date: Fri, 30 Aug 2024 16:42:35 +0200 Subject: [PATCH 1/2] ci: code scanning with CodeQL (#1251) * ci: code scanning with CodeQL * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..fd64e164 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,92 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + schedule: + - cron: '23 18 * * 5' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: python + build-mode: none + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From 56f2b581bfceaf4be67bf55ea6ba76aa4dd68bc3 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Fri, 30 Aug 2024 18:06:41 +0200 Subject: [PATCH 2/2] Add emissions and fuel consumption from fuel refinieries (#1253) * Add emissions and fuel consumption from fuel refinieries * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- config/config.default.yaml | 3 ++ doc/configtables/industry.csv | 1 + doc/release_notes.rst | 3 ++ scripts/prepare_sector_network.py | 49 ++++++++++++++++++++++++++----- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 2026c11f..4290760e 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -798,6 +798,7 @@ industry: MWh_MeOH_per_tMeOH: 5.528 hotmaps_locate_missing: false reference_year: 2019 + oil_refining_emissions: 0.013 # docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#costs @@ -1078,6 +1079,8 @@ plotting: gas pipeline new: '#a87c62' # oil oil: '#c9c9c9' + oil primary: '#d2d2d2' + oil refining: '#e6e6e6' imported oil: '#a3a3a3' oil boiler: '#adadad' residential rural oil boiler: '#a9a9a9' diff --git a/doc/configtables/industry.csv b/doc/configtables/industry.csv index 4187e118..fd80e804 100644 --- a/doc/configtables/industry.csv +++ b/doc/configtables/industry.csv @@ -35,3 +35,4 @@ MWh_CH4_per_tMeOH,MWhCH4/tMeOH,float,"The energy amount of methane needed to pro MWh_MeOH_per_tMeOH,LHV,float,"The energy amount per ton of methanol. From `DECHEMA (2017) `_, page 74." hotmaps_locate_missing,--,"{true,false}",Locate industrial sites without valid locations based on city and countries. reference_year,year,YYYY,The year used as the baseline for industrial energy demand and production. Data extracted from `JRC-IDEES 2015 `_ +oil_refining_emissions,tCO2/MWh,float,"The emissions from oil fuel processing (e.g. oil in petrochemical refinieries). The default value of 0.013 tCO2/MWh is based on DE statistics for 2019; the EU value is very similar." diff --git a/doc/release_notes.rst b/doc/release_notes.rst index e912da2d..0508252f 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -11,6 +11,9 @@ Release Notes Upcoming Release ================ +* Added option to specify emissions fuel processing (e.g. oil in petrochemical + refinieries) with setting ``industry: oil_refining_emissions:``. + * Bugfix for passing function arguments in rule :mod:`solve_operations_network`. * Represent Kosovo (XK) as separate country. diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 9d099e07..5f579c5d 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -573,14 +573,47 @@ def add_carrier_buses(n, carrier, nodes=None): fossils = ["coal", "gas", "oil", "lignite"] if options.get("fossil_fuels", True) and carrier in fossils: - n.madd( - "Generator", - nodes, - bus=nodes, - p_nom_extendable=True, - carrier=carrier, - marginal_cost=costs.at[carrier, "fuel"], - ) + suffix = "" + + if carrier == "oil" and cf_industry["oil_refining_emissions"] > 0: + + n.madd( + "Bus", + nodes + " primary", + location=location, + carrier=carrier + " primary", + unit=unit, + ) + + n.madd( + "Link", + nodes + " refining", + bus0=nodes + " primary", + bus1=nodes, + bus2="co2 atmosphere", + location=location, + carrier=carrier + " refining", + p_nom=1e6, + efficiency=1 + - ( + cf_industry["oil_refining_emissions"] + / costs.at[carrier, "CO2 intensity"] + ), + efficiency2=cf_industry["oil_refining_emissions"], + ) + + suffix = " primary" + + else: + + n.madd( + "Generator", + nodes + suffix, + bus=nodes + suffix, + p_nom_extendable=True, + carrier=carrier + suffix, + marginal_cost=costs.at[carrier, "fuel"], + ) # TODO: PyPSA-Eur merge issue