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
3 changes: 2 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! The command line interface for the simulation.
use crate::input::load_model;
use crate::log;
use crate::output::create_output_directory;
use crate::settings::Settings;
use crate::{input::load_model, log};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS Code seems determined to format use statements like this sometimes. No idea why

use ::log::{error, info};
use anyhow::{ensure, Context, Result};
use clap::{Parser, Subcommand};
Expand Down
2 changes: 1 addition & 1 deletion src/commodity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(missing_docs)]
use crate::input::*;
use crate::input::{define_id_getter, HasID};
use crate::time_slice::{TimeSliceID, TimeSliceLevel};
use indexmap::IndexMap;
use serde::Deserialize;
Expand Down
26 changes: 13 additions & 13 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ use std::fs;
use std::path::Path;
use std::rc::Rc;

pub mod agent;
pub use agent::read_agents;
pub mod asset;
mod agent;
use agent::read_agents;
mod asset;
use asset::read_assets;
pub mod commodity;
pub use commodity::read_commodities;
pub mod process;
pub use process::read_processes;
pub mod region;
pub use region::read_regions;
mod commodity;
use commodity::read_commodities;
mod process;
use process::read_processes;
mod region;
use region::read_regions;
mod time_slice;
pub use time_slice::read_time_slice_info;
use time_slice::read_time_slice_info;

/// Read a series of type `T`s from a CSV file.
///
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn read_toml<T: DeserializeOwned>(file_path: &Path) -> Result<T> {
}

