Package ComboCode :: Package cc :: Package statistics :: Module ResoStats :: Class ResoStats
[hide private]
[frames] | no frames]

Class ResoStats

source code


Environment with several tools to perform statistics on the peak and integrated intensities of resolved molecular lines.

Instance Methods [hide private]
 
__init__(self, star_name, code='GASTRoNOoM', path_code='codeJun2013', lll_p=None, use_bestvlsr=1, vmin=0.0, vmax=0.0)
Initializing an instance of IntIntStats.
source code
 
setInstrument(self, sample_transitions)
Set and read the data objects for this statistics module.
source code
 
setIntensities(self)
The data intensities are stored in the dictionary self.dintint/self.dpeakint, the model intensities in self.mintint/self.mpeakint.
source code
(float,float)
calcLoglikelihoodThreshold(self, bfms=[], ist=None)
Determine the loglikelihood thresholds from the model grid, assuming the amount of free parameters in the model grid is known.
source code
 
setNoisy(self, ist, isnoisy)
Set a transition given by its index to be included or excluded in the proper best fit determination, through either integrated or peak Tmbs.
source code
 
resetNoisy(self, factor)
Change criterion for noisy lines.
source code
 
resetLineStrengths(self)
Reset the line strengths of the data and calculate the ratio with model line strengths.
source code
 
includeTrans(self, ist)
Include a transition in selecting the best fit models.
source code
 
excludeTrans(self, ist)
Exclude a transition in selecting the best fit models.
source code
 
listTrans(self)
List all the transitions that have both data and sphinx models associated with them.
source code
 
setUncertainty(self, ist, value)
Change the default uncertainty for a given transition.
source code
 
setLoglikelihoodThreshold(self, ist, value)
Set the loglikelihood below which models are considered best fit models
source code
 
setLLL(self, ist, value)
Convenience method that runs setLogelikelihoodThreshold().
source code
 
printStats(self, bfms=[])
Print the statistics for all transitions and models.
source code
list[Star()]
selectBestFitModels(self, mode='int', use_lll=1, output=1)
Returns a list of Star() models for which the uncertainty criteria are satisfied for the selected transitions.
source code
list[Star()]
selectBestFitModelsLLL(self, output=1)
Same function as selectBestFitModels, but uses only the loglikelihood statistic.
source code
 
findLLLRange(self, includedTrans=1)
Determines whether a model lies within a 95% confidence interval around the best fitting model (per line).
source code
 
selectBestFitperLine(self, use_lll=1, excludevib=1)
Checks which lines are fitted by which models, using all four selection criteria.
source code
 
selectBestFitperLineLLL(self, excludevib=1, plot=0)
Checks which lines are fitted by which models according to the loglikelihood statistic.
source code
 
calcLLL(self, plot=0)
Calculate the loglikelihood function per transition.
source code
 
calcLLLrange(self, plot=0)
Calculate whether the loglikelihood function per transition kies within the confidence interval.
source code
 
calcRatioIntTmb(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0)
Calculate the ratio of the integrated main beam intensity per transition.
source code
 
combineRatioIntLLL(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0) source code
 
makeInput(self, model_array) source code
 
calcRatioPeakTmb(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0)
Calculate the ratio of the peak main beam intensity per transition.
source code
 
calcRatioComboTmb(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0)
Combine the ratio of the integrated and peak main beam intensity per transition.
source code
 
calcChiSquared(self, P=2, useTeleUncertainties=1, useNoisy=1, err=0.2, err_noisy=0.3)
Calculate the (reduced) chi squared of the integrated main beam intensities.
source code
 
plotBestFit(self, plot_int=1, plot_peak=0, plot_combo=0)
Can only be perfomed after self.selectBestFitperLine().
source code
 
printBestFitperLine(self, bfm_int=1, bfm_peak=0, bfm_combo=0, bfm_lll=1)
Print output of selectBestFitperLine(), using fittedLines_bfmxxx.
source code
 
printBestFitperModel(self, bfm_int=1, bfm_peak=0, bfm_combo=0, bfm_lll=1)
Print output of selectBestFitperLine(), using fittedModels_bfmxxx.
source code

Inherited from cc.statistics.Statistics.Statistics: doDataStats, setDataInfo, setModels

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, star_name, code='GASTRoNOoM', path_code='codeJun2013', lll_p=None, use_bestvlsr=1, vmin=0.0, vmax=0.0)
(Constructor)

source code 

Initializing an instance of IntIntStats.

Then run setInstrument, setModels and setIntensities. The rest of the class works interactively.

