Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes/upcoming.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ready to be released, carry out the following steps:
- The `addition_limit` column in `process_investment_constraints.csv` is now optional ([#1427])
- Memory usage and performance has been drastically improved for divisible assets with many units
([#1464])
- `asset_capacities.csv` now reports total and mothballed capacity and unit counts ([#1461])

## Breaking changes

Expand Down
8 changes: 7 additions & 1 deletion schemas/output/asset_capacities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ fields:
description: The total capacity of the asset in this year
- name: num_units
type: integer
description: The number of units making up the asset in this year
description: The total number of units making up the asset in this year
- name: mothballed_capacity
type: number
description: The capacity of the asset that is mothballed in this year
- name: mothballed_units
type: integer
description: The number of units that are mothballed in this year
13 changes: 11 additions & 2 deletions src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::region::RegionID;
use crate::simulation::PriceMap;
use crate::time_slice::{TimeSliceID, TimeSliceSelection};
use crate::units::{
Activity, ActivityPerCapacity, Capacity, FlowPerActivity, MoneyPerActivity, MoneyPerCapacity,
MoneyPerFlow, UnitType, Year,
Activity, ActivityPerCapacity, Capacity, Dimensionless, FlowPerActivity, MoneyPerActivity,
MoneyPerCapacity, MoneyPerFlow, UnitType, Year,
};
use anyhow::{Context, Result, ensure};
use indexmap::IndexMap;
Expand Down Expand Up @@ -834,6 +834,11 @@ impl Asset {
events.iter().map(|event| event.num_units).sum()
}

/// Get the capacity which is mothballed.
pub fn mothballed_capacity(&self) -> Capacity {
self.capacity().unit_size() * Dimensionless(self.get_num_mothballed_units() as f64)
}

/// Get the remaining number of units that are not mothballed.
///
/// For non-commissioned assets, this always returns the total number of units.
Expand Down Expand Up @@ -1612,6 +1617,10 @@ mod tests {
assert_eq!(commissioned_multi_unit.num_units(), 3);
let asset = commissioned_multi_unit.with_mothballed_units(num_mothballed, Some(2020));
assert_eq!(asset.get_num_mothballed_units(), num_mothballed);
assert_eq!(
asset.mothballed_capacity(),
Capacity(4.0 * num_mothballed as f64)
);
assert_eq!(asset.get_num_nonmothballed_units(), 3 - num_mothballed);
assert_eq!(asset.has_any_mothballed_units(), num_mothballed > 0);
}
Expand Down
48 changes: 47 additions & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ struct AssetCapacityRow {
asset_id: AssetID,
capacity: Capacity,
num_units: u32,
mothballed_capacity: Capacity,
mothballed_units: u32,
}

/// Represents the flow-related data in a row of the commodity flows CSV file.
Expand Down Expand Up @@ -638,6 +640,8 @@ impl DataWriter {
asset_id: asset.id().unwrap(),
capacity: asset.total_capacity(),
num_units: asset.capacity().num_units(),
mothballed_capacity: asset.mothballed_capacity(),
mothballed_units: asset.get_num_mothballed_units(),
};
self.asset_capacities.serialize(row)?;
}
Expand Down Expand Up @@ -709,7 +713,9 @@ impl DataWriter {
mod tests {
use super::*;
use crate::asset::AssetPool;
use crate::fixture::{appraisal_output, asset, assets, commodity_id, region_id, time_slice};
use crate::fixture::{
appraisal_output, asset, assets, commodity_id, multi_unit_asset, region_id, time_slice,
};
use crate::simulation::investment::appraisal::AppraisalOutput;
use crate::time_slice::TimeSliceID;
use indexmap::indexmap;
Expand Down Expand Up @@ -761,6 +767,46 @@ mod tests {
asset_id: asset.id().unwrap(),
capacity: asset.total_capacity(),
num_units: 1,
mothballed_capacity: Capacity(0.0),
mothballed_units: 0,
};
let records: Vec<AssetCapacityRow> =
csv::Reader::from_path(dir.path().join(ASSET_CAPACITIES_FILE_NAME))
.unwrap()
.into_deserialize()
.try_collect()
.unwrap();
assert_equal(records, iter::once(expected));
}

#[rstest]
fn write_asset_capacities_with_mothballed_units(multi_unit_asset: Asset) {
let milestone_year = 2020;
let dir = tempdir().unwrap();
let mut assets = AssetPool::new();
assets.commission_new(2010, &mut vec![multi_unit_asset.into()]);
let asset = assets
.iter()
.next()
.unwrap()
.clone()
.with_mothballed_units(1, Some(milestone_year));

{
let mut writer = DataWriter::create(dir.path(), dir.path(), false).unwrap();
writer
.write_asset_capacities(milestone_year, std::slice::from_ref(&asset))
.unwrap();
writer.flush().unwrap();
}

let expected = AssetCapacityRow {
milestone_year,
asset_id: asset.id().unwrap(),
capacity: Capacity(12.0),
num_units: 3,
mothballed_capacity: Capacity(4.0),
mothballed_units: 1,
};
let records: Vec<AssetCapacityRow> =
csv::Reader::from_path(dir.path().join(ASSET_CAPACITIES_FILE_NAME))
Expand Down
92 changes: 46 additions & 46 deletions tests/data/circularity/asset_capacities.csv
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
milestone_year,asset_id,capacity,num_units
2020,0,4010.2,1
2020,1,1738.05,1
2020,2,3789.64,1
2020,3,716.5,1
2020,4,573.9,1
2020,5,3.964844,1
2020,6,2.999,1
2020,7,1.0,1
2020,8,31.54,1
2020,9,451.91,1
2020,10,176.58,1
2020,11,20.99,1
2020,12,15.0,1
2020,13,2900.0,1
2020,14,399.98,1
2030,0,4010.2,1
2030,1,1738.05,1
2030,2,3789.64,1
2030,5,3.964844,1
2030,6,2.999,1
2030,13,2900.0,1
2030,14,399.98,1
2030,15,802.563016789748,28
2030,16,1849.28399075358,36
2030,17,3680.183145405077,26
2030,18,298.6475820926018,57
2030,19,2944.1465163240614,16
2030,20,165.3505808753475,27
2040,5,3.964844,1
2040,6,2.999,1
2040,16,1849.28399075358,36
2040,18,298.6475820926018,57
2040,19,1288.064100891777,7
2040,20,165.3505808753475,27
2040,21,942.563016229748,28
2040,22,2198.390989008045,39
2040,23,34.19605824723177,15
2040,24,5.471369319196239,6
2040,25,9.118948865327066,9
2040,26,132.08198143321187,15
2040,27,453.28514602874316,33
2040,28,972.485651665613,26
2040,29,2349.6972514094086,33
2040,30,475.9494033301804,33
2040,31,2627.9227668603858,37
milestone_year,asset_id,capacity,num_units,mothballed_capacity,mothballed_units
2020,0,4010.2,1,0.0,0
2020,1,1738.05,1,0.0,0
2020,2,3789.64,1,0.0,0
2020,3,716.5,1,0.0,0
2020,4,573.9,1,0.0,0
2020,5,3.964844,1,0.0,0
2020,6,2.999,1,0.0,0
2020,7,1.0,1,0.0,0
2020,8,31.54,1,0.0,0
2020,9,451.91,1,0.0,0
2020,10,176.58,1,0.0,0
2020,11,20.99,1,0.0,0
2020,12,15.0,1,0.0,0
2020,13,2900.0,1,0.0,0
2020,14,399.98,1,0.0,0
2030,0,4010.2,1,0.0,0
2030,1,1738.05,1,0.0,0
2030,2,3789.64,1,0.0,0
2030,5,3.964844,1,0.0,0
2030,6,2.999,1,0.0,0
2030,13,2900.0,1,0.0,0
2030,14,399.98,1,0.0,0
2030,15,802.563016789748,28,0.0,0
2030,16,1849.28399075358,36,0.0,0
2030,17,3680.183145405077,26,0.0,0
2030,18,298.6475820926018,57,0.0,0
2030,19,2944.1465163240614,16,0.0,0
2030,20,165.3505808753475,27,0.0,0
2040,5,3.964844,1,0.0,0
2040,6,2.999,1,0.0,0
2040,16,1849.28399075358,36,0.0,0
2040,18,298.6475820926018,57,0.0,0
2040,19,1288.064100891777,7,0.0,0
2040,20,165.3505808753475,27,0.0,0
2040,21,942.563016229748,28,0.0,0
2040,22,2198.390989008045,39,0.0,0
2040,23,34.19605824723177,15,0.0,0
2040,24,5.471369319196239,6,0.0,0
2040,25,9.118948865327066,9,0.0,0
2040,26,132.08198143321187,15,0.0,0
2040,27,453.28514602874316,33,0.0,0
2040,28,972.485651665613,26,0.0,0
2040,29,2349.6972514094086,33,0.0,0
2040,30,475.9494033301804,33,0.0,0
2040,31,2627.9227668603858,37,0.0,0
92 changes: 46 additions & 46 deletions tests/data/circularity_npv/asset_capacities.csv
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
milestone_year,asset_id,capacity,num_units
2020,0,4010.2,1
2020,1,1738.05,1
2020,2,3789.64,1
2020,3,716.5,1
2020,4,573.9,1
2020,5,3.964844,1
2020,6,2.999,1
2020,7,1.0,1
2020,8,31.54,1
2020,9,451.91,1
2020,10,176.58,1
2020,11,20.99,1
2020,12,15.0,1
2020,13,2900.0,1
2020,14,399.98,1
2030,0,4010.2,1
2030,1,1738.05,1
2030,2,3789.64,1
2030,5,3.964844,1
2030,6,2.999,1
2030,13,2900.0,1
2030,14,399.98,1
2030,15,802.563016789748,28
2030,16,1849.28399075358,36
2030,17,3680.183145405077,26
2030,18,298.6475820926018,57
2030,19,2944.1465163240614,16
2030,20,165.3505808753475,27
2040,5,3.964844,1
2040,6,2.999,1
2040,16,1849.28399075358,36
2040,18,298.6475820926018,57
2040,19,1288.064100891777,7
2040,20,165.3505808753475,27
2040,21,942.563016229748,28
2040,22,2198.390989008045,39
2040,23,34.19605824723177,15
2040,24,5.471369319196239,6
2040,25,9.118948865327066,9
2040,26,132.08198143321187,15
2040,27,453.28514602874316,33
2040,28,972.485651665613,26
2040,29,2349.6972514094086,33
2040,30,475.9494033301804,33
2040,31,2627.9227668603858,37
milestone_year,asset_id,capacity,num_units,mothballed_capacity,mothballed_units
2020,0,4010.2,1,0.0,0
2020,1,1738.05,1,0.0,0
2020,2,3789.64,1,0.0,0
2020,3,716.5,1,0.0,0
2020,4,573.9,1,0.0,0
2020,5,3.964844,1,0.0,0
2020,6,2.999,1,0.0,0
2020,7,1.0,1,0.0,0
2020,8,31.54,1,0.0,0
2020,9,451.91,1,0.0,0
2020,10,176.58,1,0.0,0
2020,11,20.99,1,0.0,0
2020,12,15.0,1,0.0,0
2020,13,2900.0,1,0.0,0
2020,14,399.98,1,0.0,0
2030,0,4010.2,1,0.0,0
2030,1,1738.05,1,0.0,0
2030,2,3789.64,1,0.0,0
2030,5,3.964844,1,0.0,0
2030,6,2.999,1,0.0,0
2030,13,2900.0,1,0.0,0
2030,14,399.98,1,0.0,0
2030,15,802.563016789748,28,0.0,0
2030,16,1849.28399075358,36,0.0,0
2030,17,3680.183145405077,26,0.0,0
2030,18,298.6475820926018,57,0.0,0
2030,19,2944.1465163240614,16,0.0,0
2030,20,165.3505808753475,27,0.0,0
2040,5,3.964844,1,0.0,0
2040,6,2.999,1,0.0,0
2040,16,1849.28399075358,36,0.0,0
2040,18,298.6475820926018,57,0.0,0
2040,19,1288.064100891777,7,0.0,0
2040,20,165.3505808753475,27,0.0,0
2040,21,942.563016229748,28,0.0,0
2040,22,2198.390989008045,39,0.0,0
2040,23,34.19605824723177,15,0.0,0
2040,24,5.471369319196239,6,0.0,0
2040,25,9.118948865327066,9,0.0,0
2040,26,132.08198143321187,15,0.0,0
2040,27,453.28514602874316,33,0.0,0
2040,28,972.485651665613,26,0.0,0
2040,29,2349.6972514094086,33,0.0,0
2040,30,475.9494033301804,33,0.0,0
2040,31,2627.9227668603858,37,0.0,0
46 changes: 23 additions & 23 deletions tests/data/missing_commodity/asset_capacities.csv
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
milestone_year,asset_id,capacity,num_units
2020,0,4002.26,1
2020,1,3782.13,1
2020,2,3.964844,1
2020,3,2.43,1
2020,4,2900.0,1
2020,5,399.98,1
2030,0,4002.26,1
2030,1,3782.13,1
2030,2,3.964844,1
2030,3,2.43,1
2030,4,2900.0,1
2030,5,399.98,1
2030,6,1849.28399075358,36
2030,7,4.582296913025608,13
2030,8,178.91233238712087,66
2030,9,189.58177552751894,30
2040,6,1849.28399075358,36
2040,8,178.91233238712087,66
2040,9,189.58177552751894,30
2040,10,2198.390989008045,39
2040,11,2420.9001984218153,34
2040,12,2556.897827215511,36
milestone_year,asset_id,capacity,num_units,mothballed_capacity,mothballed_units
2020,0,4002.26,1,0.0,0
2020,1,3782.13,1,0.0,0
2020,2,3.964844,1,0.0,0
2020,3,2.43,1,0.0,0
2020,4,2900.0,1,0.0,0
2020,5,399.98,1,0.0,0
2030,0,4002.26,1,0.0,0
2030,1,3782.13,1,0.0,0
2030,2,3.964844,1,0.0,0
2030,3,2.43,1,0.0,0
2030,4,2900.0,1,0.0,0
2030,5,399.98,1,0.0,0
2030,6,1849.28399075358,36,0.0,0
2030,7,4.582296913025608,13,0.0,0
2030,8,178.91233238712087,66,0.0,0
2030,9,189.58177552751894,30,0.0,0
2040,6,1849.28399075358,36,0.0,0
2040,8,178.91233238712087,66,0.0,0
2040,9,189.58177552751894,30,0.0,0
2040,10,2198.390989008045,39,0.0,0
2040,11,2420.9001984218153,34,0.0,0
2040,12,2556.897827215511,36,0.0,0
Loading
Loading