Krang reference

The Krang is the main class of krangpower. It has facilities to drive the OpenDSS engine, retrieve and query elements and options, saving and loading circuit data as JSON, representing the circuit as graph, perform repeated solutions and reporting the results as DataFrames. The basic workflow pertaining the Krang is illustrated in the Usage page.

It’s worth spending a word about Krang.brain. This is an instance of OpendssdirectEnhancer and is designed to expose the exact same interface as the module OpenDSSDirect.py. This means that you can use Krang.brain exactly as you would use this module, with two advantages:

  • Results are returned in enhanced data containers as suitable, rather than as raw strings (integers will be of type int, arrays will be of type numpy.ndarray, pyhysical quantities will have a pint unit measure);
  • It’s bracket-indicizable with a string and returns a PackedOpendssElement.

More info on OpendssdirectEnhancer is available at the OpendssdirectEnhancer reference page.

Class reference

class krangpower.Krang(*args)
__getattr__(item)

Krang.item, aside from retrieving the builtin attributes, wraps by default the calls to opendssdirect’s ‘class_to_dataframe’ utility function. These are accessible via capital letter calls. Both singular and plural are accepted. (e.g., ‘Line’ or ‘Lines’, ‘RegControl’ , ‘Regcontrol’, ‘RegControls’, but not ‘transformers’)

__getitem__(item)

Krang[‘bus.nname’], Krang[‘load.load1’], Krang[‘load1’] gets the component or a list of components of the bus; Krang[(‘bus.nname’,)], Krang[‘bus.b1’,’bus.b2’] gets a BusView to which you can add components with <<. Note that in order to get a BusView of a single bus, one needs to explicitly pack it in a tuple.

__init__(*args)

Initialize self. See help(type(self)) for accurate signature.

__lshift__(other)

The left-shift operator << adds components to the Krang. Components that can and have to be directly added to the krang are those that represent data (WireData, TSData, LineGeometry…) or those that are in the circuit but above the topology (such as Monitors and all the Controllers). The names of these elements must not be blank when they are added.

brain = None

Krang.brain is an instance of OpendssdirectEnhancer. It has the same interface as OpenDSSDirect.py, but is bracket-indicizable with strings and returns enhanced data structures such as pint qtys and numpy arrays.

bus_coords

Returns a dict with the bus coordinates already loaded in Opendss. Beware that coordinates loaded through a link_kml or link_csv are not immediately loaded in the Opendss, but they are just before a solution is launched.

command(cmd_str: str, echo=True)

Performs an opendss textual command and adds the commands to the record Krang.com if echo is True.

drag_solve()

Instead of launching a monolithic duty solve, This command solves one step at a time and saves node currents and voltages in the two DataFrames returned.

export(object_descriptor)

Wraps the OpenDSS export command. Returns a DataFrame for csv exports, an ElementTree for xml exports. Has a help attribute.

get(*opts)

Takes a list of circuit options and returns them as dict of name, value.

static get_unit_registry()

Retrieves krangpower’s UnitRegistry.

Notifies Krang of a csv file with bus coordinates to use.

make_json_dict()

Returns a complete description of the circuit and its objects as a json.dumpable-dict.

name

The name of the circuit..

plot(object_descriptor)

Wraps the OpenDSS export command. Has a help attribute.

save_dss(path)

Saves a file with the text commands that were imparted by the Krang.command method aside from those for which echo was False. The file output should be loadable and runnable in traditional OpenDSS with no modifications.

save_json(path)

Saves in path a complete description of the circuit and its objects

set(**opts_vals)

Sets circuit options according to a dict. Option that have a physical dimensionality (such as stepsize) can be specified as pint quantities; otherwise, the default opendss units will be used.

show(object_descriptor)

Wraps the OpenDSS show command. Has a help attribute.

snap()

Solves a circuit snapshot.

solve(echo=True)

Imparts the solve command to OpenDSS.