Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Created August 24, 2022 04:40
Show Gist options
  • Save ZGainsforth/2b6a21ae3df0c85ef39c1ff722d2d398 to your computer and use it in GitHub Desktop.
Save ZGainsforth/2b6a21ae3df0c85ef39c1ff722d2d398 to your computer and use it in GitHub Desktop.
Fityk script file to fit three peaks in an EDS spectrum and output areas. Does all peak simultaneously and includes edge jumps pinned to fluoresence line intensities.
# Fityk script. Fityk version: 1.3.1. Created: Tue Aug 23 16:58:39 2022
set verbosity = -1 #the rest of the file is not shown
set autoplot = 0
reset
# ------------ settings ------------
set box_constraints = 1
set default_sigma = sqrt
set domain_percent = 30
set epsilon = 1e-012
set fit_replot = 0
set fitting_method = levenberg_marquardt
set ftol_rel = 1
set function_cutoff = 0
set guess_uses_weights = 1
set height_correction = 1
set lm_lambda_down_factor = 10
set lm_lambda_start = 0.001
set lm_lambda_up_factor = 10
set lm_max_lambda = 1e+015
set lm_stop_rel_change = 1e-007
set log_output = 0
set logfile = ''
set max_fitting_time = 0
set max_wssr_evaluations = 1000
set nm_convergence = 0.0001
set nm_distribution = bound
set nm_move_all = 0
set nm_move_factor = 1
set numeric_format = '%g'
set on_error = stop
set pseudo_random_seed = 0
set refresh_period = 4
set width_correction = 1
set xtol_rel = 0
# ------------ datasets ------------
@0 < 'P:\Ryugu\A0026-pFIB02\20220508 - TitanX - Ryugu A0026-pFIB02 Flat A\0160 - EDS on Carbon globule, 915s\Bruker Quants\Globule Main.txt' text
use @0
# Name this dataset.
title = 'CNO'
# Set fitting range.
A = x > 0.130 and x < 0.8
# ------------ variables and functions ------------
# HWHM is common to all of CNO edges.
$HWHM = ~0.032
$EnergyShift = 0.02
# Background.
$Bkg_a0 = ~100.0
$Bkg_a1 = ~-100.0
# Three gaussians for fluorescence lines. They can only change amplitude.
$CK_height = ~10.0
$CK_center = 0.259
$NK_height = ~10.0
$NK_center = 0.394
$OK_height = ~10.0
$OK_center = 0.514
# And three edges to go with the fluorescence lines.
# They are not free to vary. Their height is pinned to the fluorescence line heights and only vary in overall intensity.
$EdgeHeight = ~10
$CK_EdgePos = 0.284
$NK_EdgePos = 0.400
$OK_EdgePos = 0.535
# Now place all the model components
%Bkg = Linear($Bkg_a0, $Bkg_a1)
%CK = Gaussian($CK_height, $CK_center, $HWHM)
%NK = Gaussian($NK_height, $NK_center, $HWHM)
%OK = Gaussian($OK_height, $OK_center, $HWHM)
%CKEdge = Sigmoid($EdgeHeight*$CK_height, 0, $CK_EdgePos, $HWHM)
%NKEdge = Sigmoid($EdgeHeight*$NK_height, 0, $NK_EdgePos, $HWHM)
%OKEdge = Sigmoid($EdgeHeight*$OK_height, 0, $OK_EdgePos, $HWHM)
# ------------ models ------------
@0: F = %Bkg + %CK + %NK + %OK + %CKEdge + %NKEdge + %OKEdge
fit @0
plot [0:1] [1:max(y)]
info peaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment