Function Definitions

This page details the functions and classes defined in the henrietta package.

lightcurves

henrietta.lightcurves.download_kepler_lc(star='Kepler-186', quarter='all', cadence='long', quality_bitmask='hard', kind='PDCSAP_FLUX', **kw)[source]

This function is a wrapper to download one or more quarters of Kepler lightcurve data, and extract a LightCurve object from it.

When downloading a Kepler LightCurveFile from online, we get lots of information, including multiple different kinds of light curves for the same star. The goal of this little wrapper is to make it easy to get just one single light curve to play with.

This has been tested only on data from the main Kepler mission. For K2 data, you may need to download a TPF.

Parameters:
star: str, int

The name of the star whose light curve you want to download. This can be a name (“Kepler-42”, “KOI-961”) or a KIC number (8561063)

quarter: str, int
Which Kepler quarter to download?

‘all’ = download the entire mission of data 1, 2, 3 … = download a specific quarter

cadence: str

‘long’ for Kepler long cadence ‘short’ for Kepler short cadence

quality_bitmask: str, int

‘none’ = ignore no data ‘default’ = ignore data with serious quality issues ‘hard’ = be a little more cautious in what we call good data ‘hardest’ = be too cautious about what we call good data

kind: str

“SAP_FLUX” = simple aperture photometry “PDCSAP_FLUX” = SAP, with pre-search data conditioning applied to get rid of some instrumental systematics from the light curves (but watch out! some astrophysical signals might be messed up too!)

kw : dict

Additional keywords will be passed to .from_archive.

Returns:
lc: LightCurve object

This is a lightkurve-style LightCurve object, which contains the attributes lc.time (times in JD) and lc.flux (the brightness of the star), as well as lots of methods for analysis and plotting.

henrietta.lightcurves.extract_transits(lc, period, epoch, window=0.05)[source]

This function splits a light curve into two complementary light curves: one that includes just the transits (and a bit of a window surrounding them) and one that contains all the other non-transit parts of the light curve.

Parameters:
lc: object

The ‘lightkurve’ object which contains transit data (time, flux) that we are analyzing.

period: float

The period (days) of the planet’s orbit.

epoch: float

The JD value reported for the mid-transit time of this planet. Epoch is used to find other transits in the data.

window: float

The transit duration (in days), used here to specify a window of data points to extract as the in-transit data.

Returns:
transits: LightCurve object

This is a lightkurve-style LightCurve object, which contains the attributes lc.time (times in JD) and lc.flux (the brightness of the star). This object contains the data points between ingress egress of a transit.

notransits: LightCurve object

This is a lightkurve-style LightCurve object, which contains the attributes lc.time (times in JD) and lc.flux (the brightness of the star). This object contains the data points outside of a transit.

henrietta.lightcurves.locate_transits(lc, period, t0=0, name=None, color='green', **kw)[source]

This function takes in a lightcurve object along with the planet’s period and epoch in order to identify on the plot each expected location of a transit

lc should be a lightkurve object which has times and fluxes. period should be in days t0 should be in BJD

statistics

henrietta.statistics.catch_photons_in_bucket(rate=1, diameter=1.0, time=1800.0, visualize=True)[source]

Simulate a telescope catching photons, for a given photon flux (photons/s/m**2), telescope diameter (m), and exposure time (s).

Parameters:
rate: float

The rate at which photons are coming towards us, expressed in units of (photons/s/m**2).

diameter: float

The effective diameter of a circular telescope, expressed in units of (m).

time: float

The exposure duration, expressed in units of (s).

Returns:
N: int

The number of photons that land in the telescope

henrietta.statistics.create_approximate_lightcurve(N=100, cadence=0.020833333333333332, duration=1)[source]

Create a lightkurve object, assuming we detect a particular number of photons per exposure, but treating the PDF for photon counts with the Gaussian approximation, instead of a true Poisson distribution.

Parameters:
N: float

The average number of photons per exposure.

cadence: float

