Repository: obspy/obspy

Issue:
Error reading REFTEK130 file with unoccupied first three channels
ObsPy version 1.1.0 (Windows) installed via Anaconda

Hello ObsPy community, 

I'm facing the situation where three component data has been recorded on the velocity channels (4-6) of a reftek 130, but the acceleration channels (1-3) of the datalogger are unoccupied (file 093000000_001B7740 attached). Is there a way to only read in the data on the velocity channels 4-6? 
 
Using the read function on the attached file gives the following error message:
`IndexError: index 0 is out of bounds for axis 0 with size 0`

Attached file:
[093000000_001B7740.zip](https://github.com/obspy/obspy/files/1891075/093000000_001B7740.zip)

Datalogger setup:
AAAA Ch 1-3    Not connected
AAAA Ch 4-6    3C surface geophone


Discussion:
Please post full code to reproduce and full error traceback.
@megies Thanks Tobias, 

Code is simply:

`from obspy import read`
`st = read("093000000_001B7740")`

```
Traceback (most recent call last):

  File "<ipython-input-13-f8db228425d2>", line 7, in <module>
    component_codes = ['CHZ', 'CHN', 'CHE'])

  File "<decorator-gen-158>", line 2, in read

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\core\util\decorator.py", line 301, in _map_example_filename
    return func(*args, **kwargs)

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\core\stream.py", line 235, in read
    st.extend(_read(file, format, headonly, **kwargs).traces)

  File "<decorator-gen-159>", line 2, in _read

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\core\util\decorator.py", line 211, in uncompress_file
    result = func(filename, *args, **kwargs)

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\core\stream.py", line 277, in _read
    headonly=headonly, **kwargs)

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\core\util\base.py", line 412, in _read_from_plugin
    list_obj = read_format(filename, **kwargs)

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\io\reftek\core.py", line 102, in _read_reftek130
    verbose=verbose)

  File "C:\Users\jfarrugia\AppData\Local\conda\conda\envs\work\lib\site-packages\obspy\io\reftek\core.py", line 288, in to_stream
    starttime = packets_[0]['time']

IndexError: index 0 is out of bounds for axis 0 with size 0
```

Resolving patch:
diff --git a/obspy/io/reftek/core.py b/obspy/io/reftek/core.py
--- a/obspy/io/reftek/core.py
+++ b/obspy/io/reftek/core.py
@@ -272,7 +272,9 @@ def to_stream(self, network="", location="", component_codes=None,
                 "reftek130": eh._to_dict()}
             delta = 1.0 / eh.sampling_rate
             delta_nanoseconds = int(delta * 1e9)
-            for channel_number in np.unique(data['channel_number']):
+            inds_dt = data['packet_type'] == b"DT"
+            data_channels = np.unique(data[inds_dt]['channel_number'])
+            for channel_number in data_channels:
                 inds = data['channel_number'] == channel_number
                 # channel number of EH/ET packets also equals zero (one of the
                 # three unused bytes in the extended header of EH/ET packets)


Test patch:
diff --git a/obspy/io/reftek/tests/test_core.py b/obspy/io/reftek/tests/test_core.py
--- a/obspy/io/reftek/tests/test_core.py
+++ b/obspy/io/reftek/tests/test_core.py
@@ -554,6 +554,29 @@ def test_reading_file_with_multiple_events(self):
         for tr in st[8:]:
             self.assertEqual(tr.stats.station, 'TL02')
 
+    def test_reading_file_with_no_data_in_channel_zero(self):
+        """
+        Test reading a file that has no data packets in channel zero (e.g.
+        6-channel Reftek and only recording on channels 4-6)
+
+        Simply reuse the existing test data omitting the data packet that has
+        channel zero.
+        """
+        with open(self.reftek_file_vpu, 'rb') as fh:
+            data = fh.read()
+        # only use first packet (the EH packet) and last packet (a DT packet
+        # for channel number 1, i.e. channel 2)
+        data = data[:1024] + data[-1024:]
+        bio = io.BytesIO(data)
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            st = obspy.read(bio, format='REFTEK130')
+        self.assertEqual(len(st), 1)
+        # just a few basic checks, reading data is covered in other tests
+        tr = st[0]
+        self.assertEqual(tr.id, ".TL02..DS 11")
+        self.assertEqual(len(tr), 890)
+
 
 def suite():
     return unittest.makeSuite(ReftekTestCase, "test")