Skip to main content

powerio_tx/
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_core::Source;
18//! use powerio_tx::{TargetFormat, format_id_for, parse, write_as};
19//!
20//! let src = "\
21//! function mpc = example
22//! mpc.version = '2';
23//! mpc.baseMVA = 100;
24//! mpc.bus = [
25//! \t1\t3\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
26//! \t2\t1\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
27//! ];
28//! mpc.branch = [
29//! \t1\t2\t0.01\t0.1\t0\t0\t0\t0\t0\t0\t1\t-360\t360;
30//! ];
31//! ";
32//! let source = Source::from_bytes("example.m", src.as_bytes().to_vec())?
33//!     .with_format(format_id_for("matpower")?);
34//! let module = parse(source)?;
35//! assert_eq!(module.value().buses().len(), 2);
36//! // An unchanged parsed module echoes its source bytes exactly.
37//! assert_eq!(write_as(&module, TargetFormat::Matpower)?.text, src);
38//! # Ok::<(), powerio_core::Error>(())
39//! ```
40
41/// The powerio crate version, for provenance fields written by downstream
42/// crates whose own version can drift from the core's.
43pub const VERSION: &str = env!("CARGO_PKG_VERSION");
44
45mod collect;
46pub mod dc;
47pub mod diagnostics;
48pub mod error;
49pub mod format;
50pub mod gen_cost;
51pub mod geo;
52pub mod indexed;
53pub mod network;
54mod normalize;
55mod operations;
56pub mod solver_tables;
57pub mod version;
58
59pub use dc::{DcConvention, DcNetworkData, dc_network_data};
60pub use diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSeverity, EmitFamily};
61pub use error::{Error, ErrorCategory, Result};
62pub use format::routing::{
63    Detection, JSON_CLASSES, JsonClass, classify_json_bytes, classify_json_text,
64};
65#[cfg(test)]
66pub(crate) use format::test_parse::{parse_file, parse_str};
67pub use format::{
68    Conversion, DisplayData, DisplayFormat, OpfDataSolution, PwdDisplay, PwdSubstation,
69    PypsaCsvOutputs, PypsaCsvSequence, SOURCE_FORMAT_NAMES, TargetFormat, WriteOptions,
70    convert_file, convert_file_with_options, convert_str, convert_str_with_options,
71    display_format_from_name, format_id_for, parse, parse_display_bytes, parse_display_file,
72    parse_egret_time_series, parse_goc3_json, parse_opfdata_json, parse_pypsa_csv_time_series,
73    target_format_from_name, write, write_as, write_as_with_options, write_dir,
74    write_dir_with_options, write_egret_json, write_matpower, write_network, write_pandapower_json,
75    write_powermodels_json, write_powerworld, write_pslf, write_psse, write_psse_rev,
76    write_pypsa_csv, write_pypsa_csv_folder, write_surge_json, write_with_options,
77};
78pub use gen_cost::{GenCostPatch, GenCostPolicyReport, MissingGenCostPolicy, parse_gen_cost_csv};
79pub use geo::{
80    Canvas, CoordinateSpace, CoordsKind, ElementKey, GeoApplyReport, GeoFeature, GeoGeometry,
81    GeoLayer, GeoMeta, GeoParsed, GeoTarget, Location, apply_substation_points,
82    geo_layer_from_aux_substations, geo_layer_from_pwd, pwd_mercator_to_lonlat,
83};
84pub use indexed::{ConnectivityReport, IndexCore, IndexedNetwork};
85pub use network::{
86    Area, BalancedNetwork, Branch, BranchCharging, BranchCurrentRatings, BranchRatingSet,
87    BranchSolution, Bus, BusId, BusType, DEFAULT_BASE_FREQUENCY, Extras, GenCaps, GenCost,
88    Generator, Hvdc, Impedance, Load, LoadVoltageModel, Shunt, ShuntBlock, SolverParams,
89    SourceFormat, Storage, Switch, SwitchedShuntControl, SwitchedShuntMode, Transformer3W,
90    TransformerControl, TransformerControlMode, Winding, repair_values, series_admittance_of,
91};
92pub use normalize::{
93    NormalizeOptions, NormalizeSourceRows, NormalizedNetwork, POWER_MODELS_ANGLE_BOUND_PAD,
94};
95pub use operations::Selector;
96
97pub use solver_tables::{
98    NORMALIZED_SOLVER_TABLES_PASS, NormalizedSolverTables, SolverArcRow, SolverArcTerminal,
99    SolverBranchRow, SolverBusRow, SolverCostRow, SolverGeneratorRow, SolverHvdcRow, SolverLoadRow,
100    SolverShuntRow, SolverStorageRow, SolverSwitchRow, SolverTableIndex, SolverTableUnits,
101};