Fitting multiple intervals

From HelioWiki Home Page
Jump to navigation Jump to search

Fitting Multiple Intervals using the OSPEX 'Fit Options' GUI

Introduction

This section covers using the OSPEX 'Fit Options' GUI to fit multiple intervals. This document assumes that the user has a working knowledge of the procedure outlined in OSPEX GUI Users Guide for fitting a single interval. More information on looping options and control parameters can be found here

The 'Fit Options' GUI Looping Procedure

Once a single interval has been fit it may be of interest to the user to view how various parameters change with time. One way to do this is to fit a series of intervals individually, however this is a time consuming process. The 'Fit Options' GUI has a number of different ways to automatically fit a series of time intervals selected by the user. To start the process the 'Fit Options' GUI should appear as below:

Fit Options GUI after a single completed fit

In this case a single fit has been completed and we would like to fit subsequent intervals. There are a few choices we must make. The first is to select the intervals we would like to fit. We can do this by selecting the first interval in the series, then selecting the last interval while holding down the SHIFT key. All intervals between the two selected intervals will also be highlighted at this point.

Intervals to fit can be selected from the command line as follows:
obj -> set, spex_intervals_tofit = [4,5,6,7,9]
The interval numbers are the same as those defined when setting up the intervals in the [OSPEX GUI Users Guide]. The intervals are set from the lowest interval to the highest if the loop is set to forward or the opposite if the loop is set to reverse (see below). The interval numbers are automatically sorted from lowest to highest or highest to lowest depending on the loop direction. Intervals can only be looped through in this order.

Our next choice is the loop mode. The 'Loop Mode' Button is on the left around the midpoint of the GUI. The loop mode determines how we will attempt to fit each interval in our selected series. The options are as follows:

Loop Mode Options

  • Automatic - Attempts to fit each interval from starting parameters with no other user input, when lowest reduced chi-squared is reached the loop moves on to the next interval in the series and continues the process
  • Manual First + Automatic - The user adjusts the starting parameters and does the fit on the first interval as described in OSPEX GUI Users Guide, once this fit is accepted all other fits are done automatically with no further user input
  • Manual All Intervals - The user fits each interval as described in OSPEX GUI Users Guide. Looping through the intervals will set the starting parameters for each interval, but the user can modify them and must accept each fit for the loop to continue

In most cases it is wise to choose Manual First + Automatic in order to be sure that the first fit in your series has physically reasonable values before continuing with the rest of the fits automatically. From the command line this can be set by:
obj -> set, spex_fit_manual = 1 Other choices are 0 for automatic on all intervals or 2 for manual on all intervals

The next choice is the loop direction. The 'Loop Direction' button is immediately to the right of the 'Loop Mode' button. This allows us to choose whether we want to start with the latest time and go backwards or start with the earliest time and go forwards. Accordingly the two options available are:

Loop Direction Options

  • Forward - Starts at the earliest time and loops through all selected intervals to the latest time
  • Backwards - Starts at the latest time and loops through all selected intervals to the earliest time

This can be set from the command line as follows:
obj -> set, spex_fit_reverse = 0 spex_fit_reverse can be set to 0 for forward or 1 for reverse

Now we must select our 'Parameter Initialization Method'. The choices for this are right below the 'Loop Mode' and 'Loop Directions' buttons. The 'Parameter Initialization Method' allows us to select the way in which starting parameters for each interval in the loop will be selected. It is broken up so we can select the starting parameters for the first interval fit by one method, then use a different method for the each subsequent interval. Our choices are as follows:

First Interval

  • Program Defaults - The first interval fit will use the program default values for all parameters. This includes the value of the parameter as well as whether it is free or fixed
  • Current Values (Shown Above) - The values are taken from the 'Show Func' display above the 'Loop Mode' and 'Loop Direction' buttons, the parameters are fixed or free in the same way they are in the Current Function displayed in 'Show Func'
  • Final Fit Parameters from Interval: - Uses the final fit parameters from a chosen interval as the starting parameters for the first interval in the loop, the parameters are fixed or free as they are in the chosen interval
  • Starting Fit Parameters from Interval: - Uses the starting parameters from a chosen interval as the starting parameters for the first interval in the loop, the parameters are fixed or free as they are in the chosen interval

Set the method to choose the initial parameters for the first interval fit from the command line as follows:
obj -> set, spex_fit_firstint_method = 'current'</spam>
Other choices that can be used are default, fn, or sn. All options are defined here

