This file is indexed.

/usr/lib/python2.7/dist-packages/stfio/stfio.py is in python-stfio 0.15.4-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.10
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.




"""
The stfio module provides functions to read/write data from/to
common electrophysiology file formats
"""


from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
    def swig_import_helper():
        import importlib
        pkg = __name__.rpartition('.')[0]
        mname = '.'.join((pkg, '_stfio')).lstrip('.')
        try:
            return importlib.import_module(mname)
        except ImportError:
            return importlib.import_module('_stfio')
    _stfio = swig_import_helper()
    del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_stfio', [dirname(__file__)])
        except ImportError:
            import _stfio
            return _stfio
        if fp is not None:
            try:
                _mod = imp.load_module('_stfio', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _stfio = swig_import_helper()
    del swig_import_helper
else:
    import _stfio
del _swig_python_version_info
try:
    _swig_property = property
except NameError:
    pass  # Python < 2.2 doesn't have 'property'.

try:
    import builtins as __builtin__
except ImportError:
    import __builtin__

def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
    if (name == "thisown"):
        return self.this.own(value)
    if (name == "this"):
        if type(value).__name__ == 'SwigPyObject':
            self.__dict__[name] = value
            return
    method = class_type.__swig_setmethods__.get(name, None)
    if method:
        return method(self, value)
    if (not static):
        if _newclass:
            object.__setattr__(self, name, value)
        else:
            self.__dict__[name] = value
    else:
        raise AttributeError("You cannot add attributes to %s" % self)


def _swig_setattr(self, class_type, name, value):
    return _swig_setattr_nondynamic(self, class_type, name, value, 0)


def _swig_getattr(self, class_type, name):
    if (name == "thisown"):
        return self.this.own()
    method = class_type.__swig_getmethods__.get(name, None)
    if method:
        return method(self)
    raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))


def _swig_repr(self):
    try:
        strthis = "proxy of " + self.this.__repr__()
    except __builtin__.Exception:
        strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
    _object = object
    _newclass = 1
except __builtin__.Exception:
    class _object:
        pass
    _newclass = 0

