def empirical_svd(stream_list, linear=True):
<EOL>stachans = list(set([(tr.stats.station, tr.stats.channel)<EOL>for st in stream_list for tr in st]))<EOL>for stachan in stachans:<EOL><INDENT>lengths = []<EOL>for st in stream_list:<EOL><INDENT>lengths.append(len(st.select(station=stachan[<NUM_LIT:0>],<EOL>channel=stachan[<NUM_LIT:1>])[<NUM_LIT:0>]))<EOL><DEDENT>min_length = min(lengths)<EOL>for st in stream_list:<EOL><INDENT>tr = st.select(station=stachan[<NUM_LIT:0>],<EOL>channel=stachan[<NUM_LIT:1>])[<NUM_LIT:0>]<EOL>if len(tr.data) > min_length:<EOL><INDENT>sr = tr.stats.sampling_rate<EOL>if abs(len(tr.data) - min_length) > (<NUM_LIT:0.1> * sr):<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise IndexError(msg)<EOL><DEDENT>msg = '<STR_LIT>'<EOL>warnings.warn(str(tr) + msg)<EOL>tr.data = tr.data[<NUM_LIT:0>:min_length]<EOL><DEDENT><DEDENT><DEDENT>if linear:<EOL><INDENT>first_subspace = stacking.linstack(stream_list)<EOL><DEDENT>else:<EOL><INDENT>first_subspace = stacking.PWS_stack(streams=stream_list)<EOL><DEDENT>second_subspace = first_subspace.copy()<EOL>for i in range(len(second_subspace)):<EOL><INDENT>second_subspace[i].data = np.diff(second_subspace[i].data)<EOL>delta = second_subspace[i].stats.delta<EOL>second_subspace[i].stats.starttime += <NUM_LIT:0.5> * delta<EOL><DEDENT>return [first_subspace, second_subspace]<EOL>
Empirical subspace detector generation function.

Takes a list of templates and computes the stack as the first order
subspace detector, and the differential of this as the second order
subspace detector following the empirical subspace method of
`Barrett & Beroza, 2014 - SRL
<http://srl.geoscienceworld.org/content/85/3/594.extract>`_.

:type stream_list: list
:param stream_list:
    list of streams to compute the subspace detectors from, where streams
    are :class:`obspy.core.stream.Stream` objects.
:type linear: bool
:param linear: Set to true by default to compute the linear stack as the \
    first subspace vector, False will use the phase-weighted stack as the \
    first subspace vector.

:returns: list of two :class:`obspy.core.stream.Stream` s