<commit_before>#----------------------------------------------------------------------------
# Name:         comlink
# Purpose:      Commercial MW link Class to handle all processing steps
#
# Authors:      <NAME>
#
# Created:      01.12.2014
# Copyright:    (c) <NAME> 2014
# Licence:      The MIT License
#----------------------------------------------------------------------------


from __future__ import division

import numpy as np
import matplotlib.pyplot as plt

from . import wet_dry
from . import baseline
from . import A_R_relation

class Comlink():
    """
    Commercial microwave link (CML) class for all data processing 
    
    Attributes
    ----------

    data : pandas.DataFrame
        DataFrame which holds at minimum the TX- and RX-levels. For each,
        far end and near end entries can exists. Furthermore, for protection
        links additional TX- and RX-level may exists. The naming convention 
        is:
         'tx_far'         = TX level far end 
         'tx_near'        = TX level near end
         'rx_far'         = RX level far end
         'rx_near'        = RX level near end
         'tx_far_protect' = TX level far end of protection link
         ....
         ...
         ..
         .
        Further columns can be present in the DataFrame, 
        e.g. RTT (the round trip time of a SNMP data acquisition request).
    param : 
        Metadata for the CML. Important are the site locations and the 
        CML frequency.
    
    """
    def __init__(self, metadata, TXRX_df):
        self.metadata = metadata
        self.data = TXRX_df
        self.processing_info = {}

        # TODO Check column names for the available TX and RX values
        
        # TODO resolve protection link data in DataFrame

        tx_rx_pairs = {'fn': {'name': 'far-near', 
                              'tx': 'tx_far',
                              'rx': 'rx_near',
                              'color': 'r'},
                       'nf': {'name': 'near-far',
                              'tx': 'tx_near',
                              'rx': 'rx_far',
                              'color': 'b'}}

        # Calculate TX-RX
        for pair_id, column_names in tx_rx_pairs.iteritems():
            self.data['txrx_' + pair_id] = self.data[column_names['tx']] \
                                         - self.data[column_names['rx']]
        self.processing_info['tx_rx_pairs'] = tx_rx_pairs
    
    def info(self):
        """Print MW link info 
        
        WIP: Print rudimentary MW link information
        
        """
        
        # TODO: Deal with protection links or links for which only
        #       unidirectional data is available
        
        print '============================================================='
        print 'ID: ' + self.metadata['link_id']
        print '-------------------------------------------------------------'
        print '     Site A                       Site B'
        print ' IP: ' + self.metadata['ip_a'] + '                  '  \
                      + self.metadata['ip_b']
        print '  f:   --------- ' + str(self.metadata['f_GHz_nf']) \
                                    + ' GHz ----------> '
        print '      <--------- ' + str(self.metadata['f_GHz_fn']) \
                                    + ' GHz ---------- ' 
        print '  L: ' + str(self.metadata['length_km']) + ' km'
        print '============================================================='
    
    def plot(self, 
             param_list=['txrx'], 
             resampling_time=None, 
             add_raw_data=False,
             figsize=(6,4),
             **kwargs):
        """ WIP for generic plotting function
        
        Parameters
        ----------
        
        param_list : str, list of str, tuple of str, list of tuple of str
            List of parameters to plot.....
            ....
            ...bla bla
        ...
        ..
        .
        
        """

        if resampling_time is not None:
            df_temp = self.data.resample(resampling_time)
        else:
            df_temp = self.data

        if type(param_list) is str:
            param_list = [param_list,]

        fig, ax = plt.subplots(len(param_list), 1, 
                               squeeze=False,
                               figsize=figsize)

        for i, param in enumerate(param_list):
            if type(param) is str:
                if param in self.data.columns:
                    df_temp[param].plot(ax=ax[i][0], 
                                        label=param,
                                        **kwargs)
                else:
                    # Try parameter + tx_rx_pair_identifier
                    for txrx_pair_id in self.processing_info['tx_rx_pairs']:
                        if param == 'tx' or param == 'rx':
                            param_temp = self.processing_info['tx_rx_pairs']\
                                                        [txrx_pair_id]\
                                                        [param]
                        else:
                            param_temp = param + '_' + txrx_pair_id
                            
                        color = self.processing_info['tx_rx_pairs']\
                                                    [txrx_pair_id]\
                                                    ['color']
                        name = self.processing_info['tx_rx_pairs']\
                                                   [txrx_pair_id]\
                                                   ['name']
                        df_temp[param_temp].plot(ax=ax[i][0], 
                                                 label=name,
                                                 color=color,
                                                 **kwargs)
            elif type(param) is tuple:
                for param_item in param:
                    df_temp[param_item].plot(ax=ax[i][0], 
                                             label=param_item, 
                                             **kwargs)
            ax[i][0].legend(loc='best')
        return ax<commit_msg>Generic plot function now add ylabel according to param<commit_after>#----------------------------------------------------------------------------
