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

Add equivalences to report #31

Merged
merged 8 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,39 @@ class CO2FootprintFactory implements TraceObserverFactory {
}


// Compute CO2 footprint equivalences
List<Double> 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
*/
String country = config.getCountry()
Double car = total_co2 / 251 as Double
if (country && country != 'United States of America') {
car = total_co2 / 175 as Double
}
Double plane = total_co2 / 244 as Double
Double tree = total_co2 / 917 as Double
car = car.round(2)
plane = plane.round(2)
tree = tree.round(2)
Double plane_percent
Double plane_flights
if (total_co2 <= 50000) {
plane_percent = total_co2 * 100 / 50000 as Double
plane_percent = plane_percent.round(2)
} else {
plane_flights = total_co2 / 50000 as Double
plane_flights = plane_flights.round(2)
}

return [car, plane, tree, plane_percent, plane_flights]
}


/**
* Class to generate text output
*/
Expand Down Expand Up @@ -665,7 +698,15 @@ 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],
plane: equivalences[1],
tree: equivalences[2],
plane_percent: equivalences[3],
plane_flights: equivalences[4]
]
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<meta name="description" content="Nextflow workflow report for run id [${workflow.runName}]">
<meta name="author" content="Sabrina Krakau">
<link rel="icon" type="image/png" href="https://www.nextflow.io/img/favicon.png" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<title>[${workflow.runName}] Nextflow Workflow Report</title>

Expand Down Expand Up @@ -200,16 +201,42 @@ <h4>Workflow execution completed unsuccessfully!</h4>
<dd class="col-sm-9">version ${workflow.nextflow.version}, build ${workflow.nextflow.build} (${workflow.nextflow.timestamp})</dd>
</dl>

<dl>
<dt>Total CO2 footprint measures</dt>
<dd>
<dt class="col-sm-3">Total CO2 emission</dt>
<dd class="col-sm-9"><samp>${co2_totals.co2} g</samp></dd>
<dt>Total CO2 footprint measures</dt>
<dl class="row small">
<dt class="col-sm-3">Total CO2 emission</dt>
<dd class="col-sm-9">${co2_totals.co2} g</dd>

<dt class="col-sm-3">Total energy consumption</dt>
<dd class="col-sm-9"><samp>${co2_totals.energy} Wh</samp></dd>
</dd>
<dt class="col-sm-3">Total energy consumption</dt>
<dd class="col-sm-9">${co2_totals.energy} Wh</dd>
</dl>

<p>This is equivalent to:</p>
<dl class="row small">
<dt class="col-sm-6"><i class="fa fa-tree"></i> Months a tree would need to sequester this amount of CO2</dt>
<dd class="col-sm-3">${co2_totals.tree}</dd>

<dt class="col-sm-6"><i class="fa fa-car"></i> Km by car</dt>
<dd class="col-sm-3">${co2_totals.car}</dd>

<dt class="col-sm-6"><i class="fa fa-plane"></i> Km by plane</dt>
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved
<dd class="col-sm-3">${co2_totals.plane}</dd>

<% if (co2_totals.plane_percent) { %>
<dt class="col-sm-6"><i class="fa fa-plane"></i> Percentage of a flight Paris - London</dt>
<dd class="col-sm-3">${co2_totals.plane_percent}%</dd>
<% } %>

<% if (co2_totals.plane_flights) { %>
<dt class="col-sm-6"><i class="fa fa-plane"></i> Number of flights Paris - London</dt>
<dd class="col-sm-3">${co2_totals.plane_flights}</dd>
<% } %>
</dl>

<p>The calculation of these values is based on the carbon footprint computation method
developed in the Green Algorithms project: www.green-algorithms.org</p>
<p>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</p>
</div>
</div>

Expand Down