Skip to content

`fetch` fails if unit name not found in astropy

Created by: e-q

Some of the 40m EPICS channels have the unit "Volts" specified in their EPICS record. fetch aborts the transfer because this isn't an exact match to an astropy unit. Is it possible for this to fail more gracefully, i.e. just leave the unit field blank if it doesn't match up to something?

Here's the traceback, gwpy.__version__ = '0.1b3'

In [8]: mydata = TimeSeriesDict.fetch(chans16.values(),t1,t1+1,verbose='True',host='fb',port=8088)
Connecting to fb:8088... Connected.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-f3f7b57f6b6a> in <module>()
----> 1 mydata = TimeSeriesDict.fetch(chans16.values(),t1,t1+1,verbose='True',host='fb',port=8088)

/usr/local/lib/python2.7/dist-packages/gwpy/utils/deps.pyc in wrapper(*args, **kwargs)
     80             func.func_globals[modname] = import_method_dependency(module,
     81                                                                   stacklevel=2)
---> 82             return func(*args, **kwargs)
     83         return wrapper
     84     return decorate_method

/usr/local/lib/python2.7/dist-packages/gwpy/timeseries/core.pyc in fetch(cls, channels, start, end, host, port, verify, verbose, connection, pad, type, dtype)
    761                 for buffer_, c in zip(buffers, channels):
    762                     ts = cls.EntryClass.from_nds2_buffer(
--> 763                         buffer_, dtype=dtype.get(c))
    764                     out.append({c: ts}, pad=pad,
    765                                gap=pad is None and 'raise' or 'pad')

/usr/local/lib/python2.7/dist-packages/gwpy/utils/deps.pyc in wrapper(*args, **kwargs)
     80             func.func_globals[modname] = import_method_dependency(module,
     81                                                                   stacklevel=2)
---> 82             return func(*args, **kwargs)
     83         return wrapper
     84     return decorate_method

/usr/local/lib/python2.7/dist-packages/gwpy/timeseries/core.pyc in from_nds2_buffer(cls, buffer_, **metadata)
    307         epoch = Time(buffer_.gps_seconds, buffer_.gps_nanoseconds,
    308                      format='gps')
--> 309         channel = Channel.from_nds2(buffer_.channel)
    310         return cls(buffer_.data, epoch=epoch, channel=channel, **metadata)
    311

/usr/local/lib/python2.7/dist-packages/gwpy/detector/channel.pyc in from_nds2(cls, nds2channel)
    442         }.get(nds2channel.data_type)
    443         return cls(name, sample_rate=sample_rate, unit=unit, dtype=dtype,
--> 444                    type=ctype)
    445
    446     # -------------------------------------------------------------------------

/usr/local/lib/python2.7/dist-packages/gwpy/detector/channel.pyc in __init__(self, name, sample_rate, unit, type, dtype, frametype, model, url)
    124             self.type = type
    125         self.sample_rate = sample_rate
--> 126         self.unit = unit
    127         self.dtype = dtype
    128         self.frametype = frametype

/usr/local/lib/python2.7/dist-packages/gwpy/detector/channel.pyc in unit(self, u)
    186             self._unit = None
    187         else:
--> 188             self._unit = units.Unit(u)
    189
    190     @property

/usr/lib/python2.7/dist-packages/astropy/units/core.pyc in __call__(self, s, represents, format, namespace, doc, parse_strict)
   1733                            .format(s, format_clause, six.text_type(e)))
   1734                     if parse_strict == 'raise':
-> 1735                         raise ValueError(msg)
   1736                     elif parse_strict == 'warn':
   1737                         warnings.warn(msg, UnitsWarning)

ValueError: 'Volts' did not parse as unit: At col 0, Volts is not a valid unit. Did you mean Volt or volt?