Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing non-NaNable ccd images #158

Merged
merged 7 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ 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
^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 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
^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion stellarphot/photometry/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still need a line here making the data float, it just doesn't need a type check:

Suggested change
# Set high pixels to NaN (make sure ccd_image.data is a float array first)
# Set high pixels to NaN (make sure ccd_image.data is a float array first)
ccd_image.data = ccd_image.data.astype(float)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't I cast it to float during the NaN replacement? (On iPhone, can't see code)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cast it as float for the comparison (inside the brackets) but the data itself is still int I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I fixed it now.

ccd_image.data = ccd_image.data.astype(float)
ccd_image.data[ccd_image.data > max_adu] = np.nan

# Extract necessary values from sourcelist structure
Expand Down
21 changes: 19 additions & 2 deletions stellarphot/photometry/tests/test_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)


Expand Down