We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CSS format reading / file type detection
Hello,

Was advised on the mailing list to post this issue here.

I've been happily working with CSS format files generated by the Pisces package but have a small issue when trying to read them with ObsPy. Essentially, I get an unknown file format error using 'read' unless I specify what the data format is explicitly, i.e., st = read("file.wfdisc", format = "CSS"). 

Without specifying the format, the full traceback is:

```
TypeError                                 Traceback (most recent call last)
<ipython-input-2-6eef146513fc> in <module>()
----> 1 st = read('/DEMO_data/2018001.DEMO.wfdisc')

<decorator-gen-146> in read(pathname_or_url, format, headonly, starttime, endtime, nearest_sample, dtype, apply_calib, check_compression, **kwargs)

~/anaconda3/lib/python3.6/site-packages/obspy/core/util/decorator.py in _map_example_filename(func, *args, **kwargs)
    299                         except IOError:
    300                             pass
--> 301         return func(*args, **kwargs)
    302     return _map_example_filename
    303 

~/anaconda3/lib/python3.6/site-packages/obspy/core/stream.py in read(pathname_or_url, format, headonly, starttime, endtime, nearest_sample, dtype, apply_calib, check_compression, **kwargs)
    233         pathname = pathname_or_url
    234         for file in sorted(glob(pathname)):
--> 235             st.extend(_read(file, format, headonly, **kwargs).traces)
    236         if len(st) == 0:
    237             # try to give more specific information why the stream is empty

<decorator-gen-147> in _read(filename, format, headonly, **kwargs)

~/anaconda3/lib/python3.6/site-packages/obspy/core/util/decorator.py in uncompress_file(func, filename, *args, **kwargs)
    209     else:
    210         # no compressions
--> 211         result = func(filename, *args, **kwargs)
    212     return result
    213 

~/anaconda3/lib/python3.6/site-packages/obspy/core/stream.py in _read(filename, format, headonly, **kwargs)
    275     """
    276     stream, format = _read_from_plugin('waveform', filename, format=format,
--> 277                                        headonly=headonly, **kwargs)
    278     # set _format identifier for each element
    279     for trace in stream:

~/anaconda3/lib/python3.6/site-packages/obspy/core/util/base.py in _read_from_plugin(plugin_type, filename, format, **kwargs)
    390                 break
    391         else:
--> 392             raise TypeError('Unknown format for file %s' % filename)
    393     else:
    394         # format given via argument

TypeError: Unknown format for file /DEMO_data/2018001.DEMO.wfdisc
```
It seems the automatic file type detection isn't working, something I note was in a thread about 3 years ago (http://lists.swapbytes.de/archives/obspy-users/2015-February/001642.html). However, I'm not sure if this is ObsPy related, or Pisces related.

I've attached files representing a 30 second example here.

System details:
ObsPy 1.1.0, installed via Anaconda Navigator, running on OSX 10.11.6 with Python version is 3.6.4.

Many thanks.

