interpolation

Is there easy way in python to extrapolate data points to the future?

北慕城南 提交于 2019-11-28 23:49:41
I have a simple numpy array, for every date there is a data point. Something like this: >>> import numpy as np >>> from datetime import date >>> from datetime import date >>> x = np.array( [(date(2008,3,5), 4800 ), (date(2008,3,15), 4000 ), (date(2008,3, 20), 3500 ), (date(2008,4,5), 3000 ) ] ) Is there easy way to extrapolate data points to the future: date(2008,5,1), date(2008, 5, 20) etc? I understand it can be done with mathematical algorithms. But here I am seeking for some low hanging fruit. Actually I like what numpy.linalg.solve does, but it does not look applicable for the

Best way to interpolate values in SQL

寵の児 提交于 2019-11-28 23:30:23
I have a table with rate at certain date : Rates Id | Date | Rate ----+---------------+------- 1 | 01/01/2011 | 4.5 2 | 01/04/2011 | 3.2 3 | 04/06/2011 | 2.4 4 | 30/06/2011 | 5 I want to get the output rate base on a simple linear interpolation. So if I enter 17/06/2011: Date Rate ---------- ----- 01/01/2011 4.5 01/04/2011 3.2 04/06/2011 2.4 17/06/2011 30/06/2011 5.0 the linear interpolation is (5 + 2,4) / 2 = 3,7 Is there a way to do a simple query (SQL Server 2005), or this kind of stuff need to be done in a programmatic way (C#...) ? Something like this (corrected): SELECT CASE WHEN next

Fast interpolation of regularly sampled 3D data with different intervals in x,y, and z

亡梦爱人 提交于 2019-11-28 23:16:15
I have some volumetric imaging data consisting of values sampled on a regular grid in x,y,z, but with a non-cubic voxel shape (the space between adjacent points in z is greater than in x,y). I would eventually like to be able to interpolate the values on some arbitrary 2D plane that passes through the volume, like this: I'm aware of scipy.ndimage.map_coordinates , but in my case using it is less straightforward because it implicitly assumes that the spacing of the elements in the input array are equal across dimensions. I could first resample my input array according to the smallest voxel

Extending a Swift class with Objective C category

人走茶凉 提交于 2019-11-28 23:04:43
Im in a situation where I need to use Objective C category to extend a Swift class. I've done something as follows: In "SomeClass.swift": class SomeClass: NSObject { } In "SomeClass+Extension.h": #import "Project-Swift.h" @interface SomeClass (Extension) -(void)someMethod(); @end This has worked well. And if I try to use the SomeClass extension in my Objective C code, it is fine. The problem is, if I want to use someMethod() in a another Swift class, I will need to put the SomeClass+Extension.h file into my ObjC-BridgingHeader.h file. But doing this will cause a circuclar dependency, because

Problem with 2D interpolation in SciPy, non-rectangular grid

爷,独闯天下 提交于 2019-11-28 21:59:18
I've been trying to use scipy.interpolate.bisplrep() and scipy.interpolate.interp2d() to find interpolants for data on my (218x135) 2D spherical-polar grid. To these I pass 2D arrays, X and Y, of the Cartesian positions of my grid nodes. I keep getting errors like the following (for linear interp. with interp2d): "Warning: No more knots can be added because the additional knot would coincide with an old one. Probably cause: s too small or too large a weight to an inaccurate data point. (fp>s) kx,ky=1,1 nx,ny=4,5 m=29430 fp=1390609718.902140 s=0.000000" I get a similar result for bivariate

Matplotlib contour from xyz data: griddata invalid index

試著忘記壹切 提交于 2019-11-28 21:40:50
问题 I'm trying to do a contour plot using matplotlib of a file with the following format: x1 y1 z1 x2 y2 z2 etc I can load it with numpy.loadtxt to get the vectors. So far, no trouble. I read this to learn how to plot, and can reproduce it by copy paste, so i'm sure nothin is wrong with my installation: http://matplotlib.org/examples/pylab_examples/griddata_demo.html I understand I have to input x and y as vector and z as an array ,which can be done with griddata. This is also what i find on this

Writing a paint program à la MS Paint - how to interpolate between mouse move events?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 21:37:16
I want to write a paint program in the style of MS Paint. For painting things on screen when the user moves the mouse, I have to wait for mouse move events and draw on the screen whenever I receive one. Apparently, mose move events are not sent very often, so I have to interpolate the mouse movement by drawing a line between the current mouse position and the previous one. In pseudocode, this looks something like this: var positionOld = null def handleMouseMove(positionNew): if mouse.button.down: if positionOld == null: positionOld = positionNew screen.draw.line(positionOld,positionNew)

How to interpolate hue values in HSV colour space?

自作多情 提交于 2019-11-28 19:36:50
I'm trying to interpolate between two colours in HSV colour space to produce a smooth colour gradient. I'm using a linear interpolation, eg: h = (1 - p) * h1 + p * h2 s = (1 - p) * s1 + p * s2 v = (1 - p) * v1 + p * v2 (where p is the percentage, and h1, h2, s1, s2, v1, v2 are the hue, saturation and value components of the two colours) This produces a good result for s and v but not for h. As the hue component is an angle, the calculation needs to work out the shortest distance between h1 and h2 and then do the interpolation in the right direction (either clockwise or anti-clockwise). What

How to interpolate a 2D curve in Python

陌路散爱 提交于 2019-11-28 14:29:57
I have a set of x & y coordinate which is a curve / shape, I want the smooth the curve / sharp and plot a graph. I tried different interpolation to smooth the curve / shape, But it still cannot fit my expectation. Using point to draw a smooth curve / shape. Like the following, using x, y point to get a smooth circle / curve However, I get something like circle.jpg curve.jpg square.jpg I also get trouble on spline interpolation, and rbf interpolation. for cubic_spline_interpolation, I got ValueError: Error on input data for univariate_spline_interpolated, I got ValueError: x must be strictly

Interpolate / Extend quarterly to monthly series

旧街凉风 提交于 2019-11-28 14:13:42
I have a data.frame that contains quarterly observations. I now want to interpolate monthly values (preferred cubic, linear is fine). The intermediate goal should be to create a data.frame with DATE as the index and missing values for all the monthly observations. Googling showed that I should create an empty data.frame for the whole time range and then merge it - but what ever I tried so far gave me errors. Here's my procedure; but since I'm a newb to r , I'm open to any suggestions for changes. > str(ger) 'data.frame': 93 obs. of 2 variables: $ DATE : Date, format: "1991-01-01" "1991-04-01"