title: Python 3D polynomial surface fit, order dependent
body: <p>I am currently working with astronomical data among which I have comet images. I would like to remove the background sky gradient in these images due to the time of capture (twilight). The first program I developed to do so took user selected points from Matplotlib's "ginput" (x,y) pulled the data for each coordinate (z) and then gridded the data in a new array with SciPy's "griddata."</p>
  
  <p>Since the background is assumed to vary only slightly, I would like to fit a 3d low order polynomial to this set of (x,y,z) points. However, the "griddata" does not allow for an input order:</p>
  
  <pre><code>griddata(points,values, (dimension_x,dimension_y), method='nearest/linear/cubic')
  </code></pre>
  
  <p>Any ideas on another function that may be used or a method for developing a leas-squares fit that will allow me to control the order?</p>