コード例 #1
0
ファイル: document_models.py プロジェクト: aalfaizz/tespy
def document_connection_params(nw, df, c):
    """Document parameter specification of connections.

    Parameters
    ----------
    nw : tespy.networks.network.Network
        Network object for unit information.

    df : pandas.core.frame.DataFrame
        DataFrame containing the connection parameter data.

    c : tespy.connections.connection.Connection
        Connection object, required for LaTeX equation generation.

    Returns
    -------
    latex : str
        LaTeX code for all connections.
    """
    label = 'Specified connection parameters'
    latex = r'\subsection{' + label + '}' + '\n\n'

    equations = ''
    for col in df.columns:
        if col == 'label':
            continue
        equations += generate_latex_eq(c, fpd[col]['latex_eq'],
                                       fpd[col]['text']) + '\n\n'
        col_header = (col.replace('_', r'\_') + ' in ' +
                      hlp.latex_unit(nw.get_attr(col + '_unit')) + ' ('
                      r'\ref{eq:Connection_' + fpd[col]['text'] + '})')
        df.rename(columns={col: col_header}, inplace=True)

    latex += create_latex_table(df, label)
    latex += r'\subsection{Equations applied}' + '\n\n'
    latex += equations
    return latex
コード例 #2
0
def document_connection_params(nw, df, specs, eqs, c, rpt):
    """Document parameter specification of connections.

    Parameters
    ----------
    nw : tespy.networks.network.Network
        Network object for unit information.

    df : pandas.core.frame.DataFrame
        DataFrame containing the connection parameter data.

    specs : pandas.core.frame.DataFrame
        DataFrame containing information on model input specifications.

    eqs : list
        List of parameters to generate equations for.

    c : tespy.connections.connection.Connection
        Connection object, required for LaTeX equation generation.

    rpt : dict
        Formatting data for the report.

    Returns
    -------
    latex : str
        LaTeX code for all connections.
    """
    if rpt['include_results']:
        label = 'Connection specifications and results'
    else:
        label = 'Specified connection parameters'
    latex = r'\subsection{' + label + '}' + '\n\n'

    equations = ''
    for col in df.columns:
        unit = col + '_unit'
        if col == 'Td_bp':
            unit = 'T_unit'
        col_header = (
            col.replace('_', r'\_') + ' in ' +
            hlp.latex_unit(nw.get_attr(unit)))
        if col in eqs:
            col_header += (
                r' (\ref{eq:Connection_' + fpd[col]['text'] + '})')
            equations += generate_latex_eq(
                c, fpd[col]['latex_eq'], fpd[col]['text']) + '\n\n'

        for row in df.index:
            fmt = rpt['Connection'][col]['float_fmt']
            if specs.loc[row, col] and rpt['include_results']:
                df.loc[row, col] = r'\bftab ' + fmt.format(df.loc[row, col])
            else:
                df.loc[row, col] = fmt.format(df.loc[row, col])

        df.rename(columns={col: col_header}, inplace=True)

    num_col = len(df.columns)

    latex += create_latex_table(df, label, col_fmt='l' + num_col * 'r')
    latex += r'\subsection{Equations applied}' + '\n\n'
    latex += equations
    return latex
