def METHOD_NAME(quality, flowrate, wn, detection_limit=0):
    """ 
    Extent of contaminant in the pipes [USEPA15]_.
    Parameters
    ----------
    quality : pandas DataFrame
        A pandas DataFrame containing node water quality
        (index = times, columns = node names).
    flowrate : pandas DataFrame
        A pandas DataFrame containing pipe flowrate
        (index = times, columns = pipe names).
    wn : wntr WaterNetworkModel
        Water network model.  The water network model is needed to 
        get pipe length, and pipe start and end node.
    detection_limit : float
        Contaminant detection limit.
    Returns
    -------
    A pandas Series with extent of contamination (m)
    """
    pipe_names = wn.pipe_name_list
    link_length = []
    link_start_node = []
    link_end_node = []
    for name in pipe_names:
        link = wn.get_link(name)
        link_start_node.append(link.start_node_name)
        link_end_node.append(link.end_node_name)
        link_length.append(link.length)
    link_start_node = pd.Series(index=pipe_names, data=link_start_node)
    link_end_node = pd.Series(index=pipe_names, data=link_end_node)
    link_length = pd.Series(index=pipe_names, data=link_length)
    # flow_dir, pos_flow, neg_flow, link_contam are indexed by pipe names (col) 
    # and times (rows)
    flow_dir = np.sign(flowrate.loc[:,pipe_names])
    node_contam = quality > detection_limit
    pos_flow = np.array(node_contam.loc[:,link_start_node])
    neg_flow = np.array(node_contam.loc[:,link_end_node])
    link_contam = ((flow_dir>0)&pos_flow) | ((flow_dir<0)&neg_flow)
    # contam_len is cummax over time (has the node ever been contaminated)
    contam_len = (link_contam * link_length).cummax()
    # EC is a time series with the sum across nodes
    EC = contam_len.sum(axis=1)
    return EC