1- //! Code for reading in the commodity cost CSV file.
1+ //! Code for reading in the commodity levies CSV file.
22use super :: super :: * ;
3- use crate :: commodity:: { BalanceType , CommodityCost , CommodityCostMap , CommodityID } ;
3+ use crate :: commodity:: { BalanceType , CommodityID , CommodityLevy , CommodityLevyMap } ;
44use crate :: id:: IDCollection ;
55use crate :: region:: { parse_region_str, RegionID } ;
66use crate :: time_slice:: TimeSliceInfo ;
@@ -10,26 +10,26 @@ use serde::Deserialize;
1010use std:: collections:: { HashMap , HashSet } ;
1111use 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 > >
7171where
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 }
0 commit comments