0

I am creating a program that creates a galaxy spectra for ages not specified in a given catalogue using interpolation from the nearest ages.

I am trying to find a solution to make sure I am not extrapolating by adding another if statement to my runinterpolation function below.

Limits is a list of ages in the form [[age1,age2],[age3,age4],...] Data is a list of dataframes with the corresponding data to be interpolated for each k in limits.

For ages above/below the given ages in the original data, the previous function returns the lowest/highest age for the limit, i.e. [[age1,age1]]

I cannot seem to write an if statement that says if age1 = age2, create a column with age1's non interpolated data.

The functions for interpolation are below:

# linear interpolation
def interpolation(limits,data,age):
    interp = sc.interp1d(limits,data)
    interped = interp(age)
    return interped     

#runs the interpolation for each age, values returned as columns 
#of new dataframe   
def runinterpolation(limits,data,ages):
    int_data = pd.DataFrame(index=Lambda)
    for x,y,z in zip(limits,data,ages):
        W = interpolation(x,y,z)
        int_data[z] = W
    return int_data

Any help is much appreciated.

Cmf55
  • 61
  • 1
  • 8
  • Have you looked at pandas built in [series interpolation](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.interpolate.html#pandas-series-interpolate)? Look at this [answer](http://stackoverflow.com/a/10465162/2087463) for some reference. – tmthydvnprt Jul 25 '16 at 12:17
  • Can you provide some [example data](http://stackoverflow.com/q/20109391/2087463)...? – tmthydvnprt Jul 25 '16 at 12:21

0 Answers0