The time between successive exposures (in days).

duration: float

The total time spanned by the light curve (in days).

henrietta.statistics.create_photon_lightcurve(N=100, cadence=0.020833333333333332, duration=1)[source]

Create a lightkurve object, assuming we detect a particular number of photons per exposure.

Parameters:
N: float

The average number of photons per exposure.

cadence: float

The time between successive exposures (in days).

duration: float

The total time spanned by the light curve (in days).

modeling

henrietta.modeling.BATMAN(t, period=1.0, t0=0, radius=0.1, a=10.0, b=0.0, baseline=1.0, ld1=0.1, ld2=0.3)[source]

This function returns a model transit light curve for a given array of times and set of parameters. It currently assumes a circular orbit.

Parameters:
t : array

An array of times, in units of days.

period : float

The orbital period of the planet, in units of days.

t0 : float

One mid-transit time, in units of days.

radius : float

The radius of the planet, in units of stellar radii. (This is sometimes also called Rp/R*).

a : float

The orbital distance (semimajor axis) of the planet, in stellar radii. (This is sometimes also called a/R*).

b : float

The transit impact parameter of the planet, in stellar radii. (This is closely related to the inclination.)

baseline : float

The out-of-transit flux level, in whatever units you want.

ld : list or array of floats

The limb-darkening coefficients, for a quadratic limb-darkening.

henrietta.modeling.example_transit_model(period=0.5, t0=0, radius=0.1, a=10.0, b=0.0, tmin=-0.5, tmax=0.5, cadence=0.0006944444444444445, ylim=[0.985, 1.005], ax=None, **plotkw)[source]

This function makes an example plot of a model transit light curve.

Parameters:
period : float

The orbital period of the planet, in units of days.

t0 : float

One mid-transit time, in units of days.

radius : float

The radius of the planet, in units of stellar radii. (This is sometimes also called Rp/R*).

a : float

The orbital distance (semimajor axis) of the planet, in stellar radii. (This is sometimes also called a/R*).

b : float

The transit impact parameter of the planet, in stellar radii. (This is closely related to the inclination.)

tmin : float

The minimum time to plot, in days.

tmax : float

The maximum time to plot, in days.

cadence : float

The cadence (time-step) to use, in days.

ylim : list

The ylimits for the plot.

ax : matplotlib.axes object

If an ax is fed in as a keyword argument, the plot will be added to that existing plot axes. To include multiple different models on the same plot, say:

ax = example_transit_model() ax = example_transit_model(rp=0.042, ax=ax) ax = example_transit_model(rp=0.042, b=0.9, ax=ax) …

plotkw : dict

Any extra keywords will be passed along to matplotlib.pyplot.plot

Returns:
plotted_ax : matplotlib.axes object

The axes into which the model was was plotted.

henrietta.modeling.plot_with_transit_model(lc, period=1.0, t0=0, radius=0.1, a=10.0, b=0.0, baseline=1.0, ld1=0.1, ld2=0.3, planet_name='', goodness=None, show_errors=False, datakw={}, modelkw={})[source]

This function will take in a lightcurve for a planet with a given set of transit parameters (period, t0, radius, a, b, baseline) and will plot a batman light curve model. Limb-darkening coefficients can also be specified in the form [u1,u2].

Parameters:
lc : LightCurve object

Data contained in a lightkurve LightCurve object.

period : float

The orbital period of the planet, in units of days.

t0 : float

One mid-transit time, in units of days.

radius : float

The radius of the planet, in units of stellar radii. (This is sometimes also called Rp/R*).

a : float

The orbital distance (semimajor axis) of the planet, in stellar radii. (This is sometimes also called a/R*).

b : float

The transit impact parameter of the planet, in stellar radii. (This is closely related to the inclination.)

baseline : float

The out-of-transit flux level, in whatever units you want.

ld : list or array of floats

The limb-darkening coefficients, for a quadratic limb-darkening.

planet_name : string

The name of the planet, which will be displayed as the title

