Miscellaneous ================================= A collection of useful miscellaneous functions, implemented in the ``fredtools.Miscellaneous`` subpackage. General purpose ------------------------------------------------ .. autofunction:: fredtools.mergePDF .. autofunction:: fredtools.getLineFromFile .. autofunction:: fredtools.getHistogram .. autofunction:: fredtools.sigma2fwhm .. autofunction:: fredtools.fwhm2sigma .. autofunction:: fredtools.wrapAngle .. autofunction:: fredtools.roundToMultiple .. autofunction:: fredtools.getCPUNo DICOM UIDs ------------------------------------------------ Functions for reading the UIDs identifying the dicoms and the references between them, and for checking that the dicoms describing a single patient treatment plan are consistent. When many dicoms are to be matched to each other, it is recommended to read them once with ``getDicomsInfo`` and to answer all the consecutive queries from the returned information, instead of calling the ``checkUID_*`` functions for every pair of dicoms. .. autofunction:: fredtools.getDicomsInfo .. autofunction:: fredtools.sortDicomsFromInfo .. autofunction:: fredtools.matchDicomsByUID .. autofunction:: fredtools.getSOPInstanceUID .. autofunction:: fredtools.getFrameOfReferenceUID .. autofunction:: fredtools.getRNReferencedStructureSetUID .. autofunction:: fredtools.getRSReferencedImageUIDs .. autofunction:: fredtools.getRDReferencedPlanUID .. autofunction:: fredtools.checkUID_RNtoRS .. autofunction:: fredtools.checkUID_RStoCT .. autofunction:: fredtools.checkUID_RNtoRD Model fitting ------------------------------------------------ General purpose fitting of a model function to data with the least squares method. The model is an ordinary python function of the positions and of the parameters, and the data can be given as numpy arrays of any dimension (e.g. a profile, a 2D or a 3D array, or a list of points) or as a SimpleITK image, for which the positions are the physical positions of the voxel centers. The parameters can be limited or fixed, and data points can be excluded from the fit with a mask, with a range of the data values, or by setting them to NaN. The excluded points are removed before the fit, so they do not influence the uncertainties of the parameters, but the fitted model is still returned for all the data points, in the format of the input data (an array of the same shape or an image with the same frame of reference). The result of the fit holds the fitted values of the parameters with their uncertainties and can calculate the fitted model and its uncertainty at any positions, quantities derived from the parameters with their uncertainties, and a text summary of the fit. The fit is made with ``scipy.optimize.least_squares``. .. autofunction:: fredtools.fit .. autoclass:: fredtools.fitParam .. autoclass:: fredtools.fitResult() :members: Built-in models ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ready model functions which can be given to ``fredtools.fit``, each with a function guessing the start values of its parameters from the data. The guessed parameters are returned in the form taken by ``fredtools.fit`` and can be changed before the fit, e.g. to fix some of them. The Gaussian models include a constant offset (background), which is fitted by default and can be fixed when its value is known. .. autofunction:: fredtools.modelGauss1D .. autofunction:: fredtools.guessGauss1D .. autofunction:: fredtools.modelGauss2D .. autofunction:: fredtools.guessGauss2D .. autofunction:: fredtools.modelPolynomial .. autofunction:: fredtools.guessPolynomial Landau, Vavilov and Gauss distributions ------------------------------------------------ Functions for calculating and fitting the Landau and Vavilov probability density functions, as well as their convolutions with a Gaussian, useful for instance for fitting energy deposition spectra. .. autofunction:: fredtools.pdfLandau .. autofunction:: fredtools.pdfLandauGauss .. autofunction:: fredtools.pdfVavilov .. autofunction:: fredtools.fitLandau .. autofunction:: fredtools.fitLandauGauss .. autofunction:: fredtools.fitVavilov Logging ------------------------------------------------ FREDtools uses the standard Python logging framework. All the output produced by the functions, including the summaries requested with the ``displayInfo`` argument, is emitted through loggers. The logging verbosity and format can be controlled with the functions below. .. autofunction:: fredtools.configureLogging .. autofunction:: fredtools.getLogger