diff --git a/geomagio/edge/EdgeFactory.py b/geomagio/edge/EdgeFactory.py index 7b92a33ea51715e3a2702c0acf8d1d00995c82e8..307275a9cd826e1a22b8d876030a89419ee31341 100644 --- a/geomagio/edge/EdgeFactory.py +++ b/geomagio/edge/EdgeFactory.py @@ -17,7 +17,7 @@ import obspy.core from datetime import datetime from obspy import earthworm from obspy.core import UTCDateTime -from .. import ChannelConverter +from .. import ChannelConverter, TimeseriesUtility from ..TimeseriesFactory import TimeseriesFactory from ..TimeseriesFactoryException import TimeseriesFactoryException from ..ObservatoryMetadata import ObservatoryMetadata @@ -183,12 +183,11 @@ class EdgeFactory(TimeseriesFactory): if (starttime is None or endtime is None): starttime, endtime = self._get_stream_start_end_times(timeseries) - for channel in channels: if timeseries.select(channel=channel).count() == 0: 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: self._put_channel(timeseries, observatory, channel, type, interval, starttime, endtime) diff --git a/geomagio/iaga2002/IAGA2002Writer.py b/geomagio/iaga2002/IAGA2002Writer.py index 56c510f3d0dbc273eea1dc9e06cb8723fb5da909..cd070075a3c5e046044ea54586301c142d857793 100644 --- a/geomagio/iaga2002/IAGA2002Writer.py +++ b/geomagio/iaga2002/IAGA2002Writer.py @@ -3,7 +3,7 @@ from cStringIO import StringIO from datetime import datetime import numpy import textwrap -from .. import ChannelConverter +from .. import ChannelConverter, TimeseriesUtility from ..TimeseriesFactoryException import TimeseriesFactoryException from ..Util import create_empty_trace import IAGA2002Parser @@ -30,6 +30,11 @@ class IAGA2002Writer(object): channels: array_like 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 if len(channels) != 4: self._pad_to_four_channels(timeseries, channels) diff --git a/geomagio/pcdcp/PCDCPWriter.py b/geomagio/pcdcp/PCDCPWriter.py index e26c29075ae4b3320619ac617ce5190babe4f767..3042df76e476185449be5b5cf288cc8aa20fa280 100644 --- a/geomagio/pcdcp/PCDCPWriter.py +++ b/geomagio/pcdcp/PCDCPWriter.py @@ -3,7 +3,8 @@ import numpy import PCDCPParser from cStringIO import StringIO from datetime import datetime -from geomagio import ChannelConverter +from .. import ChannelConverter, TimeseriesUtility +from ..TimeseriesFactoryException import TimeseriesFactoryException from obspy.core import Stream @@ -26,6 +27,11 @@ class PCDCPWriter(object): channels : array_like 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 out.write(self._format_header(stats)) out.write(self._format_data(timeseries, channels))