goodness : function

A function that takes an array of values for (data-model), and returns a goodness of fit metric.

datakw : dictionary

A dictionary with keywords that will be passed to the plt.plot() command that displays the actual data points.

modelkw : dictionary

A dictionary with keywords that will be passed to the plt.plot() command that displays the actual the smooth model.

henrietta.modeling.simulate_transit_data(N=1000000.0, cadence=0.001388888888888889, duration=3.0, tmin=0.0, **kw)[source]

This function will generate a simulated LightCurve dataset with a given fractional noise (sigma) and time spacing (cadence), with a transit injected into it (whose parameters are set by any extra keyword arguments that you feed in, like period, radius, …)

Parameters:
N : float

The average number of photons expected per exposure, to set the standard deviation of the noise.

cadence : float

The integration time of the measurements, in days.

duration : float

The total length of time covered by the light curve.

**kw : dict

Any additional keywords will be passed onward to the batman model to set the parameters of the transit model. Valid additional keywords are period, t0, radius, a, b, ld.

Returns:
lc : LightCurve

A simulated lightkurve LightCurve, with a transit injected, and the specified noise.

fitting

This module contains functions and class definitions to extend the astropy.modeling toolkit to be visualizeable.

class henrietta.fitting.VisualizedFitter(optimizer, statistic)[source]

Objects that inherit from a VisualizedFitter can do the normal stuff an astropy.fitting.Fitter can do, but they also visualize the process with panels that show what’s happening.

Methods

__call__() This method performs the actual fitting and modifies the parameter list of a model.
objective_function(fps, *args) Function to minimize.
visualize(model, x, y[, filename, animate]) Yo
name = 'fitter'

def __init__(self, optimizer=optimizers.Simplex, goodness=sumofsquares, **kwargs):

# shortcuts to make it easier to keep track of the optimizer and statistic self.optimizer = optimizer self.statistic = VisualizedStatistic(fitter=self, goodness=goodness) super().__init__(optimizer=self.optimizer, statistic=self.statistic)
visualize(model, x, y, filename=None, animate=True, **kwargs)[source]

Yo

class henrietta.fitting.VisualizedGuessNCheckFitter(goodness=<function sumofsquares>, **kwargs)[source]

Methods

__call__(model, x, y[, N]) Run the guess-n-check “optimization.”
objective_function(fps, *args) Function to minimize.
visualize(model, x, y[, filename, animate]) Yo
class henrietta.fitting.VisualizedSimplexFitter(goodness=<function sumofsquares>, **kwargs)[source]

Methods

__call__(model, x, y[, z, weights]) Fit data to this model.
objective_function(fps, *args) Function to minimize.
visualize(model, x, y[, filename, animate]) Yo
class henrietta.fitting.VisualizedStatistic(goodness=<function sumofsquares>, fitter=None)[source]

Objects that inherit from VisualizedStatistic should be a drop-in replacement for the astropy.modeling.statistic.leastsq. The simplest class definiton that modifies this would simply be to redefine the .name attribute and the .goodness() method.

Methods

__call__(measured_vals, updated_model, …) Generic goodness-of-fit statistic.
henrietta.fitting.setup_line_model(slope=[0, 5], intercept=[-10, 10])[source]

This function sets up an astropy line model, which can then be used for fitting.

Parameters that are fed in as single values will be held fixed.

Parameters that are fed in as two-element lists will be varied, using the two values as their allowable bounds.

Parameters:
slope : float, or 2-element list

The

henrietta.fitting.setup_transit_model(period=1.58, t0=0.0, radius=[0.0, 0.5], a=[3.0, 50.0], b=0.385, baseline=1.0, ld1=0.1, ld2=0.3)[source]

This function sets up an astropy transit model, which can then be used for fitting.

Parameters that are fed in as single values will be held fixed.

Parameters that are fed in as two-element lists will be varied, using the two values as their allowable bounds.

Parameters:
(same as we’ve seen in other transit modeling)