Skip to content

Commit

Permalink
Sort the data based on phase during initialization and add correspond…
Browse files Browse the repository at this point in the history
…ing test. Also test for unique bins.
  • Loading branch information
jackieblaum committed Aug 29, 2024
1 parent 7eb0a76 commit 843396e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eclipsebin/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __init__(self, phases, fluxes, flux_errors, nbins=200, fraction_in_eclipse=0
raise ValueError(
"Number of data points must be greater than or equal to the number of bins."
)

self.data = {"phases": phases, "fluxes": fluxes, "flux_errors": flux_errors}
sort_idx = np.argsort(phases)
self.data = {"phases": phases[sort_idx], "fluxes": fluxes[sort_idx], "flux_errors": flux_errors[sort_idx]}
self.params = {"nbins": nbins, "fraction_in_eclipse": fraction_in_eclipse}

# Identify primary and secondary eclipse minima
Expand Down
18 changes: 18 additions & 0 deletions tests/test_eclipsing_binary_binner.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def test_initialization(wrapped_light_curve):
assert len(binner.data["phases"]) == 100
assert len(binner.data["fluxes"]) == 100
assert len(binner.data["flux_errors"]) == 100
# Check if the data is sorted
assert np.all(np.diff(binner.data["phases"]) >= 0)


def test_initialization_invalid_data(unwrapped_light_curve):
Expand Down Expand Up @@ -139,6 +141,10 @@ def test_calculate_eclipse_bins(wrapped_light_curve, unwrapped_light_curve):
assert len(primary_bin_right_edges) == bins_in_primary
assert len(secondary_bin_right_edges) == bins_in_secondary

# Check if the bin edges are unique
assert len(np.unique(primary_bin_right_edges)) == bins_in_primary
assert len(np.unique(secondary_bin_right_edges)) == bins_in_secondary

# Test the unwrapped light curve
phases, fluxes, flux_errors = unwrapped_light_curve
binner_unwrapped = EclipsingBinaryBinner(
Expand Down Expand Up @@ -169,6 +175,10 @@ def test_calculate_eclipse_bins(wrapped_light_curve, unwrapped_light_curve):
assert len(primary_bin_right_edges_unwrapped) == bins_in_primary_unwrapped
assert len(secondary_bin_right_edges_unwrapped) == bins_in_secondary_unwrapped

# Check if the bin edges are unique
assert len(np.unique(primary_bin_right_edges_unwrapped)) == bins_in_primary_unwrapped
assert len(np.unique(secondary_bin_right_edges_unwrapped)) == bins_in_secondary_unwrapped


def test_calculate_out_of_eclipse_bins(wrapped_light_curve, unwrapped_light_curve):
"""
Expand Down Expand Up @@ -197,6 +207,10 @@ def test_calculate_out_of_eclipse_bins(wrapped_light_curve, unwrapped_light_curv
assert len(ooe1_right_edges) == bins_in_ooe1
assert len(ooe2_right_edges) == bins_in_ooe2

# Check if the bin edges are unique
assert len(np.unique(ooe1_right_edges)) == bins_in_ooe1
assert len(np.unique(ooe2_right_edges)) == bins_in_ooe2

# Test the unwrapped light curve
phases, fluxes, flux_errors = unwrapped_light_curve
binner = EclipsingBinaryBinner(phases, fluxes, flux_errors, nbins=50)
Expand All @@ -220,6 +234,10 @@ def test_calculate_out_of_eclipse_bins(wrapped_light_curve, unwrapped_light_curv
assert len(ooe1_right_edges) == bins_in_ooe1
assert len(ooe2_right_edges) == bins_in_ooe2

# Check if the bin edges are unique
assert len(np.unique(ooe1_right_edges)) == bins_in_ooe1
assert len(np.unique(ooe2_right_edges)) == bins_in_ooe2


def test_find_bin_edges(wrapped_light_curve, unwrapped_light_curve):
"""
Expand Down

0 comments on commit 843396e

Please sign in to comment.