OSPEX Users Guide

From RHESSI Wiki

Jump to: navigation, search


Using OSPEX to Analyze a RHESSI Spectrum


This document goes through the steps necessary in using OSPEX to determine the best-fit photon spectrum from a measured RHESSI count-rate spectrum accumulated for a single time interval during a flare. It is based on OSPEX - The Basics, Part Two. The guide below assumes that the user has already created a spectrum file as described in the HESSI GUI Users Guide. Once a single interval has been fit see the Fitting multiple intervals document for methods of looping through and fitting intervals. Once multiple intervals have been fit use the View fit results GUI to look at fit parameters as a function of time or interval number. The results can be saved as described here. Command Line instructions are also given for fitting a RHESSI time interval. The list of parameters available can be found at the OSPEX Control, Administration, and Information Parameters page.

Starting the OSPEX GUI and Loading a Spectrum File

To start the OSPEX GUI at the sswidl command line type:

o = ospex()

This command sets up an OSPEX object named o, and starts the OSPEX GUI. The following screen appears when the GUI starts:

The OSPEX GUI Start Screen

Select the File button in the upper left corner, and choose the Select Input button in the drop down menu that appears. From here we can select the spectrum file for the flare we would like to analyze. The path to the file can either be entered manually or the file can be selected using the Browse button. Once the spectrum file is selected the accompanying Spectrometer Response Matrix (SRM) file will be found automatically as long as files are saved in the same directory with the original names. For the 21Apr2002 flare the Select Input GUI looks like the following once the spectrum file for detector four is selected:

The Spectrum File Selection GUI

Note that the GUI allows you to display the spectrum file in various ways. To compare it to the spectrum created in the HESSI GUI tutorial we can plot the time profile. For the spectrum file for the 21Apr2002 event using only the front segment of detector 4 (4F), we see:

The RHESSI lightcurve for the 21Apr2002 flare

This should be same as the time profile we created during the HESSI GUI tutorial. The count flux data is displayed in the default energy bands. The Select Input GUI also allows you to display an energy profile of data, as well as a spectrogram of the data should these be preferable ways of viewing the spectrum file.

From the command line input files can be selected:
o->set, spex_specfile='d:\ospex\hsi_spectrum_20020421_000100.fits'
o->set, spex_drmfile='d:\ospex\hsi_srm_20020421_000100.fits'
Note the path to the spectrum and SRM file depends upon where it is stored on your machine.
This can also be done from the sswidl command line by using the plot_time method:
o->plot_time, /data
This will plot the time profile of the spectrum as shown above. This can also be called with other keywords.

Selecting Background

Before we can fit any time intervals during the flare we need to select background. The simplest method of selecting background will be described.

Lets look at a simple method for choosing background. First choose the Select Background button under File in the main OSPEX GUI. The Select Background GUI should appear. For our case we will leave it at the default settings, because of this we will be using the same background for all energy bands and times.

First we want to display the time profile for the spectrum. The easiest way to do this is to select the 'Plot v. Time' option in the GUI. Now select 'Change'. Using the default settings this takes us to the GUI for defining a background interval graphically. We can use the mouse to define a interval. RHESSI begins taking data for approximately five minutes in nighttime before it’s orbit starts and for five minutes after its orbit. This data is non-solar and we can use it to define the non-solar background levels. Right click at the beginning of a nighttime interval and left click at the end. Choose the 'Adjust to data boundaries' button then 'Accept' and 'Close'. This chooses the background time interval. Select the 'Plot Spectrum' button in the main Select Background GUI and you will see an energy profile of your selected background. The top panel below shows what you should expect to see after picking your background interval, the lower panel, the spectrum of the background chosen.

The Background Interval (upper panel) and Spectrum (lower panel)
To set the background interval from the command line as above:
o -> set, spex_bk_time_interval=['21-Apr-2002 00:27:52', '21-Apr-2002 00:30:44']
To plot the a time profile of the original data,data minus the background and background data:
o -> plot_time, /data, /bksub, /bkdata
To plot the spectrum of the background in the selected background interval:
o -> plotman, class='spex_bkint', spex_units='flux'
There are other options available for for setting the properties of the background, some are described here

