Edit Existing Datasets

This section guides you on editing an existing dataset and its associated objects using pySAInt. It will use the "network.xlsx" file generated from the Write Excel Files in SAInt Import Format section.

For new users, before following this section, we highly recommend starting with the previous sections to become familiar with pySAInt’s basic functionalities.

For this section, ensure the presence of the "network.xlsx" file in your current working directory.

1. Read Excel Files in SAInt Import Format

Using pySAInt, it’s possible to read an existing network from the SAInt Network Import Excel File and convert it into a pySAInt dataset. This process begins by initializing an empty electric dataset. Then, the read_electric_network method from pySAInt is used to populate this dataset with the data from the SAInt Network Import Excel File.

The read_electric_network method accepts the following arguments:

Parameter Type Description

path_or_buf

str, path_object

The path where the SAInt Network Import Excel File is located.

import pysaint as ps

# This creates an empty electric dataset called "triangle"
triangle = ps.create_electric_dataset()

# Populate the triangle dataset with the network data in "network.xlsx".
triangle.read_electric_network("network.xlsx")
python

2. Query the Objects in a Dataset

The triangle dataset, now populated with the network objects from the "network.xlsx" file, is prepared for queries regarding the objects contained within the dataset.

Getting Objects and Properties: For querying the objects and their properties within the dataset, we can use get_object method of the dataset. This method accepts the following arguments:

Parameter Type Description

ObjType

str

SAInt object type (e.g., ENET for electric network).

Name

str

Object name.

# Retrieve the ESTR object "BATTERY" from the dataset
obj = triangle.get_object(ObjType="ESTR", Name="BATTERY")

# Access the properties of the ESTR object "BATTERY"
obj_props = obj.props
print(obj.props)
python

Getting a Specific Object Property: For a more focused query, the get_object_property method can be used to retrieve a specific object property. This method accepts the following arguments:

Parameter Type Description

ObjType

str

SAInt object type (e.g., ENET for electric network).

Name

str

Object name.

prop

str

Object property.

# Retrieve the "MaxCapDef" property of the ESTR object "BATTERY"
estr_maxcapdef = triangle.get_object_property(
  ObjType="ESTR",
  Name="BATTERY",
  prop="MaxCapDef"
)
python

3. Edit the Object Property Values in a Dataset

The add_object method of the dataset is flexible for managing your dataset’s objects. It enables users not only to add new objects but also to update existing object properties or add new properties to them.

Modifying Existing Property Values: If an object is added again with the same name and object type but with a different value for an existing property, the method updates this property accordingly. Let’s update the MaxCapDef property value of the estr object BATTERY.

# Change the "MaxCapDef" property value of the ESTR object "BATTERY"
triangle.add_object(ObjType="ESTR", Name="BATTERY", MaxCapDef=50)
python

A user warning is generated to indicate that an existing property value has been updated.

Adding New Properties to Existing Objects: You can also add new properties to an existing object in the dataset by specifying the new property in the add_object call. This does not generate a warning unless it’s changing an existing property’s value. Let’s add the PGMINDEF property to the estr object BATTERY.

# Add the "PGMINDEF" property to the ESTR object "BATTERY"
triangle.add_object(ObjType="ESTR", Name="BATTERY", PGMINDEF=5)
python