I have data that is a list of positions from 0-20 with corresponding intensities, in increments of 0.1. They are discrete values and not a function. The values are (close to) symmetrical and there should be a center point around 10 where if you fold the plot on itself you would have overlapping points. I've done this so far by summing the difference between each pair of values equidistant from center. The data is currently in a dataframe.
This seems different than the question "how to minimize a function with discrete variable values in scipy" because there the objective was actually to find the minimum of a function but I don't have a function.
The issue is there are many options that might actually be the best center position (realistically, from ~9-11 in increments of 0.1) and I don't want to have to manually change the center value, but it's not a function so fmin from scipy.optimize returns values for the center which are not in 0.1 increments. My code so far that does it is:
#Position data has values from 0-20 in 0.1 increments
stepsize = 0.1
max_pos = 15 #max that center could be at
HAB_slice['Position Relative to Center'] = HAB_slice['Position'] - center_guess #Defines position relative to center
HAB_slice['Radial Position'] = np.abs(HAB_slice['Position Relative to Center'].values) #absolute value based on previous
possible_pos = np.linspace(0, max_pos, max_pos / stepsize+1)
for i in range(0, len(possible_pos)): # Loop sums absolute values of difference between same absolute difference from zero. Smaller value is generally best value
temp = HAB_slice[HAB_slice['Radial Position']==possible_pos[i]]
if len(temp) == 2:
center_sum += np.abs(temp['I'].diff().values[1])
And then manually changing the value for center_guess until center_sum is the smallest that it gets, which is really tedious. Note 'I' values are basically the y values.
Can someone show me a method of automating this that does not require the minimizing thing to be a function so that it iterates through the actual values of 'Position' to find the one that yields the smallest center_sum?