Parameters:
  • star_name (string) - Star name from Star.dat
  • code (string) - the code used for producing your output

    (default: 'GASTRoNOoM')

  • path_code (string) - Output folder in the code's home folder

    (default: 'codeSep2010')

  • lll_p (int) - The number of variable parameters in the model grid. If None, the automatic loglikelihood determination is not done. You can still set the threshold values with a class bound method.

    (default: None)

  • use_bestvlsr (bool) - Use the fitted best-guess for the v_lsr when determining the velocity grid for the model. If not, the vlsr from the Star.dat file or the fits file is used.

    (default: 1)

  • vmin (float) - The minimum value in km/s of the spectral line window. Ideally this is the same for all lines under consideration. If an invalid spectral window is given (vmax==vmin, or vmin>vmax), the spectral window is taken from the line fit results. This leads to a different window for each line under consideration, and is not recommended for calculating the loglikelihood.

    (default: 0.0)

  • vmax (float) - The maximum value in km/s of the spectral line window. Ideally this is the same for all lines under consideration. If an invalid spectral window is given (vmax==vmin, or vmin>vmax), the spectral window is taken from the line fit results. This leads to a different window for each line under consideration, and is not recommended for calculating the loglikelihood.

    (default: 0.0)

Overrides: object.__init__

setInstrument(self, sample_transitions)

source code 

Set and read the data objects for this statistics module.

In this case, a list of sample transitions in which the data will be read is the only input required.

Make sure sample_transitions are copies of the originals, such as returned by Transition.extractTransFromStars().

Parameters:
  • sample_transitions (list[Transition()]) - Sample transitions used as reference for the data files.
Overrides: cc.statistics.Statistics.Statistics.setInstrument

setIntensities(self)

source code 

The data intensities are stored in the dictionary self.dintint/self.dpeakint, the model intensities in self.mintint/self.mpeakint.

They keys in the dictionaries are the Transition to which the sphinx or datafiles belong.

The model values are lists in accordance with self.star_grid, the data values are single floats for the first dataset for the transition.

In addition, the loglikelihoods are calculated.

calcLoglikelihoodThreshold(self, bfms=[], ist=None)

source code 

Determine the loglikelihood thresholds from the model grid, assuming the amount of free parameters in the model grid is known.

The latter is given by STAT_LLL_P in the CC input.

If a selection of models is given, and the index of a sample transition the max lll of the selection of models and threshold value based on that --- for this sample trans --- are returned. No values are remembered in this case.

Parameters:
  • bfms (list[Star]) - Subselection of models for which the LLL threshold is calculated. If None, ist is ignored, and the LLL threshold is calculated for the whole collection of models, the value for which is saved in self.lll_threshold

    (default: [])

  • ist (int) - If bfms is not an empty list, this gives the index of the sample trans for which the lll threshold is calculated based on subgrid of Star() models, given by bfms. If bfms == [], ist is ignored.

    (default: None)

Returns: (float,float)
The max lll and lll threshold for this sample transistion and subset of models. None if no subset of models was given.

setNoisy(self, ist, isnoisy)

source code 

Set a transition given by its index to be included or excluded in the proper best fit determination, through either integrated or peak Tmbs. The other option is to merely look at the 3 sigma level compared to the model peak value.

By default, the script checks if dtmb is above 3 sigma in the dataset.

Sometimes if dtmb is between 2 sigma and 3 sigma, one may want to include it properly anyway. Also if the peak Tmb determination is not very accurate just because of the noisy data, it may be necessary to include it regardless. This is possible here.

Note that the state of the 'noisiness' has to be included when calling this method. False or True works, of course.

Parameters:
  • ist (int/list) - The index/indices of the transitions to be included.
  • isnoisy (bool) - Is the dataset noisy or not?

resetNoisy(self, factor)

source code 

Change criterion for noisy lines. By default, the script checks if the peak of the line profile is above 3 sigma in the dataset. With this method, the factor can be changed.

The integrated line strengths are also recalculated based on the new criterion.

Parameters:
  • factor (int) - Sigma level. If the peak intensity of a line is below this level, it is marked as noisy.

resetLineStrengths(self)

source code 

Reset the line strengths of the data and calculate the ratio with model line strengths. Also recalculate the loglikelihood in this case.

The fitted line profile is used in case the line is flagged as noisy by setting use_fit. The fit is either a gaussian or a parabolic fit as determined by LPTools.fitLP

includeTrans(self, ist)

source code 

Include a transition in selecting the best fit models.

By default, all transitions that have data and sphinx models associated with them are selected.

Use the index of the transition to include them.

Parameters:
  • ist (int/list) - The index/indices of the transitions to be included.

excludeTrans(self, ist)

source code 

Exclude a transition in selecting the best fit models.

