Fitlc from the command line

This new version is object oriented. What this means is that all the data needed by fitlc and all the routines used by fitlc are stored in a single IDL variable (an object). To just jump right in here's the code to load, fit, and output the result for this fitlc file:

var = obj_new( 'fitlc_var', '385' )
var->explore, /scargle
var->refine, /amoeba
print, var->get_best_fit()
; prints ' 0.79020298 1.8578014 3778.8875 0.38985080 24.890598'
var->save_fit
obj_destroy, var
Objects are created in IDL with the obj_new() function, and destroyed with the obj_destroy procedure. Let me emphasize that it is essential to destroy objects when you are done with them. Also, you must destroy objects with the obj_destroy procedure. Objects store a lot of data that can suck up memory, and the fitlc_var objects store a lot of data in pointers. If you don't properly destroy a fitlc_var object with the obj_destroy procedure, then all that data will remain in your memory until you exit IDL, use the '.reset' command, or use heap_gc. Even if an object variable goes out of scope, or is overwritten by another variable declaration (ex: var = 1) the data stored in the object will remain in memory until IDL is reset or the heap_gc command is executed. So anytime you create an object with obj_new you must explicitly destory it with obj_destroy to avoid memory leaks.

Here's the current list of object functions and procedures you can use and the syntax to call them:

  • variable = obj_new( 'fitlc_var', filename[, settings_file=settings_file, templates_file=templates_file] )
    This is the object declaration and is how you get things started. You must create a new object for every variable you want to fit. Now you can give it a settings file which allows you to put all your settings in one file, instead of repeating them in each individual fitlc file (you can still do that though). Also you can specify the templates filename if it isn't just 'templates'.

  • variable->explore[, /scargle, /amoeba, /pikaia]
    The first step of fitting is to 'explore' space. Basically, fit a whole bunch of periods to find out where the best fit might be. This exploration can be done with scargle (really fast), amoeba (slow), or pikaia (really slow). It will default to pikaia. If you put the word 'scargle' or 'amoeba' in your fitlc file or the settings file, then it will default to scargle or amoeba. If you call this procedure with any of the /scargle, /amoeba, or /pikaia keywords, that will overrule all other defaults.

  • variable->refine[, /amoeba, /pikaia]
    The second step is to refine the variable period, and look for a best fit. This is always done with template fitting. If you place the word 'refineamoeba' in your fitlc or settings file it will use amoeba, otherwise pikaia. Fitlc will look for a best fit around the 5 best periods from the explore phase. To have it check 'x' best periods put 'pers_to_check = x' in either your fitlc or settings file. If you haven't called the 'explore' procedure when you call the refine procedure, it will call it for you.

  • fit = variable->template_fit( period, template_index, [range=range, /pikaia, /amoeba] )
    Use this to perform a template fit to any given period and template. Just pass the period and the template index (zero-indexed). If you give it a range it will try to search around the given period within that range. For fitting with pikaia it will actually be limited to find a best fit at period +/- range. However there isn't actually a way to tell amoeba, "don't fit outside this range" so with amoeba the range simply gives it a scale length to begin searching over when fitting for the best period. It returns the best fit, a row vector with these values:
    [ period, chisq, epoch, [amplitude, magnitude]*number_filters ]

  • best_period = variable->get_scargle_results( [periods=periods, power=power, sig=sig] )
    This returns the best period from scargle. The three keywords are optional outputs. Periods and power are the periodogram from scargle. Sig is the power level that denotes a statistically significant variability at the level set by the 'fap' setting. By default, 'fap = 0.05', which corresponds to variability at the 99.95% confidence level.

  • fit = variable->get_best_fit( [tempind=tempind] )
    This returns the overall best fit. It will automatically call the refine and explore procedures if they haven't already been called. It returns the index of the best fitting template in the tempind keyword, and returns a row vector that has these values:
    [ period, chisq, epoch, [amplitude, magnitude]*number_filters ]

  • variable->save_fit[, filename=filename]
    This will write out the typical fitlc output files, using 'filename' as the basename (defaults to the input filename). If refine and explore haven't yet been called, then they will be called automatically.

  • obj_destroy, variable
    This is how to destroy variable objects when you are done with them. This must be done to avoid memory leaks!

Helpful Routines

This also comes with two standard routines that are called from the command line, make_variables and fitlc_var_automate. The former is used to generate large numbers of simulated variables from the templates, and the latter is used to automatically apply fitlc_var to all the fitlc files in a directory. Here is the calling syntax for both:

make_variables, fitlc_filename[, settings=settings]
fitlc_var_automate, filter[, fileout=fileout, settings=settings]

fitlc_var_automate is very straight-forward, just give it a standard filter like you would for the 'ls' command. So if all the fitlc files in your directory end with '.fitlc', just call: filtc_var_automate, '*.fitlc' You can pass it the name of a settings file if you have one.

make_variables needs the name of a fitlc file to work. It generates variables with time sampling and photometric errors that match the conditions in the fitlc file it is passed. It also accepts a settings file that controls the properties of the files it generates. The settings file can contain the following parameters:

SyntaxDescriptionDefault
templates = 'filename'filename of the template file to use'templates'
minamp = valueminimum amplitude to generate0.5
maxamp = valuemaximum amplitude to generate1.2
maxrange = valueThe range of mean magnitudes to allow1.0
minperiod = valueminimum period to generate0.2
maxperiod = valuemaximum period to generate0.9
vars_per_template = valueNumber of variables to generate for each template500
mincolor = valueminimum color to generate0.5
maxcolor = valuemaximum color to generate1.5
one_filter = 1Ignore all but the first filter0
plain = 1Don't output filter flags to the new files0
header = ['string','string',...]Create a header to be output to all the variables-
ampratios = [ 0.0, val, val, ...]Let the amplitudes of the other filters be a ratio of the amplitude in the first filter. The amplitudes of any filter will be random if the value in ampratios is 0.-