API Reference
Module Structure
Section titled “Module Structure”import pyramses
# Core classespyramses.sim # Simulator interfacepyramses.cfg # Test case configurationpyramses.extractor # Result extractionpyramses.cur # Curve data containerpyramses.curplot # Curve plotting utilitypyramses.sim — Simulator
Section titled “pyramses.sim — Simulator”The main simulation interface. Wraps the RAMSES dynamic library (DLL/SO).
Constructor
Section titled “Constructor”ram = pyramses.sim(custLibDir=None)| Parameter | Type | Description |
|---|---|---|
custLibDir | str or None | Custom path to RAMSES library directory. Default: use bundled libraries. |
Methods
Section titled “Methods”execSim(case, t_pause=None)
Section titled “execSim(case, t_pause=None)”Execute a simulation.
ram.execSim(case) # Run full simulationram.execSim(case, 0) # Start simulation pausedram.execSim(case, 10.0) # Pause at t = 10 scontSim(t_pause=None)
Section titled “contSim(t_pause=None)”Continue a paused simulation.
ram.contSim() # Continue to endram.contSim(20.0) # Continue until t = 20 sgetLastErr()
Section titled “getLastErr()”Return the last error message issued by RAMSES.
err = ram.getLastErr()print(err)getJac()
Section titled “getJac()”Export the system Jacobian matrix. Returns sparse matrices (E, A) in descriptor form.
E, A = ram.getJac()getObs(comp_type, comp_name, obs_name)
Section titled “getObs(comp_type, comp_name, obs_name)”Get the current value of an observable during a paused simulation.
voltage = ram.getObs('BUS', '1041', 'mag')addObs(comp_type, comp_name, obs_name)
Section titled “addObs(comp_type, comp_name, obs_name)”Add a runtime observable for real-time plotting (requires Gnuplot).
ram.addObs('BUS', '1041', 'mag')chgPrm(comp_type, comp_name, param_name, value)
Section titled “chgPrm(comp_type, comp_name, param_name, value)”Change a parameter during a paused simulation.
ram.chgPrm('EXC', 'g1', 'V0', 1.05)pyramses.cfg — Test Case Configuration
Section titled “pyramses.cfg — Test Case Configuration”Defines the input files and configuration for a simulation.
Constructor
Section titled “Constructor”case = pyramses.cfg() # Empty configurationcase = pyramses.cfg("cmd.txt") # Load from command fileMethods
Section titled “Methods”addData(filename)
Section titled “addData(filename)”Add a data file (network, dynamic models, settings).
case.addData("network.dat")case.addData("dynamic.dat")addDst(filename)
Section titled “addDst(filename)”Set the disturbance file.
case.addDst("disturbance.dst")addInit(filename)
Section titled “addInit(filename)”Set the initialization output file.
case.addInit("init.trace")addTrj(filename)
Section titled “addTrj(filename)”Set the trajectory output file.
case.addTrj("result.rtrj")addObs(filename)
Section titled “addObs(filename)”Set the observables definition file (required when trajectory file is set).
case.addObs("obs.obs")addCont(filename) / addDisc(filename)
Section titled “addCont(filename) / addDisc(filename)”Set continuous/discrete trace output files.
case.addCont("cont.trace")case.addDisc("disc.trace")addRunObs(obs_string)
Section titled “addRunObs(obs_string)”Add a runtime observable (for real-time Gnuplot display).
case.addRunObs("BUS 1041 mag")addOut(filename)
Section titled “addOut(filename)”Set the output file path.
case.addOut(os.path.join(os.getcwd(), 'output.trace'))writeCmdFile(userFile=None)
Section titled “writeCmdFile(userFile=None)”Write the command file to disk. Returns the command string if no file given.
case.writeCmdFile("my_cmd.txt") # Write to filecmd_str = case.writeCmdFile() # Return as stringGetters
Section titled “Getters”case.getTrj() # Get trajectory file pathcase.getInit() # Get initialization file pathcase.getOut() # Get output file pathpyramses.extractor — Result Extraction
Section titled “pyramses.extractor — Result Extraction”Extract and plot time-series data from RAMSES trajectory files.
Constructor
Section titled “Constructor”ext = pyramses.extractor(case.getTrj())Methods
Section titled “Methods”getBus(busname)
Section titled “getBus(busname)”Returns bus-level data.
bus = ext.getBus('1041')bus.mag.plot() # Voltage magnitude (pu)bus.pha.plot() # Voltage phase angle (deg)getSync(syncname)
Section titled “getSync(syncname)”Returns synchronous machine data.
sync = ext.getSync('g1')sync.speed.plot() # Rotor speedsync.angle.plot() # Rotor anglesync.P.plot() # Active powersync.Q.plot() # Reactive powergetInj(injname)
Section titled “getInj(injname)”Returns injector observable data.
inj = ext.getInj('L_11')getTwop(twopname)
Section titled “getTwop(twopname)”Returns two-port observable data.
getDctl(dctlname)
Section titled “getDctl(dctlname)”Returns discrete controller observable data.
getBranch(branchname)
Section titled “getBranch(branchname)”Returns branch (line/transformer) data.
getShunt(shuntname) / getLoad(loadname)
Section titled “getShunt(shuntname) / getLoad(loadname)”Returns shunt or load data.
pyramses.cur — Curve Container
Section titled “pyramses.cur — Curve Container”A named tuple storing time-series data.
from pyramses import cur
# Attributescurve.time # numpy array of time valuescurve.value # numpy array of data valuescurve.msg # description stringPlotting
Section titled “Plotting”curve.plot() # Plot single curvepyramses.curplot([c1, c2, c3]) # Plot multiple curvesComplete Example
Section titled “Complete Example”import pyramsesimport os
# Create test casecase = pyramses.cfg()case.addData("network.dat")case.addData("dynamic.dat")case.addData("settings.dat")case.addInit("init.trace")case.addDst("disturbance.dst")case.addTrj("result.rtrj")case.addObs("obs.obs")case.addCont("cont.trace")case.addDisc("disc.trace")
# Run simulationram = pyramses.sim()ram.execSim(case)
# Extract resultsext = pyramses.extractor(case.getTrj())
# Plot bus voltagesext.getBus('1041').mag.plot()ext.getBus('1042').mag.plot()
# Plot generator speedext.getSync('g1').speed.plot()
# Clean updel ram