Skip to content

Commit

Permalink
Merge pull request #192 from ibi-group/upstream-merge-2023-11-08
Browse files Browse the repository at this point in the history
Upstream merge 2023-11-08
  • Loading branch information
miles-grant-ibigroup authored Nov 8, 2023
2 parents f4d18fd + de8bace commit a89009c
Show file tree
Hide file tree
Showing 66 changed files with 1,398 additions and 76 deletions.
54 changes: 54 additions & 0 deletions doc-templates/Emissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# CO₂ Emissions calculation

## Contact Info

- Digitransit Team

## Documentation

Graph build import of CO₂ Emissions from GTFS data sets (through custom emissions.txt extension)
and the ability to attach them to itineraries by Digitransit team.
The emissions are represented in grams per kilometer (g/Km) unit.

Emissions data is located in an emissions.txt file within a gtfs package and has the following columns:

`route_id`: route id

`avg_co2_per_vehicle_per_km`: Average carbon dioxide equivalent value for the vehicles used on the route at grams/Km units.

`avg_passenger_count`: Average passenger count for the vehicles on the route.

For example:
```csv
route_id,avg_co2_per_vehicle_per_km,avg_passenger_count
1234,123,20
2345,0,0
3456,12.3,20.0
```

Emissions data is loaded from the gtfs package and embedded into the graph during the build process.


### Configuration
To enable this functionality, you need to enable the "Co2Emissions" feature in the
`otp-config.json` file.

```JSON
//otp-config.json
{
"Co2Emissions": true
}

```
Include the `emissions` object in the
`build-config.json` file. The `emissions` object should contain parameters called
`carAvgCo2PerKm` and `carAvgOccupancy`. The `carAvgCo2PerKm` provides the average emissions value for a car in g/km and
the `carAvgOccupancy` provides the average number of passengers in a car.

<!-- INSERT: config -->

## Changelog

### OTP 2.5

- Initial implementation of the emissions calculation.
7 changes: 6 additions & 1 deletion docs/BuildConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Sections follow that describe particular settings in more depth.
| demDefaults | `object` | Default properties for DEM extracts. | *Optional* | | 2.3 |
|    [elevationUnitMultiplier](#demDefaults_elevationUnitMultiplier) | `double` | Specify a multiplier to convert elevation units from source to meters. | *Optional* | `1.0` | 2.3 |
| [elevationBucket](#elevationBucket) | `object` | Used to download NED elevation tiles from the given AWS S3 bucket. | *Optional* | | na |
| [emissions](sandbox/Emissions.md) | `object` | Emissions configuration. | *Optional* | | na |
| [fares](sandbox/Fares.md) | `object` | Fare configuration. | *Optional* | | 2.0 |
| gtfsDefaults | `object` | The gtfsDefaults section allows you to specify default properties for GTFS files. | *Optional* | | 2.3 |
|    blockBasedInterlining | `boolean` | Whether to create stay-seated transfers in between two trips with the same block id. | *Optional* | `true` | 2.3 |
Expand Down Expand Up @@ -1163,7 +1164,11 @@ case where this is not the case.
"enabled" : true
}
}
]
],
"emissions" : {
"carAvgCo2PerKm" : 170,
"carAvgOccupancy" : 1.3
}
}
```

Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ based on merged pull requests. Search GitHub issues and pull requests for smalle
- Ignore negative travel-times in Raptor [#5443](https://github.com/opentripplanner/OpenTripPlanner/pull/5443)
- Fix sort order bug in optimized transfers [#5446](https://github.com/opentripplanner/OpenTripPlanner/pull/5446)
- Siri file loader [#5460](https://github.com/opentripplanner/OpenTripPlanner/pull/5460)
- Calculate CO₂ emissions of itineraries [#5278](https://github.com/opentripplanner/OpenTripPlanner/pull/5278)
[](AUTOMATIC_CHANGELOG_PLACEHOLDER_DO_NOT_REMOVE)

## 2.4.0 (2023-09-13)
Expand Down
1 change: 1 addition & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Here is a list of all features which can be toggled on/off and their default val
| `TransferConstraints` | Enforce transfers to happen according to the _transfers.txt_(GTFS) and Interchanges(NeTEx). Turing this _off_ will increase the routing performance a little. | ✓️ | |
| `ActuatorAPI` | Endpoint for actuators (service health status). | | ✓️ |
| `AsyncGraphQLFetchers` | Whether the @async annotation in the GraphQL schema should lead to the fetch being executed asynchronously. This allows batch or alias queries to run in parallel at the cost of consuming extra threads. | | |
| `Co2Emissions` | Enable the emissions sandbox module. | | ✓️ |
| `DataOverlay` | Enable usage of data overlay when calculating costs for the street network. | | ✓️ |
| `FaresV2` | Enable import of GTFS-Fares v2 data. | | ✓️ |
| `FlexRouting` | Enable FLEX routing. | | ✓️ |
Expand Down
79 changes: 79 additions & 0 deletions docs/sandbox/Emissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# CO₂ Emissions calculation

## Contact Info

- Digitransit Team

## Documentation

Graph build import of CO₂ Emissions from GTFS data sets (through custom emissions.txt extension)
and the ability to attach them to itineraries by Digitransit team.
The emissions are represented in grams per kilometer (g/Km) unit.

Emissions data is located in an emissions.txt file within a gtfs package and has the following columns:

`route_id`: route id

`avg_co2_per_vehicle_per_km`: Average carbon dioxide equivalent value for the vehicles used on the route at grams/Km units.

`avg_passenger_count`: Average passenger count for the vehicles on the route.

For example:
```csv
route_id,avg_co2_per_vehicle_per_km,avg_passenger_count
1234,123,20
2345,0,0
3456,12.3,20.0
```

Emissions data is loaded from the gtfs package and embedded into the graph during the build process.


### Configuration
To enable this functionality, you need to enable the "Co2Emissions" feature in the
`otp-config.json` file.

```JSON
//otp-config.json
{
"Co2Emissions": true
}