class Recording(_object):
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, Recording, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, Recording, name)
    __repr__ = _swig_repr

    def __init__(self, *args):
        this = _stfio.new_Recording(*args)
        try:
            self.this.append(this)
        except __builtin__.Exception:
            self.this = this
    __swig_destroy__ = _stfio.delete_Recording
    __del__ = lambda self: None
    __swig_setmethods__["dt"] = _stfio.Recording_dt_set
    __swig_getmethods__["dt"] = _stfio.Recording_dt_get
    if _newclass:
        dt = _swig_property(_stfio.Recording_dt_get, _stfio.Recording_dt_set)
    __swig_setmethods__["file_description"] = _stfio.Recording_file_description_set
    __swig_getmethods__["file_description"] = _stfio.Recording_file_description_get
    if _newclass:
        file_description = _swig_property(_stfio.Recording_file_description_get, _stfio.Recording_file_description_set)
    __swig_setmethods__["time"] = _stfio.Recording_time_set
    __swig_getmethods__["time"] = _stfio.Recording_time_get
    if _newclass:
        time = _swig_property(_stfio.Recording_time_get, _stfio.Recording_time_set)
    __swig_setmethods__["date"] = _stfio.Recording_date_set
    __swig_getmethods__["date"] = _stfio.Recording_date_get
    if _newclass:
        date = _swig_property(_stfio.Recording_date_get, _stfio.Recording_date_set)
    __swig_setmethods__["comment"] = _stfio.Recording_comment_set
    __swig_getmethods__["comment"] = _stfio.Recording_comment_get
    if _newclass:
        comment = _swig_property(_stfio.Recording_comment_get, _stfio.Recording_comment_set)
    __swig_setmethods__["xunits"] = _stfio.Recording_xunits_set
    __swig_getmethods__["xunits"] = _stfio.Recording_xunits_get
    if _newclass:
        xunits = _swig_property(_stfio.Recording_xunits_get, _stfio.Recording_xunits_set)
    __swig_setmethods__["datetime"] = _stfio.Recording_datetime_set
    __swig_getmethods__["datetime"] = _stfio.Recording_datetime_get
    if _newclass:
        datetime = _swig_property(_stfio.Recording_datetime_get, _stfio.Recording_datetime_set)

    def __getitem__(self, at):
        return _stfio.Recording___getitem__(self, at)

    def __len__(self):
        return _stfio.Recording___len__(self)

    def write(self, *args):
        """
        Writes a Recording to a file.

            Arguments:
            fname  -- file name
        #ifndef TEST_MINIMAL
            ftype  -- file type (string). At present, only "hdf5" is supported.
        #else
            ftype  -- file type (string). At present, "hdf5", "gdf", "cfs" and "ibw" are supported.
        #endif // TEST_MINIMAL
            verbose-- Show info while writing

            Returns:
            True upon successful completion.
        Writes a Recording to a file.

            Arguments:
            fname  -- file name
        #ifndef TEST_MINIMAL
            ftype  -- file type (string). At present, only "hdf5" is supported.
        #else
            ftype  -- file type (string). At present, "hdf5", "gdf", "cfs" and "ibw" are supported.
        #endif // TEST_MINIMAL
            verbose-- Show info while writing

            Returns:
            True upon successful completion.
        Writes a Recording to a file.

            Arguments:
            fname  -- file name
        #ifndef TEST_MINIMAL
            ftype  -- file type (string). At present, only "hdf5" is supported.
        #else
            ftype  -- file type (string). At present, "hdf5", "gdf", "cfs" and "ibw" are supported.
        #endif // TEST_MINIMAL
            verbose-- Show info while writing

            Returns:
            True upon successful completion.
        """
        return _stfio.Recording_write(self, *args)


    def aspandas(self):
        import sys
        import numpy as np
        has_pandas = True
        try:
            import pandas as pd
        except ImportError:
            has_pandas = False
        if has_pandas:
            chnames = [ch.name for ch in self]
            channels = np.array([np.concatenate([sec for sec in ch]) for ch in self])
            date_range = pd.date_range(start=self.datetime, periods=channels.shape[1],
                                       freq='%dU' % np.round(self.dt*1e3))
            return pd.DataFrame(channels.transpose(), index=date_range, columns=chnames)
        else:
            sys.stderr.write("Pandas is not available on this system\n")
            return None

Recording_swigregister = _stfio.Recording_swigregister
Recording_swigregister(Recording)

class Channel(_object):
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, Channel, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, Channel, name)
    __repr__ = _swig_repr

    def __init__(self, *args):
        this = _stfio.new_Channel(*args)
        try:
            self.this.append(this)
        except __builtin__.Exception:
            self.this = this
    __swig_destroy__ = _stfio.delete_Channel
    __del__ = lambda self: None
    __swig_setmethods__["name"] = _stfio.Channel_name_set
    __swig_getmethods__["name"] = _stfio.Channel_name_get
    if _newclass:
        name = _swig_property(_stfio.Channel_name_get, _stfio.Channel_name_set)
    __swig_setmethods__["yunits"] = _stfio.Channel_yunits_set
    __swig_getmethods__["yunits"] = _stfio.Channel_yunits_get
    if _newclass:
        yunits = _swig_property(_stfio.Channel_yunits_get, _stfio.Channel_yunits_set)

    def __getitem__(self, at):
        return _stfio.Channel___getitem__(self, at)

    def __len__(self):
        return _stfio.Channel___len__(self)
Channel_swigregister = _stfio.Channel_swigregister
Channel_swigregister(Channel)

class Section(_object):
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, Section, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, Section, name)
    __repr__ = _swig_repr

    def __init__(self, nparray):
        this = _stfio.new_Section(nparray)
        try:
            self.this.append(this)
        except __builtin__.Exception:
            self.this = this
    __swig_destroy__ = _stfio.delete_Section
    __del__ = lambda self: None

    def __getitem__(self, at):
        return _stfio.Section___getitem__(self, at)

    def __len__(self):
        return _stfio.Section___len__(self)

    def asarray(self):
        """Returns the section as a numpy array."""
        return _stfio.Section_asarray(self)

