Coverage for /opt/obspy/update-docs/src/obspy/obspy/core/util/base : 96%

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 -*- Base utilities and constants for ObsPy.
:copyright: The ObsPy Development Team (devs@obspy.org) :license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """
# defining ObsPy modules currently used by runtests and the path function 'xseed', 'seisan', 'sh', 'segy', 'taup', 'seg2', 'db', 'realtime', 'datamark'] 'seedlink']
# default order of automatic format detection 'Q', 'SH_ASC', 'SLIST', 'TSPAIR', 'SEGY', 'SU', 'SEG2', 'WAV', 'PICKLE', 'DATAMARK']
# C file pointer/ descriptor class """ C file pointer class for type checking with argtypes """
""" Weak replacement for the Python's tempfile.TemporaryFile.
This function is a replacment for :func:`tempfile.NamedTemporaryFile` but will work also with Windows 7/Vista's UAC.
:type dir: str :param dir: If specified, the file will be created in that directory, otherwise the default directory for temporary files is used. :type suffix: str :param suffix: The temporary file name will end with that suffix. Defaults to ``'.tmp'``.
.. warning:: Caller is responsible for deleting the file when done with it.
.. rubric:: Example
>>> ntf = NamedTemporaryFile() >>> ntf._fileobj # doctest: +ELLIPSIS <open file '<fdopen>', mode 'w+b' at 0x...> >>> ntf._fileobj.close() >>> os.remove(ntf.name)
>>> filename = NamedTemporaryFile().name >>> fh = open(filename, 'wb') >>> fh.write("test") >>> fh.close() >>> os.remove(filename) """
""" Creates an NumPy array depending on the given data type and fill value.
If no ``fill_value`` is given a masked array will be returned.
:param delta: Number of samples for data chunk :param dtype: NumPy dtype for returned data chunk :param fill_value: If ``None``, masked array is returned, else the array is filled with the corresponding value
.. rubric:: Example
>>> createEmptyDataChunk(3, 'int', 10) array([10, 10, 10])
>>> createEmptyDataChunk(6, np.dtype('complex128'), 0) array([ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j])
>>> createEmptyDataChunk(3, 'f') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE masked_array(data = [-- -- --], mask = ..., ...) """ and len(fill_value) == 2: # if two values are supplied use these as samples bordering to our data # and interpolate between: # include left and right sample (delta + 2) # cut ls and rs and ensure correct data type else:
""" Function to find the absolute path of a test data file
The ObsPy modules are installed to a custom installation directory. That is the path cannot be predicted. This functions searches for all installed ObsPy modules and checks whether the file is in any of the "tests/data" subdirectories.
:param filename: A test file name to which the path should be returned. :return: Full path to file.
.. rubric:: Example
>>> getExampleFile('slist.ascii') # doctest: +SKIP /custom/path/to/obspy/core/tests/data/slist.ascii
>>> getExampleFile('does.not.exists') # doctest: +ELLIPSIS Traceback (most recent call last): ... IOError: Could not find file does.not.exists ... """ "of ObsPy modules"
""" Function to add all available doctests of the module with given name (e.g. "obspy.core") to the given unittest TestSuite. All submodules in the module's root directory are added. Occurring errors are shown as warnings.
:type testsuite: unittest.TestSuite :param testsuite: testsuite to which the tests should be added :type module_name: str :param module_name: name of the module of which the tests should be added
.. rubric:: Example
>>> import unittest >>> suite = unittest.TestSuite() >>> add_doctests(suite, "obspy.core") """
# skip directories without __init__.py # skip tests directories # skip scripts directories # skip lib directories continue # loop over all files # skip if not python source file # get module name
""" Function to add all available unittests of the module with given name (e.g. "obspy.core") to the given unittest TestSuite. All submodules in the "tests" directory whose names are starting with ``test_`` are added.
:type testsuite: unittest.TestSuite :param testsuite: testsuite to which the tests should be added :type module_name: str :param module_name: name of the module of which the tests should be added
.. rubric:: Example
>>> import unittest >>> suite = unittest.TestSuite() >>> add_unittests(suite, "obspy.core") """
""" Gets a dictionary of all available plug-ins of a group or subgroup.
:type group: str :param group: Group name. :type subgroup: str, optional :param subgroup: Subgroup name (defaults to None). :rtype: dict :returns: Dictionary of entry points of each plug-in.
.. rubric:: Example
>>> _getEntryPoints('obspy.plugin.waveform') # doctest: +ELLIPSIS {...'SLIST': EntryPoint.parse('SLIST = obspy.core.ascii')...} """ else:
""" Gets a ordered dictionary of all available plug-ins of a group or subgroup. """ # get all available entry points # loop through official supported waveform plug-ins and add them to # ordered dict of entry points # skip plug-ins which are not installed # extend entry points with any left over waveform plug-ins
'trigger': _getEntryPoints('obspy.plugin.trigger'), 'filter': _getEntryPoints('obspy.plugin.filter'), 'rotate': _getEntryPoints('obspy.plugin.rotate'), 'detrend': _getEntryPoints('obspy.plugin.detrend'), 'integrate': _getEntryPoints('obspy.plugin.integrate'), 'differentiate': _getEntryPoints('obspy.plugin.differentiate'), 'waveform': _getOrderedEntryPoints('obspy.plugin.waveform', 'readFormat', WAVEFORM_PREFERRED_ORDER), 'waveform_write': _getOrderedEntryPoints('obspy.plugin.waveform', 'writeFormat', WAVEFORM_PREFERRED_ORDER), 'event': _getEntryPoints('obspy.plugin.event', 'readFormat'), 'taper': _getEntryPoints('obspy.plugin.taper'), }
""" A "automagic" function searching a given dict of entry points for a valid entry point and returns the function call. Otherwise it will raise a default error message.
.. rubric:: Example
>>> _getFunctionFromEntryPoint('detrend', 'simple') # doctest: +ELLIPSIS <function simple at 0x...>
>>> _getFunctionFromEntryPoint('detrend', 'XXX') # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: Detrend type "XXX" is not supported. Supported types: ... """ # get entry point else: # search using lower cases only if k.lower() == type.lower()][0] # check if any entry points are available at all msg = "Your current ObsPy installation does not support " + \ "any %s functions. Please make sure " + \ "SciPy is installed properly." raise ImportError(msg % (group.capitalize())) # ok we have entry points, but specified function is not supported # import function point # any issue during import of entry point should be raised, so the user has # a chance to correct the problem 'obspy.plugin.%s' % (group), entry_point.name)
""" Get matplotlib version information.
:returns: Matplotlib version as a list of three integers or ``None`` if matplotlib import fails. The last version number can indicate different things like it being a version from the old svn trunk, the latest git repo, some release candidate version, ... If the last number cannot be converted to an integer it will be set to 0. """ except ImportError: version = None
""" Reads a single file from a plug-in's readFormat function. """ # get format entry point # auto detect format - go through all known formats in given sort order # search isFormat for given entry point 'obspy.plugin.%s.%s' % (plugin_type, format_ep.name), 'isFormat') # check format else: else: # format given via argument except IndexError: msg = "Format \"%s\" is not supported. Supported types: %s" raise TypeError(msg % (format, ', '.join(EPS))) # file format should be known by now # search readFormat for given entry point 'obspy.plugin.%s.%s' % (plugin_type, format_ep.name), 'readFormat') except ImportError: msg = "Format \"%s\" is not supported. Supported types: %s" raise TypeError(msg % (format_ep.name, ', '.join(EPS))) # read
if __name__ == '__main__': doctest.testmod(exclude_empty=True) |