[DEMO_data.zip](https://github.com/obspy/obspy/files/2043136/DEMO_data.zip)





--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `obspy/io/css/core.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3 CSS bindings to ObsPy core module.
4 """
5 from __future__ import (absolute_import, division, print_function,
6                         unicode_literals)
7 from future.builtins import *  # NOQA
8 
9 import os
10 
11 import numpy as np
12 
13 from obspy import Stream, Trace, UTCDateTime
14 from obspy.core.compatibility import from_buffer
15 
16 
17 DTYPE = {
18     # Big-endian integers
19     b's4': b'>i',
20     b's2': b'>h',
21     # Little-endian integers
22     b'i4': b'<i',
23     b'i2': b'<h',
24     # ASCII integers
25     b'c0': (b'S12', np.int),
26     b'c#': (b'S12', np.int),
27     # Big-endian floating point
28     b't4': b'>f',
29     b't8': b'>d',
30     # Little-endian floating point
31     b'f4': b'<f',
32     b'f8': b'<d',
33     # ASCII floating point
34     b'a0': (b'S15', np.float32),
35     b'a#': (b'S15', np.float32),
36     b'b0': (b'S24', np.float64),
37     b'b#': (b'S24', np.float64),
38 }
39 
40 
41 def _is_css(filename):
42     """
43     Checks whether a file is CSS waveform data (header) or not.
44 
45     :type filename: str
46     :param filename: CSS file to be checked.
47     :rtype: bool
48     :return: ``True`` if a CSS waveform header file.
49     """
50     # Fixed file format.
51     # Tests:
52     #  - the length of each line (283 chars)
53     #  - two epochal time fields
54     #    (for position of dot and if they convert to UTCDateTime)
55     #  - supported data type descriptor
56     try:
57         with open(filename, "rb") as fh:
58             lines = fh.readlines()
59             # check for empty file
60             if not lines:
61                 return False
62             # check every line
63             for line in lines:
64                 assert(len(line.rstrip(b"\n\r")) == 283)
65                 assert(line[26:27] == b".")
66                 UTCDateTime(float(line[16:33]))
67                 assert(line[71:72] == b".")
68                 UTCDateTime(float(line[61:78]))
69                 assert(line[143:145] in DTYPE)
70     except Exception:
71         return False
72     return True
73 
74 
75 def _is_nnsa_kb_core(filename):
76     """
77     Checks whether a file is NNSA KB Core waveform data (header) or not.
78 
79     :type filename: str
80     :param filename: NNSA KB Core file to be checked.
81     :rtype: bool
82     :return: ``True`` if a NNSA KB Core waveform header file.
83     """
84     # Fixed file format.
85     # Tests:
86     #  - the length of each line (287 chars)
87     #  - two epochal time fields
88     #    (for position of dot and if they convert to UTCDateTime)
89     #  - supported data type descriptor
90     try:
91         with open(filename, "rb") as fh:
92             lines = fh.readlines()
93             # check for empty file
94             if not lines:
95                 return False
96             # check every line
97             for line in lines:
98                 assert(len(line.rstrip(b"\n\r")) == 287)
99                 assert(line[27:28] == b".")
100                 UTCDateTime(float(line[16:33]))
101                 assert(line[73:74] == b".")
102                 UTCDateTime(float(line[62:79]))
103                 assert(line[144:146] in DTYPE)
104     except Exception:
105         return False
106     return True
107 
108 
109 def _read_css(filename, **kwargs):
110     """
111     Reads a CSS waveform file and returns a Stream object.
112 
113     .. warning::
114         This function should NOT be called directly, it registers via the
115         ObsPy :func:`~obspy.core.stream.read` function, call this instead.
116 
117     :type filename: str
118     :param filename: CSS file to be read.
119     :rtype: :class:`~obspy.core.stream.Stream`
120     :returns: Stream with Traces specified by given file.
121     """
122     # read metafile with info on single traces
123     with open(filename, "rb") as fh:
124         lines = fh.readlines()
125     basedir = os.path.dirname(filename)
126     traces = []
127     # read single traces
128     for line in lines:
129         npts = int(line[79:87])
130         dirname = line[148:212].strip().decode()
131         filename = line[213:245].strip().decode()
132         filename = os.path.join(basedir, dirname, filename)
133         offset = int(line[246:256])
134         dtype = DTYPE[line[143:145]]
135         if isinstance(dtype, tuple):
136             read_fmt = np.dtype(dtype[0])
137             fmt = dtype[1]
138         else:
139             read_fmt = np.dtype(dtype)
140             fmt = read_fmt
141         with open(filename, "rb") as fh:
142             fh.seek(offset)
143             data = fh.read(read_fmt.itemsize * npts)
144             data = from_buffer(data, dtype=read_fmt)
145             data = np.require(data, dtype=fmt)
146         header = {}
147         header['station'] = line[0:6].strip().decode()
148         header['channel'] = line[7:15].strip().decode()
149         header['starttime'] = UTCDateTime(float(line[16:33]))
150         header['sampling_rate'] = float(line[88:99])
151         header['calib'] = float(line[100:116])
152         header['calper'] = float(line[117:133])
153         tr = Trace(data, header=header)
154         traces.append(tr)
155     return Stream(traces=traces)
156 
157 
158 def _read_nnsa_kb_core(filename, **kwargs):
159     """
160     Reads a NNSA KB Core waveform file and returns a Stream object.
161 
162     .. warning::
163         This function should NOT be called directly, it registers via the
164         ObsPy :func:`~obspy.core.stream.read` function, call this instead.
165 
166     :type filename: str
167     :param filename: NNSA KB Core file to be read.
168     :rtype: :class:`~obspy.core.stream.Stream`
169     :returns: Stream with Traces specified by given file.
170     """
171     # read metafile with info on single traces
172     with open(filename, "rb") as fh:
173         lines = fh.readlines()
174     basedir = os.path.dirname(filename)
175     traces = []
176     # read single traces
177     for line in lines:
178         npts = int(line[80:88])
179         dirname = line[149:213].strip().decode()
180         filename = line[214:246].strip().decode()
181         filename = os.path.join(basedir, dirname, filename)
182         offset = int(line[247:257])
183         dtype = DTYPE[line[144:146]]
184         if isinstance(dtype, tuple):
185             read_fmt = np.dtype(dtype[0])
186             fmt = dtype[1]
187         else:
188             read_fmt = np.dtype(dtype)
189             fmt = read_fmt
190         with open(filename, "rb") as fh:
191             fh.seek(offset)
192             data = fh.read(read_fmt.itemsize * npts)
193             data = from_buffer(data, dtype=read_fmt)
194             data = np.require(data, dtype=fmt)
195         header = {}
196         header['station'] = line[0:6].strip().decode()
197         header['channel'] = line[7:15].strip().decode()
198         header['starttime'] = UTCDateTime(float(line[16:33]))
199         header['sampling_rate'] = float(line[89:100])
200         header['calib'] = float(line[101:117])
201         header['calper'] = float(line[118:134])
202         tr = Trace(data, header=header)
203         traces.append(tr)
204     return Stream(traces=traces)
205
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/obspy/io/css/core.py b/obspy/io/css/core.py
--- a/obspy/io/css/core.py
+++ b/obspy/io/css/core.py
@@ -62,9 +62,9 @@
             # check every line
             for line in lines:
                 assert(len(line.rstrip(b"\n\r")) == 283)
-                assert(line[26:27] == b".")
+                assert(b"." in line[26:28])
                 UTCDateTime(float(line[16:33]))
-                assert(line[71:72] == b".")
+                assert(b"." in line[71:73])
                 UTCDateTime(float(line[61:78]))
                 assert(line[143:145] in DTYPE)
     except Exception:

{"golden_diff": "diff --git a/obspy/io/css/core.py b/obspy/io/css/core.py\n--- a/obspy/io/css/core.py\n+++ b/obspy/io/css/core.py\n@@ -62,9 +62,9 @@\n             # check every line\n             for line in lines:\n                 assert(len(line.rstrip(b\"\\n\\r\")) == 283)\n-                assert(line[26:27] == b\".\")\n+                assert(b\".\" in line[26:28])\n                 UTCDateTime(float(line[16:33]))\n-                assert(line[71:72] == b\".\")\n+                assert(b\".\" in line[71:73])\n                 UTCDateTime(float(line[61:78]))\n                 assert(line[143:145] in DTYPE)\n     except Exception:\n", "issue": "CSS format reading / file type detection\nHello,\r\n\r\nWas advised on the mailing list to post this issue here.\r\n\r\nI've been happily working with CSS format files generated by the Pisces package but have a small issue when trying to read them with ObsPy. Essentially, I get an unknown file format error using 'read' unless I specify what the data format is explicitly, i.e., st = read(\"file.wfdisc\", format = \"CSS\"). \r\n\r\nWithout specifying the format, the full traceback is:\r\n\r\n```\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-2-6eef146513fc> in <module>()\r\n----> 1 st = read('/DEMO_data/2018001.DEMO.wfdisc')\r\n\r\n<decorator-gen-146> in read(pathname_or_url, format, headonly, starttime, endtime, nearest_sample, dtype, apply_calib, check_compression, **kwargs)\r\n\r\n~/anaconda3/lib/python3.6/site-packages/obspy/core/util/decorator.py in _map_example_filename(func, *args, **kwargs)\r\n    299                         except IOError:\r\n    300                             pass\r\n--> 301         return func(*args, **kwargs)\r\n    302     return _map_example_filename\r\n    303 \r\n\r\n~/anaconda3/lib/python3.6/site-packages/obspy/core/stream.py in read(pathname_or_url, format, headonly, starttime, endtime, nearest_sample, dtype, apply_calib, check_compression, **kwargs)\r\n    233         pathname = pathname_or_url\r\n    234         for file in sorted(glob(pathname)):\r\n--> 235             st.extend(_read(file, format, headonly, **kwargs).traces)\r\n    236         if len(st) == 0:\r\n    237             # try to give more specific information why the stream is empty\r\n\r\n<decorator-gen-147> in _read(filename, format, headonly, **kwargs)\r\n\r\n~/anaconda3/lib/python3.6/site-packages/obspy/core/util/decorator.py in uncompress_file(func, filename, *args, **kwargs)\r\n    209     else:\r\n    210         # no compressions\r\n--> 211         result = func(filename, *args, **kwargs)\r\n    212     return result\r\n    213 \r\n\r\n~/anaconda3/lib/python3.6/site-packages/obspy/core/stream.py in _read(filename, format, headonly, **kwargs)\r\n    275     \"\"\"\r\n    276     stream, format = _read_from_plugin('waveform', filename, format=format,\r\n--> 277                                        headonly=headonly, **kwargs)\r\n    278     # set _format identifier for each element\r\n    279     for trace in stream:\r\n\r\n~/anaconda3/lib/python3.6/site-packages/obspy/core/util/base.py in _read_from_plugin(plugin_type, filename, format, **kwargs)\r\n    390                 break\r\n    391         else:\r\n--> 392             raise TypeError('Unknown format for file %s' % filename)\r\n    393     else:\r\n    394         # format given via argument\r\n\r\nTypeError: Unknown format for file /DEMO_data/2018001.DEMO.wfdisc\r\n```\r\nIt seems the automatic file type detection isn't working, something I note was in a thread about 3 years ago (http://lists.swapbytes.de/archives/obspy-users/2015-February/001642.html). However, I'm not sure if this is ObsPy related, or Pisces related.\r\n\r\nI've attached files representing a 30 second example here.\r\n\r\nSystem details:\r\nObsPy 1.1.0, installed via Anaconda Navigator, running on OSX 10.11.6 with Python version is 3.6.4.\r\n\r\nMany thanks.\r\n\r\n[DEMO_data.zip](https://github.com/obspy/obspy/files/2043136/DEMO_data.zip)\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nCSS bindings to ObsPy core module.\n\"\"\"\nfrom __future__ import (absolute_import, division, print_function,\n                        unicode_literals)\nfrom future.builtins import *  # NOQA\n\nimport os\n\nimport numpy as np\n\nfrom obspy import Stream, Trace, UTCDateTime\nfrom obspy.core.compatibility import from_buffer\n\n\nDTYPE = {\n    # Big-endian integers\n    b's4': b'>i',\n    b's2': b'>h',\n    # Little-endian integers\n    b'i4': b'<i',\n    b'i2': b'<h',\n    # ASCII integers\n    b'c0': (b'S12', np.int),\n    b'c#': (b'S12', np.int),\n    # Big-endian floating point\n    b't4': b'>f',\n    b't8': b'>d',\n    # Little-endian floating point\n    b'f4': b'<f',\n    b'f8': b'<d',\n    # ASCII floating point\n    b'a0': (b'S15', np.float32),\n    b'a#': (b'S15', np.float32),\n    b'b0': (b'S24', np.float64),\n    b'b#': (b'S24', np.float64),\n}\n\n\ndef _is_css(filename):\n    \"\"\"\n    Checks whether a file is CSS waveform data (header) or not.\n\n    :type filename: str\n    :param filename: CSS file to be checked.\n    :rtype: bool\n    :return: ``True`` if a CSS waveform header file.\n    \"\"\"\n    # Fixed file format.\n    # Tests:\n    #  - the length of each line (283 chars)\n    #  - two epochal time fields\n    #    (for position of dot and if they convert to UTCDateTime)\n    #  - supported data type descriptor\n    try:\n        with open(filename, \"rb\") as fh:\n            lines = fh.readlines()\n            # check for empty file\n            if not lines:\n                return False\n            # check every line\n            for line in lines:\n                assert(len(line.rstrip(b\"\\n\\r\")) == 283)\n                assert(line[26:27] == b\".\")\n                UTCDateTime(float(line[16:33]))\n                assert(line[71:72] == b\".\")\n                UTCDateTime(float(line[61:78]))\n                assert(line[143:145] in DTYPE)\n    except Exception:\n        return False\n    return True\n\n\ndef _is_nnsa_kb_core(filename):\n    \"\"\"\n    Checks whether a file is NNSA KB Core waveform data (header) or not.\n\n    :type filename: str\n    :param filename: NNSA KB Core file to be checked.\n    :rtype: bool\n    :return: ``True`` if a NNSA KB Core waveform header file.\n    \"\"\"\n    # Fixed file format.\n    # Tests:\n    #  - the length of each line (287 chars)\n    #  - two epochal time fields\n    #    (for position of dot and if they convert to UTCDateTime)\n    #  - supported data type descriptor\n    try:\n        with open(filename, \"rb\") as fh:\n            lines = fh.readlines()\n            # check for empty file\n            if not lines:\n                return False\n            # check every line\n            for line in lines:\n                assert(len(line.rstrip(b\"\\n\\r\")) == 287)\n                assert(line[27:28] == b\".\")\n                UTCDateTime(float(line[16:33]))\n                assert(line[73:74] == b\".\")\n                UTCDateTime(float(line[62:79]))\n                assert(line[144:146] in DTYPE)\n    except Exception:\n        return False\n    return True\n\n\ndef _read_css(filename, **kwargs):\n    \"\"\"\n    Reads a CSS waveform file and returns a Stream object.\n\n    .. warning::\n        This function should NOT be called directly, it registers via the\n        ObsPy :func:`~obspy.core.stream.read` function, call this instead.\n\n    :type filename: str\n    :param filename: CSS file to be read.\n    :rtype: :class:`~obspy.core.stream.Stream`\n    :returns: Stream with Traces specified by given file.\n    \"\"\"\n    # read metafile with info on single traces\n    with open(filename, \"rb\") as fh:\n        lines = fh.readlines()\n    basedir = os.path.dirname(filename)\n    traces = []\n    # read single traces\n    for line in lines:\n        npts = int(line[79:87])\n        dirname = line[148:212].strip().decode()\n        filename = line[213:245].strip().decode()\n        filename = os.path.join(basedir, dirname, filename)\n        offset = int(line[246:256])\n        dtype = DTYPE[line[143:145]]\n        if isinstance(dtype, tuple):\n            read_fmt = np.dtype(dtype[0])\n            fmt = dtype[1]\n        else:\n            read_fmt = np.dtype(dtype)\n            fmt = read_fmt\n        with open(filename, \"rb\") as fh:\n            fh.seek(offset)\n            data = fh.read(read_fmt.itemsize * npts)\n            data = from_buffer(data, dtype=read_fmt)\n            data = np.require(data, dtype=fmt)\n        header = {}\n        header['station'] = line[0:6].strip().decode()\n        header['channel'] = line[7:15].strip().decode()\n        header['starttime'] = UTCDateTime(float(line[16:33]))\n        header['sampling_rate'] = float(line[88:99])\n        header['calib'] = float(line[100:116])\n        header['calper'] = float(line[117:133])\n        tr = Trace(data, header=header)\n        traces.append(tr)\n    return Stream(traces=traces)\n\n\ndef _read_nnsa_kb_core(filename, **kwargs):\n    \"\"\"\n    Reads a NNSA KB Core waveform file and returns a Stream object.\n\n    .. warning::\n        This function should NOT be called directly, it registers via the\n        ObsPy :func:`~obspy.core.stream.read` function, call this instead.\n\n    :type filename: str\n    :param filename: NNSA KB Core file to be read.\n    :rtype: :class:`~obspy.core.stream.Stream`\n    :returns: Stream with Traces specified by given file.\n    \"\"\"\n    # read metafile with info on single traces\n    with open(filename, \"rb\") as fh:\n        lines = fh.readlines()\n    basedir = os.path.dirname(filename)\n    traces = []\n    # read single traces\n    for line in lines:\n        npts = int(line[80:88])\n        dirname = line[149:213].strip().decode()\n        filename = line[214:246].strip().decode()\n        filename = os.path.join(basedir, dirname, filename)\n        offset = int(line[247:257])\n        dtype = DTYPE[line[144:146]]\n        if isinstance(dtype, tuple):\n            read_fmt = np.dtype(dtype[0])\n            fmt = dtype[1]\n        else:\n            read_fmt = np.dtype(dtype)\n            fmt = read_fmt\n        with open(filename, \"rb\") as fh:\n            fh.seek(offset)\n            data = fh.read(read_fmt.itemsize * npts)\n            data = from_buffer(data, dtype=read_fmt)\n            data = np.require(data, dtype=fmt)\n        header = {}\n        header['station'] = line[0:6].strip().decode()\n        header['channel'] = line[7:15].strip().decode()\n        header['starttime'] = UTCDateTime(float(line[16:33]))\n        header['sampling_rate'] = float(line[89:100])\n        header['calib'] = float(line[101:117])\n        header['calper'] = float(line[118:134])\n        tr = Trace(data, header=header)\n        traces.append(tr)\n    return Stream(traces=traces)\n", "path": "obspy/io/css/core.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nCSS bindings to ObsPy core module.\n\"\"\"\nfrom __future__ import (absolute_import, division, print_function,\n                        unicode_literals)\nfrom future.builtins import *  # NOQA\n\nimport os\n\nimport numpy as np\n\nfrom obspy import Stream, Trace, UTCDateTime\nfrom obspy.core.compatibility import from_buffer\n\n\nDTYPE = {\n    # Big-endian integers\n    b's4': b'>i',\n    b's2': b'>h',\n    # Little-endian integers\n    b'i4': b'<i',\n    b'i2': b'<h',\n    # ASCII integers\n    b'c0': (b'S12', np.int),\n    b'c#': (b'S12', np.int),\n    # Big-endian floating point\n    b't4': b'>f',\n    b't8': b'>d',\n    # Little-endian floating point\n    b'f4': b'<f',\n    b'f8': b'<d',\n    # ASCII floating point\n    b'a0': (b'S15', np.float32),\n    b'a#': (b'S15', np.float32),\n    b'b0': (b'S24', np.float64),\n    b'b#': (b'S24', np.float64),\n}\n\n\ndef _is_css(filename):\n    \"\"\"\n    Checks whether a file is CSS waveform data (header) or not.\n\n    :type filename: str\n    :param filename: CSS file to be checked.\n    :rtype: bool\n    :return: ``True`` if a CSS waveform header file.\n    \"\"\"\n    # Fixed file format.\n    # Tests:\n    #  - the length of each line (283 chars)\n    #  - two epochal time fields\n    #    (for position of dot and if they convert to UTCDateTime)\n    #  - supported data type descriptor\n    try:\n        with open(filename, \"rb\") as fh:\n            lines = fh.readlines()\n            # check for empty file\n            if not lines:\n                return False\n            # check every line\n            for line in lines:\n                assert(len(line.rstrip(b\"\\n\\r\")) == 283)\n                assert(b\".\" in line[26:28])\n                UTCDateTime(float(line[16:33]))\n                assert(b\".\" in line[71:73])\n                UTCDateTime(float(line[61:78]))\n                assert(line[143:145] in DTYPE)\n    except Exception:\n        return False\n    return True\n\n\ndef _is_nnsa_kb_core(filename):\n    \"\"\"\n    Checks whether a file is NNSA KB Core waveform data (header) or not.\n\n    :type filename: str\n    :param filename: NNSA KB Core file to be checked.\n    :rtype: bool\n    :return: ``True`` if a NNSA KB Core waveform header file.\n    \"\"\"\n    # Fixed file format.\n    # Tests:\n    #  - the length of each line (287 chars)\n    #  - two epochal time fields\n    #    (for position of dot and if they convert to UTCDateTime)\n    #  - supported data type descriptor\n    try:\n        with open(filename, \"rb\") as fh:\n            lines = fh.readlines()\n            # check for empty file\n            if not lines:\n                return False\n            # check every line\n            for line in lines:\n                assert(len(line.rstrip(b\"\\n\\r\")) == 287)\n                assert(line[27:28] == b\".\")\n                UTCDateTime(float(line[16:33]))\n                assert(line[73:74] == b\".\")\n                UTCDateTime(float(line[62:79]))\n                assert(line[144:146] in DTYPE)\n    except Exception:\n        return False\n    return True\n\n\ndef _read_css(filename, **kwargs):\n    \"\"\"\n    Reads a CSS waveform file and returns a Stream object.\n\n    .. warning::\n        This function should NOT be called directly, it registers via the\n        ObsPy :func:`~obspy.core.stream.read` function, call this instead.\n\n    :type filename: str\n    :param filename: CSS file to be read.\n    :rtype: :class:`~obspy.core.stream.Stream`\n    :returns: Stream with Traces specified by given file.\n    \"\"\"\n    # read metafile with info on single traces\n    with open(filename, \"rb\") as fh:\n        lines = fh.readlines()\n    basedir = os.path.dirname(filename)\n    traces = []\n    # read single traces\n    for line in lines:\n        npts = int(line[79:87])\n        dirname = line[148:212].strip().decode()\n        filename = line[213:245].strip().decode()\n        filename = os.path.join(basedir, dirname, filename)\n        offset = int(line[246:256])\n        dtype = DTYPE[line[143:145]]\n        if isinstance(dtype, tuple):\n            read_fmt = np.dtype(dtype[0])\n            fmt = dtype[1]\n        else:\n            read_fmt = np.dtype(dtype)\n            fmt = read_fmt\n        with open(filename, \"rb\") as fh:\n            fh.seek(offset)\n            data = fh.read(read_fmt.itemsize * npts)\n            data = from_buffer(data, dtype=read_fmt)\n            data = np.require(data, dtype=fmt)\n        header = {}\n        header['station'] = line[0:6].strip().decode()\n        header['channel'] = line[7:15].strip().decode()\n        header['starttime'] = UTCDateTime(float(line[16:33]))\n        header['sampling_rate'] = float(line[88:99])\n        header['calib'] = float(line[100:116])\n        header['calper'] = float(line[117:133])\n        tr = Trace(data, header=header)\n        traces.append(tr)\n    return Stream(traces=traces)\n\n\ndef _read_nnsa_kb_core(filename, **kwargs):\n    \"\"\"\n    Reads a NNSA KB Core waveform file and returns a Stream object.\n\n    .. warning::\n        This function should NOT be called directly, it registers via the\n        ObsPy :func:`~obspy.core.stream.read` function, call this instead.\n\n    :type filename: str\n    :param filename: NNSA KB Core file to be read.\n    :rtype: :class:`~obspy.core.stream.Stream`\n    :returns: Stream with Traces specified by given file.\n    \"\"\"\n    # read metafile with info on single traces\n    with open(filename, \"rb\") as fh:\n        lines = fh.readlines()\n    basedir = os.path.dirname(filename)\n    traces = []\n    # read single traces\n    for line in lines:\n        npts = int(line[80:88])\n        dirname = line[149:213].strip().decode()\n        filename = line[214:246].strip().decode()\n        filename = os.path.join(basedir, dirname, filename)\n        offset = int(line[247:257])\n        dtype = DTYPE[line[144:146]]\n        if isinstance(dtype, tuple):\n            read_fmt = np.dtype(dtype[0])\n            fmt = dtype[1]\n        else:\n            read_fmt = np.dtype(dtype)\n            fmt = read_fmt\n        with open(filename, \"rb\") as fh:\n            fh.seek(offset)\n            data = fh.read(read_fmt.itemsize * npts)\n            data = from_buffer(data, dtype=read_fmt)\n            data = np.require(data, dtype=fmt)\n        header = {}\n        header['station'] = line[0:6].strip().decode()\n        header['channel'] = line[7:15].strip().decode()\n        header['starttime'] = UTCDateTime(float(line[16:33]))\n        header['sampling_rate'] = float(line[89:100])\n        header['calib'] = float(line[101:117])\n        header['calper'] = float(line[118:134])\n        tr = Trace(data, header=header)\n        traces.append(tr)\n    return Stream(traces=traces)\n", "path": "obspy/io/css/core.py"}]}