Fit Options - Selecting Time Intervals and Doing Fits

We can now start to fit time intervals during the flare. To start choose the Select Fit Options and Do Fit… choice from the File Drop down menu. This brings up the Fit Options GUI. Once again we’ll go through a simple set of options for setting up and fitting time intervals during the flare. For our case we start by defining our time intervals. To do this select the 'Change Fit Intervals' button on the upper right of the GUI. This brings up the GUI that allows us to select time intervals graphically.

The pop up GUI for selecting time intervals graphically

Left click in the main OSPEX window at the point at were we would like to define the start of our time period and left click at the end. Usually you will want to select a large time interval at this step. Once this is done double click in the highlighted interval. A popup menu will appear with various options for breaking up this large interval into smaller intervals. It should appear as below.

The selected time interval(red) along with the menu used to break it into smaller intervals

The large time interval can now be broken into smaller intervals of equal length. The length of each interval in seconds is set in the Select Time Intervals for Analysis widget. In this case 20 seconds was selected. Selecting the 'Break into Sub-Intervals of Equal Length (set in widget)' option from the pop up menu breaks our large time interval into a series of 20 second intervals. Once this is done we select the 'Adjust to Data Boundaries' option then 'Accept' and 'Close'. The 'Adjust to data boundaries' option insures that the newly created time intervals fall on the boundaries of the time bins we selected when creating the spectrum file. We have defined our time intervals for analysis.

The fit intervals can also be set directly from the command line as follows
o->set, spex_fit_time_interval=[ ['21-Apr-2002 00:56:40', '21-Apr-2002 00:57:00'], $
['21-Apr-2002 00:57:00', '21-Apr-2002 00:57:20'], $
['21-Apr-2002 00:57:40', '21-Apr-2002 00:58:00'] ]
Any number of intervals can be defined by the user. The above is an example of defining three intervals.

Spectral Fitting

Now we are ready to begin fitting. The first step is to select an interval. We do this by picking an interval from the list that appears in the top right hand panel of the ‘Fit Options’ GUI (see below). After selecting an interval from the list we have created, select the 'Plot Spectrum' button in the lower panel of the GUI. A plot of the count flux v. energy will appear in the main OSPEX GUI.

Selecting a Time Interval to Fit
Plot of the Spectrum(white) of the interval to be fit along with the selected background(purple)

Now we are ready to fit this interval. To start we select the ‘Do Fit’ button at the bottom of the ‘Fit Options’ GUI. The ‘Choose Fit Function Components and Set Parameters’ GUI appears. This is where we will set up our fit function and do our fit. The first thing we need to do is select our fit function components. By default the component for a single temperature thermal fit (vth) appears in the GUI. Clicking on the arrow next to the drop down list of components labeled ‘Choose’ at the top of GUI shows the complete list of available fit components, to select a component choose it from the list and click the ‘Add’ button to the right of the drop down list. In this case we’ve selected the single broken power law component ( bpow) and a component which modifies the detector response matrix (drm_mod) in addition to vth.

The Fit Function Setup with components chosen and starting parameters adjusted

Before we do the fit we must start adjusting parameters to set it up. The first pair of decisions we need to make are the energy range we would like to fit and which parameters we want to allow to vary (free parameters) during the fit. To select the energy range select the ‘Change’ button next to ‘Energy range(s) to Fit’ near the bottom of the GUI. A text window will appear labeled ‘XTEXTEDIT’, simply enter the energy range you would like to fit. In this case we choose ‘6.0 to 40.0’. We can decide on this energy range by noting that are we in the A1 attenuator state. That means that many counts below ~6keV are due to K-escape and are not the result of the incident photon spectrum, hence we set the low end of our energy range at 6keV. We set the high end of our energy range by determining where our data returns to the background level. In this case that occurs around 40keV. The energy range can also be set by checking the 'Auto-set Max' box next to the change button. This will change the upper limit of the energy range fit to the nearest 10keV of where the data returns to the background level with a minimum value of 20keV. For example if this option is selected and the data returns to the background level at 37keV the upper limit is set to 40keV, if the data returns to the background level at 12keV it is set to 20keV. This is a useful option when looping through intervals since the energy range we would like to fit can vary as a function of time or interval number. This option will not set the lower limit of the energy range. This must still be done manually.

