Esempio n. 1
0
    def test_read_write_clf(self):
        # write clf to file and read it back
        try:
            with NamedTemporaryFile(suffix='.ini', delete=False,
                                    mode='w') as f:
                f.write(CLF)
            cl = ChannelList.read(f.name)
            assert len(cl) == 4
            a = cl[0]
            assert a.name == 'H1:GDS-CALIB_STRAIN'
            assert a.sample_rate == 16384 * units.Hz
            assert a.frametype == 'H1_HOFT_C00'
            assert a.frequency_range[0] == 4. * units.Hz
            assert a.frequency_range[1] == float('inf') * units.Hz
            assert a.safe is False
            assert a.params == {
                'qhigh': '150',
                'safe': 'unsafe',
                'fidelity': 'clean'
            }
            b = cl[1]
            assert b.name == 'H1:ISI-GND_STS_HAM2_X_DQ'
            assert b.frequency_range[0] == .1 * units.Hz
            assert b.frequency_range[1] == 60. * units.Hz
            c = cl[2]
            assert c.name == 'H1:ISI-GND_STS_HAM2_Y_DQ'
            assert c.sample_rate == 256 * units.Hz
            assert c.safe is False
            d = cl[3]
            assert d.name == 'H1:ISI-GND_STS_HAM2_Z_DQ'
            assert d.safe is True
            assert d.params['fidelity'] == 'glitchy'
        finally:
            if os.path.isfile(f.name):
                os.remove(f.name)
        # write omega config again using ChannelList.write and read it back
        # and check that the two lists match
        try:
            with NamedTemporaryFile(suffix='.ini', delete=False,
                                    mode='w') as f2:

                cl.write(f2)
            cl2 = type(cl).read(f2.name)
            assert cl == cl2
        finally:
            if os.path.isfile(f2.name):
                os.remove(f2.name)
Esempio n. 2
0
    def test_read_write_clf(self):
        # write clf to file and read it back
        try:
            with NamedTemporaryFile(suffix='.ini', delete=False,
                                    mode='w') as f:
                f.write(CLF)
            cl = ChannelList.read(f.name)
            assert len(cl) == 4
            a = cl[0]
            assert a.name == 'H1:GDS-CALIB_STRAIN'
            assert a.sample_rate == 16384 * units.Hz
            assert a.frametype == 'H1_HOFT_C00'
            assert a.frequency_range[0] == 4. * units.Hz
            assert a.frequency_range[1] == float('inf') * units.Hz
            assert a.safe is False
            assert a.params == {'qhigh': '150', 'safe': 'unsafe',
                                'fidelity': 'clean'}
            b = cl[1]
            assert b.name == 'H1:ISI-GND_STS_HAM2_X_DQ'
            assert b.frequency_range[0] == .1 * units.Hz
            assert b.frequency_range[1] == 60. * units.Hz
            c = cl[2]
            assert c.name == 'H1:ISI-GND_STS_HAM2_Y_DQ'
            assert c.sample_rate == 256 * units.Hz
            assert c.safe is False
            d = cl[3]
            assert d.name == 'H1:ISI-GND_STS_HAM2_Z_DQ'
            assert d.safe is True
            assert d.params['fidelity'] == 'glitchy'
        finally:
            if os.path.isfile(f.name):
                os.remove(f.name)
        # write omega config again using ChannelList.write and read it back
        # and check that the two lists match
        try:
            with NamedTemporaryFile(suffix='.ini', delete=False,
                                    mode='w') as f2:

                cl.write(f2)
            cl2 = type(cl).read(f2.name)
            assert cl == cl2
        finally:
            if os.path.isfile(f2.name):
                os.remove(f2.name)
Esempio n. 3
0
    def read(cls, list_file, maxchans=10):
        """
        Read from a file. Returns a channel `dict`

        Parameters
        ----------
        list_file : `str`
            File list to read dict from
        maxchans : `int`, optional
            Maximum number of channels to read.
            Default set to 10 channels.

        Returns
        -------
        Gives a `dict`
        """
        chandict = ChannelDict(list_file)
        channels = ChannelList.read(list_file)
        for channel in channels:
            # add channel to it's sub group
            try:
                chandict[channel.group].append(channel)
            # if key doesn't exist...add it
            except KeyError:
                chandict[channel.group] = []
                chandict[channel.group].append(channel)
        # Now remake the dict based on maxchans
        chandict2 = {}
        for key in chandict.keys():
            nchans = 0
            ngroups = (len(chandict[key]) / maxchans)
            if not ((len(chandict[key]) % maxchans) == 0):
                ngroups += 1
            for group in range(ngroups):
                newkey = '%s %d' % (key, group + 1)
                chandict2[newkey] = []
                totmax = min((group + 1) * maxchans, len(chandict[key]))
                for ii in range(group * maxchans, totmax):
                    chandict2[newkey].append(chandict[key][ii])
        return chandict2