Use Pandas DataFrames to Simplify Workflows

In this section, we will utilize pandas DataFrames to add objects, profiles, and events into the pySAInt dataset.

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

1. Use Pandas DataFrames to Add Objects

We begin by initializing an empty electric dataset and adding an ENET object.

import pysaint as ps

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

# Add an ENET object
triangle.add_object(ObjType="ENET", Name="triangle")
python

Now, we can populate it with other network objects using the add_objects_from_dataframe method. This method is particularly useful when adding multiple objects of the same object type.

This method accepts the following arguments:

Parameter Type Description

df

pandas.DataFrame

DataFrame of properties with SAInt names.

Name_col

str

Column containing object names.

prop_cols

list

List of property column names.

destination_ObjType

str

SAInt Object type to map onto.

1.1. Add Nodes and Branches

First, let’s prepare the node and line dataframes with the required properties:

import pandas as pd

# Create nodes dataframe
nodes_df = pd.DataFrame({
  'Name': ['NODE1', 'NODE2', 'NODE3'],
  'X': [0, 1, 0],
  'Y': [0, 1, 2]
})
# Create lines dataframe
lines_df = pd.DataFrame({
  'Name': ['LINE1', 'LINE2', 'LINE3'],
  'FromName': ['NODE1', 'NODE2', 'NODE3'],
  'ToName': ['NODE2', 'NODE3', 'NODE1'],
  'PMAXDEF': [400, 400, 400]
})
python

Now, let’s add the nodes and lines to the triangle dataset:

# Add nodes
triangle.add_objects_from_dataframe(
  nodes_df,
  Name_col='Name',
  prop_cols=['X', 'Y'],
  destination_ObjType='ENO'
)
# Add lines
triangle.add_objects_from_dataframe(
  lines_df,
  Name_col='Name',
  prop_cols=['FromName', 'ToName', 'PMAXDEF'],
  destination_ObjType='LI'
)
python

1.2. Add Fuel and Externals

We can still use the add_object method when adding a single object of a specific object type. Let’s add FUEL, XGEN, PV, and ESTR objects using this method.

# Add FUEL object
triangle.add_object(ObjType="FUEL", Name="GAS", FuelUnit="MMBTU", FuelPriceDef=5, CO2=54000)

# Add PV and XGEN objects
triangle.add_object(ObjType="XGEN", Name="GEOTHERMAL", NodeName="NODE1", PMAXDEF=10)
triangle.add_object(ObjType="PV", Name="SOLAR", NodeName="NODE1", PMAXDEF=50)

# Add storage object
triangle.add_object(
    ObjType="ESTR",
    Name="BATTERY",
    NodeName="NODE1",
    PGMAXDEF=20,
    PDMAXDEF=20,
    MaxCapDef=40,
    PGeff=0.9,
    PDeff=0.9
)
python

Now, let’s use the add_objects_from_dataframe method to add multiple demand and fuel generator objects.

# Create demand dataframe
demand_df = pd.DataFrame({
  'Name': ['DEMAND1', 'DEMAND2'],
  'NodeName': ['NODE1', 'NODE2'],
  'PSETPRCDEF': [100000]*2
})
# Add demand objects
triangle.add_objects_from_dataframe(
  demand_df,
  Name_col='Name',
  prop_cols=['NodeName', 'PSETPRCDEF'],
  destination_ObjType='EDEM'
)

# Create fuel generators dataframe
fgen_df = pd.DataFrame({
  'Name': ['GAS_CT', 'GAS_CC'],
  'NodeName': ['NODE3', 'NODE2'],
  'FuelName': ['GAS']*2,
  'PMAXDEF': [100, 400],
  'PMINDEF': [40, 140],
  'MaxUpRampDef': [10, 2],
  'MaxDownRampDef': [10, 2],
  'FC0': [100, 100],
  'FC1': [9, 7]
})
# Add fuel generators
triangle.add_objects_from_dataframe(
  fgen_df,
  Name_col='Name',
  prop_cols=['NodeName', 'FuelName', 'PMAXDEF', 'PMINDEF', 'MaxUpRampDef', 'MaxDownRampDef', 'FC0', 'FC1'],
  destination_ObjType='FGEN'
)
python

