Skip to content

Commit 5eb91cf

Browse files
committed
Rename "commodity costs" to "levies" everywhere
Closes #552.
1 parent c94cf76 commit 5eb91cf

11 files changed

Lines changed: 68 additions & 67 deletions

File tree

docs/generate_input_format_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Regions": ["regions"],
1414
"Agents": ["agents", "agent_*"],
1515
"Assets": ["assets"],
16-
"Commodities": ["commodities", "commodity_costs", "demand", "demand_slicing"],
16+
"Commodities": ["commodities", "commodity_levies", "demand", "demand_slicing"],
1717
"Processes": ["processes", "process_*"],
1818
}
1919

docs/glossary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ capacity can produce 31.536 PJ energy output in a year.
4141
produced and/or consumed by *Process*es* in the model. A *Service Demand* is a type of commodity
4242
that is defined at the end point of the system.
4343

44-
**Commodity Cost:** Represents a tax, levy or other external cost on a commodity. Commodity costs
45-
can be applied to all commodity production (sum of output of all processes for that commodity), net
44+
**Commodity Levy:** Represents a tax, levy or other external cost on a commodity. Levies can be
45+
applied to all commodity production (sum of output of all processes for that commodity), net
4646
production (sum of output and input for all processes), or all consumption (sum of input for all
4747
processes). It can also be negative, indicating an incentive on commodity
4848
production/consumption/net.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Commodity costs
1+
title: Commodity levies
22
description: |
33
Defines levies for commodities (or, if `value` is negative, incentives).
44
@@ -31,4 +31,4 @@ fields:
3131
`net` (applies to consumption and production)
3232
- name: value
3333
type: number
34-
title: The value of the commodity cost
34+
title: The value of the levy/incentive

src/commodity.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ define_id_type! {CommodityID}
1313
/// A map of [`Commodity`]s, keyed by commodity ID
1414
pub type CommodityMap = IndexMap<CommodityID, Rc<Commodity>>;
1515

16-
/// A map of [`CommodityCost`]s, keyed by region ID, year and time slice ID
17-
pub type CommodityCostMap = HashMap<(RegionID, u32, TimeSliceID), CommodityCost>;
16+
/// A map of [`CommodityLevy`]s, keyed by region ID, year and time slice ID
17+
pub type CommodityLevyMap = HashMap<(RegionID, u32, TimeSliceID), CommodityLevy>;
1818