By default, all transitions that have data and sphinx models associated with them are selected.

Use the index of the transition to exclude them.

Parameters:
  • ist (int/list) - The index/indices of the transitions to be included.

listTrans(self)

source code 

List all the transitions that have both data and sphinx models associated with them.

Can be used to figure the index of each transition so you can in- or exclude them.

Also indicates whether it is a noisy line or not.

setUncertainty(self, ist, value)

source code 

Change the default uncertainty for a given transition.

Makes use of the template transition index! (see listTrans method)

The value is given as a decimal number, i.e. x% / 100.

Parameters:
  • ist (int) - The index of transition
  • value (float) - The new uncertainty requested

setLoglikelihoodThreshold(self, ist, value)

source code 

Set the loglikelihood below which models are considered best fit models

Makes use of the template transition index!

An automatically calculated value is determined as well from the lll values of all models. This assumes the amount of variable parameters in the model grid is known, and set through the CC input! (STAT_LLL_P)

Parameters:
  • ist (int) - The index of transition
  • value (float) - The new loglikelihood threshold requested

setLLL(self, ist, value)

source code 

Convenience method that runs setLogelikelihoodThreshold().

Parameters:
  • ist (int) - The index of transition
  • value (float) - The new loglikelihood threshold requested

printStats(self, bfms=[])

source code 

Print the statistics for all transitions and models.

Parameters:
  • bfms (list[Star]) - A list of a subselection of Star() models. If specified only the models in this list will be printed.

    (default: [])

selectBestFitModels(self, mode='int', use_lll=1, output=1)

source code 

Returns a list of Star() models for which the uncertainty criteria are satisfied for the selected transitions.

Transitions can be selected or deselected by the includeTrans and excludeTrans methods.

The uncertainty criteria are preset but can be changed by the setUncertainty method.

Note that for lines in which the peak Tmb is less than 3*sigma, the goodness of fit is determined based on the comparison between peak of sphinx model and the 3*sigma level. Less: included, more: excluded. Note that the sphinx peak values are scaled down by the uncertainty on the data, to take into account data uncertainties as well.

Parameters:
  • mode (string) - The mode for model selection. Include: int, peak, combo int: based on the integrated intensity ratios, peak: based on the peak intensity ratios combo: Based on both

    (default: 'int')

  • use_lll (bool) - Also use the loglikelihood statistics in selecting best fit models. For this it is required to set a threshold loglikelihood value: Anything smaller than this is included in the best fit model list. Use the setLoglikelihoodThreshold() or setLLL()

    (default: 1)

Returns: list[Star()]
The 'best fitting' Star() models according to the uncertainty criteria.

selectBestFitModelsLLL(self, output=1)

source code 

Same function as selectBestFitModels, but uses only the loglikelihood statistic.

Returns: list[Star()]
The 'best fitting' Star() models according to the loglikelihood statistic.

findLLLRange(self, includedTrans=1)

source code 

Determines whether a model lies within a 95% confidence interval around the best fitting model (per line). As the best fitting model is included in the arrays, at least one model within the range is to be expected.

Based on Decin et al. 2007:

  • l_m \leq l \leq l_m - quant/2
  • l_m \leq l \leq lll_threshold

The 'output' is divided into three components. * Dictionary confidenceLLL (transitions as keywords) Gives the difference between the calculate loglikelihood and the threshold value * Dictionary condidenceLLL_verdict (transitions as keywords) Contains the result (1 or 0) for every model per transition * Array confidenceLLL_models Models that fit all included transitions

selectBestFitperLine(self, use_lll=1, excludevib=1)

source code 

Checks which lines are fitted by which models, using all four selection criteria. For every criterion, a list 'ocurrences_bfmxxx' is made. This list contains a sublist for each model, len(list) = # models. Every sublist contains a one or zero, indicating wether a line is fitted by the model according to the criterion, len(sublist) = # lines.

The lists fittedLines_bfmxxx contain how often a line was modelled according to the criterion, len(list) = # lines.

The lists fittedModels_bfmxxx contain the number of lines each model fitted according to the criterion, len(list) = # models.

selectBestFitperLineLLL(self, excludevib=1, plot=0)

source code 

Checks which lines are fitted by which models according to the loglikelihood statistic. A list 'ocurrences_bfmlll' is made. This list contains a sublist for each model, len(list) = # models. Every sublist contains a one or zero, indicating wether a line is fitted by the model according to the criterion, len(sublist) = # lines.

The list fittedLines_bfmlll contains how often a line was modelled according to the criterion, len(list) = # lines.

The list fittedModels_bfmlll contains the number of lines each model fitted according to the criterion, len(list) = # models.

