Package ComboCode :: Package cc :: Package data :: Module LPTools
[hide private]
[frames] | no frames]

Module LPTools

source code

Some tools for measuring line profiles of emission lines.

Author: R. Lombaert

Functions [hide private]
(float,float)
readTelescopeProperties(telescope)
Read the telescope properties from Telescope.dat.
source code
LPDataReader()
readLineProfile(filename)
Read a line profile, independent of the type of extension.
source code
float
integrateLPData(vexp, filename=None, lprof=None, window=1.2)
Integrate a line profile read from a fits file or a txt file.
source code
float
getPeakLPData(filename=None, lprof=None, vlsr=None, method='mean', npoints=5)
Calculate the peak value of a line profile read from a fits file or a txt file.
source code
float
getLPDataFWHM(lprof)
Calculate the FWHM of the line profile.
source code
funclib.soft_parabola
varyInitialFit(vel, flux, initial, index, values, vary, function=<function soft_parabola at 0x1091905f0>, vary_window=0)
Fit a function to a line profile for different initial guesses of a single parameter.
source code
funclib.function() (some function)
fitFunction(x, y, initial, function, vary)
Fit a function to a set of x and y values.
source code
tuple(float)
checkLPShape(vel, flux, vlsr, vexp, window=2.0, show=0)
Check the shape of the line profile, to see if any irregular patterns are present.
source code
dict[float,float,float,float,funclib.Function(), funclib.Function(),funclib.Function()]
fitLP(filename=None, lprof=None, theory=0, show=0, cfg='', convert_ms_kms=0, vary_pars=['vexp'], i_vexp=15.0, i_gamma=1.0, do_gauss=0)
Fit a line profile with a soft parabola, and a Gaussian component if required.
source code
Variables [hide private]
  __package__ = 'ComboCode.cc.data'
Function Details [hide private]

readTelescopeProperties(telescope)

source code 

Read the telescope properties from Telescope.dat.

This currently includes the telescope size in m, and the default absolute flux calibration uncertainty.

Parameters:
  • telescope (str) - The telescope requested
Returns: (float,float)
The telescope size and absolute flux calibration uncertainty

readLineProfile(filename)

source code 

Read a line profile, independent of the type of extension.

Parameters:
  • filename (string) - The filename to the data file of the line profile. If None a line profile object is expected.

    (default: None)

Returns: LPDataReader()
The line profile

integrateLPData(vexp, filename=None, lprof=None, window=1.2)

source code 

Integrate a line profile read from a fits file or a txt file.

Requires a terminal expansion velocity to determine the window in which the integration is done.

If a fits file is read, the source velocity is taken from it (if available) If a text file is read, a source velocity needs to be given as input.

Parameters:
  • vexp (float) - The terminal gas velocity
  • filename (string) - The filename to the data file of the line profile. If None a line profile object is expected.

    (default: None)

  • lprof (LPDataReader()) - A line profile object (LPDataReader or inheriting classes) If None, a filename is expected!

    (default: None)

  • window (float) - The factor with which vexp is multiplied when selecting the integration window in the velocity grid.

    (default: 1.2)

Returns: float
The integrated intensity of the profile

getPeakLPData(filename=None, lprof=None, vlsr=None, method='mean', npoints=5)

source code 

Calculate the peak value of a line profile read from a fits file or a txt file.

If a fits file is read, the source velocity is taken from it (if available) If a text file is read, a source velocity needs to be given as input.

The peak value is defined as the mean of central 5 flux points around the source velocity.

Parameters:
  • filename (string) - The filename to the data file of the line profile. If None a line profile object is expected.

    (default: None)

  • lprof (LPDataReader()) - A line profile object (LPDataReader or inheriting classes) If None, a filename is expected!

    (default: None)

  • vlsr (float) - If you want to provide your own vlsr for some reason. Leave as default if you don't have a good reason to do that.

    (default: None)

  • method (str) - The method applied: either 'mean' or 'fit'. Mean derives the peak value from the mean of the npoints flux points around the vlsr. Fit takes the central peak flux at from the fit.

    (default: 'mean')

  • npoints (int) - The number of points around vlsr used for deriving the peak value via the mean method.

    (default: 5)

Returns: float
The peak intensity of the profile

getLPDataFWHM(lprof)

source code 

Calculate the FWHM of the line profile.

Parameters:
  • lprof (LPDataReader()) - the line profile object.
Returns: float
the fwhm of the line

varyInitialFit(vel, flux, initial, index, values, vary, function=<function soft_parabola at 0x1091905f0>, vary_window=0)

source code 

Fit a function to a line profile for different initial guesses of a single parameter.

The best fit function is returned. Best fit is determined by checking for the smallest relative error for the parameter in question.