Subsequent Intervals

  • Program Defaults - All intervals after the first interval will use default values of the parameters as well as the default free or fixed values
  • Fitted Parameters from most recently fit interval - All intervals after the first interval fit will use the final values of the last interval fit as their starting parameters including the free or fixed values
  • Starting Parameters from most recently fit interval - All intervals after the first interval will use the starting parameters from the last interval fit as their starting parameters including the free or fixed values
  • Fitted parameters from previous iteration on each interval - All intervals will use the value of the final fitted parameters from the last time that interval was fit. If no fit was was previously done on an interval, the current values from 'Show Func' will be used. Note that if this option is selected it is applied to the first interval as well, therefore you will not be allowed to choose a separate method for the first interval. All intervals will use their previous values for free and fixed unless they were never fit, in this case they will use the free or fixed values from the current interval.

Set the method to fit each subsequent interval after the first from the command line as follows:
obj -> set, spex_fit_start_method = 'previous_int'
Other choices that can be used are default, previous_start, previous_iter. All options are defined here

The parameter initialization method will set all the parameters from the start of each loop through each fit interval starting with the special case of the first interval and moving through all the subsequent intervals. However a fit option that can vary the greatly over the time of the loop is the 'energy range to fit'. In most cases we want to fit the entire energy range of the flare above the background level. If this energy range stays the same over the entire duration of the loop we can set it in the 'Change Fit Function Components and Set Parameters' GUI using the 'Change' button next to 'Energy range(s) to fit' at the bottom of the GUI.

From the command line, for example, we can set the erange by setting:
obj -> set, spex_erange = [6,40] where 6keV is the low end of the energy range and 40keV is the high end.

However in many cases the flare will extend to higher energies as it approaches it's peak time and the fall to lower energies as it decays. While looping we will not be able to adjust the energy range for each fit unless we do each fit manually. If we select the 'Auto-set Max' button at the bottom of the 'Change Fit Function Components and Set Parameters' GUI or below the list of time intervals in the 'SPEX Fit Options' GUI the high end of the energy range to fit will be automatically adjusted for each interval to the point where the spectrum reaches the background. This is not exact, the value is adjusted to nearest multiple of 10 in keV with a lower limit of 20keV. The low end of the energy range will remain fixed at the value to which it was set.

From the command line we can set the maximum of the enrange automatically by:
obj -> spex_fit_auto_erange = 1 this sets the maximum to within 5keV of where the spectrum reaches the background level.

Combinations of Looping Options

When fitting a flare there are many combinations of options that can be used when looping through fit interval, as described above. Some methods, and when they might advantageous to use, are discussed below.

  • When fitting a flare for it's entire duration, start with an interval at the peak first, then loop backwards to the start of the flare from that interval using the Manual + Automatic for the loop mode option, along with the Fitted Parameters from most recently fit interval option for Subsequent Intervals. Once this is done, start at the peak interval again and loop forward to the end of the flare using the same option for Subsequent Intervals. The count rate statistics are better at the peak of the flare, meaning the parameters for the fit should not be greatly affected by statistical fluctuations in the counts. This should yield the best set of starting parameters for the subsequent intervals when used with the Fitted Parameters from most recently fit interval option. The problems with this method arise when the attenuator states change over the duration of the flare. Using the final fit parameters in one attenuator state as the starting parameters in another state can fail because the low energy portion of the spectrum is distorted by the attenuators and in some cases not well modeled by the fit components and the RHESSI SRM files. In the earlier and later portions of the flare problems may occur because of low count statistics, independent of the attenuator state. In this case the fit model may become distorted when automatically looping through these intervals. One solution is to enhance the statistics by defining longer time intervals at the start and end of the flare so more counts are included in each interval.
  • If you have already fit a set of time intervals and would like to add a component to your model the Fitted Parameters from previous iteration on each interval option for Subsequent Intervals may be a good choice. This is also a good choice if you are changing other fit options such as the background selection or energy range fit but keeping the same fit component model. The Previous Iteration method is most successful when small changes are made to each fit, such as adding drm_mod or pileup_mod. In cases where bigger changes are made to the model such as removing bpow and replacing it with thick target to model the non-thermal portion of the spectrum a better option is redoing all fits using the Fitted Parameters from most recently fit interval method.

Saving Results and Settings

Once a series of intervals have been fit, the results and settings can be saved in a script . Under the File drop down menu in the main OSPEX GUI select Write Script -> and Fit Results. A GUI will pop up which allows the user to select the name and path of the the script which contains the settings for the session. The file must be saved as a .pro file. Once this is done another window will appear allowing the user to select the name and path of the results file. This must be saved as a .fits file. When starting a new session the script can be used to set the options and results using the Set Parameters from Script -> Initialize All Parameters First option under the File drop down menu.

The script and results can also be saved from the command line:
obj -> writescript, outfile = 'xxx.pro', fit_outfile = 'xxx.fits'
Additional options for the writescript command can be found here