bigfunctions > get_transport_emissions
get_transport_emissions¶
Call or Deploy get_transport_emissions
?
✅ You can call this get_transport_emissions
bigfunction directly from your Google Cloud Project (no install required).
- This
get_transport_emissions
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
get_transport_emissions(distance_km)
Description
Get the transport CO2 emissions given the distance_km
by transport mode
from impactco2.fr
Examples¶
Get transport emissions for 200 km
select bigfunctions.eu.get_transport_emissions(200)
select bigfunctions.us.get_transport_emissions(200)
select bigfunctions.europe_west1.get_transport_emissions(200)
+-------------------------------------------------------------------------------------------------------------------------------------------+
| co2_emissions_by_transport_mode |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| [
{"id": 2, "name": "High-speed train","value":0.46},
{"id": 22,"name": "Carpooling combustion (1 passenger)","value":19.2},
...
]
|
+-------------------------------------------------------------------------------------------------------------------------------------------+
Need help using get_transport_emissions
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using get_transport_emissions
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Use cases¶
A logistics company uses BigQuery to store data about its deliveries. Each record in the deliveries
table includes the distance_km
for each delivery. The company wants to calculate the estimated CO2 emissions for each delivery, broken down by different transportation modes (e.g., truck, train, plane) to understand its environmental impact and explore potential optimizations.
They can use the get_transport_emissions
function within a query like this:
SELECT
delivery_id,
distance_km,
bigfunctions.eu.get_transport_emissions(distance_km) AS co2_emissions
FROM
`project.dataset.deliveries`;
This query adds a new column, co2_emissions
, to the results. This column contains an array of structs, where each struct represents a transportation mode and its associated CO2 emission for the given distance. The company can then further process this data:
- Aggregate emissions by transport mode: Unnest the
co2_emissions
array and aggregate the total emissions for each transport mode across all deliveries. This allows them to see which modes contribute most to their carbon footprint.
SELECT
transport.name,
SUM(transport.value) AS total_emissions
FROM
`project.dataset.deliveries`,
UNNEST(bigfunctions.eu.get_transport_emissions(distance_km)) AS transport
GROUP BY 1
ORDER BY
total_emissions DESC
-
Compare emissions for different delivery routes: If they have multiple potential routes for a delivery, they can use this function to estimate the emissions for each route and choose the most environmentally friendly option.
-
Scenario planning: The company could use this function to model the impact of switching to different transport modes for a portion of their deliveries. For example, what would be the CO2 reduction if 20% of truck deliveries were switched to rail?
-
Reporting and dashboards: Integrate the emission data into reports and dashboards to monitor progress towards sustainability goals.
By using the get_transport_emissions
function directly within their BigQuery workflows, the logistics company can efficiently analyze their emissions data without needing to manage external APIs or data transfers. This enables them to make data-driven decisions to optimize their operations for lower environmental impact.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!