calcLLL(self, plot=0)

source code 

Calculate the loglikelihood function per transition. Output similar to that of calcRatioxxxTmb.

Output can be found in: * Dictionary line_lll: dictionary containing whether a line satisfies the condition or not. One list per transition, each list containing the verdict per model. * List model_lll: list containing the verdict per transition, per model. Number of lists = number of models. Length of each list = number of transitions. * List verdict_model_lll: list containing the verdict per transition, per model. Number of lists = number of models. Each list contains a single number.

calcLLLrange(self, plot=0)

source code 

Calculate whether the loglikelihood function per transition kies within the confidence interval. Output similar to that of calcRatioxxxTmb.

Output can be found in: * Dictionary line_lll_range: dictionary containing whether a line satisfies the condition or not. One list per transition, each list containing the verdict per model. * List model_lll_range: list containing the verdict per transition, per model. Number of lists = number of models. Length of each list = number of transitions. * List verdict_model_lll_range: list containing the verdict per transition, per model. Number of lists = number of models. Each list contains a single number.

calcRatioIntTmb(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0)

source code 

Calculate the ratio of the integrated main beam intensity per transition.

Parameters:
  • useNoisy (bool) - assign a larger error to noisy lines
  • useRms (bool) - use statistical noise in addition to instrumental error
  • err (float) - error on data
  • err_noisy (float) - error on noisy data (only needed when useNoisy = 1)
  • plot (bool

    Output can be found in: * Dictionary verdict_ratioint: dictionary containing whether a line satisfies the condition or not. One list per transition, each list containing the verdict per model. * List model_ratioint: list containing the verdict per transition, per model. Number of lists = number of models. Length of each list = number of transitions. * List model_ratioint_verdict: list containing the verdict per transition, per model. Number of lists = number of models. Each list contains a single number.

    ) - Plot the output

calcRatioPeakTmb(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0)

source code 

Calculate the ratio of the peak main beam intensity per transition.

Parameters:
  • useNoisy (bool) - assign a larger error to noisy lines
  • useRms (bool) - use statistical noise in addition to instrumental error
  • err (float) - error on data
  • err_noisy (float

    Output can be found in: * Dictionary verdict_ratiopeak: dictionary containing whether a line satisfies the condition or not. One list per transition, each list containing the verdict per model. * List model_ratiopeak: list containing the verdict per transition, per model. Number of lists = number of models. Length of each list = number of transitions. * List model_ratiopeak_verdict: list containing the verdict per transition, per model. Number of lists = number of models. Each list contains a single number.

    ) - error on noisy data (only needed when useNoisy = 1)

calcRatioComboTmb(self, useNoisy=1, useRms=0, err=0.2, err_noisy=0.3, plot=0)

source code 

Combine the ratio of the integrated and peak main beam intensity per transition.

Parameters:
  • useNoisy (bool) - assign a larger error to noisy lines
  • useRms (bool) - use statist. noise in addition to instrumental error
  • err (float) - error on data
  • err_noisy (float

    Output can be found in: * Dictionary verdict_ratiocombo: dictionary containing whether a line satisfies the condition or not. One list per transition, each list containing the verdict per model. * List model_ratiocombo: list containing the verdict per transition, per model. Number of lists = number of models. Length of each list = number of transitions. * List model_ratiocombo_verdict: list containing the verdict per transition, per model. Number of lists = number of models. Each list contains a single number.

    ) - error on noisy data (only needed when useNoisy = 1)

calcChiSquared(self, P=2, useTeleUncertainties=1, useNoisy=1, err=0.2, err_noisy=0.3)

source code 

Calculate the (reduced) chi squared of the integrated main beam intensities.

Output can be found in:

  • list chiSquared: Chi squared values of each model
  • list redChiSquared: Reduced chi squared values of each model
  • float errRedChiSquared: Error on reduced chi squared
  • list redChiSquaredWithinThreeSigma: Models that have a reduced chi squared within three sigma of the best model (ie the model with the lowest reduced chi squared)
Parameters:
  • P (int) - Degrees of freedom = len(data) - P
  • useTeleUncertainties (bool) - Use telescope uncertainties instead of a fixed error.
  • useNoisy (bool) - Use a higher uncertainty for noisy lines
  • err (float) - Fixed uncertainty on lines (if not telescope uncertainties)
  • err_noisy (float) - Uncertainty on noisy lines

plotBestFit(self, plot_int=1, plot_peak=0, plot_combo=0)

source code 

Can only be perfomed after self.selectBestFitperLine().

Visualization of self.occurences_bfm(mode), self,verdict_(mode)_soft, and self.occurences_bfmlll.