Ask Your Question
0

Dyntools error? "no attribute 'xdata'"

asked 2019-09-16 17:26:48 -0500

wassup_doc gravatar image

Has anyone ever seen this error?

File ".\dyntools.py", line 1459, in get_data
AttributeError: OUTDATA instance has no attribute 'xdata'

This is the last piece of the stack callback upon hitting this error in python2.7.. It appears to show up when I try to open and read the data in too many .out files using the CHNF command. If I only open a read a small subset of files (e.g. 1-10 .out files) then my code works fine, but if I try to open and read 100+ files then I get this error.

Any thoughts?

Can we access the DYNTOOLS code anywhere? looks like PSSBIN only has a .pyc binary file.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-09-17 03:14:30 -0500

drsgao gravatar image

updated 2019-09-19 10:20:47 -0500

The problem with many OUT files is not a new one. I have not got an definitive answer from Siemens but I guess is somehow related to poor memory management.

My solution is to convert the OUT file to Excel XLSX files and then use matplotlib with openpyxl or pandas to plot.

Converting to XLSX is quite straight forward, take a look at this post Convert dynamic OUT files to Excel XLSX files. By the way, you can get rid of the Siemens watermark this way.

The dyntools module is compiled percisely because Siemens does not want anyone to see the source code. Altough you can use Python's "help()" function to see the documentations inside the module.

Edit: The problem is that if you pass a list of OUT files to instantiate one single chnf object, it's gonna explode. It won't explode if you loop through the OUT files one by one. Python's garbage collection should make sure that the unused chnf object would be erased, so perforamce and memory should not be impacted.

You can use multiprocessing to speed up things, here is an example:

import os
import time
import multiprocessing as mp

# you may need to add the PSSBIN path to your environmental variable
import dyntools

def boolOut2Xlsx(str_path_out, str_path_xlsx, bool_show=False,
                 bool_overwritesheet=False, str_sheet='', list_chn=[]):
    '''This function converts the PSSE OUT file into an Excel workbook (XLSX).

    Dependency
    ----------
    dyntools : PSSE Python module

    Parameters
    ----------
    str_path_out : str
        The path of the OUT file.

    str_path_xlsx : str
        The path of the XLSX file.

    bool_overwritesheet : boolean
        Whether to overwrite the current worksheet.

        True = overwrite;
        False = not overwirte.

        Defualt = Flase

    str_sheet : str
        Name of the worksheet.

    list_chn : list
        A list containing the desired channels to be included in the XLSX.

        Empty list means all channels. Note that this could make the XLSX very large.

        Default = emtpy list (all channels)

    Returns
    -------
    list of two bools : list
        This list has two elements. If no exception (conversion assumed successful), the 
        first element will be True, else, it will be False. The second element is always
        True. This is to denote function end (end of conversion).'''

    try:

        # use the CHNF in dyntools, let it read the OUT file path
        obj_chnf = dyntools.CHNF(str_path_out) 

        # if not empty list
        if list_chn:

            list_chn = list_chn

        else:

            # the channel ids are return as a tuple
            tup_id = obj_chnf.get_id(str_path_out)

            # get the total id number
            # turn the tuple into a list then get the length of the list
            int_id_num = len(list(tup_id[1]))

            list_chn   = range(1, int_id_num, 1)

        # this is output line
        obj_chnf.xlsout(channels=list_chn, show=bool_show,
                        xlsfile=str_path_xlsx, outfile=str_path_out,
                        sheet=str_sheet, overwritesheet=bool_overwritesheet)

        return [True, True]

    except Exception as e:

        print(repr(e))

        return [False, True]

def out2xlsx_with_mp(chunk_outfile, chunk_xlsx):

    start = time.time()

    jop = []

    for k, v in zip(chunk_out, chunk_xlsx):

        jop = []

        for z in xrange(0, len(k)):

            p = mp.Process(target=boolOut2Xlsx, args=(k[z], v[z]))

            jop.append(p)

            p.start()

        for j in jop:

            j.join()

    dur = time.time() - start

    print('Time ...
(more)
edit flag offensive delete link more

Comments

Won't I run into the same problem converting the .out data to .csv or .xlsx? If looping over 100 .out files within python and accessing the .out data that way causes issues then it seems looping over the same 100 .out files and dumping the data to excel would cause the same issue.? any experience?

wassup_doc gravatar imagewassup_doc ( 2019-09-17 10:05:08 -0500 )edit

See my edited answer.

drsgao gravatar imagedrsgao ( 2019-09-19 09:58:51 -0500 )edit

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

1 follower

Stats

Asked: 2019-09-16 17:26:48 -0500

Seen: 474 times

Last updated: Sep 19 '19