Skip to content

Commit

Permalink
Add documentation through mkdocs and add example light curve figure.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackieblaum committed Oct 7, 2024
1 parent 536dfa7 commit bb369d5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/binning-scheme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# How the Binning Scheme Works

## Overview

This binning scheme divides an eclipsing binary light curve into four segments: two eclipse regions and two out-of-eclipse regions. The user can specify the fraction of the total bins `nbins` that should be placed within the eclipse regions, `fraction_within_eclipse`. Within each segment of the light curve, bins are chosen such that an approximately equal number of data points fall within each bin.

Consider the following light curve as an example. In all cases, the code assumes that the light curve has been normalized such that the out-of-eclipse flux is close to one.

<img src="images/asas_sn_light_curve_ex.png" alt="Light Curve Example">

## Eclipse Detection

### Eclipse minima

**Primary eclipse minimum:** This code assumes that the overall minimum flux value of the light curve falls within the primary eclipse (it's okay if this isn't the true minimum of the primary eclipse).

**Secondary eclipse minimum:** To find the secondary eclipse, the code searches the section of the light curve falling at least 0.2 in phase in either direction. The minimum flux value within this section is taken to be the secondary eclipse minimum (again, it's only necessary that this minimum falls within the secondary eclipse).

### Eclipse ingress and egress

**Ingress:** To find the approximate location of the start of the eclipse, the code examines the phases prior to that of the eclipse minimum found in the previous step. Given the absolute tolerance `atol_primary` or `atol_secondary`, which may be specified by the user, the code selects the greatest phase for which the flux is close to one within the selected region.

**Egress:** Same thing, except in the other direction.

## Binning

### Bin distribution

Given the desired number of total bins `nbins`, the code determines the number of bins that will fall within each of the four segments of the light curve.

The code first delegates bins to the eclipse regions. The number of bins to place within the eclipse regions is determined by multiplying `fraction_within_eclipse` by `nbins`. The bins are then divided equally between the two eclipses (with the primary holding an additional bin in the case of an odd number). In the case that there are more desired bins than data points falling within an eclipse region, the number of bins is reduced to equal that number of data points.

The remainder of the bins are divided equally within the out-of-eclipse regions.

### Binning within each segment

Once the bin distribution has been calculated, [`pandas.qcut()`](https://pandas.pydata.org/docs/reference/api/pandas.qcut.html) applies a quantile-based discretization function to calculate bin edges such that an approximately equal number of data points fall within each phase bin. This choice of binning helps to retain important features of the light curve while maintaining a specified number of bins.
38 changes: 38 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Installation

Install the package using `pip`:

```bash
pip install eclipsebin
```

# Prepare your Light Curve

* **Phase your light curve.** Phases must fall between 0 and 1.
* **Convert magnitude to flux.**
* **Normalize the fluxes.** The out-of-eclipse normalized flux should be close to 1.


# Create an EclipsingBinaryBinner Object

Assuming you already have your phases, fluxes, and flux uncertainties stored as `phases`, `fluxes`, and `fluxerrs`, respectively, initialize your `EclipsingBinaryBinner`:

```bash
import eclipsebin as ebin

# Example usage
binner = ebin.EclipsingBinaryBinner(phases, fluxes, fluxerrs, nbins=200, fraction_in_eclipse=0.5, atol_primary=0.001, atol_secondary=0.05)
```
Here `nbins` indicates the desired total number of bins, and `fraction_in_eclipse` indicates the fraction of that total number of bins that you wish to place within the eclipse regions.

You can also optionally set `atol_primary` and/or `atol_secondary`, which specify the absolute tolerance of the corresponding eclipse ingress and egress regarding their proximity to one. These arguments are typically only necessary for systems with significant ellipsoidal variations, as the out-of-eclipse regions are more variable. By default, these values are calculated within the code by taking `proximity_to_one * 0.05`, where `proximity_to_one` indicates the distance of the corresponding eclipse minimum* from unity.

*Note that this is a rough approximation and may be inaccurate for some light curves. See [Binning Scheme](docs/binning-scheme.md) for more details.

Now just call one simple function to bin your light curve, and plot it if you wish.

```bash
bin_centers, bin_means, bin_stds = binner.bin_light_curve(plot=True)
```

And voila, you have your binned light curve! Do with it as you wish.
Binary file added docs/images/asas_sn_light_curve_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ theme:
nav:
- Home: index.md
- Getting Started: getting-started.md
- Binning Scheme: binning-scheme.md
- API Reference: api-reference.md

# Custom URL to deploy
Expand Down

0 comments on commit bb369d5

Please sign in to comment.