From 6fdc76624d242e59a98c459f820da69c77430e74 Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Mon, 31 Aug 2020 21:53:15 +1000 Subject: [PATCH 1/9] fixture fix --- gunagala/tests/test_psf.py | 49 ++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/gunagala/tests/test_psf.py b/gunagala/tests/test_psf.py index e932c54..00a9629 100644 --- a/gunagala/tests/test_psf.py +++ b/gunagala/tests/test_psf.py @@ -4,15 +4,15 @@ from gunagala.psf import PSF, MoffatPSF, PixellatedPSF - -@pytest.fixture(scope='module') -def psf_moffat(): +def make_psf_moffat(): psf = MoffatPSF(FWHM=1 / 30 * u.arcminute, shape=4.7) return psf - @pytest.fixture(scope='module') -def psf_pixellated(): +def psf_moffat(): + return(make_psf_moffat()) + +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], @@ -25,6 +25,9 @@ def psf_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): @@ -33,8 +36,8 @@ def test_base(): @pytest.mark.parametrize("psf, type", [ - (psf_moffat(), MoffatPSF), - (psf_pixellated(), PixellatedPSF)], + (make_psf_moffat(), MoffatPSF), + (make_psf_pixellated(), PixellatedPSF)], ids=["moffat", "pixellated"] ) def test_instance(psf, type): @@ -93,8 +96,8 @@ def test_shape(psf): @pytest.mark.parametrize("psf, t_pixel_scale, pixel_scale", [ - (psf_moffat(), 2.85, 2.85), - (psf_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): @@ -104,8 +107,8 @@ def test_pixel_scale(psf, t_pixel_scale, pixel_scale): @pytest.mark.parametrize("psf, expected_n_pix, pixel_scale", [ - (psf_moffat(), 4.25754067000986, 2.85), - (psf_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): @@ -114,8 +117,8 @@ def test_n_pix(psf, expected_n_pix, pixel_scale): @pytest.mark.parametrize("psf, expected_peak, pixel_scale", [ - (psf_moffat(), 0.7134084656751443, 2.85), - (psf_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): @@ -133,10 +136,10 @@ def test_shape(psf_moffat): @pytest.mark.parametrize("psf, image_size", [ - (psf_moffat(), (21, 21)), - (psf_pixellated(), (21, 21)), - (psf_moffat(), (7, 9)), - (psf_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", @@ -155,10 +158,10 @@ def test_pixellated_dimension(psf, image_size): @pytest.mark.parametrize("psf, offset", [ - (psf_moffat(), (0.0, 0.0)), - (psf_pixellated(), (0.0, 0.0)), - (psf_moffat(), (0.3, -0.7)), - (psf_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", @@ -172,8 +175,8 @@ def test_offsets(psf, offset): @pytest.mark.parametrize("psf, test_size", [ - (psf_moffat(), (1.3, -1.3)), - (psf_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): From f5bdbb69c36b72eea91d6fd46e13db8c8f1f23c4 Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Mon, 31 Aug 2020 22:01:21 +1000 Subject: [PATCH 2/9] somehow fixtures were renamed --- gunagala/tests/test_psf.py | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/gunagala/tests/test_psf.py b/gunagala/tests/test_psf.py index 00a9629..95b6ff9 100644 --- a/gunagala/tests/test_psf.py +++ b/gunagala/tests/test_psf.py @@ -45,48 +45,48 @@ def test_instance(psf, type): assert isinstance(psf, PSF) -def test_pix(pix_psf): - assert isinstance(pix_psf, PixellatedPSF) - assert isinstance(pix_psf, PSF) +def test_pix(psf_pixellated): + assert isinstance(psf_pixellated, PixellatedPSF) + assert isinstance(psf_pixellated, PSF) -def test_FWHM(psf): - assert psf.FWHM == 2 * u.arcsecond - psf.FWHM = 4 * u.arcsecond - assert psf.FWHM == 1 / 15 * u.arcminute +def test_FWHM(psf_moffat): + assert psf_moffat.FWHM == 2 * u.arcsecond + psf_moffat.FWHM = 4 * u.arcsecond + assert psf_moffat.FWHM == 1 / 15 * u.arcminute with pytest.raises(ValueError): - psf.FWHM = -1 * u.degree - psf.FWHM = 2 * u.arcsecond + psf_moffat.FWHM = -1 * u.degree + psf_moffat.FWHM = 2 * u.arcsecond -def test_pixel_scale(psf): +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(pix_psf): - pix_psf.pixel_scale = (1 / 3) * u.arcsecond / u.pixel - assert pix_psf.pixel_scale == (1 / 3) * u.arcsecond / u.pixel - pix_psf.pixel_scale = (2 / 3) * 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): +def test_n_pix(psf_moffat): assert psf.n_pix == 4.25754067000986 * u.pixel -def test_n_pix_pix(pix_psf): - assert pix_psf.n_pix.to(u.pixel).value == pytest.approx(21.01351017) +def test_n_pix_pix(psf_pixellated): + assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.01351017) -def test_peak(psf): +def test_peak(psf_moffat): assert psf.peak == 0.7134084656751443 / u.pixel -def test_peak_pix(pix_psf): - assert pix_psf.peak.to(1 / u.pixel).value == pytest.approx(0.08073066) +def test_peak_pix(psf_pixellated): + assert psf_pixellated.peak.to(1 / u.pixel).value == pytest.approx(0.08073066) -def test_shape(psf): +def test_shape(psf_moffat): assert psf.shape == 4.7 psf.shape = 2.5 assert psf.shape == 2.5 From 7ede66790a204bb1d4327b92097c735a6e299005 Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Mon, 31 Aug 2020 22:02:32 +1000 Subject: [PATCH 3/9] fix for linspace now requiring Ints via discretize --- gunagala/psf.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gunagala/psf.py b/gunagala/psf.py index acbe974..64c48b2 100644 --- a/gunagala/psf.py +++ b/gunagala/psf.py @@ -198,10 +198,24 @@ def pixellated(self, size=(21, 21), offsets=(0.0, 0.0)): self.x_0 = offsets[1] self.y_0 = offsets[0] - xrange = (-(size[1] - 1) / 2, (size[1] + 1) / 2) - yrange = (-(size[0] - 1) / 2, (size[0] + 1) / 2) + x_min = - (size[1] - 1) / 2 + x_max = (size[1] + 1) / 2 - return discretize_model(self, xrange, yrange, mode='oversample', factor=10) + y_min = - (size[0] - 1) / 2 + y_max = (size[0] + 1) / 2 + + print(size, x_min, x_max, y_min, y_max) + + if not(x_min.is_integer()) or not(x_max.is_integer()): + raise ValueError(f"Size[1] yields a non-integer range: {x_min} to {x_max}") + + if not(y_min.is_integer()) or not(y_max.is_integer()): + raise ValueError(f"Size[0] yields a non-integer range: {y_min} to {y_max}") + + x_range = (int(x_min), int(x_max)) + y_range = (int(y_min), int(y_max)) + + return discretize_model(self, x_range, y_range, mode='oversample', factor=10) class MoffatPSF(FittablePSF, Moffat2D): From 90ed706832638a1edffe614f644e3fa5c4e5f4e7 Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Tue, 1 Sep 2020 21:43:29 +1000 Subject: [PATCH 4/9] undo this as it is an astropy bug fix instead --- gunagala/psf.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/gunagala/psf.py b/gunagala/psf.py index 64c48b2..acbe974 100644 --- a/gunagala/psf.py +++ b/gunagala/psf.py @@ -198,24 +198,10 @@ def pixellated(self, size=(21, 21), offsets=(0.0, 0.0)): self.x_0 = offsets[1] self.y_0 = offsets[0] - x_min = - (size[1] - 1) / 2 - x_max = (size[1] + 1) / 2 + xrange = (-(size[1] - 1) / 2, (size[1] + 1) / 2) + yrange = (-(size[0] - 1) / 2, (size[0] + 1) / 2) - y_min = - (size[0] - 1) / 2 - y_max = (size[0] + 1) / 2 - - print(size, x_min, x_max, y_min, y_max) - - if not(x_min.is_integer()) or not(x_max.is_integer()): - raise ValueError(f"Size[1] yields a non-integer range: {x_min} to {x_max}") - - if not(y_min.is_integer()) or not(y_max.is_integer()): - raise ValueError(f"Size[0] yields a non-integer range: {y_min} to {y_max}") - - x_range = (int(x_min), int(x_max)) - y_range = (int(y_min), int(y_max)) - - return discretize_model(self, x_range, y_range, mode='oversample', factor=10) + return discretize_model(self, xrange, yrange, mode='oversample', factor=10) class MoffatPSF(FittablePSF, Moffat2D): From a3db4d58860e3031f72078db90a09b377f2785ed Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Fri, 4 Sep 2020 08:34:56 +1000 Subject: [PATCH 5/9] require astropy >= 4.02 --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ce2c837..e7a9863 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.02, pyYAML, numpy, scipy, matplotlib # version should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386) version = 0.1.dev0 From abd82ab0f5e5d7968083f26a9db0f921672548de Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Tue, 27 Oct 2020 10:04:02 +1100 Subject: [PATCH 6/9] fix np.where not carrying units through --- gunagala/imager.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 From 2c6488ec2a76ad98f2935a4efc7a97d01d14b14a Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Tue, 27 Oct 2020 10:06:43 +1100 Subject: [PATCH 7/9] ignore pytest_cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From 02f0a176028ed72287bcbb7cc68ac86cf6d0664b Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Tue, 27 Oct 2020 10:13:48 +1100 Subject: [PATCH 8/9] added tol to a pytest.approx case --- gunagala/tests/test_psf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gunagala/tests/test_psf.py b/gunagala/tests/test_psf.py index e015ef5..bbfc9f9 100644 --- a/gunagala/tests/test_psf.py +++ b/gunagala/tests/test_psf.py @@ -75,7 +75,7 @@ def test_n_pix(psf_moffat): def test_n_pix_pix(psf_pixellated): - assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.01351017) + assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.01351017, 0.1) def test_peak(psf_moffat): From 91df4e9a74d66bde857116f17de9a05a2c43fdcd Mon Sep 17 00:00:00 2001 From: Lee Spitler Date: Tue, 27 Oct 2020 10:37:05 +1100 Subject: [PATCH 9/9] fix astropy version typo --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e7a9863..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>=4.02, 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