# Name:         comlink
# Purpose:      Commercial MW link Class to handle all processing steps
#
# Authors:      <NAME>
#
# Created:      01.12.2014
# Copyright:    (c) <NAME> 2014
# Licence:      The MIT License
#----------------------------------------------------------------------------


from __future__ import division

import numpy as np
import matplotlib.pyplot as plt

from . import wet_dry
from . import baseline
from . import A_R_relation

class Comlink():
    """
    Commercial microwave link (CML) class for all data processing 
    
    Attributes
    ----------

    data : pandas.DataFrame
        DataFrame which holds at minimum the TX- and RX-levels. For each,
        far end and near end entries can exists. Furthermore, for protection
        links additional TX- and RX-level may exists. The naming convention 
        is:
         'tx_far'         = TX level far end 
         'tx_near'        = TX level near end
         'rx_far'         = RX level far end
         'rx_near'        = RX level near end
         'tx_far_protect' = TX level far end of protection link
         ....
         ...
         ..
         .
        Further columns can be present in the DataFrame, 
        e.g. RTT (the round trip time of a SNMP data acquisition request).
    param : 
        Metadata for the CML. Important are the site locations and the 
        CML frequency.
    
    """
    def __init__(self, metadata, TXRX_df):
        self.metadata = metadata
        self.data = TXRX_df
        self.processing_info = {}

        # TODO Check column names for the available TX and RX values
        
        # TODO resolve protection link data in DataFrame

        tx_rx_pairs = {'fn': {'name': 'far-near', 
                              'tx': 'tx_far',
                              'rx': 'rx_near',
                              'color': 'r'},
                       'nf': {'name': 'near-far',
                              'tx': 'tx_near',
                              'rx': 'rx_far',
                              'color': 'b'}}

        # Calculate TX-RX
        for pair_id, column_names in tx_rx_pairs.iteritems():
            self.data['txrx_' + pair_id] = self.data[column_names['tx']] \
                                         - self.data[column_names['rx']]
        self.processing_info['tx_rx_pairs'] = tx_rx_pairs
    
    def info(self):
        """Print MW link info 
        
        WIP: Print rudimentary MW link information
        
        """
        
        # TODO: Deal with protection links or links for which only
        #       unidirectional data is available
        
        print '============================================================='
        print 'ID: ' + self.metadata['link_id']
        print '-------------------------------------------------------------'
        print '     Site A                       Site B'
        print ' IP: ' + self.metadata['ip_a'] + '                  '  \
                      + self.metadata['ip_b']
        print '  f:   --------- ' + str(self.metadata['f_GHz_nf']) \
                                    + ' GHz ----------> '
        print '      <--------- ' + str(self.metadata['f_GHz_fn']) \
                                    + ' GHz ---------- ' 
        print '  L: ' + str(self.metadata['length_km']) + ' km'
        print '============================================================='
    
    def plot(self, 
             param_list=['txrx'], 
             resampling_time=None, 
             add_raw_data=False,
             figsize=(6,4),
             **kwargs):
        """ WIP for generic plotting function
        
        Parameters
        ----------
        
        param_list : str, list of str, tuple of str, list of tuple of str
            List of parameters to plot.....
            ....
            ...bla bla
        ...
        ..
        .
        
        """

        if resampling_time is not None:
            df_temp = self.data.resample(resampling_time)
        else:
            df_temp = self.data

        if type(param_list) is str:
            param_list = [param_list,]

        fig, ax = plt.subplots(len(param_list), 1, 
                               squeeze=False,
                               figsize=figsize)

        for i, param in enumerate(param_list):
            if type(param) is str:
                if param in self.data.columns:
                    df_temp[param].plot(ax=ax[i][0], 
                                        label=param,
                                        **kwargs)
                else:
                    # Try parameter + tx_rx_pair_identifier
                    for txrx_pair_id in self.processing_info['tx_rx_pairs']:
                        if param == 'tx' or param == 'rx':
                            param_temp = self.processing_info['tx_rx_pairs']\
                                                        [txrx_pair_id]\
                                                        [param]
                        else:
                            param_temp = param + '_' + txrx_pair_id
                            
                        color = self.processing_info['tx_rx_pairs']\
                                                    [txrx_pair_id]\
                                                    ['color']
                        name = self.processing_info['tx_rx_pairs']\
                                                   [txrx_pair_id]\
                                                   ['name']
                        df_temp[param_temp].plot(ax=ax[i][0], 
                                                 label=name,
                                                 color=color,
                                                 **kwargs)
            elif type(param) is tuple:
                for param_item in param:
                    df_temp[param_item].plot(ax=ax[i][0], 
                                             label=param_item, 
                                             **kwargs)
            ax[i][0].legend(loc='best')
            ax[i][0].set_ylabel(param)
        return ax
{'fraction_non_alphanumeric': 0.1457140553181195, 'fraction_numerical': 0.0031449076687363924, 'mean_word_length': 0.9789372905696505, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2808050', 'n_tokens_mistral': 3033, 'n_tokens_neox': 2852, 'n_words': 778}