/// Read an f64, checking that it is between 0 and 1
pub fn deserialise_proportion_nonzero<'de, D>(deserialiser: D) -> Result<f64, D::Error>
fn deserialise_proportion_nonzero<'de, D>(deserialiser: D) -> Result<f64, D::Error>
where
D: Deserializer<'de>,
{
Expand Down Expand Up @@ -142,7 +142,7 @@ impl IDCollection for HashSet<Rc<str>> {
///
/// As this function is only ever used for top-level CSV files (i.e. the ones which actually define
/// the IDs for a given type), we use an ordered map to maintain the order in the input files.
pub fn read_csv_id_file<T>(file_path: &Path) -> Result<IndexMap<Rc<str>, T>>
fn read_csv_id_file<T>(file_path: &Path) -> Result<IndexMap<Rc<str>, T>>
where
T: HasID + DeserializeOwned,
{
Expand Down Expand Up @@ -197,7 +197,7 @@ where
}

/// Check that fractions sum to (approximately) one
pub fn check_fractions_sum_to_one<I>(fractions: I) -> Result<()>
fn check_fractions_sum_to_one<I>(fractions: I) -> Result<()>
where
I: Iterator<Item = f64>,
{
Expand Down
10 changes: 5 additions & 5 deletions src/input/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use std::collections::HashSet;
use std::path::Path;
use std::rc::Rc;

pub mod objective;
mod objective;
use objective::read_agent_objectives;
pub mod region;
mod region;
use region::read_agent_regions;
pub mod search_space;
mod search_space;
use search_space::read_agent_search_space;
pub mod commodity;
mod commodity;
use commodity::read_agent_commodities;

const AGENT_FILE_NAME: &str = "agents.csv";
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn read_agents(
/// # Returns
///
/// A map of Agents, with the agent ID as the key
pub fn read_agents_file(model_dir: &Path) -> Result<AgentMap> {
fn read_agents_file(model_dir: &Path) -> Result<AgentMap> {
let file_path = model_dir.join(AGENT_FILE_NAME);
let agents_csv = read_csv(&file_path)?;
read_agents_file_from_iter(agents_csv).with_context(|| input_err_msg(&file_path))
Expand Down
10 changes: 5 additions & 5 deletions src/input/agent/commodity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ const AGENT_COMMODITIES_FILE_NAME: &str = "agent_commodities.csv";
#[derive(PartialEq, Debug, Deserialize)]
struct AgentCommodityRaw {
/// Unique agent id identifying the agent.
pub agent_id: String,
agent_id: String,
/// The commodity that the agent is responsible for.
pub commodity_id: String,
commodity_id: String,
/// The year the commodity portion applies to.
pub year: u32,
year: u32,
/// The proportion of the commodity production that the agent is responsible for.
#[serde(deserialize_with = "deserialise_proportion_nonzero")]
pub commodity_portion: f64,
commodity_portion: f64,
}

impl AgentCommodityRaw {
pub fn to_agent_commodity(
fn to_agent_commodity(
&self,
commodities: &CommodityMap,
milestone_years: &[u32],
Expand Down
4 changes: 2 additions & 2 deletions src/input/agent/region.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Code for loading the agent regions CSV file.
use crate::input::region::{define_region_id_getter, read_regions_for_entity};
use crate::input::HasID;
use super::super::region::{define_region_id_getter, read_regions_for_entity};
use super::super::HasID;
use crate::region::RegionSelection;
use anyhow::Result;
use serde::Deserialize;
Expand Down
10 changes: 5 additions & 5 deletions src/input/agent/search_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ const AGENT_SEARCH_SPACE_FILE_NAME: &str = "agent_search_space.csv";
#[derive(PartialEq, Debug, Deserialize)]
struct AgentSearchSpaceRaw {
/// The agent to apply the search space to.
pub agent_id: String,
agent_id: String,
/// The commodity to apply the search space to.
pub commodity_id: String,
commodity_id: String,
/// The year to apply the search space to.
pub year: u32,
year: u32,
/// The processes that the agent will consider investing in. Expressed as process IDs separated
/// by semicolons or `None`, meaning all processes.
pub search_space: Option<String>,
search_space: Option<String>,
}

impl AgentSearchSpaceRaw {
pub fn to_agent_search_space(
fn to_agent_search_space(
&self,
process_ids: &HashSet<Rc<str>>,
commodities: &CommodityMap,
Expand Down
2 changes: 1 addition & 1 deletion src/input/asset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Code for reading [Asset]s from a CSV file.
use super::*;
use crate::asset::Asset;
use crate::input::*;
use crate::process::ProcessMap;
use anyhow::{ensure, Context, Result};
use itertools::Itertools;
Expand Down
8 changes: 4 additions & 4 deletions src/input/commodity.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Code for reading in commodity-related data from CSV files.
use super::*;
use crate::commodity::{Commodity, CommodityMap};
use crate::input::*;
use crate::time_slice::TimeSliceInfo;
use anyhow::Result;
use std::collections::HashSet;
use std::path::Path;
use std::rc::Rc;

pub mod cost;
mod cost;
use cost::read_commodity_costs;
pub mod demand;
mod demand;
use demand::read_demand;
pub mod demand_slicing;
mod demand_slicing;

const COMMODITY_FILE_NAME: &str = "commodities.csv";

Expand Down
14 changes: 7 additions & 7 deletions src/input/commodity/cost.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Code for reading in the commodity cost CSV file.
use super::super::*;
use crate::commodity::{BalanceType, CommodityCost, CommodityCostMap};
use crate::input::*;
use crate::time_slice::TimeSliceInfo;
use anyhow::{ensure, Context, Result};
use serde::Deserialize;
Expand All @@ -14,17 +14,17 @@ const COMMODITY_COSTS_FILE_NAME: &str = "commodity_costs.csv";
#[derive(PartialEq, Debug, Deserialize, Clone)]
struct CommodityCostRaw {
/// Unique identifier for the commodity (e.g. "ELC")
pub commodity_id: String,
commodity_id: String,
/// The region to which the commodity cost applies.
pub region_id: String,
region_id: String,
/// Type of balance for application of cost.
pub balance_type: BalanceType,
balance_type: BalanceType,
/// The year to which the cost applies.
pub year: u32,
year: u32,
/// The time slice to which the cost applies.
pub time_slice: String,
time_slice: String,
/// 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.
pub value: f64,
value: f64,
}

/// Read costs associated with each commodity from commodity costs CSV file.
Expand Down
2 changes: 1 addition & 1 deletion src/input/commodity/demand.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Code for working with demand for a given commodity. Demand can vary by region, year and time
//! slice.
use super::super::*;
use super::demand_slicing::{read_demand_slices, DemandSliceMap, DemandSliceMapKey};
use crate::commodity::DemandMap;
use crate::input::*;
use crate::time_slice::TimeSliceInfo;
use anyhow::{ensure, Result};
use serde::Deserialize;
Expand Down
2 changes: 1 addition & 1 deletion src/input/commodity/demand_slicing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Demand slicing determines how annual demand is distributed across the year.
use super::super::*;
use super::demand::*;
use crate::input::*;
use crate::time_slice::{TimeSliceID, TimeSliceInfo};
use anyhow::{ensure, Context, Result};
use itertools::Itertools;
Expand Down
14 changes: 7 additions & 7 deletions src/input/process.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//! Code for reading process-related information from CSV files.
use super::*;
use crate::commodity::{Commodity, CommodityMap, CommodityType};
use crate::input::*;
use crate::process::{ActivityLimitsMap, Process, ProcessFlow, ProcessMap, ProcessParameter};
use crate::region::RegionSelection;
use crate::time_slice::TimeSliceInfo;
use anyhow::Result;
use anyhow::{bail, ensure, Context, Result};
use serde::Deserialize;
use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::rc::Rc;
pub mod availability;

mod availability;
use availability::read_process_availabilities;
pub mod flow;
mod flow;
use flow::read_process_flows;
pub mod parameter;
mod parameter;
use parameter::read_process_parameters;
pub mod region;
use anyhow::bail;
mod region;
use region::read_process_regions;

const PROCESSES_FILE_NAME: &str = "processes.csv";
Expand Down
2 changes: 1 addition & 1 deletion src/input/process/availability.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Code for reading process availabilities CSV file
use crate::input::*;
use super::super::*;
use crate::process::ActivityLimitsMap;
use crate::time_slice::TimeSliceInfo;
use anyhow::{Context, Result};
Expand Down
2 changes: 1 addition & 1 deletion src/input/process/flow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code for reading process flows file
use super::super::*;
use super::define_process_id_getter;
use crate::commodity::CommodityMap;
use crate::input::*;
use crate::process::{FlowType, ProcessFlow};
use anyhow::{ensure, Context, Result};
use itertools::Itertools;
Expand Down
20 changes: 10 additions & 10 deletions src/input/process/parameter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Code for reading process parameters CSV file
use super::super::*;
use super::define_process_id_getter;
use crate::input::*;
use crate::process::ProcessParameter;
use ::log::warn;
use anyhow::{ensure, Context, Result};
Expand All @@ -14,15 +14,15 @@ const PROCESS_PARAMETERS_FILE_NAME: &str = "process_parameters.csv";

#[derive(PartialEq, Debug, Deserialize)]
struct ProcessParameterRaw {
pub process_id: String,
pub start_year: Option<u32>,
pub end_year: Option<u32>,
pub capital_cost: f64,
pub fixed_operating_cost: f64,
pub variable_operating_cost: f64,
pub lifetime: u32,
pub discount_rate: Option<f64>,
pub capacity_to_activity: Option<f64>,
process_id: String,
start_year: Option<u32>,
end_year: Option<u32>,
capital_cost: f64,
fixed_operating_cost: f64,
variable_operating_cost: f64,
lifetime: u32,
discount_rate: Option<f64>,
capacity_to_activity: Option<f64>,
}
define_process_id_getter! {ProcessParameterRaw}

Expand Down
4 changes: 2 additions & 2 deletions src/input/process/region.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code for reading the process region CSV file
use super::super::region::{define_region_id_getter, read_regions_for_entity};
use super::super::*;
use super::define_process_id_getter;
use crate::input::region::{define_region_id_getter, read_regions_for_entity};
use crate::input::*;
use crate::region::RegionSelection;
use anyhow::Result;
use serde::Deserialize;
Expand Down
4 changes: 2 additions & 2 deletions src/input/time_slice.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Code for reading in time slice info from a CSV file.
use crate::input::*;
use super::*;
use crate::time_slice::{TimeSliceID, TimeSliceInfo};
use anyhow::{ensure, Context, Result};
use indexmap::IndexSet;
use indexmap::{IndexMap, IndexSet};
use serde::Deserialize;
use std::path::Path;
use std::rc::Rc;
Expand Down
2 changes: 1 addition & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(missing_docs)]
use crate::agent::AgentMap;
use crate::commodity::CommodityMap;
use crate::input::*;
use crate::input::{input_err_msg, read_toml};
use crate::process::ProcessMap;
use crate::region::RegionMap;
use crate::time_slice::TimeSliceInfo;
Expand Down