pint.templates.lctemplate.LCTemplate

class pint.templates.lctemplate.LCTemplate(primitives, norms=None, cache_kwargs=None)[source]

Bases: object

Manage a lightcurve template (collection of LCPrimitive objects).

IMPORTANT: a constant background is assumed in the overall model, so there is no need to furnish this separately.

Parameters:

Methods

Delta([delta])

Report peak separation -- reckoned by default as the distance between the first and final component locations.

add_energy_dependence(index[, slope_free])

add_primitive(prim[, norm, inplace])

[Convenience] -- return a new LCTemplate with the specified LCPrimitive added and renormalized.

approx_derivative(phases[, log10_ens, ...])

approx_gradient(phases[, log10_ens, eps])

approx_hessian(phases[, log10_ens, eps])

cdf(x[, log10_ens])

check_bounds([free])

check_derivative([atol, rtol, order, eps, quiet])

check_gradient([atol, rtol, quiet, seed, en, ph])

closest_to_peak(phases)

copy()

delete_primitive(index[, inplace])

Return a new LCTemplate with the primitive at index removed.

delta([index])

Return radio lag -- reckoned by default as the position of the first peak following phase 0.

derivative(phases[, log10_ens, order, use_cache])

Return the derivative of the template with respect to pulse phase (as opposed to the gradient of the template with respect to some of the template parameters).

eval_cache(phases[, log10_ens, order])

Cached values are stored on edges in both phase and, if applicable, energy, so lookup is straightforward.

free_parameters()

Free all parameters.

freeze_parameters()

Freeze all parameters.

get_amplitudes([log10_ens])

Return maximum amplitude of a component.

get_bounds([free])

get_cache([order])

get_code()

Return a short string encoding the components in the template.

get_display_point([do_rotate])

Return phase shift which optimizes the display of the profile.

get_errors([free])

get_eval_string()

Return a string that can be "eval"ed to make a cloned set of primitives and template.

get_fixed_energy_version([log10_en])

get_free_mask()

Return a mask with True if parameters are free, else False.

get_gaussian_prior()

get_location()

get_parameter_names([free])

get_parameters([free])

gradient(phases[, log10_ens, free, template_too])

gradient_derivative(phases[, log10_ens, free])

Return d/dphi(gradient).

has_bridge()

hessian(phases[, log10_ens, free])

Return the hessian of the primitive and normalization angles.

integrate(phi1, phi2[, log10_ens, suppress_bg])

Integrate profile from phi1 to phi2.

is_energy_dependent()

mark_cache_dirty()

max([resolution])

mean_single_component(index, phases[, ...])

mean_value(phases[, log10_ens, weights, bins])

Compute the mean value of the profile over the codomain of phases.

norm()

norm_ok()

num_parameters([free])

Return the total number of free parameters.

order_primitives([order])

Re-order components in place.

prof_string([outputfile])

Return a string compatible with the format used by pygaussfit.

random(n[, weights, log10_ens, return_partition])

Return n pseudo-random variables drawn from the distribution given by this light curve template.

rotate(dphi)

Adjust the template by dphi.

set_cache([order])

Populate the cache with values along the bin edges.

set_cache_properties([ncache, en_edges])

Set the granularity and behavior of the cache.

set_errors(errs)

set_overall_phase(ph)

Put the peak of the first component at phase ph.

set_parameters(p[, free])

single_component(index, phases[, log10_ens, ...])

Evaluate a single component of template.

swap_primitive(index[, ptype])

Swap the specified primitive for a new one with the parameters that match the old one as closely as possible.

write_profile(fname, nbin[, integral, ...])

Write out a two-column tabular profile to file fname.

set_cache_properties(ncache=1000, en_edges=None)[source]

Set the granularity and behavior of the cache.

In all cases, ncache sets the phase resolution. If it is desired to have energy dependence, en_edges must be specified as a set of edges in log10 space which fully encompass all possible photon energies that wil be used.

Interpolation is always linear (bilinear in energy if applicable.)

set_cache(order=0)[source]

Populate the cache with values along the bin edges.

eval_cache(phases, log10_ens=3, order=0)[source]

Cached values are stored on edges in both phase and, if applicable, energy, so lookup is straightforward.

num_parameters(free=True)[source]

Return the total number of free parameters.

free_parameters()[source]

Free all parameters. Convenience function.

freeze_parameters()[source]

Freeze all parameters. Convenience function.

get_free_mask()[source]

Return a mask with True if parameters are free, else False.

set_overall_phase(ph)[source]

Put the peak of the first component at phase ph.

get_amplitudes(log10_ens=3)[source]

Return maximum amplitude of a component.

