def isosurface(da, coord, target):
    """
        Returns the values of a coordinate in the input array where the input array values equals
        a prescribed target. E.g. returns the depth of the 20 degC isotherm. Returns nans for all
        points in input array where isosurface is not defined. If 
        Author: Thomas Moore
        Date: 02/10/2018
        
        Parameters
        ----------
        da : xarray DataArray
            Array of values to be isosurfaced
        coord : str
            Name of coordinate to contruct isosurface about
        target : value
            Isosurface value
            
        Returns
        -------
        isosurface : xarray DataArray
            Values of coord where da is closest to target. If multiple occurences of target occur 
            along coord, only the maximum value of coord is returned
            
        Examples
        --------
        >>> A = xr.DataArray(np.random.normal(size=(5,5)), 
        ...                  coords=[('x', np.arange(5)), ('y', np.arange(5))])
        >>> isosurface(A, coord='x', target=0)
        >>> doppyo.utils.isosurface(A, coord='x', target=0)
        <xarray.DataArray 'isosurface' (y: 5)>
        array([ 4.,  1., nan,  3.,  4.])
        Coordinates:
          * y        (y) int64 0 1 2 3 4
  
        Limitations
        -----------
        If multiple occurences of target occur along coord, only the maximum value of coord is
        returned
        
        To do
        -----
        The current version includes no interpolation between grid spacing. This should be added as
        an option in the future
    """
    mask = da > target
    da_mask = mask * da[coord]
    isosurface = da_mask.max(coord)
    return isosurface.where(da.max(dim=coord) > target).rename('isosurface')
