IterativeFitting

Fitting complex spectra

The IterativeFitting function offers a further option for fitting single spectra or entire data cubes. It is particularly suitable for line-rich sources with a large number of molecules and fit parameters. The use of the myXCLASSFit and myXCLASSMapFit function leads to difficulties with sources with many molecules and thus many fit parameters, as sometimes several hundred parameters have to be fitted simultaneously, which requires a lot of computing time and large amounts of memory. The IterativeFitting function now offers the possibility of not optimizing all fit parameters at the same time, but to perform the fitting in an iterative procedure. The IterativeFitting function starts with calculating the contribution of all other molecules for each molecule described in the given molfit file. To do this, the function creates a copy of the molfit file for each molecule and removes the contribution of the current molecule. It then determines the emission and absorption function caused by the other molecules. It is therefore essential that local overlap is also taken into account. In the next step the fit parameters that belong to the current molecule are fitted to the data, whereby the contributions of the other molecules are ensured by taking the emission and absorption functions into account. After completion of the individual molecule fits, a new molfit file is created, which contains the optimized fit parameters from the individual molecule fits. This optimized molfit file is now used as the input file for the next iteration step and the aforementioned procedures are carried out again. This is repeated until the steps specified by the user are reached. Any defined iso ratio and collision partner file are also optimized within each molecule fit and reassembled in a similar way at the end of each iteration step. The IterativeFitting function offers the possibility to create plots describing the fit results at the end of each iteration step and / or at the end of the whole fit procedure. Details of the IterativeFitting are described in Sect. “IterativeFitting”.

Example call of the IterativeFitting function:

>>> from xclass import task_myXCLASSFit
>>> import os

# get path of current directory
>>> LocalPath = os.getcwd() + "/"

# set path and name of molfit file
>>> MolfitFileName = LocalPath + "files/my_molecules.molfit"

# set path and name of observational (obs.) xml file
>>> ObsXMLFileName = LocalPath + "files/my_observation.xml"

# set path and name of algorithm (alg.) xml file
>>> AlgorithmXMLFileOverAll = LocalPath + "files/my_algorithm__trf.xml"

# flag for fast fitting
>>> FastFlag = True

# define number of cores
>>> NumberProcessors = 20

# set number of iterations
>>> LocalNumRep = 1

# set update flag
>>> UpdateFlag = False

# create transition plots at the end of the fitting procedure
>>> DoFinalPlotFlag = True

# call IterativeFitting function
>>> iter_class = task_myXCLASSFit.IterativeFitting( \
                                  MolfitFileName = MolfitFileName, \
                                  ObsXMLFileName = ObsXMLFileName, \
                                  AlgXMLFileName = AlgorithmXMLFileOverAll, \
                                  FastFlag = FastFlag, \
                                  NumberProcessors = NumberProcessors, \
                                  UpdateFlag = UpdateFlag,
                                  NumRep = LocalNumRep, \
                                  DoFinalPlotFlag = DoFinalPlotFlag)