当前位置: 首页>>代码示例>>Python>>正文


Python scipy.interpolate方法代码示例

本文整理汇总了Python中scipy.interpolate方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.interpolate方法的具体用法?Python scipy.interpolate怎么用?Python scipy.interpolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy的用法示例。


在下文中一共展示了scipy.interpolate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_interpolate_index_values

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interpolate_index_values(self):
        s = Series(np.nan, index=np.sort(np.random.rand(30)))
        s[::3] = np.random.randn(10)

        vals = s.index.values.astype(float)

        result = s.interpolate(method='index')

        expected = s.copy()
        bad = isna(expected.values)
        good = ~bad
        expected = Series(np.interp(vals[bad], vals[good],
                                    s.values[good]),
                          index=s.index[bad])

        assert_series_equal(result[bad], expected)

        # 'values' is synonymous with 'index' for the method kwarg
        other_result = s.interpolate(method='values')

        assert_series_equal(other_result, result)
        assert_series_equal(other_result[bad], expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_missing.py

示例2: test_interp_limit

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_limit(self):
        s = Series([1, 3, np.nan, np.nan, np.nan, 11])

        expected = Series([1., 3., 5., 7., np.nan, 11.])
        result = s.interpolate(method='linear', limit=2)
        assert_series_equal(result, expected)

        # GH 9217, make sure limit is an int and greater than 0
        methods = ['linear', 'time', 'index', 'values', 'nearest', 'zero',
                   'slinear', 'quadratic', 'cubic', 'barycentric', 'krogh',
                   'polynomial', 'spline', 'piecewise_polynomial', None,
                   'from_derivatives', 'pchip', 'akima']
        s = pd.Series([1, 2, np.nan, np.nan, 5])
        msg = (r"Limit must be greater than 0|"
               "time-weighted interpolation only works on Series or"
               r" DataFrames with a DatetimeIndex|"
               r"invalid method '(polynomial|spline|None)' to interpolate|"
               "Limit must be an integer")
        for limit in [-1, 0, 1., 2.]:
            for method in methods:
                with pytest.raises(ValueError, match=msg):
                    s.interpolate(limit=limit, method=method) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_missing.py

示例3: test_interp_limit_before_ends

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_limit_before_ends(self):
        # These test are for issue #11115 -- limit ends properly.
        s = Series([np.nan, np.nan, 5, 7, np.nan, np.nan])

        expected = Series([np.nan, np.nan, 5., 7., 7., np.nan])
        result = s.interpolate(method='linear', limit=1,
                               limit_direction='forward')
        assert_series_equal(result, expected)

        expected = Series([np.nan, 5., 5., 7., np.nan, np.nan])
        result = s.interpolate(method='linear', limit=1,
                               limit_direction='backward')
        assert_series_equal(result, expected)

        expected = Series([np.nan, 5., 5., 7., 7., np.nan])
        result = s.interpolate(method='linear', limit=1,
                               limit_direction='both')
        assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_missing.py

示例4: test_interp_timedelta64

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_timedelta64(self):
        # GH 6424
        df = Series([1, np.nan, 3],
                    index=pd.to_timedelta([1, 2, 3]))
        result = df.interpolate(method='time')
        expected = Series([1., 2., 3.],
                          index=pd.to_timedelta([1, 2, 3]))
        assert_series_equal(result, expected)

        # test for non uniform spacing
        df = Series([1, np.nan, 3],
                    index=pd.to_timedelta([1, 2, 4]))
        result = df.interpolate(method='time')
        expected = Series([1., 1.666667, 3.],
                          index=pd.to_timedelta([1, 2, 4]))
        assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_missing.py

示例5: test_interp_basic

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_basic(self):
        df = DataFrame({'A': [1, 2, np.nan, 4],
                        'B': [1, 4, 9, np.nan],
                        'C': [1, 2, 3, 5],
                        'D': list('abcd')})
        expected = DataFrame({'A': [1., 2., 3., 4.],
                              'B': [1., 4., 9., 9.],
                              'C': [1, 2, 3, 5],
                              'D': list('abcd')})
        result = df.interpolate()
        assert_frame_equal(result, expected)

        result = df.set_index('C').interpolate()
        expected = df.set_index('C')
        expected.loc[3, 'A'] = 3
        expected.loc[5, 'B'] = 9
        assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_missing.py

示例6: test_interp_rowwise

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_rowwise(self):
        df = DataFrame({0: [1, 2, np.nan, 4],
                        1: [2, 3, 4, np.nan],
                        2: [np.nan, 4, 5, 6],
                        3: [4, np.nan, 6, 7],
                        4: [1, 2, 3, 4]})
        result = df.interpolate(axis=1)
        expected = df.copy()
        expected.loc[3, 1] = 5
        expected.loc[0, 2] = 3
        expected.loc[1, 3] = 3
        expected[4] = expected[4].astype(np.float64)
        assert_frame_equal(result, expected)

        result = df.interpolate(axis=1, method='values')
        assert_frame_equal(result, expected)

        result = df.interpolate(axis=0)
        expected = df.interpolate()
        assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_missing.py

示例7: test_interp_ignore_all_good

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_ignore_all_good(self):
        # GH
        df = DataFrame({'A': [1, 2, np.nan, 4],
                        'B': [1, 2, 3, 4],
                        'C': [1., 2., np.nan, 4.],
                        'D': [1., 2., 3., 4.]})
        expected = DataFrame({'A': np.array(
            [1, 2, 3, 4], dtype='float64'),
            'B': np.array(
            [1, 2, 3, 4], dtype='int64'),
            'C': np.array(
            [1., 2., 3, 4.], dtype='float64'),
            'D': np.array(
            [1., 2., 3., 4.], dtype='float64')})

        result = df.interpolate(downcast=None)
        assert_frame_equal(result, expected)

        # all good
        result = df[['B', 'D']].interpolate(downcast=None)
        assert_frame_equal(result, df[['B', 'D']]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_missing.py

示例8: make_lookup_table

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def make_lookup_table(self):
        """Construct lookup table radiance <-> BT

        To convert a channel radiance to a brightness temperature,
        applying the (inverse) Planck function is not correct, because the
        Planck function applies to monochromatic radiances only.  Instead,
        to convert from radiance (in W m^-2 sr^-1 Hz^-1) to brightness
        temperature, we use a lookup table.  This lookup table is
        constructed by considering blackbodies at a range of temperatures,
        then calculating the channel radiance.  This table can then be
        used to get a mapping from radiance to brightness temperature.

        This method does not return anything, but fill self.lookup_table.
        """
        self.lookup_table = numpy.zeros(
            shape=(2, self.T_lookup_table.size), dtype=numpy.float64)
        self.lookup_table[0, :] = self.T_lookup_table
        self.lookup_table[1, :] = self.blackbody_radiance(self.T_lookup_table)
        self.L_to_T = scipy.interpolate.interp1d(self.lookup_table[1, :],
                                                 self.lookup_table[0, :],
                                                 kind='linear',
                                                 bounds_error=False,
                                                 fill_value=(0, 2000)) 
开发者ID:atmtools,项目名称:typhon,代码行数:25,代码来源:em.py

示例9: __call__

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def __call__(self, pkg):
        pkg = format_package(pkg)
        wav = pkg['chunk']
        wav = wav.data.numpy()
        factor = random.choice(self.factors)
        x_lr = decimate(wav, factor).copy()
        x_lr = torch.FloatTensor(x_lr)
        x_ = F.interpolate(x_lr.view(1, 1, -1),
                           scale_factor=factor,
                           align_corners=True,
                           mode='linear').view(-1)
        if self.report:
            if 'report' not in pkg:
                pkg['report'] = {}
            pkg['report']['resample_factor'] = factor
        pkg['chunk'] = x_
        return pkg 
开发者ID:santi-pdp,项目名称:pase,代码行数:19,代码来源:transforms.py

示例10: test_interpolate

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interpolate(self):
        ts = Series(np.arange(len(self.ts), dtype=float), self.ts.index)

        ts_copy = ts.copy()
        ts_copy[5:10] = np.NaN

        linear_interp = ts_copy.interpolate(method='linear')
        tm.assert_series_equal(linear_interp, ts)

        ord_ts = Series([d.toordinal() for d in self.ts.index],
                        index=self.ts.index).astype(float)

        ord_ts_copy = ord_ts.copy()
        ord_ts_copy[5:10] = np.NaN

        time_interp = ord_ts_copy.interpolate(method='time')
        tm.assert_series_equal(time_interp, ord_ts)

        # try time interpolation on a non-TimeSeries
        # Only raises ValueError if there are NaNs.
        non_ts = self.series.copy()
        non_ts[0] = np.NaN
        pytest.raises(ValueError, non_ts.interpolate, method='time') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:test_missing.py

示例11: test_interp_limit

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interp_limit(self):
        s = Series([1, 3, np.nan, np.nan, np.nan, 11])

        expected = Series([1., 3., 5., 7., np.nan, 11.])
        result = s.interpolate(method='linear', limit=2)
        assert_series_equal(result, expected)

        # GH 9217, make sure limit is an int and greater than 0
        methods = ['linear', 'time', 'index', 'values', 'nearest', 'zero',
                   'slinear', 'quadratic', 'cubic', 'barycentric', 'krogh',
                   'polynomial', 'spline', 'piecewise_polynomial', None,
                   'from_derivatives', 'pchip', 'akima']
        s = pd.Series([1, 2, np.nan, np.nan, 5])
        for limit in [-1, 0, 1., 2.]:
            for method in methods:
                with pytest.raises(ValueError):
                    s.interpolate(limit=limit, method=method) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_missing.py

示例12: _skip_if_no_pchip

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def _skip_if_no_pchip():
    try:
        from scipy.interpolate import pchip_interpolate  # noqa
    except ImportError:
        import pytest
        pytest.skip('scipy.interpolate.pchip missing') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_missing.py

示例13: _skip_if_no_akima

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def _skip_if_no_akima():
    try:
        from scipy.interpolate import Akima1DInterpolator  # noqa
    except ImportError:
        import pytest
        pytest.skip('scipy.interpolate.Akima1DInterpolator missing') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_missing.py

示例14: test_interpolate

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interpolate(self, datetime_series, string_series):
        ts = Series(np.arange(len(datetime_series), dtype=float),
                    datetime_series.index)

        ts_copy = ts.copy()
        ts_copy[5:10] = np.NaN

        linear_interp = ts_copy.interpolate(method='linear')
        tm.assert_series_equal(linear_interp, ts)

        ord_ts = Series([d.toordinal() for d in datetime_series.index],
                        index=datetime_series.index).astype(float)

        ord_ts_copy = ord_ts.copy()
        ord_ts_copy[5:10] = np.NaN

        time_interp = ord_ts_copy.interpolate(method='time')
        tm.assert_series_equal(time_interp, ord_ts)

        # try time interpolation on a non-TimeSeries
        # Only raises ValueError if there are NaNs.
        non_ts = string_series.copy()
        non_ts[0] = np.NaN
        msg = ("time-weighted interpolation only works on Series or DataFrames"
               " with a DatetimeIndex")
        with pytest.raises(ValueError, match=msg):
            non_ts.interpolate(method='time') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:29,代码来源:test_missing.py

示例15: test_interpolate_pchip

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import interpolate [as 别名]
def test_interpolate_pchip(self):
        _skip_if_no_pchip()

        ser = Series(np.sort(np.random.uniform(size=100)))

        # interpolate at new_index
        new_index = ser.index.union(Index([49.25, 49.5, 49.75, 50.25, 50.5,
                                           50.75]))
        interp_s = ser.reindex(new_index).interpolate(method='pchip')
        # does not blow up, GH5977
        interp_s[49:51] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_missing.py


注:本文中的scipy.interpolate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。