2. Use Pandas DataFrames to Add Profiles

We can use the add_profiles_from_dataframe method of the dataset to efficiently add profiles into our dataset. This method is particularly useful when adding profiles that share similar properties such as, info, time step, profile type, interpolation type etc. It streamlines the process by allowing the addition of multiple profiles with differences limited to profile name and mean properties.

This method accepts the following arguments:

Parameter Type Description

df

pandas.DataFrame

DataFrame with profile names as columns and mean as time series data

TimeStep

float

Profile property

InterpolationType

str

Profile property

DurationType

str

Profile property

DistributionType

str

Profile property

PRFTIME

str

Profile property

PrflType

str

Profile property, Defaults to DETERMINISTIC.

Info

str

Profile property, Defaults to None.

Let’s add the normalized profiles for demand and solar.

import datetime

# Create profiles dataframe
profiles_df = pd.DataFrame({
  'NORMALIZED_DEMAND': [0.6, 0.55, 0.6, 0.65, 0.65, 0.7, 0.75, 0.8, 0.8, 0.75, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 0.95, 0.9, 0.85, 0.8, 0.75, 0.7, 0.65],
  "NORMALIZED_SOLAR": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.25, 0.4, 0.55, 0.7, 0.8, 0.85, 0.8, 0.7, 0.55, 0.4, 0.25, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0],
})
triangle.add_profiles_from_dataframe(
  df=profiles_df,
  TimeStep=datetime.timedelta(hours=1),
  PRFTIME="h",
  PrflType="DETERMINISTIC",
  InterpolationType="STEP",
  DurationType="PERIODIC",
  DistributionType='UNIFORM',
)
python

3. Use Pandas DataFrames to Add Events

We can use the add_events_from_dataframe method of the dataset to efficiently add scenario events into our dataset and link them to existing dataset scenarios and profiles. This method accepts the following arguments:

Parameter Type Description

df

pandas.DataFrame

Events DataFrame

scenario

str

Name of the scenario

prop_cols

list

List of event property columns

First, let’s add a REFERENCE scenario to the triangle dataset.

# Add scenario(s) to the dataset
triangle.add_scenario(
    Name="REFERENCE",
    SceType="DCUCOPF",
    StartTime=datetime.datetime(year=2019, month=6, day=1),
    EndTime=datetime.datetime(year=2019, month=6, day=2),
    TimeStep=datetime.timedelta(hours=1),
    TimeHorizon=datetime.timedelta(hours=24),
    TimeLookAhead=0,
    TimeStepLookAhead=0
)
python

Now, let’s add the events for the EDEM and PV objects to the triangle dataset and link them to the REFERENCE scenario and existing profiles.

import datetime

# Create events dataframe
events_df = pd.DataFrame({
    'ObjType': ['EDEM', 'EDEM', 'PV'],
    'ObjName': ['DEMAND1', 'DEMAND2', 'SOLAR'],
    'Parameter': ['PSET', 'PSET', 'PSET'],
    'StartTime': [datetime.datetime(year=2019, month=6, day=1, hour=1)]*3,
    'Profile': ['NORMALIZED_DEMAND', 'NORMALIZED_DEMAND', 'NORMALIZED_SOLAR'],
    'Value': [200, 250,  "PV.SOLAR.PMAX"],
    'Unit':['[MW]']*3
})
# Add events to dataset and link them to "REFERENCE" scenario
triangle.add_events_from_dataframe(
  df=events_df,
  scenario="REFERENCE",
  prop_cols=['ObjType', 'ObjName', 'Parameter', 'StartTime', 'Profile', 'Value', 'Unit']
)
python