def water_service_availability(expected_demand, demand):
    """
    Compute water service availability (WSA) at junctions, defined as follows:
        
    .. math:: WSA = \\dfrac{demand}{expected\\_demand}
        
    where 
    :math:`demand` is the actual demand computed from a hydraulic simulation, and 
    :math:`expected\\_demand` is the expected demand computed from base demands and demand 
    patterns. Expected demand can be computed using the 
    :class:`~wntr.metrics.hydraulic.expected_demand` method.

    WSA can be averaged over times and/or nodes (see below).  If 
    expected demand is 0 for a particular junction, water service availability 
    will be set to NaN for that junction. 

    * To compute water service availability for each junction and timestep, 
      expected_demand and demand should be pandas DataFrames (index = times, columns = junction names). 
    
    * To compute an average water service availability for each junction (averaged over time), 
      expected_demand and demand should be a pandas Series, indexed by junction.  
      To convert a DataFrame (index = times, columns = junction names) to a 
      Series indexed by junction, use the following code:
    
        :math:`expected\\_demand.sum(axis=0)`
		
        :math:`demand.sum(axis=0)`
    
    * To compute an average water service availability for each timestep (averaged over junctions), 
      expected_demand and demand should be a pandas Series, indexed by time.  
      To convert a DataFrame (index = times, columns = junction names) to a 
      Series indexed by time, use the following code:
        
        :math:`expected\\_demand.sum(axis=1)`
		
        :math:`demand.sum(axis=1)`
        
    Parameters
    ----------
    expected_demand : pandas DataFrame or pandas Series (see note above)
        Expected demand.  
    
    demand : pandas DataFrame or pandas Series (see note above)
        Actual demand (generally from a PDD hydraulic simulation)

    Returns
    -------
    A pandas DataFrame or pandas Series that contains water service 
    availability.
    """
    wsa = demand.div(expected_demand)
    return wsa
