Ask Your Question
1

Data extraction subroutine for a dynamic snapshot or dyr ? (like caspy ?)

asked 2013-08-06 07:35:23 -0500

Yagna gravatar image

I would like to know if there is a way to extract individual CON data from a dynamic snapshot or dyr file and read it into a variable ? There are similar resources for a saved case (load flow data) but not for the dynamic data. Please let me know if there is an API to read the CON data (not dlst or docu which only displays the results and not return the values)

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2013-08-06 20:28:25 -0500

JervisW gravatar image

updated 2013-08-08 20:40:02 -0500

(edit - thanks @Yagna)

The best way to get these variables is by using DSRVL.

Here is the function signature:

value = psspy.dsrval(name, index)

where the name parameter can be:

TIME simulation time

DELT Simulation time step

STATE State variable values

CON Real model parameters

VAR Real model variable values

As @Yagna mentioned, you can use the combination of mdlind and dsrval to collect any value you wish:

def dynamic_values(bus, id, plant_type, model_quantity):
  """
  Returns the complete list of model quantities for the plant type at the
  machine requested:

  plant_type:
    'GEN', 'COMP', 'STAB', 'EXC', 'GOV', 'TLC', 'MINXL', 'MAXXL'
  model_quantity:
    'CON', 'STATE', 'VAR', 'ICON'

  """
  index_lookup = {
       'CON': psspy.dsrval,
       'STATE': psspy.dsrval,
       'VAR': psspy.dsrval,
       'ICON': character_or_integer_icon}

  # get starting index.
  index = psspy.mdlind(bus, id, plant_type, model_quantity)

  get_value = index_lookup(model_quantity)
  values = []

  # increase the index, and store the value until we get get all values.
  while 1:

    try:
      _, value = get_value(model_quantity, index)
    except psspy.PsseException, e:
      if e.ierr == 2:
        # no more data available.
        break
      else:
        raise

    values.append(value)
    index += 1

  return values

You can use the above function to get all of the values in the array

# a list of all CON values at machine on bus 100.
cons = dynamic_values(100, '1', 'GEN', 'CON')

If you also wanted to read 'ICON' type values, you'd need to write the character_or_integer_icon function. Because both dsrival and dscval use the ICON string as their quantity name. The only way you'll know if they are different is by checking for an error ierr=3 or by using some smarts based on the requested plant_type.

edit flag offensive delete link more

Comments

1

@JervisW Thanks for getting back. I wanted to make sure that there is no straightforward way of doing this before I attempt to do it the hard way. If I do pursue this and hit upon some good script, I'll definitely share and reach out here for suggestions.

Yagna gravatar imageYagna ( 2013-08-06 22:09:51 -0500 )edit

@Yagna I'd love to see what you come up with

JervisW gravatar imageJervisW ( 2013-08-07 06:42:42 -0500 )edit
1

@JervisW I came across DSRVAL. This API could save us a lot of time without parsing DLST or DOCU. Now, the solution is rather simple, a combination of mdlind and dsrval can be used to get the CON values one at a time and store it in a 2D array or any format of our choice.

Yagna gravatar imageYagna ( 2013-08-07 07:47:08 -0500 )edit

That one looks perfect. I"ll update the answer, good find mate

JervisW gravatar imageJervisW ( 2013-08-08 20:05:00 -0500 )edit
0

answered 2016-09-20 09:34:03 -0500

perolofl gravatar image

updated 2016-09-21 01:11:18 -0500

Unfortunately the function

def dynamic_values(bus, id, plant_type, model_quantity):

presented in answer 1 above is not working as intended. It will not only return all CONs for the called plant model but also for all remaining CONs up to the maximum number in PSS/E. For example for 50000 bus size up to 320000 CONS are allowed. Call of dsrval will only through an exception for invalid indices, e.g. index 320001!

The function will work if you use NCON or NICON argument in mdlind to get the number of CONs/ICONs used by the model, for example 14 for GENROU model. The returned list should then be restricted to the first 14 CONs from the starting index.

The following code will return all quantities for a model:

def plantdynamic_values(bus, id, type, quantity):

"""
Returns the complete list of model quantities for the plant type at the
machine requested:

type:
'GEN', 'COMP', 'STAB', 'EXC', 'GOV', 'TLC', 'MINXL', 'MAXXL'
quantity:
'CON', 'STATE', 'VAR', 'ICON'

"""
# get starting index and number of constants.
ierr,index = psspy.mdlind(bus, id, type, quantity)
if ierr==1 or ierr==2: print 'Machine at bus %s id %s not in network' % (bus,id)
if ierr==3: print "Machine at bus %s id %s: Invalid value %s of ’STRING1’ " % (bus,id,type)
if ierr==5: print "Machine at bus %s id %s: Invalid value %s of ’STRING2’ " % (bus,id,quantity)
if ierr>0: return []
ierr,ncons = psspy.mdlind(bus, id, type, 'N'+quantity)
values = []
# get all values for this model and store the value.
for i in range(ncons):
    if quantity=='ICON':
        ierr, value = psspy.dsival(quantity, index+i)
        if ierr==3: ierr, value = psspy.dscval(quantity, index+i)
    else: ierr, value = psspy.dsrval(quantity, index+i)
    if ierr==0: values.append(value)
return values
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

3 followers

Stats

Asked: 2013-08-06 07:35:23 -0500

Seen: 3,572 times

Last updated: Sep 21 '16