コード例 #3
0
def document_connections(nw, rpt):
    """Document connection specifications.

    Parameters
    ----------
    nw : tespy.networks.network.Network
        TESPy model.

    rpt : dict
        Formatting data for the report.

    Returns
    -------
    latex : str
        LaTeX code for all connections.
    """

    ref_data = {'m': [], 'p': [], 'h': [], 'T': []}

    cols = nw.results['Connection'].columns
    conn_data = nw.results['Connection'].copy().loc[:, ~cols.isin(nw.fluids)]
    fluid_data = nw.results['Connection'].copy().loc[:, nw.fluids]

    specs = nw.specifications['Connection'].copy()
    if not rpt['include_results']:
        conn_data = conn_data[specs]
        fluid_data = fluid_data[specs]
    # it is possible to exclude fluid results
    elif not rpt['Connection']['fluid']['include_results']:
        fluid_data = fluid_data[specs]

    ref_spec = nw.specifications['Ref'].dropna(
        how='all').dropna(how='all', axis=1)

    # get some Connection object for equation generator
    c = nw.get_conn(specs.index[0])

    for c in nw.get_conn(ref_spec.index):
        for param in ref_data.keys():
            if c.get_attr(param).ref_set:
                ref_dict = {'label': c.label.replace('_', r'\_')}
                ref_dict.update(
                    {'reference':
                     c.get_attr(param).ref.obj.label.replace('_', r'\_'),
                     'factor in -': c.get_attr(param).ref.factor,
                     'delta in ' + hlp.latex_unit(
                         nw.get_attr(param + '_unit')):
                     c.get_attr(param).ref.delta})

                ref_data[param] += [ref_dict]

    latex = r'\section{Connections in ' + nw.mode + ' mode}' + '\n\n'

    # if list is empty, all parameters will be included
    if len(rpt['Connection']['params']) > 0:
        for col in conn_data.columns:
            if col not in rpt['Connection']['params'] and not any(specs[col]):
                conn_data[col] = np.nan

    df = data_to_df(conn_data)
    if len(df) > 0:
        eqs = df[specs].dropna(how='all').dropna(how='all', axis=1).columns
        latex += document_connection_params(nw, df, specs, eqs, c, rpt)

    df = data_to_df(fluid_data)
    if len(df) > 0:
        eqs = df[specs].dropna(how='all').dropna(how='all', axis=1).columns
        latex += document_connection_fluids(df, specs, eqs, c, rpt)

    for property, data in ref_data.items():
        df = data_to_df(data)
        if len(df) > 0:
            latex += document_connection_ref(df, property, c)

    return latex
コード例 #4
0
ファイル: document_models.py プロジェクト: aalfaizz/tespy
def document_connections(nw):
    """Document connection specifications.

    Parameters
    ----------
    nw : tespy.networks.network.Network
        TESPy model.

    Returns
    -------
    latex : str
        LaTeX code for all connections.
    """
    conn_data = []

    ref_data = {'m': [], 'p': [], 'h': [], 'T': []}
    ref_params = ['m', 'p', 'h', 'T']

    fluid_data = []

    for c in nw.conns.index:
        data_dict = {'label': c.label.replace('_', r'\_')}
        fluid_dict = data_dict.copy()

        data_dict.update({
            param: c.get_attr(param).val
            for param in fpd.keys() if c.get_attr(param).val_set
        })

        conn_data += [data_dict]

        for param in ref_params:
            if c.get_attr(param).ref_set:
                ref_dict = {'label': c.label.replace('_', r'\_')}
                ref_dict.update({
                    'reference':
                    c.get_attr(param).ref.obj.label.replace('_', r'\_'),
                    'factor in -':
                    c.get_attr(param).ref.factor,
                    'delta in ' + hlp.latex_unit(nw.get_attr(param + '_unit')):
                    c.get_attr(param).ref.delta
                })

                ref_data[param] += [ref_dict]

        fluid_dict.update({
            fluid: c.fluid.val[fluid]
            for fluid in nw.fluids if c.fluid.val_set[fluid]
        })
        if c.fluid.balance:
            fluid_dict.update({'balance': c.fluid.balance})

        fluid_data += [fluid_dict]

    latex = r'\section{Connections in ' + nw.mode + ' mode}' + '\n\n'
    df = data_to_df(conn_data)
    if len(df) > 0:
        latex += document_connection_params(nw, df, c)

    df = data_to_df(fluid_data)
    if len(df) > 0:
        latex += document_connection_fluids(df, c)

    for property, data in ref_data.items():
        df = data_to_df(data)
        if len(df) > 0:
            latex += document_connection_ref(df, property, c)

    return latex