title: Fitting parabolic shape to data (is it possible to use logic statements with SciPy CurveFit?)
body: <p>I’m trying to fit data with a parabola shape of the form: 
  <strong>Y(x) = a(1 – (x/b)^2)    for |x| &lt; b .......
  Y(x) = 0 otherwise</strong>
  And I’ve added in two extra degrees of freedom so the parabola can be horizontally and vertically shifted.</p>
  
  <pre><code>from scipy.optimize import curve_fit
  
  def parabolic(self, t, *p): 
      a, b, c, d = p        
      if abs(t) &gt; b:
          return 0
      else:
          return a*(1-(((t-c)/b)**2)) + d
  </code></pre>
  
  <p>I’m trying to use curve_fit from scipy.optimize and have created a parabolic function, which I then try to fit with using: </p>
  
  <pre><code>coeff, cov = curve_fit(parabolic, data[:,0], data[:,1], p0) #Return co-effs for fit and      covariance, p0 = user given seed fitting parameters
  </code></pre>
  
  <p>The script returns an error though related to using logic in my parabolic fit definition. When I remove the logic statement and just fit to the entire data (which is a background noise level with a parabolic shape in the centre), the results are awful as the fit tries to include the background noise level.</p>
  
  <p>All suggestions welcomed.</p>
  
  <p>Thanks</p>