get_code()[source]

Return a short string encoding the components in the template.

integrate(phi1, phi2, log10_ens=3, suppress_bg=False)[source]

Integrate profile from phi1 to phi2.

NB that because of the phase modulo ambiguity, it is not uniquely definite what the phi2 < phi1 case means:

integral(0.8,0.2) == -integral(0.2,0.8) integral(0.8,1.2) == 1-integral(0.2,0.8)

To break the ambiguity, we support non-modulo phase here, so you can just write integral(0.8,1.2) if that’s what you mean.

__call__(phases, log10_ens=3, suppress_bg=False, use_cache=False)[source]

Evaluate template at the provided phases and (if provided) energies. If “suppress_bg” is set, ignore the DC component.

derivative(phases, log10_ens=3, order=1, use_cache=False)[source]

Return the derivative of the template with respect to pulse phase (as opposed to the gradient of the template with respect to some of the template parameters).

single_component(index, phases, log10_ens=3, add_bg=False)[source]

Evaluate a single component of template.

gradient_derivative(phases, log10_ens=3, free=False)[source]

Return d/dphi(gradient). This is the derivative with respect to pulse phase of the gradient with respect to the parameters.

hessian(phases, log10_ens=3, free=True)[source]

Return the hessian of the primitive and normalization angles.

The primitives components are not coupled due to the additive form of the template. However, because each normalization depends on multiple hyper angles, there is in general coupling between the normalization components and the primitive components. The general form of the terms is

(1) block diagonal hessian terms from primitive (2 ) for the unmixed derivative of the norms, the sum of the hessian of the hyper angles over the primitive terms (3) for mixed derivatives, the product gradient of the norm

In general, this is pretty complicated if some parameters are free and some are not, and (currently) this method isn’t used in fitting, so for ease of implementation, simply evaluate the whole hessian, then return only the relevant parts for the free parameters.

delta(index=None)[source]

Return radio lag – reckoned by default as the position of the first peak following phase 0.

Delta(delta=False)[source]

Report peak separation – reckoned by default as the distance between the first and final component locations.

delta [False] – if True, return the first peak position

prof_string(outputfile=None)[source]

Return a string compatible with the format used by pygaussfit. Assume all primitives are gaussians.

random(n, weights=None, log10_ens=3, return_partition=False)[source]

Return n pseudo-random variables drawn from the distribution given by this light curve template.

For simplicity, if weights are not provided, unit weights are assumed. If energies are not provided, a vector of 1 GeV (3) is assumed.

Next, optionally using the weights and the energy vectors, the probability for each realization to arise from the primitives or the background is determined. Those probabilities are used in a multinomial to determine which component will generate each photon, and finally using that partition the correct number of phases are simulated from each component.

Weights (“w”) are interpreted as the probability to originate from the source, which includes the DC component, so the total prob. to be DC is (1-w) (background) + w*sum_prims (unpulsed).

swap_primitive(index, ptype=<class 'pint.templates.lcprimitives.LCLorentzian'>)[source]

Swap the specified primitive for a new one with the parameters that match the old one as closely as possible.

delete_primitive(index, inplace=False)[source]

Return a new LCTemplate with the primitive at index removed.

The flux is renormalized to preserve the same pulsed ratio (in the case of an energy-dependent template, at the pivot energy).

add_primitive(prim, norm=0.1, inplace=False)[source]

[Convenience] – return a new LCTemplate with the specified LCPrimitive added and renormalized.

order_primitives(order=0)[source]

Re-order components in place.

order == 0: order by ascending position order == 1: order by descending maximum amplitude order == 2: order by descending normalization

get_eval_string()[source]

Return a string that can be “eval”ed to make a cloned set of primitives and template.

mean_value(phases, log10_ens=None, weights=None, bins=20)[source]

Compute the mean value of the profile over the codomain of phases. Mean is taken over energy and is unweighted unless a set of weights are provided.

rotate(dphi)[source]

Adjust the template by dphi.

get_display_point(do_rotate=False)[source]

Return phase shift which optimizes the display of the profile.

This is determined by finding the 60% window which contains the most flux and returning the left edge. Rotating the profile such that this edge is at phi=0.20 would then center this interval, so the resulting phase shift would do that.

write_profile(fname, nbin, integral=False, suppress_bg=False)[source]

Write out a two-column tabular profile to file fname.

The first column indicates the left edge of the phase bin, while the right column indicates the profile value.

Parameters:
  • integral (bool) – if True, integrate the profile over the bins. Otherwise, differential value at indicated bin phase.

  • suppress_bg (bool) – if True, do not include the unpulsed (DC) component