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.