1919
/// A map of demand values, keyed by region ID, year and time slice selection
2020
pub type DemandMap = HashMap<(RegionID, u32, TimeSliceSelection), f64>;
@@ -40,7 +40,7 @@ pub struct Commodity {
4040
/// every combination of parameters. Note that these values can be negative, indicating an
4141
/// incentive.
4242
#[serde(skip)]
43-
pub costs: CommodityCostMap,
43+
pub levies: CommodityLevyMap,
4444
/// Demand as defined in input files. Will be empty for non-service-demand commodities.
4545
///
4646
/// The [`TimeSliceSelection`] part of the key is always at the same [`TimeSliceLevel`] as the
@@ -67,9 +67,10 @@ pub enum BalanceType {
6767

6868
/// Represents a tax or other external cost on a commodity, as specified in input data.
6969
///
70-
/// For example, a CO2 price could be specified in input data to be applied to net CO2.
70+
/// For example, a CO2 price could be specified in input data to be applied to net CO2. Note that
71+
/// the value can also be negative, indicating an incentive.
7172
#[derive(PartialEq, Clone, Debug)]
72-
pub struct CommodityCost {
73+
pub struct CommodityLevy {
7374
/// Type of balance for application of cost
7475
pub balance_type: BalanceType,
7576
/// Cost per unit commodity
@@ -115,16 +116,16 @@ mod tests {
115116
}
116117

117118
#[test]
118-
fn test_commodity_cost_map() {
119+
fn test_commodity_levy_map() {
119120
let ts = TimeSliceID {
120121
season: "winter".into(),
121122
time_of_day: "day".into(),
122123
};
123-
let value = CommodityCost {
124+
let value = CommodityLevy {
124125
balance_type: BalanceType::Consumption,
125126
value: 0.5,
126127
};
127-
let mut map = CommodityCostMap::new();
128+
let mut map = CommodityLevyMap::new();
128129
assert!(map
129130
.insert(("GBR".into(), 2010, ts.clone()), value.clone())
130131
.is_none());

src/fixture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::agent::{
55
AgentSearchSpaceMap, DecisionRule,
66
};
77
use crate::asset::{Asset, AssetPool};
8-
use crate::commodity::{Commodity, CommodityCostMap, CommodityID, CommodityType, DemandMap};
8+
use crate::commodity::{Commodity, CommodityID, CommodityLevyMap, CommodityType, DemandMap};
99
use crate::process::{
1010
Process, ProcessEnergyLimitsMap, ProcessFlowsMap, ProcessMap, ProcessParameter,
1111
ProcessParameterMap,
@@ -62,7 +62,7 @@ pub fn svd_commodity() -> Commodity {
6262
description: "".into(),
6363
kind: CommodityType::ServiceDemand,
6464
time_slice_level: TimeSliceLevel::DayNight,
65-
costs: CommodityCostMap::new(),
65+
levies: CommodityLevyMap::new(),
6666
demand: DemandMap::new(),
6767
}
6868
}

src/input/agent/commodity_portion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod tests {
194194
use crate::agent::{
195195
Agent, AgentCostLimitsMap, AgentObjectiveMap, AgentSearchSpaceMap, DecisionRule,
196196
};
197-
use crate::commodity::{Commodity, CommodityCostMap, CommodityID, CommodityType, DemandMap};
197+
use crate::commodity::{Commodity, CommodityID, CommodityLevyMap, CommodityType, DemandMap};
198198
use crate::time_slice::TimeSliceLevel;
199199
use std::rc::Rc;
200200

@@ -222,7 +222,7 @@ mod tests {
222222
description: "A commodity".into(),
223223
kind: CommodityType::SupplyEqualsDemand,
224224
time_slice_level: TimeSliceLevel::Annual,
225-
costs: CommodityCostMap::new(),
225+
levies: CommodityLevyMap::new(),
226226
demand: DemandMap::new(),
227227
}),
228228
)]);
@@ -261,7 +261,7 @@ mod tests {
261261
description: "Another commodity".into(),
262262
kind: CommodityType::SupplyEqualsDemand,
263263
time_slice_level: TimeSliceLevel::Annual,
264-
costs: CommodityCostMap::new(),
264+
levies: CommodityLevyMap::new(),
265265
demand: DemandMap::new(),
266266
}),
267267
);

src/input/commodity.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use anyhow::Result;
77
use std::collections::HashSet;
88
use std::path::Path;
99

10-
mod cost;
11-
use cost::read_commodity_costs;
10+
mod levy;
11+
use levy::read_commodity_levies;
1212
mod demand;
1313
use demand::read_demand;
1414
mod demand_slicing;
@@ -36,7 +36,7 @@ pub fn read_commodities(
3636
let commodities =
3737
read_csv_id_file::<Commodity, CommodityID>(&model_dir.join(COMMODITY_FILE_NAME))?;
3838
let commodity_ids = commodities.keys().cloned().collect();
39-
let mut costs = read_commodity_costs(
39+
let mut costs = read_commodity_levies(
4040
model_dir,
4141
&commodity_ids,
4242
region_ids,
@@ -57,7 +57,7 @@ pub fn read_commodities(
5757
.into_iter()
5858
.map(|(id, mut commodity)| {
5959
if let Some(costs) = costs.remove(&id) {
60-
commodity.costs = costs;
60+
commodity.levies = costs;
6161
}
6262
if let Some(demand) = demand.remove(&id) {
6363
commodity.demand = demand;
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Code for reading in the commodity cost CSV file.
1+
//! Code for reading in the commodity levies CSV file.
22
use super::super::*;
3-
use crate::commodity::{BalanceType, CommodityCost, CommodityCostMap, CommodityID};
3+
use crate::commodity::{BalanceType, CommodityID, CommodityLevy, CommodityLevyMap};
44
use crate::id::IDCollection;
55
use crate::region::{parse_region_str, RegionID};
66
use crate::time_slice::TimeSliceInfo;
@@ -10,26 +10,26 @@ use serde::Deserialize;
1010
use std::collections::{HashMap, HashSet};
1111
use std::path::Path;
1212

13-
const COMMODITY_COSTS_FILE_NAME: &str = "commodity_costs.csv";
13+
const COMMODITY_LEVIES_FILE_NAME: &str = "commodity_levies.csv";
1414

1515
/// Cost parameters for each commodity
1616
#[derive(PartialEq, Debug, Deserialize, Clone)]
17-
struct CommodityCostRaw {
17+
struct CommodityLevyRaw {
1818
/// Unique identifier for the commodity (e.g. "ELC")
1919
commodity_id: String,
20-
/// The region(s) to which the commodity cost applies.
20+
/// The region(s) to which the levy applies.
2121
regions: String,
2222
/// Type of balance for application of cost.
2323
balance_type: BalanceType,
2424
/// The year(s) to which the cost applies.
2525
years: String,
2626
/// The time slice to which the cost applies.
2727
time_slice: String,
28-
/// Cost per unit commodity. For example, if a CO2 price is specified in input data, it can be applied to net CO2 via this value.
28+
/// Cost per unit commodity
2929
value: f64,
3030
}
3131

32-
/// Read costs associated with each commodity from commodity costs CSV file.
32+
/// Read costs associated with each commodity from levies CSV file.
3333
///
3434
/// # Arguments
3535
///
@@ -41,18 +41,18 @@ struct CommodityCostRaw {
4141
///
4242
/// # Returns
4343
///
44-
/// A map containing commodity costs, grouped by commodity ID.
45-
pub fn read_commodity_costs(
44+
/// A map containing levies, grouped by commodity ID.
45+
pub fn read_commodity_levies(
4646
model_dir: &Path,
4747
commodity_ids: &HashSet<CommodityID>,
4848
region_ids: &HashSet<RegionID>,
4949
time_slice_info: &TimeSliceInfo,
5050
milestone_years: &[u32],
51-
) -> Result<HashMap<CommodityID, CommodityCostMap>> {
52-
let file_path = model_dir.join(COMMODITY_COSTS_FILE_NAME);
53-
let commodity_costs_csv = read_csv::<CommodityCostRaw>(&file_path)?;
54-
read_commodity_costs_iter(
55-
commodity_costs_csv,
51+
) -> Result<HashMap<CommodityID, CommodityLevyMap>> {
52+
let file_path = model_dir.join(COMMODITY_LEVIES_FILE_NAME);
53+
let commodity_levies_csv = read_csv::<CommodityLevyRaw>(&file_path)?;
54+
read_commodity_levies_iter(
55+
commodity_levies_csv,
5656
commodity_ids,
5757
region_ids,
5858
time_slice_info,
@@ -61,15 +61,15 @@ pub fn read_commodity_costs(
6161
.with_context(|| input_err_msg(&file_path))
6262
}
6363

64-
fn read_commodity_costs_iter<I>(
64+
fn read_commodity_levies_iter<I>(
6565
iter: I,
6666
commodity_ids: &HashSet<CommodityID>,
6767
region_ids: &HashSet<RegionID>,
6868
time_slice_info: &TimeSliceInfo,
6969
milestone_years: &[u32],
70-
) -> Result<HashMap<CommodityID, CommodityCostMap>>
70+
) -> Result<HashMap<CommodityID, CommodityLevyMap>>
7171
where
72-
I: Iterator<Item = CommodityCostRaw>,
72+
I: Iterator<Item = CommodityLevyRaw>,
7373
{
7474
let mut map = HashMap::new();
7575

@@ -83,13 +83,13 @@ where
8383
let years = parse_year_str(&cost.years, milestone_years)?;
8484
let ts_selection = time_slice_info.get_selection(&cost.time_slice)?;
8585

86-
// Get or create CommodityCostMap for this commodity
86+
// Get or create CommodityLevyMap for this commodity
8787
let map = map
8888
.entry(commodity_id.clone())
89-
.or_insert_with(CommodityCostMap::new);
89+
.or_insert_with(CommodityLevyMap::new);
9090

91-
// Create CommodityCost
92-
let cost = CommodityCost {
91+
// Create CommodityLevy
92+
let cost = CommodityLevy {
9393
balance_type: cost.balance_type,
9494
value: cost.value,
9595
};
@@ -115,14 +115,14 @@ where
115115
// Validate map
116116
for (commodity_id, regions) in commodity_regions.iter() {
117117
let map = map.get(commodity_id).unwrap();
118-
validate_commodity_cost_map(map, regions, milestone_years, time_slice_info)
118+
validate_commodity_levy_map(map, regions, milestone_years, time_slice_info)
119119
.with_context(|| format!("Missing costs for commodity {}", commodity_id))?;
120120
}
121121
Ok(map)
122122
}
123123

124-
fn validate_commodity_cost_map(
125-
map: &CommodityCostMap,
124+
fn validate_commodity_levy_map(
125+
map: &CommodityLevyMap,
126126
regions: &HashSet<RegionID>,
127127
milestone_years: &[u32],
128128
time_slice_info: &TimeSliceInfo,
@@ -159,58 +159,58 @@ mod tests {
159159
}
160160

161161
#[fixture]
162-
fn cost_map(time_slice: TimeSliceID) -> CommodityCostMap {
163-
let cost = CommodityCost {
162+
fn cost_map(time_slice: TimeSliceID) -> CommodityLevyMap {
163+
let cost = CommodityLevy {
164164
balance_type: BalanceType::Net,
165165
value: 1.0,
166166
};
167167

168-
let mut map = CommodityCostMap::new();
168+
let mut map = CommodityLevyMap::new();
169169
map.insert(("GBR".into(), 2020, time_slice.clone()), cost.clone());
170170
map
171171
}
172172

173173
#[rstest]
174-
fn test_validate_commodity_costs_map_valid(
175-
cost_map: CommodityCostMap,
174+
fn test_validate_commodity_levies_map_valid(
175+
cost_map: CommodityLevyMap,
176176
time_slice_info: TimeSliceInfo,
177177
region_ids: HashSet<RegionID>,
178178
) {
179179
// Valid map
180180
assert!(
181-
validate_commodity_cost_map(&cost_map, &region_ids, &[2020], &time_slice_info).is_ok()
181+
validate_commodity_levy_map(&cost_map, &region_ids, &[2020], &time_slice_info).is_ok()
182182
);
183183
}
184184

185185
#[rstest]
186-
fn test_validate_commodity_costs_map_invalid_missing_region(
187-
cost_map: CommodityCostMap,
186+
fn test_validate_commodity_levies_map_invalid_missing_region(
187+
cost_map: CommodityLevyMap,
188188
time_slice_info: TimeSliceInfo,
189189
) {
190190
// Missing region
191191
let region_ids = HashSet::from(["GBR".into(), "FRA".into()]);
192192
assert_error!(
193-
validate_commodity_cost_map(&cost_map, &region_ids, &[2020], &time_slice_info),
193+
validate_commodity_levy_map(&cost_map, &region_ids, &[2020], &time_slice_info),
194194
"Missing cost for region FRA, year 2020, time slice winter.day"
195195
);
196196
}
197197

198198
#[rstest]
199-
fn test_validate_commodity_costs_map_invalid_missing_year(
200-
cost_map: CommodityCostMap,
199+
fn test_validate_commodity_levies_map_invalid_missing_year(
200+
cost_map: CommodityLevyMap,
201201
time_slice_info: TimeSliceInfo,
202202
region_ids: HashSet<RegionID>,
203203
) {
204204
// Missing year
205205
assert_error!(
206-
validate_commodity_cost_map(&cost_map, &region_ids, &[2020, 2030], &time_slice_info),
206+
validate_commodity_levy_map(&cost_map, &region_ids, &[2020, 2030], &time_slice_info),
207207
"Missing cost for region GBR, year 2030, time slice winter.day"
208208
);
209209
}
210210

211211
#[rstest]
212-
fn test_validate_commodity_costs_map_invalid(
213-
cost_map: CommodityCostMap,
212+
fn test_validate_commodity_levies_map_invalid(
213+
cost_map: CommodityLevyMap,
214214
region_ids: HashSet<RegionID>,
215215
) {
216216
// Missing time slice
@@ -224,7 +224,7 @@ mod tests {
224224
time_slices: [(time_slice.clone(), 0.5), (time_slice.clone(), 0.5)].into(),
225225
};
226226
assert_error!(
227-
validate_commodity_cost_map(&cost_map, &region_ids, &[2020], &time_slice_info),
227+
validate_commodity_levy_map(&cost_map, &region_ids, &[2020], &time_slice_info),
228228
"Missing cost for region GBR, year 2020, time slice winter.night"
229229
);
230230
}

src/input/process.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn validate_svd_commodity(
280280
#[cfg(test)]
281281
mod tests {
282282
use super::*;
283-
use crate::commodity::{CommodityCostMap, DemandMap};
283+
use crate::commodity::{CommodityLevyMap, DemandMap};
284284
use crate::fixture::{time_slice, time_slice_info};
285285
use crate::process::{FlowType, ProcessFlow};
286286
use crate::time_slice::{TimeSliceID, TimeSliceLevel};
@@ -294,7 +294,7 @@ mod tests {
294294
description: "SED commodity".into(),
295295
kind: CommodityType::SupplyEqualsDemand,
296296
time_slice_level: TimeSliceLevel::Annual,
297-
costs: CommodityCostMap::new(),
297+
levies: CommodityLevyMap::new(),
298298
demand: DemandMap::new(),
299299
}
300300
}
@@ -367,7 +367,7 @@ mod tests {
367367
description: "SVD commodity".into(),
368368
kind: CommodityType::ServiceDemand,
369369
time_slice_level: TimeSliceLevel::Annual,
370-
costs: CommodityCostMap::new(),
370+
levies: CommodityLevyMap::new(),
371371
demand,
372372
}
373373
}

0 commit comments

Comments
 (0)