```
Include the `emissions` object in the
`build-config.json` file. The `emissions` object should contain parameters called
`carAvgCo2PerKm` and `carAvgOccupancy`. The `carAvgCo2PerKm` provides the average emissions value for a car in g/km and
the `carAvgOccupancy` provides the average number of passengers in a car.

<!-- config BEGIN -->
<!-- NOTE! This section is auto-generated. Do not change, change doc in code instead. -->

### Example configuration

```JSON
// build-config.json
{
"emissions" : {
"carAvgCo2PerKm" : 170,
"carAvgOccupancy" : 1.3
}
}
```
### Overview

| Config Parameter | Type | Summary | Req./Opt. | Default Value | Since |
|------------------|:---------:|------------------------------------------------------------|:----------:|---------------|:-----:|
| carAvgCo2PerKm | `integer` | The average CO₂ emissions of a car in grams per kilometer. | *Optional* | `170` | na |
| carAvgOccupancy | `double` | The average number of passengers in a car. | *Optional* | `1.3` | na |


### Details


<!-- config END -->

## Changelog

### OTP 2.5

- Initial implementation of the emissions calculation.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@


<properties>
<otp.serialization.version.id>123</otp.serialization.version.id>
<otp.serialization.version.id>124</otp.serialization.version.id>
<!-- Lib versions - keep list sorted on property name -->
<geotools.version>30.0</geotools.version>
<google.dagger.version>2.48.1</google.dagger.version>
<jackson.version>2.15.3</jackson.version>
<jersey.version>3.1.3</jersey.version>
<junit.version>5.10.0</junit.version>
<junit.version>5.10.1</junit.version>
<micrometer.version>1.11.5</micrometer.version>
<netcdf4.version>5.5.3</netcdf4.version>
<logback.version>1.4.11</logback.version>
Expand Down Expand Up @@ -247,7 +247,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
Expand Down Expand Up @@ -579,7 +579,7 @@
<!-- This make sure all google libraries are using compatible versions. -->
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.24.0</version>
<version>26.26.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -721,7 +721,7 @@
<dependency>
<groupId>org.entur.gbfs</groupId>
<artifactId>gbfs-java-model</artifactId>
<version>3.0.11</version>
<version>3.0.13</version>
</dependency>

<!-- TESTING -->
Expand All @@ -740,13 +740,13 @@
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.6.0</version>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -772,7 +772,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
<version>32.1.3-jre</version>
</dependency>
<!-- Jersey annotation-driven REST web services (JAX-RS implementation) -->
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"@graphql-codegen/java-resolvers",
"graphql",
"io.micrometer:micrometer-registry-prometheus",
"io.micrometer:micrometer-registry-influx"
"io.micrometer:micrometer-registry-influx",
"org.entur.gbfs:gbfs-java-model"
],
// we don't use the 'monthly' preset because that only fires on the first day of the month
// when there might already other PRs open
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.opentripplanner.ext.emissions;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import org.junit.jupiter.api.Test;
import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore;
import org.opentripplanner.test.support.ResourceLoader;

public class Co2EmissionsDataReaderTest {

private static final ResourceLoader RES = ResourceLoader.of(Co2EmissionsDataReaderTest.class);
private static final File CO2_GTFS_ZIP = RES.file("emissions-test-gtfs.zip");
private static final File CO2_GTFS = RES.file("emissions-test-gtfs/");
private static final File INVALID_CO2_GTFS = RES.file("emissions-invalid-test-gtfs/");

private Co2EmissionsDataReader co2EmissionsDataReader = new Co2EmissionsDataReader(
new DefaultDataImportIssueStore()
);

@Test
void testCo2EmissionsZipDataReading() {
var emissions = co2EmissionsDataReader.readGtfsZip(CO2_GTFS_ZIP);
assertEquals(6, emissions.size());
}

@Test
void testCo2EmissionsDataReading() {
var emissions = co2EmissionsDataReader.readGtfs(CO2_GTFS);
assertEquals(6, emissions.size());
}

@Test
void testInvalidCo2EmissionsDataReading() {
var emissions = co2EmissionsDataReader.readGtfs(INVALID_CO2_GTFS);
assertEquals(0, emissions.size());
}
}
Loading

0 comments on commit a89009c

Please sign in to comment.