# Train: DEFRA 🇬🇧

💡 **High-Level Description:**

DEFRA (Department for Environment, Food & Rural Affairs) provides essential conversion factors and guidelines for calculating greenhouse gas (GHG) emissions across various sectors, including passenger rail services. As one of the main references for emissions reporting in the UK, DEFRA’s methodology ensures consistency, transparency, and accuracy when assessing the environmental impact of train travel.

The methodology focuses on direct emissions from train fuel combustion and indirect emissions associated with electricity consumption. DEFRA distinguishes between electric and diesel-powered trains, accounting for varying levels of emissions based on fuel type, train type (e.g., national, international, light rail), and distance traveled. DEFRA's framework is widely used in corporate GHG reporting, providing essential data for understanding the carbon impact of train travel and supporting efforts to reduce emissions.

**Versioning:** Add `methodology_version` to pin a specific DEFRA **Conversion Factors** year (e.g., `"2024"`). If omitted, SQUAKE **uses the latest supported year**.

***

### **Sample API Requests**

#### A. Without audit mode (for pre-booking/quotes)

```json
{
  "expand": ["items"],
  "items": [
    {
      "audit": false,
      "type": "train",
      "external_reference": "test_1",
      "origin": "BER",
      "destination": "FRA",
      "number_of_travelers": 3,
      "train_type": "national",
      "methodology": "DEFRA",
      "energy_scope": "ttw",
      "methodology_version": "2024"
    }
  ]
}
```

#### B. With audit mode (for finalized/post-booking calculations)

```json
{
  "expand": ["items"],
  "audit_for": "<Auditable Entity ID>",
  "items": [
    {
      "audit": true,
      "type": "train",
      "external_reference": "test_1",
      "origin": "BER",
      "destination": "FRA",
      "number_of_travelers": 3,
      "train_type": "national",
      "methodology": "DEFRA",
      "energy_scope": "ttw",
      "methodology_version": "2024"
    }
  ]
}
```

> **Note:** `audit_for` is optional. Provide when calculating on behalf of a specific Auditable entity; otherwise omit.

***

### **API Request Items**

* `"type": "train"` **(required)**
* `"methodology": "DEFRA"` **(required)**
* `"methodology_version"`: DEFRA **Conversion Factors** year (e.g., `"2024"`). **Optional**; if omitted → **latest supported year**.
* `"external_reference"`: Unique identifier to link the result (max 128 chars).
* `"number_of_travelers"`: Minimum `1`. **Default:** `1`.
* `"origin"` / `"destination"`: Flexible formats (postal, IATA/ICAO `^[A-Z]{3,4}$`, UN/LOCODE `^[A-Z]{2}\W?[A-Z2-9]{3}$`, or `"lat,lon"`). Distance is auto-resolved.
* `"distance_in_km"`: If provided, **overrides** origin/destination.
* `"train_type"`: Supported categories (per DEFRA): `"national"`, `"international"`, `"light"`, `"tram"`, `"underground"`.
* `"energy_scope"`: `"wtw"` (**default**) or `"ttw"`.
* `"audit"`: boolean (optional). Set to `true` to create immutable audit records for finalized calculations. Must be enabled for your account.

***

## Origin/Destination Formats (Enriched)

SQUAKE will try to resolve the `origin`/`destination` regardless of its format. Ideally:

* **Addresses:** Use the *Post* standard.
* **Airports:** Use IATA/ICAO code (regex: `^[A-Z]{3,4}$`, e.g., `"MUC"`).
* **Ports/Trade locations:** Use UN/LOCODE (regex: `^[A-Z]{2}\W?[A-Z2-9]{3}$`, e.g., `"DEHAM"`).
* **Coordinates:** Pass latitude/longitude (regex: `^[-+]?\d{1,3}\.\d{1,10}\s?,\s?[-+]?\d{1,3}\.\d{1,10}$`, e.g., `"+40.712,-74.006"`).

**UIC and Provider Codes for Trains**

* UIC code is also a valid format for trains. If the value is not valid, the system will **fallback to general, non-journey-specific emission data**.
* When you want to use a UIC or provider code, use the following format:
  * `<provider>:<uic_code>` (e.g., `sncf:FRAAA`)
* **Possible provider prefixes:**
  * `uic`
  * `uic8_sncf`
  * `sncf`
  * `sncf_tvs`
  * `entur`
  * `db`
  * `busbud`
  * `distribusion`
  * `flixbus`
  * `cff`
  * `leoexpress`
  * `obb`
  * `trenitalia`
  * `trenitalia_rtvt`
  * `trenord`
  * `ntv_rtiv`
  * `ntv`
  * `hkx`
  * `renfe`
  * `atoc`
  * `benerail`
  * `westbahn`

**Examples**

```jsonc
// Using UIC/provider code
{
  "type": "train",
  "methodology": "DEFRA",
  "origin": "atoc:1072",         // Example UK station code structure
  "destination": "atoc:5935",
  "number_of_travelers": 1,
  "energy_scope": "wtw",
  "methodology_version": "2024"
}

// Using UN/LOCODEs (for multimodal contexts)
{
  "type": "train",
  "methodology": "DEFRA",
  "origin": "GBLON",             // London
  "destination": "GBMAN",        // Manchester
  "number_of_travelers": 1
}

// Using coordinates
{
  "type": "train",
  "methodology": "DEFRA",
  "origin": "+51.503,-0.125",    // London
  "destination": "+53.480,-2.242",// Manchester
  "number_of_travelers": 1
}
```

> **Notes**
>
> * If both `origin`/`destination` **and** `distance_in_km` are provided, `distance_in_km` is used for emissions.
> * Invalid, unsupported, or unresolvable location codes will trigger a **fallback** to generic (non-journey-specific) factors consistent with the DEFRA methodology.

***

### **Default Values**

* `"train_type": "national"`
* `"energy_scope": "wtw"`
* `"methodology_version"`: **latest supported DEFRA year**

***

### **Sample API Response**

```json
{
  "carbon_quantity": 6669,
  "carbon_unit": "gram",
  "items": [
    {
      "carbon_quantity": 6669,
      "carbon_unit": "gram",
      "external_reference": "test_2",
      "type": "train",
      "methodology": "DEFRA",
      "methodology_version": "2024",
      "distance": 435.0,
      "distance_unit": "kilometer"
    }
  ]
}
```

***

### **Versions**

* **Behavior:** If `methodology_version` is omitted, SQUAKE automatically applies the **latest supported** DEFRA Conversion Factors year. Pin a year for reproducibility and audit readiness.

***

### **Bibliography**

* UK Government — **Greenhouse gas emissions: Research & statistics**: <https://www.gov.uk/environment/greenhouse-gas-emissions#research\\_and\\_statistics>
* DEFRA (2024). **Government Greenhouse Gas Conversion Factors for Company Reporting** (Rail factors).
* UK Office of Rail and Road. **National Rail Trends**.
* Eurostar. **GHG Methodology Report**.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-integration.squake.earth/api-calculations-request-response/travel/train/train-defra.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
