code: def PWS_stack(streams, weight=2, normalize=True):
      
      # First get the linear stack which we will weight by the phase stack
      Linstack = linstack(streams)
      # Compute the instantaneous phase
      instaphases = []
      print("Computing instantaneous phase")
      for stream in streams:
          instaphase = stream.copy()
          for tr in instaphase:
              analytic = hilbert(tr.data)
              envelope = np.sqrt(np.sum((np.square(analytic),
                                         np.square(tr.data)), axis=0))
              tr.data = analytic / envelope
          instaphases.append(instaphase)
      # Compute the phase stack
      print("Computing the phase stack")
      Phasestack = linstack(instaphases, normalize=normalize)
      # Compute the phase-weighted stack
      for tr in Phasestack:
          tr.data = Linstack.select(station=tr.stats.station)[0].data *\
              np.abs(tr.data ** weight)
      return Phasestack
docs: Compute the phase weighted stack of a series of streams.
  
      .. note:: It is recommended to align the traces before stacking.
  
      :type streams: list
      :param streams: List of :class:`obspy.core.stream.Stream` to stack.
      :type weight: float
      :param weight: Exponent to the phase stack used for weighting.
      :type normalize: bool
      :param normalize: Normalize traces before stacking.
  
      :return: Stacked stream.
      :rtype: :class:`obspy.core.stream.Stream`