Exemple #1
0
    def test_interpolation_dropped(self):
        """Dropped channels are correctly interpolated"""

        dt = self.dt_data / 3.0

        tstart = (self.data.t[0] + 5 * self.dt_data).values
        tend = (self.data.t[-1] - 10 * self.dt_data).values

        chan_to_drop = 1
        data = deepcopy(self.data)
        data.attrs["dropped"] = self.dropped
        data.dropped.loc[dict(chan=chan_to_drop)] = data.sel(chan=chan_to_drop)
        data.loc[dict(chan=chan_to_drop)] = np.full_like(
            data.sel(chan=chan_to_drop), np.nan)

        try:
            _data = convert_in_time_dt(tstart, tend, dt, data)
        except Exception as e:
            raise e

        _dt = (_data.t[1] - _data.t[0]).values
        assert np.all(_data.t <= data.t.max())
        assert np.all(_data.t >= data.t.min())
        assert _dt == approx(dt)

        _dt = (_data.error.t[1] - _data.error.t[0]).values
        assert np.all(_data.error.t <= data.error.t.max())
        assert np.all(_data.error.t >= data.error.t.min())
        assert _dt == approx(dt)

        _dt = (_data.dropped.t[1] - _data.dropped.t[0]).values
        assert np.all(_data.dropped.t <= data.dropped.t.max())
        assert np.all(_data.dropped.t >= data.dropped.t.min())
        assert _dt == approx(dt)
Exemple #2
0
    def test_wrong_end_time(self):
        """Checks end time wrongly set"""
        dt = self.dt_data

        tstart = (self.data.t[0] + 5 * self.dt_data).values
        tend = (self.data.t[-1] + 10 * self.dt_data).values

        try:
            _ = convert_in_time_dt(tstart, tend, dt, self.data)
        except ValueError as e:
            assert e
Exemple #3
0
    def test_identity(self):
        """Checks identity"""
        dt = self.dt_data * 1.0

        tstart = self.data.t[0].values
        tend = self.data.t[-1].values

        try:
            _data = convert_in_time_dt(tstart, tend, dt, self.data)
        except Exception as e:
            raise e

        assert np.all(_data == self.data)
Exemple #4
0
    def test_identity_dt(self):
        """Checks identity for dt = dt_data"""
        dt = self.dt_data * 1.0

        tstart = (self.data.t[0] + 5 * self.dt_data).values
        tend = (self.data.t[-1] - 10 * self.dt_data).values

        try:
            _data = convert_in_time_dt(tstart, tend, dt, self.data)
        except Exception as e:
            raise e

        for t in _data.t:
            delta = np.min(np.abs(t - self.data.t))
            try:
                assert approx(delta) == 0
            except AssertionError as e:
                print("Original and new time axis aren't identical")
                raise e

            delta = np.min(
                np.abs(_data.sel(t=t) - self.data.sel(t=t, method="nearest")))
            try:
                assert approx(delta) == 0
            except AssertionError as e:
                print("Original and new data aren't identical")
                raise e

        for t in _data.error.t:
            delta = np.min(np.abs(t - self.data.error.t))
            try:
                assert approx(delta) == 0
            except AssertionError as e:
                print("Original and new time axis of error aren't identical")
                raise e

            delta = np.min(
                np.abs(
                    _data.error.sel(t=t) -
                    self.data.error.sel(t=t, method="nearest")))
            try:
                assert approx(delta) == 0
            except AssertionError as e:
                print("Original and new error aren't identical")
                raise e
Exemple #5
0
    def test_binning(self):
        """Checks binning works as expected and returned data is withing limits"""
        dt = self.dt_data * 3.0

        tstart = (self.data.t[0] + 5 * self.dt_data).values
        tend = (self.data.t[-1] - 10 * self.dt_data).values

        try:
            _data = convert_in_time_dt(tstart, tend, dt, self.data)
        except Exception as e:
            raise e

        _dt = (_data.t[1] - _data.t[0]).values
        assert np.all(_data.t <= self.data.t.max())
        assert np.all(_data.t >= self.data.t.min())
        assert _dt == approx(dt)

        _dt = (_data.error.t[1] - _data.error.t[0]).values
        assert np.all(_data.error.t <= self.data.error.t.max())
        assert np.all(_data.error.t >= self.data.error.t.min())
        assert _dt == approx(dt)