Now we have to decide which parameters we will allow to vary during the fit (free parameters) and which will be fixed. We do this by setting the value of each parameter to 1 (free) or 0 (fixed) in the last column of each line of the fit components. For vth we can set all parameters as free. In general when modeling the thermal contribution to the spectrum the Emission Measure and Temperature are allowed to vary, in cases where the Fe line is visible above the continuum and the energy range we are fitting includes the line we can also allow to Fe abundance to vary. When using bpow we generally fix the power law index below the break (A1) to 1.5. This is a convention that was adopted to prevent the energy from non-thermal electrons from becoming infinite in the thermal part of the spectrum. The other parameters are all allowed to vary. These consist of the normalization (A0), the break energy (A2), and the power law index above the break (A3). Finally in this model we use drm_mod to account for the changes in detector resolution (A0) and gain (A1) over time. Now we need to select reasonable starting parameters. Generally we can adjust any parameters until we have a reasonable approximation of the data. An important idea to keep in mind is that the values of the parameters should be physically meaningful. Using the fit function components we have selected there are some basic guidelines we can follow. The thermal component (vth in this case) will usually model the spectrum to approximately 20keV – 25keV. We can adjust the Emission Measure (A0), and the Temperature (A1), to model the spectrum to these energies. The broken power law (bpow) can then be adjusted to model the spectrum in energies above the thermal region. It is generally sufficient to start drm_mod at the default parameters for all values and then allow the values to vary during the fit. Once this is done we are ready to attempt the fit. To do this select the ‘Fit’ button at the bottom of the ‘Choose Fit Function Components and Set Parameters’ GUI.

The spectrum with the fit components after doing fit(upper panel) along with the residuals for the fit(lower panel)

The image above shows the result of doing a RHESSI fit with our simple model. Notice that the free parameters have changed values from their original starting points. The final values produced the lowest reduced Chi-squared value that this particular model could converge to given our selection of starting parameters. The residuals show us a representation of how far the model was from the data in any energy bin. This representation is in standard deviations from the data. The residuals can give key information about systematic problems with the fit. Any patterns in the residuals can reveal short comings of the model or a poor choice of choice of starting parameters. If we are satisfied with our fit we can select the 'Accept' button on the lower right of the GUI and choose 'and continue'. Our fit will be stored in this session. We have completed all steps necessary to fit a single interval with a function starting with a RHESSI spectrum and SRM file.

To plot the data minus the background in a selected time interval along with the background spectrum from the command line:
o->plot_spectrum, /bksub, /overlay_back, spex_units = 'flux', this_interval = 62
There are many keywords available with the plot_spectrum method. Some are listed here
The fit function can be set from the command line by:
o->set, fit_function = 'vth+bpow+drm_mod'

To set the free and fixed parameters the following is used:
o->set, fit_comp_free = [1,1,1,1,0,1,1,1,1,0]
Each parameter in the array is set to 1 if the parameter is free or 0 if it is fixed. The parameters are listed in the order they appear in the fit function. Once this is done, the setting for the model component vth must be set as well:
o->set, fit_comp_spectrum=['full', ", "]
o->set, fit_comp_model=['chianti', ", "]
Note that after setting the values of fit_comp_spectrum and fit_comp_model for vth, two additional blank strings are included in the array. This is because OSPEX expects a value for each component. In this case the value for bpow and drm_mod, the 2nd and 3rd components are set as blanks because using the full thermal spectrum with the CHIANTI model does not affect them.
Now set the value of the starting parameters:
o->set, fit_comp_param = [.06,1.9,1.0,3.0,1.5,18.0,5.0,1.0,0.0,1.0]
Once again this is done in the order the parameters appear in model.
To do the fit:
o-> dofit, /all
Another example of doing this with the GUI or command line can be found here, including additional keywords for different fitting options.

Fitting Multiple Intervals and Saving Fits

Once a single interval has been fit we may want to fit a series of intervals to see how the fit parameters vary over time. The Fitting multiple intervals document covers this process. We may also also want to save our fits and settings at this point or after doing multiple fits. The procedure for saving your session is describe in Saving Results and Settings section.

Personal tools