Skip to content
Snippets Groups Projects
Commit d02b77e6 authored by Jeremy M Fee's avatar Jeremy M Fee
Browse files

Validate requested output channels, and raise more meaningful exception

parent 9d0c6ec4
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ import obspy.core ...@@ -17,7 +17,7 @@ import obspy.core
from datetime import datetime from datetime import datetime
from obspy import earthworm from obspy import earthworm
from obspy.core import UTCDateTime from obspy.core import UTCDateTime
from .. import ChannelConverter from .. import ChannelConverter, TimeseriesUtility
from ..TimeseriesFactory import TimeseriesFactory from ..TimeseriesFactory import TimeseriesFactory
from ..TimeseriesFactoryException import TimeseriesFactoryException from ..TimeseriesFactoryException import TimeseriesFactoryException
from ..ObservatoryMetadata import ObservatoryMetadata from ..ObservatoryMetadata import ObservatoryMetadata
...@@ -183,12 +183,11 @@ class EdgeFactory(TimeseriesFactory): ...@@ -183,12 +183,11 @@ class EdgeFactory(TimeseriesFactory):
if (starttime is None or endtime is None): if (starttime is None or endtime is None):
starttime, endtime = self._get_stream_start_end_times(timeseries) starttime, endtime = self._get_stream_start_end_times(timeseries)
for channel in channels: for channel in channels:
if timeseries.select(channel=channel).count() == 0: if timeseries.select(channel=channel).count() == 0:
raise TimeseriesFactoryException( raise TimeseriesFactoryException(
'Missing channel "%s" for output' % channel) 'Missing channel "%s" for output, available channels %s' %
(channel, str(TimeseriesUtility.get_channels(timeseries))))
for channel in channels: for channel in channels:
self._put_channel(timeseries, observatory, channel, type, self._put_channel(timeseries, observatory, channel, type,
interval, starttime, endtime) interval, starttime, endtime)
......
...@@ -3,7 +3,7 @@ from cStringIO import StringIO ...@@ -3,7 +3,7 @@ from cStringIO import StringIO
from datetime import datetime from datetime import datetime
import numpy import numpy
import textwrap import textwrap
from .. import ChannelConverter from .. import ChannelConverter, TimeseriesUtility
from ..TimeseriesFactoryException import TimeseriesFactoryException from ..TimeseriesFactoryException import TimeseriesFactoryException
from ..Util import create_empty_trace from ..Util import create_empty_trace
import IAGA2002Parser import IAGA2002Parser
...@@ -30,6 +30,11 @@ class IAGA2002Writer(object): ...@@ -30,6 +30,11 @@ class IAGA2002Writer(object):
channels: array_like channels: array_like
channels to be written from timeseries object channels to be written from timeseries object
""" """
for channel in channels:
if timeseries.select(channel=channel).count() == 0:
raise TimeseriesFactoryException(
'Missing channel "%s" for output, available channels %s' %
(channel, str(TimeseriesUtility.get_channels(timeseries))))
stats = timeseries[0].stats stats = timeseries[0].stats
if len(channels) != 4: if len(channels) != 4:
self._pad_to_four_channels(timeseries, channels) self._pad_to_four_channels(timeseries, channels)
......
...@@ -3,7 +3,8 @@ import numpy ...@@ -3,7 +3,8 @@ import numpy
import PCDCPParser import PCDCPParser
from cStringIO import StringIO from cStringIO import StringIO
from datetime import datetime from datetime import datetime
from geomagio import ChannelConverter from .. import ChannelConverter, TimeseriesUtility
from ..TimeseriesFactoryException import TimeseriesFactoryException
from obspy.core import Stream from obspy.core import Stream
...@@ -26,6 +27,11 @@ class PCDCPWriter(object): ...@@ -26,6 +27,11 @@ class PCDCPWriter(object):
channels : array_like channels : array_like
Channels to be written from timeseries object. Channels to be written from timeseries object.
""" """
for channel in channels:
if timeseries.select(channel=channel).count() == 0:
raise TimeseriesFactoryException(
'Missing channel "%s" for output, available channels %s' %
(channel, str(TimeseriesUtility.get_channels(timeseries))))
stats = timeseries[0].stats stats = timeseries[0].stats
out.write(self._format_header(stats)) out.write(self._format_header(stats))
out.write(self._format_data(timeseries, channels)) out.write(self._format_data(timeseries, channels))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment