def _node_loop(stations, lags, stream, clip_level,<EOL>i=<NUM_LIT:0>, mem_issue=False, instance=<NUM_LIT:0>, plot=False):
import matplotlib.pyplot as plt<EOL>energy_stream = Stream()  <EOL>for l, tr in enumerate(stream):<EOL><INDENT>j = [k for k in range(len(stations))<EOL>if stations[k] == tr.stats.station]<EOL>if len(j) > <NUM_LIT:1>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>j = [j[<NUM_LIT:0>]]<EOL><DEDENT>if len(j) == <NUM_LIT:0>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>continue<EOL><DEDENT>lag = lags[j[<NUM_LIT:0>]]<EOL>lagged_energy = np.square(<EOL>np.concatenate((tr.data,<EOL>np.zeros(<EOL>int(round(lag * tr.stats.sampling_rate)))))<EOL>)[int(round(lag * tr.stats.sampling_rate)):]<EOL>lagged_energy = np.clip(<EOL>lagged_energy, <NUM_LIT:0>, clip_level * np.mean(lagged_energy))<EOL>if '<STR_LIT>' not in locals():<EOL><INDENT>energy = (lagged_energy /<EOL>_rms(lagged_energy)).reshape(<NUM_LIT:1>, len(lagged_energy))<EOL>energy = np.nan_to_num(energy)<EOL>if not max(energy[<NUM_LIT:0>]) == <NUM_LIT:0.0>:<EOL><INDENT>energy = (<NUM_LIT> * (energy *<EOL>(<NUM_LIT:1> / max(energy[<NUM_LIT:0>])))).astype(np.int16)<EOL><DEDENT>else:<EOL><INDENT>energy = energy.astype(np.int16)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>norm_energy = (lagged_energy /<EOL>_rms(lagged_energy)).reshape(<NUM_LIT:1>, len(lagged_energy))<EOL>norm_energy = np.nan_to_num(norm_energy)<EOL>if not max(norm_energy[<NUM_LIT:0>]) == <NUM_LIT:0.0>:<EOL><INDENT>norm_energy = (<NUM_LIT> * (norm_energy *<EOL>(<NUM_LIT:1> / max(norm_energy[<NUM_LIT:0>])))).astype(np.int16)<EOL><DEDENT>else:<EOL><INDENT>norm_energy = norm_energy.astype(np.int16)<EOL><DEDENT>energy = np.concatenate((energy, norm_energy), axis=<NUM_LIT:0>)<EOL><DEDENT>energy_stream += Trace(<EOL>data=lagged_energy,<EOL>header=Stats({'<STR_LIT>': tr.stats.station,<EOL>'<STR_LIT>': tr.stats.sampling_rate}))<EOL><DEDENT>energy = np.sum(energy, axis=<NUM_LIT:0>).reshape(<NUM_LIT:1>, len(lagged_energy))<EOL>energy = energy.astype(np.uint16)<EOL>energy = np.nan_to_num(energy)<EOL>if plot:<EOL><INDENT>fig, axes = plt.subplots(len(stream) + <NUM_LIT:1>, <NUM_LIT:1>, sharex=True)<EOL>axes = axes.ravel()<EOL>for lagged_energy, tr, axis in zip(energy_stream, stream, axes):<EOL><INDENT>axis.plot(lagged_energy * <NUM_LIT:200>, '<STR_LIT:r>')<EOL>axis.plot(tr.data, '<STR_LIT:k>')<EOL><DEDENT>axes[-<NUM_LIT:1>].plot(energy[<NUM_LIT:0>])<EOL>plt.subplots_adjust(hspace=<NUM_LIT:0>)<EOL>plt.show()<EOL><DEDENT>if not mem_issue:<EOL><INDENT>return i, energy<EOL><DEDENT>else:<EOL><INDENT>np.save('<STR_LIT>' + str(instance) + '<STR_LIT>' + str(i), energy)<EOL>return i, str('<STR_LIT>' + str(instance) + '<STR_LIT>' + str(i))<EOL><DEDENT>
Internal function to allow for brightness to be paralleled.

:type stations: list
:param stations: List of stations to use.
:type lags: numpy.ndarray
:param lags: List of lags where lags[i[:]] are the lags for stations[i].
:type stream: obspy.core.stream.Stream
:param stream: Data stream to find the brightness for.
:type clip_level: float
:param clip_level: Upper limit for energy as a multiplier to the mean \
    energy.
:type i: int
:param i: Index of loop for parallelisation.
:type mem_issue: bool
:param mem_issue: If True will write to disk rather than storing data in \
    RAM.
:type instance: int
:param instance: instance for bulk parallelisation, only used if \
    mem_issue=true.
:type plot: bool
:param plot: Turn plotting on or off, defaults to False.

:returns: index
:rtype: int
:returns: network response
:rtype: numpy.ndarray