diff --git a/.gitignore b/.gitignore index 4520101..eb11712 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ distribute-*.tar.gz .project .pydevproject .settings +.pytest_cache* # Mac OSX .DS_Store diff --git a/gunagala/imager.py b/gunagala/imager.py index 50b9fcd..db4695f 100644 --- a/gunagala/imager.py +++ b/gunagala/imager.py @@ -422,8 +422,8 @@ def extended_source_signal_noise(self, surface_brightness, filter_name, total_ex # Sky counts already included in _is_saturated, need to avoid counting them twice saturated = self._is_saturated( 0 * u.electron / (u.pixel * u.second), sub_exp_time, filter_name) - signal = np.where(saturated, 0 * u.electron / u.pixel, signal) - noise = np.where(saturated, 0 * u.electron / u.pixel, noise) + signal = np.where(saturated, 0, signal) * u.electron / u.pixel + noise = np.where(saturated, 0, noise) * u.electron / u.pixel # Totals per (binned) pixel for all imagers. signal = signal * self.num_imagers * binning @@ -1001,8 +1001,8 @@ def point_source_signal_noise(self, brightness, filter_name, total_exp_time, sub # in a single sub exposure, and check against saturation_level. if saturation_check: saturated = self._is_saturated(rate * self.psf.peak, sub_exp_time, filter_name) - signal = np.where(saturated, 0.0 * u.electron, signal) - noise = np.where(saturated, 0.0 * u.electron , noise) + signal = np.where(saturated, 0.0, signal) * u.electron + noise = np.where(saturated, 0.0, noise) * u.electron return signal, noise @@ -1086,13 +1086,12 @@ def point_source_etc(self, brightness, filter_name, snr_target, sub_exp_time, sa total_exp_time = self.extended_source_etc(rate / self.psf.n_pix, filter_name, snr_target, sub_exp_time, saturation_check=False, binning=self.psf.n_pix / u.pixel) - # Saturation check. For point sources need to know maximum fraction of total electrons that will end up # in a single pixel, this is available as psf.peak. Can use this to calculate maximum electrons per pixel # in a single sub exposure, and check against saturation_level. if saturation_check: saturated = self._is_saturated(rate * self.psf.peak, sub_exp_time, filter_name) - total_exp_time = np.where(saturated, 0.0 * u.second, total_exp_time) + total_exp_time = np.where(saturated, 0.0, total_exp_time) * u.second return total_exp_time diff --git a/gunagala/tests/test_psf.py b/gunagala/tests/test_psf.py index e8085a9..bbfc9f9 100644 --- a/gunagala/tests/test_psf.py +++ b/gunagala/tests/test_psf.py @@ -4,23 +4,15 @@ from gunagala.psf import PSF, MoffatPSF, PixellatedPSF - -@pytest.fixture(scope='module') -def psf_moffat(): - return make_moffat() - - -def make_moffat(): +def make_psf_moffat(): psf = MoffatPSF(FWHM=1 / 30 * u.arcminute, shape=4.7) return psf - @pytest.fixture(scope='module') -def psf_pixellated(): - return make_pixellated() - +def psf_moffat(): + return(make_psf_moffat()) -def make_pixellated(): +def make_psf_pixellated(): psf_data = np.array([[0.0, 0.0, 0.1, 0.0, 0.0], [0.0, 0.3, 0.7, 0.4, 0.0], [0.1, 0.8, 1.0, 0.6, 0.1], @@ -33,6 +25,9 @@ def make_pixellated(): pixel_scale=(2 / 3) * u.arcsecond / u.pixel) return psf +@pytest.fixture(scope='module') +def psf_pixellated(): + return(make_psf_pixellated()) def test_base(): with pytest.raises(TypeError): @@ -41,8 +36,8 @@ def test_base(): @pytest.mark.parametrize("psf, type", [ - (make_moffat(), MoffatPSF), - (make_pixellated(), PixellatedPSF)], + (make_psf_moffat(), MoffatPSF), + (make_psf_pixellated(), PixellatedPSF)], ids=["moffat", "pixellated"] ) def test_instance(psf, type): @@ -64,14 +59,27 @@ def test_FWHM(psf_moffat): psf_moffat.FWHM = 2 * u.arcsecond +def test_pixel_scale(psf_moffat): + psf.pixel_scale = 2.85 * u.arcsecond / u.pixel + assert psf.pixel_scale == 2.85 * u.arcsecond / u.pixel + + def test_pixel_scale_pix(psf_pixellated): psf_pixellated.pixel_scale = (1 / 3) * u.arcsecond / u.pixel assert psf_pixellated.pixel_scale == (1 / 3) * u.arcsecond / u.pixel psf_pixellated.pixel_scale = (2 / 3) * u.arcsecond / u.pixel +def test_n_pix(psf_moffat): + assert psf.n_pix == 4.25754067000986 * u.pixel + + def test_n_pix_pix(psf_pixellated): - assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.0699454) + assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.01351017, 0.1) + + +def test_peak(psf_moffat): + assert psf.peak == 0.7134084656751443 / u.pixel def test_peak_pix(psf_pixellated): @@ -88,8 +96,8 @@ def test_shape(psf_moffat): @pytest.mark.parametrize("psf, t_pixel_scale, pixel_scale", [ - (make_moffat(), 2.85, 2.85), - (make_pixellated(), (1 / 3), (2 / 3))], + (make_psf_moffat(), 2.85, 2.85), + (make_psf_pixellated(), (1 / 3), (2 / 3))], ids=["moffat", "pixellated"] ) def test_pixel_scale(psf, t_pixel_scale, pixel_scale): @@ -99,8 +107,8 @@ def test_pixel_scale(psf, t_pixel_scale, pixel_scale): @pytest.mark.parametrize("psf, expected_n_pix, pixel_scale", [ - (make_moffat(), 4.25754067000986, 2.85), - (make_pixellated(), 21.06994544, (2 / 3))], + (make_psf_moffat(), 4.25754067000986, 2.85), + (make_psf_pixellated(), 21.06994544, (2 / 3))], ids=["moffat", "pixellated"] ) def test_n_pix(psf, expected_n_pix, pixel_scale): @@ -109,8 +117,8 @@ def test_n_pix(psf, expected_n_pix, pixel_scale): @pytest.mark.parametrize("psf, expected_peak, pixel_scale", [ - (make_moffat(), 0.7134084656751443, 2.85), - (make_pixellated(), 0.08073066, (2 / 3))], + (make_psf_moffat(), 0.7134084656751443, 2.85), + (make_psf_pixellated(), 0.08073066, (2 / 3))], ids=["moffat", "pixellated"] ) def test_peak(psf, expected_peak, pixel_scale): @@ -119,10 +127,10 @@ def test_peak(psf, expected_peak, pixel_scale): @pytest.mark.parametrize("psf, image_size", [ - (make_moffat(), (21, 21)), - (make_pixellated(), (21, 21)), - (make_moffat(), (7, 9)), - (make_pixellated(), (7, 9))], + (make_psf_moffat(), (21, 21)), + (make_psf_pixellated(), (21, 21)), + (make_psf_moffat(), (7, 9)), + (make_psf_pixellated(), (7, 9))], ids=["moffat_square", "pixellated_square", "moffat_rectangle", @@ -141,10 +149,10 @@ def test_pixellated_dimension(psf, image_size): @pytest.mark.parametrize("psf, offset", [ - (make_moffat(), (0.0, 0.0)), - (make_pixellated(), (0.0, 0.0)), - (make_moffat(), (0.3, -0.7)), - (make_pixellated(), (0.3, -0.7))], + (make_psf_moffat(), (0.0, 0.0)), + (make_psf_pixellated(), (0.0, 0.0)), + (make_psf_moffat(), (0.3, -0.7)), + (make_psf_pixellated(), (0.3, -0.7))], ids=["moffat_centre_offsets", "pixellated_centre_offsets", "moffat_noncentre_offsets", @@ -158,8 +166,8 @@ def test_offsets(psf, offset): @pytest.mark.parametrize("psf, test_size", [ - (make_moffat(), (1.3, -1.3)), - (make_pixellated(), (-1.3, 1.3))], + (make_psf_moffat(), (1.3, -1.3)), + (make_psf_pixellated(), (-1.3, 1.3))], ids=["moffat", "pixellated"] ) def test_pixellated_invalid_size(psf, test_size): diff --git a/setup.cfg b/setup.cfg index ce2c837..a5a15d2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,7 +48,7 @@ edit_on_github = False github_project = AstroHuntsman/gunagala # install_requires should be formatted as a comma-separated list, e.g.: # install_requires = astropy, scipy, matplotlib -install_requires = astropy, pyYAML, numpy, scipy, matplotlib +install_requires = astropy>=4.0.2, pyYAML, numpy, scipy, matplotlib # version should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386) version = 0.1.dev0