Skip to content

Commit

Permalink
added a quick test for calculate_area_fraction
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalvin committed Jan 17, 2024
1 parent 2580d9a commit 242c14b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions flint/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,13 @@ def calculate_area_correction_per_flux(

# Filter out the data
rms_data = fits.getdata(rms_image_path)
rms_data = rms_data[np.isfinite(rms_data)]
rms_data = rms_data[np.isfinite(rms_data)].flatten()

# Calculate the cumulative distribution and normalise it to 0..1
rms_hist, rms_bins = np.histogram(rms_data.flatten(), bins=500)
rms_hist, rms_bins = np.histogram(rms_data, bins=500)
rms_cdf = np.cumsum(rms_hist)
rms_cdf = rms_cdf / rms_cdf[-1]
assert np.isclose(rms_cdf[-1], 1), "Normalisation of the RMS CDF failed"

# Calculate the bin centers of the histogram / CDF
rms_bin_centre = 0.5 * (rms_bins[1:] + rms_bins[:-1])
Expand Down
23 changes: 22 additions & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import pkg_resources
import pytest

from flint.validation import RMSImageInfo, get_parser, get_rms_image_info
from flint.validation import (
RMSImageInfo,
get_parser,
get_rms_image_info,
calculate_area_correction_per_flux,
)


def test_get_parser():
Expand All @@ -25,6 +30,22 @@ def rms_path(tmpdir):
return rms_path


def test_calculate_area_correction(rms_path):
"""This is not an entirely robust check as the rms image is only
10 x 15 pixels. More testing for errors in the calling."""

flux_bin_centres = np.arange(0.00004, 0.01, 0.0001)

area_frac = calculate_area_correction_per_flux(
rms_image_path=rms_path, flux_bin_centre=flux_bin_centres, sigma=3
)

test = np.ones(100)
test[:5] = 0.0

assert np.allclose(test, area_frac)


def test_rms_image_info(rms_path):
rms_info = get_rms_image_info(rms_path=rms_path)

Expand Down

0 comments on commit 242c14b

Please sign in to comment.