code: def nanfill(a, f_a, *args, **kwargs):
      
      a = checkma(a)
      ndv = a.fill_value  
      #Note: The following fails for arrays that are not float (np.nan is float)
      b = f_a(a.filled(np.nan), *args, **kwargs)
      #the fix_invalid fill_value parameter doesn't seem to work
      out = np.ma.fix_invalid(b, copy=False)
      out.set_fill_value(ndv)
      return out
docs: Fill masked areas with np.nan
  
      Wrapper for functions that can't handle ma (e.g. scipy.ndimage)
      
      This will force filters to ignore nan, but causes adjacent pixels to be set to nan as well: http://projects.scipy.org/scipy/ticket/1155