From f0c368907d791e2132048406462fbde35cc4ddd6 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 17 Aug 2023 08:34:15 -0500 Subject: [PATCH 1/7] Updated CHANGES file. --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index e0ef1393..958e9860 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,9 @@ New Features ^^^^^^^^^^^^ + Development of new data classes for handling source list, photometry, and catalog data which include data format validation. [#125] + Aperture photometry streamlined into ``single_image_photometry`` ``multi_image_photometry`` functions that use the new data classes. [#141] ++ Photometry related notebooks updated to use new data classes. [#151] + ``multi_image_photometry`` now is a wrapper for single_image_photometry instead of a completely separate function. ++ Logging has been implemented for photmetry, so all the output can now be logged to a file. [#150] Other Changes and Additions ^^^^^^^^^^^^^^^^^^^^^^^^^^^ From e35806485af0882bc951b6307ec92264e7e0b0c4 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 17 Aug 2023 08:34:50 -0500 Subject: [PATCH 2/7] Fix issue #157 with setting ccd_data to float before flagging with NaN. --- stellarphot/photometry/photometry.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stellarphot/photometry/photometry.py b/stellarphot/photometry/photometry.py index 46c2e338..eb5b030a 100644 --- a/stellarphot/photometry/photometry.py +++ b/stellarphot/photometry/photometry.py @@ -249,7 +249,9 @@ def single_image_photometry(ccd_image, sourcelist, camera, observatory_location, "SKIPPING THIS IMAGE!") return None, None - # Set high pixels to NaN + # Set high pixels to NaN (make sure ccd_image.data is a float array first) + if ccd_image.data.dtype != np.float: + ccd_image.data = ccd_image.data.astype(np.float) ccd_image.data[ccd_image.data > max_adu] = np.nan # Extract necessary values from sourcelist structure From d82788189122a59aa63e0d78ba60768b3d2928e1 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 17 Aug 2023 08:39:13 -0500 Subject: [PATCH 3/7] Tweak to changes. --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 958e9860..daa8b79f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,7 @@ Other Changes and Additions + Major reorganizaiton of code including moving functions to new modules. [#130, #133] + Now requires python 3.10 or later. [#147] + Use pydantic for aperture settings. [#154] ++ Stomped bug in handling of ``NaN``s in ``single_image_photometry``. [#157] Bug Fixes ^^^^^^^^^ From 4097a7864d3835d5c7426cfa64ba3dea91c58955 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 17 Aug 2023 08:55:45 -0500 Subject: [PATCH 4/7] Remember np.float is deprecated, you idiot. :( --- stellarphot/photometry/photometry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stellarphot/photometry/photometry.py b/stellarphot/photometry/photometry.py index eb5b030a..183dcc3b 100644 --- a/stellarphot/photometry/photometry.py +++ b/stellarphot/photometry/photometry.py @@ -250,8 +250,8 @@ def single_image_photometry(ccd_image, sourcelist, camera, observatory_location, return None, None # Set high pixels to NaN (make sure ccd_image.data is a float array first) - if ccd_image.data.dtype != np.float: - ccd_image.data = ccd_image.data.astype(np.float) + if ccd_image.data.dtype != float: + ccd_image.data = ccd_image.data.astype(float) ccd_image.data[ccd_image.data > max_adu] = np.nan # Extract necessary values from sourcelist structure From 509ca8b09646b0a35409332585e70ff4f49d91d8 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 17 Aug 2023 11:41:07 -0500 Subject: [PATCH 5/7] Fix to typecasting (without a check). --- stellarphot/photometry/photometry.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stellarphot/photometry/photometry.py b/stellarphot/photometry/photometry.py index 183dcc3b..7b6e669c 100644 --- a/stellarphot/photometry/photometry.py +++ b/stellarphot/photometry/photometry.py @@ -250,9 +250,7 @@ def single_image_photometry(ccd_image, sourcelist, camera, observatory_location, return None, None # Set high pixels to NaN (make sure ccd_image.data is a float array first) - if ccd_image.data.dtype != float: - ccd_image.data = ccd_image.data.astype(float) - ccd_image.data[ccd_image.data > max_adu] = np.nan + ccd_image.data[ccd_image.data.astype(float) > max_adu] = np.nan # Extract necessary values from sourcelist structure star_ids = sourcelist['star_id'].value From 91a9d800043f38af280418c8def09fde631a6dde Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 17 Aug 2023 15:50:54 -0500 Subject: [PATCH 6/7] Fixing a stupid error. --- stellarphot/photometry/photometry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stellarphot/photometry/photometry.py b/stellarphot/photometry/photometry.py index 7b6e669c..b41df53e 100644 --- a/stellarphot/photometry/photometry.py +++ b/stellarphot/photometry/photometry.py @@ -250,7 +250,8 @@ def single_image_photometry(ccd_image, sourcelist, camera, observatory_location, return None, None # Set high pixels to NaN (make sure ccd_image.data is a float array first) - ccd_image.data[ccd_image.data.astype(float) > max_adu] = np.nan + ccd_image.data = ccd_image.data.astype(float) + ccd_image.data[ccd_image.data > max_adu] = np.nan # Extract necessary values from sourcelist structure star_ids = sourcelist['star_id'].value From 56c7e28ac0a25dd5665649af3b60c11b84c493be Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Thu, 17 Aug 2023 17:05:31 -0500 Subject: [PATCH 7/7] Add test for integer data --- .../photometry/tests/test_photometry.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/stellarphot/photometry/tests/test_photometry.py b/stellarphot/photometry/tests/test_photometry.py index 94b0c0ca..8aa20896 100644 --- a/stellarphot/photometry/tests/test_photometry.py +++ b/stellarphot/photometry/tests/test_photometry.py @@ -221,8 +221,11 @@ def test_find_too_close(): coords2use='pixel' -def test_aperture_photometry_no_outlier_rejection(): +# The True case below is a regression test for #157 +@pytest.mark.parametrize('int_data', [True, False]) +def test_aperture_photometry_no_outlier_rejection(int_data): fake_CCDimage = FakeCCDImage() + sources = fake_CCDimage.sources aperture = sources['aperture'][0] inner_annulus = 2 * aperture @@ -234,6 +237,18 @@ def test_aperture_photometry_no_outlier_rejection(): found_sources = source_detection(fake_CCDimage, fwhm=sources['x_stddev'].mean(), threshold=10) + + # The scale_factor is used to rescale data to integers if needed. It + # needs to be set later on when the net counts are "unscaled" in the + # asserts that constitute the actual test. + scale_factor = 1.0 + if int_data: + scale_factor = 0.75 * max_adu / fake_CCDimage.data.max() + # For the moment, ensure the integer data is NOT larger than max_adu + # because until #161 is fixed then having NaN in the data will not succeed. + data = scale_factor * fake_CCDimage.data + fake_CCDimage.data = data.astype(int) + phot, missing_sources = single_image_photometry(fake_CCDimage, found_sources, fake_camera, @@ -265,7 +280,9 @@ def test_aperture_photometry_no_outlier_rejection(): # Here we just check whether any difference is consistent with # less than the expected one sigma deviation. - assert (np.abs(expected_flux - out['aperture_net_cnts'].value) < + + # We need to remove any scaling that has been done of the data values. + assert (np.abs(expected_flux - out['aperture_net_cnts'].value / scale_factor) < np.pi * aperture**2 * fake_CCDimage.noise_dev)