pycs.disp package

Submodules

pycs.disp.disps module

Defines dispersion functions. No optimization is done here ! We just calculate the dispersion.

  • linintnp is the “default” one
  • pelt95
  • others should be ported into pycs from my f90 code :-(

They all share a common structure : give me 2 light curves as input, and you get a float describing the match. By construction the dispersion is often not symmetric, i.e. if you switch lc1 and lc2 you will get a different result. To symmetrize the techniques, use the provided symmetrize function. I return a dictionnary, containing a field “d2” that gives the dispersion (among possible other fields). Any microlensing is naturally taken into account, if present, simply using the getmags() method.

pycs.disp.disps.linintnp(lc1, lc2, interpdist=30.0, weights=True, usemask=True, plot=False)

This is the default one, fast implementation without loops (25 times faster then maltef90). If usemask == True, it is a bit slower… If you do not change the mask, it’s better to cutmask() it, then use usemask = False.

pycs.disp.disps.pelt95(lc1, lc2, decorlength=3.0, usemask=True, verbose=False, plot=False)

Dispersion method as described in Pelt Kayser Refsdal 93 & 95 For now this corresponds to D3, the third form, i.e. using only stricly neigbooring pairs, and no weighting. The fourth form uses all pairs within a given decorlength, non only neighboring.

pycs.disp.disps.linint90(lc1, lc2, interpdist=30.0, weights=True, verbose=False, plot=False, debug=False)

Do not use, historical only. Terribly slow variant of linintnp, with plenty of loops, mimics my f90 implementation of 2007…

Between two ORDERED light curves lc1 and lc2 It does skip masked points.

IT IS SLOW !!! THIS IS FOR DEMONSTRATION PURPOSES ONLY !

About the maths : interpolate linearly between the points of lc2, and sum the square of the differences between the points of lc1 and this interpolation. If you choose to weight this sum according to errors, then for each point-pair (i.e. “element”) of the sum, the weight is calculated using both the error on lc1 and the interpolated (again !) error on lc2

We try to do a minimum of loops, using the fact that the light curves are ordered.

lc1 will be the “reference”, and we will interpolate between the points of lc2 This algorithm absolutely NEEDS ordered light curves !!!!

The way we check for the mask looks a bit un-natural, but this way should be quite fast in fact. Another think to note is that there is for now no special procedure for “close-by” points, and subtraction of very close numbers is not good…

@return: a dict, containing for now :

  • “n” : the number of “pairs” that could be used
  • “d2” : the chi2 ( i.e. sum(squares)/(n-1) )

@type lc1: lightcurve @param lc1: The reference light curve. It can of course be shifted and or partially masked. @type lc2: lightcurve @param lc2: The light curve that will be interpolated. Same remark.

@type interpdist: float @param interpdist: a maximum timespan (in days) over which interpolations are done. See the code for exact details. If you are too conservative (low value), you might perhaps not use some isolated points at all… @type weights: boolean @param weights: True if you want to use the errorbars of the lightcurves @type verbose: boolean @param verbose: True if you want to see details about the curve matching @type plot: boolean @param plot: True if you want to see the actual interpolation as a matplotlib plot

@type debug: boolean @param debug: Turn this on to make it even slower…

pycs.disp.disps.symmetrize(lc1, lc2, dispersionmethod)

Calls your dispersion method on (A,B) and on (B,A) and returns the “average”.

pycs.disp.multiopt module

Functions to optimize timeshifts, microlensing, or all this at the same time between an arbitrary set of curves. These are building blocks, to be assembled to make a general optimizer.

pycs.disp.multiopt.opt_magshift(lcs, rawdispersionmethod, verbose=True, trace=False)

I optimize the magnitude shifts between lightcurves. This is usually a first thing to do. First curve does not get shifted.

You might think that this can be done by just using the median mag of a curve, but here we use the dispersion method, to get it right even in case of curves with non-overlapping regions.

pycs.disp.multiopt.opt_ml(lcs, rawdispersionmethod, verbose=True, maxit=3, stoprel=0.01, maxpowellit=5, splflat=True, trace=False)

Optimize the ml params of the lcs using the Powell method. Generic, give me as many lcs as you want, with either polynomial or spline microlensings.

Fluxshift optimization could perhaps be included in the loop later, for now we skip this.

If some of the lightcurves have no microlensing, I will “aim” at them for my first iteration. So the first iteration is special.

pycs.disp.multiopt.opt_ts_mix(lcs, rawdispersionmethod, movefirst=False, verbose=True)

Optimize the time shifts (nothing else) with a subtle mix of optimization methods.

Steps: * Run a simulated annealing, with a lower temperature bound and no other stop condition, i.e. a more or less constant number of iterations. * Starting from the best point found, explore a 5 x 5 cube * idem, but smaller * idem, but smaller * idem, but smaller * from this last point, simplex minimization

Expect about 600 calls of the rawdispersion on the couples, i.e. 600*12 = 7200 for 4 lightcurves.

Todo

Implement trace !

pycs.disp.multiopt.bruteranges(step, radius, center)

Auxiliary function for brute force exploration. Prepares the “ranges” parameter to be passed to brute force optimizer In other words, we draw a cube … radius is an int saying how many steps to go left and right of center. center is a list or array of the centers, it can be of any lenght.

You make 2*radius + 1 steps in each direction !, so radius=2 means 5 steps thus 125 calls for 4 curves.

pycs.disp.topopt module

Global optimizers that make use of the building blocks from multiopt.py They return a float, the dispersion value. They can be used with pycs.sim.run.multirun() We do not redefine the ML, but we keep it.

pycs.disp.topopt.opt_full(lcs, rawdispersionmethod, nit=5, verbose=True)

A first optimization of ml and ts, alternatively doing one after the other. Works great, seems to be a keeper. Note that I do keep the ML.

You can put a rawdispersionmethod (i.e. non symmetric) into these guys, as they will anyway apply it on AB and BA for every pair AB.

Module contents

This subpackage defines the “dispersion-inspired” family of curve shifting methods. It contains functions that optimize lightcurves (shifts, ML) so to minimize a given dispersion between them. Dispersion functions are defined in the module pycs.disp.disps.

  • multiopt defines the building blocks of these optimizers.
  • topopt assembles thoes blocks into wrapper functions.