def chunk_data(tr, samp_rate, state='<STR_LIT>'):
trout = tr.copy()  <EOL>x = np.arange(len(tr.data))<EOL>y = tr.data<EOL>chunksize = int(round(tr.stats.sampling_rate / samp_rate))<EOL>numchunks = int(y.size // chunksize)<EOL>ychunks = y[:chunksize * numchunks].reshape((-<NUM_LIT:1>, chunksize))<EOL>xchunks = x[:chunksize * numchunks].reshape((-<NUM_LIT:1>, chunksize))<EOL>if state == '<STR_LIT>':<EOL><INDENT>trout.data = ychunks.max(axis=<NUM_LIT:1>)<EOL><DEDENT>elif state == '<STR_LIT>':<EOL><INDENT>trout.data = ychunks.min(axis=<NUM_LIT:1>)<EOL><DEDENT>elif state == '<STR_LIT>':<EOL><INDENT>trout.data = ychunks.mean(axis=<NUM_LIT:1>)<EOL><DEDENT>elif state == '<STR_LIT>':<EOL><INDENT>max_env = ychunks.max(axis=<NUM_LIT:1>)<EOL>min_env = ychunks.min(axis=<NUM_LIT:1>)<EOL>indeces = np.argmax(np.vstack([np.abs(max_env), np.abs(min_env)]),<EOL>axis=<NUM_LIT:0>)<EOL>stack = np.vstack([max_env, min_env]).T<EOL>trout.data = np.array([stack[i][indeces[i]]<EOL>for i in range(len(stack))])<EOL><DEDENT>xcenters = xchunks.mean(axis=<NUM_LIT:1>)<EOL>trout.stats.starttime = tr.stats.starttime + xcenters[<NUM_LIT:0>] /tr.stats.sampling_rate<EOL>trout.stats.sampling_rate = samp_rate<EOL>return trout<EOL>
Downsample data for plotting.

Computes the maximum of data within chunks, useful for plotting waveforms
or cccsums, large datasets that would otherwise exceed the complexity
allowed, and overflow.

:type tr: obspy.core.trace.Trace
:param tr: Trace to be chunked
:type samp_rate: float
:param samp_rate: Desired sampling rate in Hz
:type state: str
:param state:
    Either 'Min', 'Max', 'Mean' or 'Maxabs' to return one of these for the
    chunks. Maxabs will return the largest (positive or negative) for
    that chunk.

:returns: :class:`obspy.core.trace.Trace`