Ask Your Question
1

Convert dynamic OUT files to Excel XLSX files

asked 2019-05-09 10:32:52 -0600

drsgao gravatar image

I have written a function to convert dynamic OUT files to Exel XLSX files. You can then plot the curves, or, better, save the worksheets you want into CSVs and then plot them using matplotlib. I am converting them to XLSX for easy sharing with colleagues.

Any improvements are welcome.

# =============================================================================
# <Function: convert .out file to excel workbook .xlsx>
# =============================================================================
def boolOut2Xlsx(str_path_out, str_path_xlsx, bool_show=False, bool_overwritesheet=False, str_sheet='', list_chn=[]):
    '''
    .. _boolOut2Xlsx :

    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:

        return [False, True]
# =============================================================================
# </Function: convert .out file to excel workbook .xlsx>
# =============================================================================
edit retag flag offensive close merge delete

Comments

Hi, I really appreciate your effort. I tried to implement this code in python and called to .py file in command prompt. It says that there is a Syntax Error and there is no any clue. I am not an expert in Python and coding either. Please help.

LassiPSSE gravatar imageLassiPSSE ( 2023-09-25 00:35:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2023-02-24 09:52:59 -0600

Ngoc Trieu gravatar image

Thank you for your sharing, how can I use it (step by step)

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

1 follower

Stats

Asked: 2019-05-09 10:32:52 -0600

Seen: 1,608 times

Last updated: Feb 24 '23