Tips and Tricks

In this section, we’ll discuss some useful techniques for maximizing efficiency and effectiveness when working with pySAInt. These insights are tailored for users who are already comfortable with pySAInt and have completed all preceding sections.

1. Flexibility with Dataset Objects

Modifying existing objects in pySAInt typically involves using the add_object method. However, directly changing the ObjType or Name of an existing dataset object isn’t supported out of the box. But don’t worry, we can still achieve this using the get_object method.

1.1. Change Object Name

Let’s see how to change the name of an object in the dataset. First, we create a triangle dataset with some basic network objects:

import pysaint as ps

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

# Add network objects
triangle.add_object(ObjType="ENET", Name="triangle")
triangle.add_object(ObjType="ENO", Name="NODE1", X=0, Y=1)
triangle.add_object(ObjType="ENO", Name="NODE2", X=1, Y=1)
triangle.add_object(ObjType="LI", Name="LINE1", FromName="NODE1", ToName="NODE2")
triangle.add_object(ObjType="EDEM", Name="DEMAND", NodeName="NODE1", PSETDEF=50)
triangle.add_object(ObjType="FGEN", Name="GAS_CC", NodeName="NODE2", PMAXDEF=100)
python

Now, let’s change the name of one of the nodes in the dataset:

# Retrieve the ENO object for "NODE1"
eno_obj = triangle.get_object(ObjType='ENO', Name='NODE1')

# Change the name of the node to "GRID"
triangle.get_object(ObjType=eno_obj.ObjType, Name=eno_obj.Name).Name = 'GRID'
python

The code above retrieves the ENO object named "NODE1" from the triangle dataset by specifying its object type (ObjType) and name (Name). Once retrieved, it sets the Name attribute of the object to "GRID", effectively changing the name of the object in the dataset to "GRID".

1.2. Change Object Type

Similarly to changing object names, we can also change object types using the get_object method in pySAInt. Let’s illustrate how to change the object type of GAS_CC from an FGEN to an XGEN.

# Retrieve the FGEN object for "GAS_CC"
fgen_obj = triangle.get_object(ObjType='FGEN', Name='GAS_CC')

# Change the object type to XGEN
triangle.get_object(ObjType=fgen_obj.ObjType, Name=fgen_obj.Name).ObjType = 'XGEN'
python

The functionality for changing object names and types in pySAInt becomes particularly valuable when working with datasets created using the read_electric_network method. This method allows users to import existing electric network data into a pySAInt dataset. Once imported, it’s common to need to make adjustments or modifications to the network objects. Being able to change the names and types of objects using get_object provides a convenient way to tailor the dataset to specific requirements or updates.

1.3. Update relational properties

After changing the name or type of an object, it’s essential that any relational properties affected by the change are also updated accordingly. For instance, we’ve altered the node name for one of the nodes in the dataset, which effects the NodeName property of the EDEM object. In pySAInt, we can update the relational properties at the dataset level which will automatically update every relational property of an object.

# Update relational properties
triangle.update_relational_properties()

# Check the NodeName property of the EDEM object
print(
  f'EDEM NodeName: {triangle.get_object_property(ObjType="EDEM", Name="DEMAND", prop="NodeName")}'
  )
python

When updating relational properties of an object, any dataset events linked to that object are also automatically updated after using the update_relational_properties method.

2. Use pySAInt with Large Networks

When dealing with large networks in pySAInt, it’s often necessary to optimize processing times, especially when constructing networks with a high volume of objects. To address this need, pySAInt offers support for accelerating computation times when handling large numbers of network objects.

To leverage this feature, users can initialize a pySAInt dataset with immutable object types and names by setting the immutable_object_type_and_name parameter to True:

import pysaint as ps

large_network = ps.create_electric_dataset(
  immutable_object_type_and_name=True
)
python

It’s important for users to ensure that object names and types remain immutable, and that there is no requirement to update relational properties within the dataset.

3. Viewing Datasets

Up to this point, pySAInt users might be wondering if there’s a way to view the pySAInt datasets in a human-readable format. In pySAInt, there are two methods to view the dataset:

  • View Dataset as a JSON

  • View Dataset as a pandas DataFrame

View Dataset as a JSON

# Get Dataset JSON
dataset_json = triangle.get_network_json()
python
Unfold this collapsible section to inspect the dataset in JSON format:
{
  "ENET": {
    "triangle": {}
  },
  "ENO": {
    "GRID": {
      "X": 0,
      "Y": 1
    },
    "NODE2": {
      "X": 1,
      "Y": 1
    }
  },
  "LI": {
    "LINE1": {
      "FromName": "GRID",
      "ToName": "NODE2"
    }
  },
  "EDEM": {
    "DEMAND": {
      "NodeName": "GRID",
      "PSETDEF": 50
    }
  },
  "XGEN": {
    "GAS_CC": {
      "NodeName": "NODE2",
      "PMAXDEF": 100
    }
  }
}
json

View Dataset as a pandas DataFrame

# Get Dataset pandas DataFrame
dataset_df = triangle.get_network_dataframe()
python
Unfold this collapsible section to inspect the dataset as a pandas DataFrame:
  ObjType      Name    X    Y NodeName FromName ToName PMAXDEF PSETDEF
0    ENET  triangle
1     ENO      GRID  0.0  1.0
2     ENO     NODE2  1.0  1.0
3      LI     LINE1                        GRID  NODE2
4    EDEM    DEMAND               GRID                            50.0
5    XGEN    GAS_CC              NODE2                   100.0
python