interpolation

pandas multiindex dataframe, ND interpolation for missing values

核能气质少年 提交于 2019-12-19 11:54:58
问题 Is it possible in pandas to interpolate for missing values in multiindex dataframe. This example below does not work as expected: arr1=np.array(np.arange(1.,10.,1.)) arr2=np.array(np.arange(2.,20.,2.)) df1=pd.DataFrame(zip(arr1,arr2,arr1+arr2,arr1*arr2),columns=['x','y','xplusy','xtimesy']) df1.set_index(['x','y'],inplace=True) df2=df1.reindex(index=zip(*df1.index.levels)+[(2,2),(3,2),(5,5)]) df2.sortlevel([0,1],inplace=True) df2.interpolate(method='linear',inplace=True) displays not what I

spatial interpolation error using idw

喜夏-厌秋 提交于 2019-12-19 10:18:37
问题 I am trying to spatially interpolate a dataset of seawater pH by lat & long: sample<-read.csv(file="Station locations 2016.csv", header=TRUE, sep=",", strip.white=T) head(sample) Station lat long pH 1 B17 -23.49174 152.0718 8.222411 2 B23 -23.49179 152.0718 8.199310 3 B26 -23.49182 152.0717 8.140428 4 B28 -23.49183 152.0717 8.100752 5 B30 -23.49185 152.0717 8.068141 6 B31 -23.49187 152.0717 8.048852 I have created a grid based on the existing ranges in lat/long data and want to interpolate

Python MemoryError in Scipy Radial Basis Function (scipy.interpolate.rbf)

怎甘沉沦 提交于 2019-12-18 16:54:09
问题 I'm trying to interpolate a not-so-large (~10.000 samples) pointcloud representing a 2D surface, using Scipy Radial Basis Function (Rbf). I got some good results, but with my last datasets I'm consistently getting MemoryError , even though the error appears almost instantly during execution (the RAM is obviously not being eaten up). I decided to hack a copy of the rbf.py file from Scipy, starting by filling it up with some print statements, which have been very useful. By decomposing the

UIImageView scaling/interpolation

左心房为你撑大大i 提交于 2019-12-18 14:59:12
问题 I have a small IPhone app that I am working on and I am displaying an image with a UIImageView. I am scaling it up using the Aspect Fit mode. I would like to have the image scale up with no interpolation/smoothing (I want it to look pixellated). Is there any way I can change this behavior? A little more general question would be can I implement my own scaling algorithm, or are there other built in ones that I can select? 回答1: You would need to set the magnificationFilter property on the view

Better way than if else if else… for linear interpolation

廉价感情. 提交于 2019-12-18 14:52:37
问题 question is easy. Lets say you have function double interpolate (double x); and you have a table that has map of known x-> y for example 5 15 7 18 10 22 note: real tables are bigger ofc, this is just example. so for 8 you would return 18+((8-7)/(10-7))*(22-18)=19.3333333 One cool way I found is http://www.bnikolic.co.uk/blog/cpp-map-interp.html (long story short it uses std::map, key= x, value = y for x->y data pairs). If somebody asks what is the if else if else way in title it is basically:

Better way than if else if else… for linear interpolation

烈酒焚心 提交于 2019-12-18 14:51:12
问题 question is easy. Lets say you have function double interpolate (double x); and you have a table that has map of known x-> y for example 5 15 7 18 10 22 note: real tables are bigger ofc, this is just example. so for 8 you would return 18+((8-7)/(10-7))*(22-18)=19.3333333 One cool way I found is http://www.bnikolic.co.uk/blog/cpp-map-interp.html (long story short it uses std::map, key= x, value = y for x->y data pairs). If somebody asks what is the if else if else way in title it is basically:

interpolate missing values 2d python

China☆狼群 提交于 2019-12-18 13:14:15
问题 I have a 2d array(or matrix if you prefer) with some missing values represented as NaN . The missing values are typically in a strip along one axis, eg: 1 2 3 NaN 5 2 3 4 Nan 6 3 4 Nan Nan 7 4 5 Nan Nan 8 5 6 7 8 9 where I would like to replace the NaN 's by somewhat sensible numbers. I looked into delaunay triangulation, but found very little documentation. I tried using astropy's convolve as it supports use of 2d arrays, and is quite straightforward. The problem with this is that

What do the different values of the kind argument mean in scipy.interpolate.interp1d?

别来无恙 提交于 2019-12-18 13:13:37
问题 The SciPy documentation explains that interp1d 's kind argument can take the values ‘linear’ , ‘nearest’ , ‘zero’ , ‘slinear’ , ‘quadratic’ , ‘cubic’ . The last three are spline orders and 'linear' is self-explanatory. What do 'nearest' and 'zero' do? 回答1: nearest "snaps" to the nearest data point. zero is a zero order spline. It's value at any point is the last raw value seen. linear performs linear interpolation and slinear uses a first order spline. They use different code and can produce

DataFrame.interpolate() extrapolates over trailing missing data

非 Y 不嫁゛ 提交于 2019-12-18 12:27:46
问题 Consider the following example in which we setup a sample dataset, create a MultiIndex, unstack the dataframe, and then execute a linear interpolation where we fill row-by-row: import pandas as pd # version 0.14.1 import numpy as np # version 1.8.1 df = pd.DataFrame({'location': ['a', 'b'] * 5, 'trees': ['oaks', 'maples'] * 5, 'year': range(2000, 2005) * 2, 'value': [np.NaN, 1, np.NaN, 3, 2, np.NaN, 5, np.NaN, np.NaN, np.NaN]}) df.set_index(['trees', 'location', 'year'], inplace=True) df = df

How to generate equispaced interpolating values

纵饮孤独 提交于 2019-12-18 11:10:10
问题 I have a list of (x,y) values that are not uniformly spaced. Here is the archive used in this question. I am able to interpolate between the values but what I get are not equispaced interpolating points. Here's what I do: x_data = [0.613,0.615,0.615,...] y_data = [5.919,5.349,5.413,...] # Interpolate values for x and y. t = np.linspace(0, 1, len(x_data)) t2 = np.linspace(0, 1, 100) # One-dimensional linear interpolation. x2 = np.interp(t2, t, x_data) y2 = np.interp(t2, t, y_data) # Plot x,y