Skip to main content

powerio/
lib.rs

1//! Typed balanced network models, parsers, and writers.
2//!
3//! Readers and writers cover MATPOWER `.m`, PowerModels JSON, PSS/E `.raw`,
4//! PowerWorld `.aux`, pandapower JSON, PyPSA CSV, egret JSON, PSLF `.epc`, GO
5//! Challenge 3 JSON, Surge JSON, and DeepMind OPFData JSON. PowerWorld `.pwb`
6//! case files are read only, and GO Challenge 3 and OPFData JSON have no
7//! canonical writer beyond same source echo; `.pwd` display files parse through
8//! [`parse_display_file`].
9//! Each reader produces a [`BalancedNetwork`]. [`BalancedNetwork::to_format`] returns the
10//! serialized target and warnings for fields the target cannot represent. See
11//! [`crate::format`] for format routing and fidelity rules.
12//!
13//! A reader that retains source text can return those bytes when writing the
14//! same format. Matrix and problem instance builders live in separate crates.
15//!
16//! ```
17//! use powerio::{parse_str, TargetFormat};
18//!
19//! let src = "\
20//! function mpc = example
21//! mpc.version = '2';
22//! mpc.baseMVA = 100;
23//! mpc.bus = [
24//! \t1\t3\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
25//! \t2\t1\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
26//! ];
27//! mpc.branch = [
28//! \t1\t2\t0.01\t0.1\t0\t0\t0\t0\t0\t0\t1\t-360\t360;
29//! ];
30//! ";
31//! let net = parse_str(src, "matpower")?.network;
32//! assert_eq!(net.buses.len(), 2);
33//! assert_eq!(net.to_format(TargetFormat::Matpower)?.text, src);
34//! # Ok::<(), powerio::Error>(())
35//! ```
36
37/// The powerio crate version, for provenance fields written by downstream
38/// crates whose own version can drift from the core's.
39pub const VERSION: &str = env!("CARGO_PKG_VERSION");
40
41pub mod dc;
42pub mod error;
43pub mod format;
44pub mod gen_cost;
45pub mod geo;
46pub mod indexed;
47pub mod network;
48mod normalize;
49mod operations;
50pub mod solver_tables;
51pub mod version;
52
53pub use dc::DcConvention;
54pub use error::{Error, ErrorCategory, Result};
55pub use format::{
56    Conversion, DisplayData, DisplayFormat, Parsed, PwdDisplay, PwdSubstation, PypsaCsvOutputs,
57    SourceDocument, TargetFormat, WriteOptions, convert_file, convert_file_with_options,
58    convert_str, convert_str_with_options, display_format_from_name, parse_bytes,
59    parse_bytes_with_name, parse_deepmind_opfdata_json, parse_display_bytes, parse_display_file,
60    parse_egret_json, parse_file, parse_goc3_json, parse_matpower, parse_matpower_file,
61    parse_pandapower_json, parse_powermodels_json, parse_powerworld, parse_pslf, parse_psse,
62    parse_str, parse_str_with_name, parse_surge_json, read_pypsa_csv_folder,
63    target_format_from_name, write_as, write_as_with_options, write_dir, write_egret_json,
64    write_matpower, write_pandapower_json, write_powermodels_json, write_powerworld, write_pslf,
65    write_psse, write_psse_rev, write_pypsa_csv_folder, write_surge_json,
66};
67pub use gen_cost::{GenCostPatch, GenCostPolicyReport, MissingGenCostPolicy, parse_gen_cost_csv};
68pub use geo::{
69    Canvas, CoordinateSpace, CoordsKind, ElementKey, GeoApplyReport, GeoFeature, GeoGeometry,
70    GeoLayer, GeoMeta, GeoParsed, GeoTarget, Location, apply_substation_points,
71    geo_layer_from_aux_substations, geo_layer_from_pwd, pwd_mercator_to_lonlat,
72};
73pub use indexed::{ConnectivityReport, IndexCore, IndexedNetwork};
74pub use network::{
75    Area, BalancedNetwork, Branch, BranchCharging, BranchCurrentRatings, BranchRatingSet,
76    BranchSolution, Bus, BusId, BusType, DEFAULT_BASE_FREQUENCY, Diagnostic, Extras, GenCaps,
77    GenCost, Generator, Hvdc, Impedance, Load, LoadVoltageModel, Shunt, ShuntBlock, SolverParams,
78    SourceFormat, Storage, Switch, SwitchedShuntControl, SwitchedShuntMode, Transformer3W,
79    TransformerControl, TransformerControlMode, Winding, series_admittance_of,
80};
81pub use normalize::{
82    NormalizeOptions, NormalizeSourceRows, NormalizedNetwork, POWER_MODELS_ANGLE_BOUND_PAD,
83};
84pub use operations::Selector;
85pub use solver_tables::{
86    NORMALIZED_SOLVER_TABLES_PASS, NormalizedSolverTables, SolverArcRow, SolverArcTerminal,
87    SolverBranchRow, SolverBusRow, SolverCostRow, SolverGeneratorRow, SolverHvdcRow, SolverLoadRow,
88    SolverShuntRow, SolverStorageRow, SolverSwitchRow, SolverTableIndex, SolverTableUnits,
89};