1

Search for machine by Id

Hello! I am brand spanking new, so thank you in advance for your patience and help.

I am attempting to create a Python script which will search for and print out all machines which share specified Id names. Eventually, I will want these machines to be added to a bus subsystem.

Just to be specific (again, brand new), I am on the Machine tab of the Network Data tab and have a list of machines...some of which have a similar Id value which I would like to grab:

  • machine bus number
  • bus name
  • Id
  • PGen value
  • PMin and
  • PMax.


I've been looking through the documentation and I have not found anything which suggests Id is a searchable index. Any suggestions or help would be awesome. I'm trying to start simple, by printing out all machine buses with a specific Id designation. Any suggestions?

Thank you!

TheNewGuy's avatar
11
TheNewGuy
asked 2025-07-31 08:08:35 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

3 Answers

1

Not sure if I understood the requirement correctly, but here's the code:

import collections

ierr, (machnum, ) = psspy.amachint(sid=-1, flag=1, string = 'NUMBER')
ierr, (machid, machname) = psspy.amachchar(sid=-1, flag=1, string = ['ID', 'NAME'])
ierr, (pgen, pmin, pmax, ) = psspy.amachreal(sid=-1, flag=1, string = ['PGEN', 'PMIN', 'PMAX'])

# remove white spaces
machid = [i.strip() for i in machid]
machname = [i.strip() for i in machname]

# group machines by ID
machines_by_id = collections.defaultdict(list)
for num, name, mid, pg, pmn, pmx in zip(machnum, machname, machid, pgen, pmin, pmax):
    machines_by_id[mid].append((num, name, pg, pmn, pmx))

# print only machines with same IDs
for mid, mach_list in machines_by_id.items():
    if len(mach_list) > 1:
        print(f"\nMachines with ID '{mid}':")
        for num, name, pg, pmn, pmx in mach_list:
            print(f"  Bus {num}, Name {name}, Pgen = {pg:.2f} MW, Pmin = {pmn:.2f} MW, Pmax = {pmx:.2f} MW")

# function to create subsystem of buses which have at least one machine with the required/defined ID
def create_subsystem(mid):

    if mid.strip() not in machines_by_id:
        print(f"No machines found with ID {mid}")
        return

    buses = [num for num, _, _, _, _ in machines_by_id[mid]]
    ierr = psspy.bsys(0, 0, [0.0, 999.0], 0, [], len(buses), buses, 0, [], 0, [])
    if ierr == 0:
        print(f"Subsystem created for machines with ID '{mid}': {buses}")
    else:
        print(f"Error creating subsystem for ID '{mid}', ierr={ierr}")

# create subsystem 
mid = '1'
create_subsystem(mid)
psys's avatar
58
psys
answered 2025-08-19 04:37:12 -0500, updated 2025-08-19 04:54:18 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

Look at this: https://www.whit.com.au/blog/2011/08/..., push the 2d array to a Pandas or Polars dataframe, then execute some filtering operations.

likethevegetable's avatar
101
likethevegetable
answered 2025-08-01 09:19:49 -0500
edit flag offensive 0 remove flag delete link

Comments

This is help, thank you. :)

TheNewGuy's avatar TheNewGuy (2025-08-01 09:40:45 -0500) edit
add a comment see more comments
0

likethevegetable, your link was helpful, but a bit over my head. I'm still very new to PSSE, so chances are I'll be doing everything the less-than-ideal way before settling into a more streamlined routine.

That being said, this is how I called the amachchar() function and got it to return a list (carray_ID) of ID tags for each machine:

ierrID, carrayID = py.amachchar(-1, 4, 'ID')

**Edit: I don't know why, but the post isn't showing the underscore in ieerID and carrayID...but there is an underscore right before the ID portion of the variable name.

TheNewGuy's avatar
11
TheNewGuy
answered 2025-08-18 13:37:26 -0500, updated 2025-08-18 13:38:55 -0500
edit flag offensive 0 remove flag delete link

Comments

Hi @TheNewGuy, The underscores sometimes automatically change into italic. You can use highlight these lines and click the code button (the one with 101010) and that should show them correctly

Mohamed_M's avatar Mohamed_M (2025-08-26 11:06:36 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer