Example #1
0
def _get_available_channels(caches):
    """Determine available channels from local gravitational-wave frame files
    """
    (cache1, cache2) = caches
    try:
        available = (set(io_gwf.iter_channel_names(cache1[-1]))
                     & set(io_gwf.iter_channel_names(cache2[0])))
    except (IndexError, TypeError):
        raise RuntimeError("Could not find data in the time range requested")
    return available
Example #2
0
 def test_iter_channel_names(self):
     # maybe need something better?
     from types import GeneratorType
     names = io_gwf.iter_channel_names(TEST_GWF_FILE)
     assert isinstance(names, GeneratorType)
     assert list(names) == TEST_CHANNELS
     with mock.patch('gwpy.utils.shell.call', mock_call):
         names = io_gwf.iter_channel_names(TEST_GWF_FILE)
         assert isinstance(names, GeneratorType)
         assert list(names) == TEST_CHANNELS
Example #3
0
 def test_iter_channel_names(self):
     # maybe need something better?
     from types import GeneratorType
     names = gwf.iter_channel_names(TEST_GWF_FILE)
     self.assertIsInstance(names, GeneratorType)
     self.assertSequenceEqual(list(names), TEST_CHANNELS)
     with mock.patch('gwpy.utils.shell.call', mock_call):
         names = gwf.iter_channel_names(TEST_GWF_FILE)
         self.assertIsInstance(names, GeneratorType)
         self.assertSequenceEqual(list(names), TEST_CHANNELS)
Example #4
0
 def test_iter_channel_names(self):
     # maybe need something better?
     from types import GeneratorType
     names = io_gwf.iter_channel_names(TEST_GWF_FILE)
     assert isinstance(names, GeneratorType)
     assert list(names) == TEST_CHANNELS
     with mock.patch('gwpy.utils.shell.call', mock_call):
         names = io_gwf.iter_channel_names(TEST_GWF_FILE)
         assert isinstance(names, GeneratorType)
         assert list(names) == TEST_CHANNELS
Example #5
0
def remove_missing_channels(channels, gwfcache):
    """Find and remove channels from a given list that are not available in
    a given cache of frame files

    Parameters
    ----------
    channels : `list` of `str`
        list of requested channels

    gwfcache : `list` of `str`
        list of paths to .gwf files

    Returns
    -------
    keep : `list` of `str`
        list of common channels found in the first and last files in the
        cache

    Notes
    -----
    As a shorthand, this utility checks `channels` against only the first
    and last frame files in `gwfcache`. This saves time and memory by not
    loading tables of contents for large numbers of very long data files.

    For every channel requested that is not available in `gwfcache`, a
    `UserWarning` will be raised.

    See Also
    --------
    gwpy.io.gwf.iter_channel_names
        for the utility used to identify frame contents
    """
    # get available channels from the first and last frame file
    available = set(io_gwf.iter_channel_names(gwfcache[0]))
    if len(gwfcache) > 1:
        available.intersection_update(io_gwf.iter_channel_names(gwfcache[-1]))
    # work out which channels to keep, and which to reject
    channels = set(channels)
    keep = channels & available
    reject = channels - keep
    for channel in reject:
        warnings.warn(
            '{} is being removed because it was not available in all '
            'requested files'.format(channel), UserWarning)
    return list(keep)
Example #6
0
def remove_missing_channels(channels, gwfcache):
    """Find and remove channels from a given list that are not available in
    a given cache of frame files

    Parameters
    ----------
    channels : `list` of `str`
        list of requested channels

    gwfcache : `list` of `str`
        list of paths to .gwf files

    Returns
    -------
    keep : `list` of `str`
        list of common channels found in the first and last files in the
        cache

    Notes
    -----
    As a shorthand, this utility checks `channels` against only the first
    and last frame files in `gwfcache`. This saves time and memory by not
    loading tables of contents for large numbers of very long data files.

    For every channel requested that is not available in `gwfcache`, a
    `UserWarning` will be raised.

    See Also
    --------
    gwpy.io.gwf.iter_channel_names
        for the utility used to identify frame contents
    """
    # get available channels from the first and last frame file
    available = set(io_gwf.iter_channel_names(gwfcache[0]))
    if len(gwfcache) > 1:
        available.intersection_update(io_gwf.iter_channel_names(gwfcache[-1]))
    # work out which channels to keep, and which to reject
    channels = set(channels)
    keep = channels & available
    reject = channels - keep
    for channel in reject:
        warnings.warn(
            '{} is being removed because it was not available in all '
            'requested files'.format(channel), UserWarning)
    return list(keep)