from __future__ import division

import numpy as np

from astropy.tests.helper import pytest
from photutils.psf import  GaussianPSF

try:
    from scipy import optimize
    HAS_SCIPY = True
except ImportError:
    HAS_SCIPY = False


widths = [0.001, 0.01, 0.1, 1]

@pytest.mark.skipif('not HAS_SCIPY')
@pytest.mark.parametrize(('width'), widths)
def test_subpixel_gauss_psf(width):
    """
    Test subpixel accuracy of Gaussian PSF by checking the sum o pixels.
    """
    gauss_psf = GaussianPSF(width)
    y, x = np.mgrid[-10:11, -10:11]
    assert np.abs(gauss_psf(x, y).sum() - 1) < 1E-12
    
@pytest.mark.skipif('not HAS_SCIPY')    
def test_gaussian_PSF_integral():
    """
    Test if Gaussian PSF integrates to unity on larger scales.
    """
    psf = GaussianPSF(10)
    y, x = np.mgrid[-100:101, -100:101]
    assert np.abs(psf(y, x).sum() - 1) < 1E-12 
    
    

from __future__ import division
import numpy as np
from astropy.tests.helper import pytest
from ..psf import GaussianPSF
try:
    from scipy import optimize
    HAS_SCIPY = True
except ImportError:
    HAS_SCIPY = False


widths = [0.001, 0.01, 0.1, 1]


@pytest.mark.skipif('not HAS_SCIPY')
@pytest.mark.parametrize(('width'), widths)
def test_subpixel_gauss_psf(width):
    """
    Test subpixel accuracy of Gaussian PSF by checking the sum o pixels.
    """
    gauss_psf = GaussianPSF(width)
    y, x = np.mgrid[-10:11, -10:11]
    assert np.abs(gauss_psf(x, y).sum() - 1) < 1E-12


@pytest.mark.skipif('not HAS_SCIPY')
def test_gaussian_PSF_integral():
    """
    Test if Gaussian PSF integrates to unity on larger scales.
    """
    psf = GaussianPSF(10)
    y, x = np.mgrid[-100:101, -100:101]
    assert np.abs(psf(y, x).sum() - 1) < 1E-12

Use relative imports for consistency; pep8
Use relative imports for consistency; pep8

  from __future__ import division
- 
  import numpy as np
- 
  from astropy.tests.helper import pytest
- from photutils.psf import  GaussianPSF
+ from ..psf import GaussianPSF
- 
  try:
      from scipy import optimize
      HAS_SCIPY = True
  except ImportError:
      HAS_SCIPY = False
  
  
  widths = [0.001, 0.01, 0.1, 1]
+ 
  
  @pytest.mark.skipif('not HAS_SCIPY')
  @pytest.mark.parametrize(('width'), widths)
  def test_subpixel_gauss_psf(width):
      """
      Test subpixel accuracy of Gaussian PSF by checking the sum o pixels.
      """
      gauss_psf = GaussianPSF(width)
      y, x = np.mgrid[-10:11, -10:11]
      assert np.abs(gauss_psf(x, y).sum() - 1) < 1E-12
-     
+ 
+ 
- @pytest.mark.skipif('not HAS_SCIPY')    
+ @pytest.mark.skipif('not HAS_SCIPY')
  def test_gaussian_PSF_integral():
      """
      Test if Gaussian PSF integrates to unity on larger scales.
      """
      psf = GaussianPSF(10)
      y, x = np.mgrid[-100:101, -100:101]
-     assert np.abs(psf(y, x).sum() - 1) < 1E-12 
+     assert np.abs(psf(y, x).sum() - 1) < 1E-12
-     
-     
  
Use relative imports for consistency; pep8
## Code Before:
from __future__ import division

import numpy as np

from astropy.tests.helper import pytest
from photutils.psf import  GaussianPSF

try:
    from scipy import optimize
    HAS_SCIPY = True
except ImportError:
    HAS_SCIPY = False


widths = [0.001, 0.01, 0.1, 1]

@pytest.mark.skipif('not HAS_SCIPY')
@pytest.mark.parametrize(('width'), widths)
def test_subpixel_gauss_psf(width):
    """
    Test subpixel accuracy of Gaussian PSF by checking the sum o pixels.
    """
    gauss_psf = GaussianPSF(width)
    y, x = np.mgrid[-10:11, -10:11]
    assert np.abs(gauss_psf(x, y).sum() - 1) < 1E-12
    
@pytest.mark.skipif('not HAS_SCIPY')    
def test_gaussian_PSF_integral():
    """
    Test if Gaussian PSF integrates to unity on larger scales.
    """
    psf = GaussianPSF(10)
    y, x = np.mgrid[-100:101, -100:101]
    assert np.abs(psf(y, x).sum() - 1) < 1E-12 
    
    

## Instruction:
Use relative imports for consistency; pep8
## Code After:
from __future__ import division
import numpy as np
from astropy.tests.helper import pytest
from ..psf import GaussianPSF
try:
    from scipy import optimize
    HAS_SCIPY = True
except ImportError:
    HAS_SCIPY = False


widths = [0.001, 0.01, 0.1, 1]


@pytest.mark.skipif('not HAS_SCIPY')
@pytest.mark.parametrize(('width'), widths)
def test_subpixel_gauss_psf(width):
    """
    Test subpixel accuracy of Gaussian PSF by checking the sum o pixels.
    """
    gauss_psf = GaussianPSF(width)
    y, x = np.mgrid[-10:11, -10:11]
    assert np.abs(gauss_psf(x, y).sum() - 1) < 1E-12


@pytest.mark.skipif('not HAS_SCIPY')
def test_gaussian_PSF_integral():
    """
    Test if Gaussian PSF integrates to unity on larger scales.
    """
    psf = GaussianPSF(10)
    y, x = np.mgrid[-100:101, -100:101]
    assert np.abs(psf(y, x).sum() - 1) < 1E-12
