Coverage for /opt/obspy/update-docs/src/obspy/obspy/core/preview : 95%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- Tools for creating and merging previews.
:copyright: The ObsPy Development Team (devs@obspy.org) :license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """
""" Creates a preview trace.
A preview trace consists of maximum minus minimum of all samples within ``delta`` seconds. The parameter ``delta`` must be a multiple of the sampling rate of the ``trace`` object.
:type delta: integer, optional :param delta: Difference between two preview points. Defaults to ``60``. :rtype: :class:`~obspy.core.Trace` :return: New Trace object.
This method will modify the original Trace object. Create a copy of the Trace object if you want to continue using the original data. """ # number of samples for a single slice of delta seconds # minimum and maximum of samples before a static time marker else: # skip starting samples # number of complete slices of data # minimum and maximum of remaining samples else: # skip tailing samples # Fill NaN value with -1. last_diff = -1 # reshape matrix # get minimum and maximum for each row # fill masked values with -1 -> means missing data
""" Merges all preview traces in one Stream object. Does not change the original stream because the data needs to be copied anyway.
:type stream: :class:`~obspy.core.Stream` :param stream: Stream object to be merged :rtype: :class:`~obspy.core.Stream` :return: Merged Stream object. """ # Group traces by id. # Throw away empty traces. continue # Initialize new Stream object. new_stream.append(value[0]) continue # All traces need to have the same delta value and also be on the same # grid spacing. It is enough to only check the sampling rate because # the algorithm that creates the preview assures that the grid spacing # is correct. value[0].id # Check dtype. # Get the minimum start and maximum endtime for all traces. # Fill with negative one values which corresponds to a gap. # Create trace and give starttime. # Loop over all traces in value and add to data. # Element-by-element comparison. np.maximum(data[start_index:end_index], trace.data) # set npts again, because data is changed in place
""" Resamples a preview Trace to the chosen number of samples.
:type trace: :class:`~obspy.core.Trace` :param trace: Trace object to be resampled. :type samples: int :param samples: Desired number of samples. :type method: str, optional :param method: Resample method. Available are ``'fast'`` and ``'accurate'``. Defaults to ``'accurate'``.
.. rubric:: Notes
This method will destroy the data in the original Trace object. Deepcopy the Trace if you want to continue using the original data.
The fast method works by reshaping the data array to a sample x int(npts/samples) matrix (npts are the number of samples in the original trace) and taking the maximum of each row. Therefore the last npts - int(npts/samples)*samples will be omitted. The worst case scenario is resampling a 1999 samples array to 1000 samples. 999 samples, almost half the data will be omitted.
The accurate method has no such problems because it will move a window over the whole array and take the maximum for each window. It loops over each window and is up to 10 times slower than the fast method. This of course is highly depended on the number of wished samples and the original trace and usually the accurate method is still fast enough. """ # Only works for preview traces. # Save same attributes for later use. # XXX: Interpolate? raise NotImplementedError(msg) # Return if no change is necessary. There obviously are no omitted samples. return 0 # Fast method. # Set new sampling rate. float(samples - 1) # Return number of omitted samples. # Slow but accurate method. int((_i + 1) * step)].max() # Set new sampling rate. float(samples - 1) # Return number of omitted samples. Should be 0 for this method. else: raise NotImplementedError('Unknown method') |