Section_swigregister = _stfio.Section_swigregister
Section_swigregister(Section)


def _read(filename, ftype, verbose, Data):
    """
    _read(filename, ftype, verbose, Data) -> bool

    Reads a file and returns a recording object.

    Arguments:
    filename -- file name
    #ifndef TEST_MINIMAL
    ftype    -- File type
    #else
    ftype    -- File type (obsolete)
    #endif // TEST_MINIMAL
    verbose  -- Show info while reading

    Returns:
    A recording object.
    """
    return _stfio._read(filename, ftype, verbose, Data)

def detect_events(*args, **kwargs):
    """
    detect_events(data, templ, dt, mode, norm=True, lowpass=0.5, highpass=0.0001) -> PyObject *



    Arguments:

    """
    return _stfio.detect_events(*args, **kwargs)

def peak_detection(invec, threshold, min_distance):
    """
    peak_detection(invec, threshold, min_distance) -> PyObject *



    Arguments:

    """
    return _stfio.peak_detection(invec, threshold, min_distance)

def risetime(invec, base, amp, frac=0.2):
    """
    risetime(invec, base, amp, frac=0.2) -> double



    Arguments:

    """
    return _stfio.risetime(invec, base, amp, frac)

import os

class StfIOException(Exception):
    """ raises Exceptions for the Stfio module """
    def __init__(self, error_msg):
        self.msg = error_msg 

    def __str__(self):
        return repr(self.msg)

filetype = {
    '.dat':'cfs',
    '.h5':'hdf5',
    '.abf':'abf',
    '.atf':'atf',
    '.axgd':'axg',
    '.axgx':'axg'}

def read(fname, ftype=None, verbose=False):
    """Reads a file and returns a Recording object.

    Arguments:
    fname  -- file name
#ifndef TEST_MINIMAL
    ftype  -- file type (string); can be one of:
              "cfs"  - CED filing system
              "hdf5" - HDF5
              "abf"  - Axon binary file
              "atf"  - Axon text file
              "axg"  - Axograph X binary file
              "heka" - HEKA binary file
              if ftype is None (default), it will be guessed from the
              extension.
#else
    ftype  -- file type (string) is obsolete.
              in the past it has been used to determine the file type.
              Now an automated file type identification is used, and this
              parameter become obsolete; eventually it will be removed.
#endif // TEST_MINIMAL
    verbose-- Show info while reading file

    Returns:
    A Recording object.
    """
    if not os.path.exists(fname):
        raise StfIOException('File %s does not exist' % fname)


    if ftype is None:
        ext = os.path.splitext(fname)[1]
        try:
            ftype = filetype[ext]
        except KeyError:
            raise StfIOException('Couldn\'t guess file type from extension (%s)' % ext)


    rec = Recording()
    if not _read(fname, ftype, verbose, rec):
        raise StfIOException('Error reading file')

    if verbose:
        print("")

    return rec


def read_tdms(fn):
    import numpy as np
    import sys
    try:
        from nptdms import TdmsFile
    except ImportError:
        sys.stderr.write("nptdms module unavailable")
        return None

    tdms_file = TdmsFile(fn)

    try:
        times = np.array(
            [[channel.data
              for channel in tdms_file.group_channels(group)
              if channel.data is not None]
             for group in tdms_file.groups()
             if group.lower() == "time"][0][0])
        dt = np.mean(np.diff(times))
    except IndexError:
        if not "Sampling Rate" in tdms_file.object().properties.keys():
            dt = 1.0
        else:
            sr = tdms_file.object().properties['Sampling Rate']
            if sr > 0:
                dt = 1e3/sr
            else:
                dt = 1.0
    chlist = [Channel(
        [Section(channel.data)
         for channel in tdms_file.group_channels(group)
         if channel.data is not None])
        for group in tdms_file.groups()
        if group.lower() != "time"]
    chlist[0].xunits = "mV"
    chlist[1].yunits = "pA"
    rec = Recording(chlist)
    rec.dt = dt
    rec.xunits = "ms"
    sys.stderr.write(fn + "\n")
    return rec

# This file is compatible with both classic and new-style classes.