Parameters:
  • vel (array) - The velocity grid
  • flux (array) - The intensity grid
  • initial (list) - initial parameters (eg [int,vlsr,vexp,gamma] for sp)
  • index (int) - Index of initial parameter to be varied
  • values (tuple) - The values used for the variable initial parameter
  • vary (list[bool]) - Allow initial parameter to be changed in fitting process. Must have same length as initial.
  • function (funclib.function) - The function to be fitted

    (default: funclib.soft_parabola)

  • vary_window (bool) - Vary the velocity window based on the third initial parameter. 1.5 for soft parabola, 3 for other functions centered on the second initial parameter. (mu/vlsr and sigma/vexp respectively)

    (default: 0)

Returns: funclib.soft_parabola
The model after minimization

fitFunction(x, y, initial, function, vary)

source code 

Fit a function to a set of x and y values.

Parameters:
  • x (array) - The x grid
  • y (array) - The y grid
  • initial (list) - initial parameters
  • function (funclib.function (e.g. funclib.soft_parabola,funclib.gauss)) - The function to be fitted
  • vary (list[bool]) - Allow initial parameter to be changed in fitting process. Must have same length as initial.
Returns: funclib.function() (some function)
The model after minimization

checkLPShape(vel, flux, vlsr, vexp, window=2.0, show=0)

source code 

Check the shape of the line profile, to see if any irregular patterns are present.

Based on the diff() method, and the std on the result of it. If sharp patterns are present, they should be picked up by this method, and an extra component can be included in fitting the line.

Detects absorption irregularities, not emission! At least, it tries to filter the emission effects out. If an emission effect is stronger than an absorption effect, it should also not detect any irregularities.

Currently checks whether a strong downward trend in the flux is associated with a strong upward trend, within a window of 6 km/s. Broader "absorption detections" are unlikely, since ISM absorption lines should not have a line width that is broader than, e.g., 3 km/s (i.e. turbulent velocity).

Still being tested!

Parameters:
  • vel (array) - The velocity grid
  • flux (array) - The flux grid
  • vlsr (float) - the central source velocity
  • vexp (float) - The expected gas terminal velocity
  • window (float) - The window for line selection. Value is multiplied with
    1. For the usual window of 2., this is 1.2 (SP). For the Gaussian window of 3., this is 1.8.

      (default: 2.)

  • show (bool) - Show the results of the diff and std methods.

    (default: 0)

Returns: tuple(float)
The details of the absorption irregularity. Assuming a Gaussian, a depth, mid point velocity, a width and a continuum value are returned. If no irregularity is found, None is returned

fitLP(filename=None, lprof=None, theory=0, show=0, cfg='', convert_ms_kms=0, vary_pars=['vexp'], i_vexp=15.0, i_gamma=1.0, do_gauss=0)

source code 

Fit a line profile with a soft parabola, and a Gaussian component if required.

The method automatically checks if a second component is needed (eg an extra absorption component). An estimate of the expansion velocity (width of the profile) and an improved guess of the vlsr are given.

A guess for the gas terminal velocity is returned, as well as its error and the fitted profile (sp/gaussian, and if applicable extra gaussian and the full fit).

Parameters:
  • filename (string) - The filename to the data file of the line profile. If None a line profile object is expected.

    (default: None)

  • lprof (LPDataReader()) - A line profile object (LPDataReader or inheriting classes) If None, a filename is expected! If not None, the results are saved in this object as well as returned upon method call

    (default: None)

  • convert_ms_kms (bool) - Convert velocity grid from m/s to km/s.

    (default: 0)

  • theory (bool) - If theoretical profile, and filename is given, set vlsr to 0 and read two columns. lprof not relevant if True.

    (default: 0)

  • vary_pars (list[string]) - The soft parabola parameters varied (can only be vexp or gamma for now). The initial values for parameters listed here are not used. If 'gamma' is requested, a reasonable guess for i_vexp when calling the method will improve the fitting results. This is done for the first guess only! If a Gaussian absorption is present improving these first guesses won't make much of a difference. However, the first guess value for gamma is still used. Vexp is always varied if absorption is present.

    (default: ['vexp'])

  • i_vexp (float) - The initial guess for the expansion velocity. Not relevant if vexp is included in vary_pars.

    (default: 15.0)

  • i_gamma (float) - The initial guess for the gamma parameter of soft parab. Not relevant if gamma is included in vary_pars.

    (default: 1.0)

  • do_gauss (bool) - Force a Gaussian fit regardless of soft parabola fit results. Still does the soft parabola fit first to allow for comparison of parameters.

    (default: 0)

  • show (bool) - Show the results of the fit

    (default: 0)

Returns: dict[float,float,float,float,funclib.Function(), funclib.Function(),funclib.Function()]
dictionary including [vexp,evexp,gamma,egamma,fitprof,gaussian, fullfit,dintint,fgintint]