diff --git a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy index 336edea..e511449 100644 --- a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy +++ b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy @@ -29,6 +29,7 @@ class CO2FootprintConfig { final private String file final private String summaryFile final private String reportFile + final private String country final private Double ci // CI: carbon intensity final private Double pue // PUE: power usage effectiveness efficiency, coefficient of the data centre final private Double powerdrawMem // Power draw of memory [W per GB] @@ -58,6 +59,7 @@ class CO2FootprintConfig { file = config.file ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_FILE_NAME summaryFile = config.summaryFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME reportFile = config.reportFile ?: CO2FootprintFactory.CO2FootprintReportObserver.DEF_REPORT_FILE_NAME + def country ci = 475 if (config.ci && config.country) @@ -66,6 +68,7 @@ class CO2FootprintConfig { ci = config.ci if (config.country) ci = retrieveCi(config.country) + country = config.conutry pue = config.pue ?: 1.67 powerdrawMem = config.powerdrawMem ?: 0.3725 @@ -74,6 +77,7 @@ class CO2FootprintConfig { String getFile() { file } String getSummaryFile() { summaryFile } String getReportFile() { reportFile } + String getCountry() { country } Double getCI() { ci } Double getPUE() { pue } Double getPowerdrawMem() { powerdrawMem } diff --git a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy index d6f435b..3742a8d 100644 --- a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy +++ b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy @@ -194,6 +194,38 @@ class CO2FootprintFactory implements TraceObserverFactory { } + // Compute CO2 footprint equivalences + List computeCO2footprintEquivalences() { + /* + * The following values were taken from the Green Algorithms publication (https://doi.org/10.1002/advs.202100707): + * The estimated emission of the average passenger car is 175 gCO2e/Km in Europe and 251 gCO2/Km in the US + * The estimated emission of flying on a jet aircraft in economy class is between 139 and 244 gCO2e/Km + * The estimated sequestered CO2 of a mature tree is ~1 Kg per month (917 g) + * A reference flight Paris to London spends 50000 gCO2 + */ + def gCO2 = total_co2 / 1000 as Double + String country = config.getCountry() + Double car = gCO2 / 175 as Double + if (country && country == 'United States of America') { + car = gCO2 / 251 as Double + } + Double tree = gCO2 / 917 as Double + car = car.round(2) + tree = tree.round(2) + Double plane_percent + Double plane_flights + if (gCO2 <= 50000) { + plane_percent = gCO2 * 100 / 50000 as Double + plane_percent = plane_percent.round(2) + } else { + plane_flights = gCO2 / 50000 as Double + plane_flights = plane_flights.round(2) + } + + return [car, tree, plane_percent, plane_flights] + } + + /** * Class to generate text output */ @@ -665,7 +697,14 @@ class CO2FootprintFactory implements TraceObserverFactory { * @return The rendered json */ protected Map renderCO2TotalsJson() { - [ co2:HelperFunctions.convertToReadableUnits(total_co2,3), energy:HelperFunctions.convertToReadableUnits(total_energy,3) ] + List equivalences = computeCO2footprintEquivalences() + [ co2:HelperFunctions.convertToReadableUnits(total_co2,3), + energy:HelperFunctions.convertToReadableUnits(total_energy,3), + car: equivalences[0], + tree: equivalences[1], + plane_percent: equivalences[2], + plane_flights: equivalences[3] + ] } /** diff --git a/plugins/nf-co2footprint/src/resources/CO2FootprintReportTemplate.html b/plugins/nf-co2footprint/src/resources/CO2FootprintReportTemplate.html index a57f9f9..9cebd9e 100644 --- a/plugins/nf-co2footprint/src/resources/CO2FootprintReportTemplate.html +++ b/plugins/nf-co2footprint/src/resources/CO2FootprintReportTemplate.html @@ -21,6 +21,7 @@ + [${workflow.runName}] Nextflow Workflow Report @@ -209,6 +210,31 @@

Workflow execution completed unsuccessfully!

${co2_totals.energy}Wh
+ +

This is equivalent to:

+
+
Months a tree would need to sequester this amount of CO2
+
${co2_totals.tree}
+ +
Km by car
+
${co2_totals.car}
+ + <% if (co2_totals.plane_percent) { %> +
Percentage of a flight Paris - London
+
${co2_totals.plane_percent}%
+ <% } %> + + <% if (co2_totals.plane_flights) { %> +
Number of flights Paris - London
+
${co2_totals.plane_flights}
+ <% } %> +
+ +

The calculation of these values is based on the carbon footprint computation method + developed in the Green Algorithms project: www.green-algorithms.org

+

Lannelongue, L., Grealey, J., Inouye, M., + Green Algorithms: Quantifying the Carbon Footprint of Computation. + Adv. Sci. 2021, 2100707. https://doi.org/10.1002/advs.202100707