Exporting fit parameters to text file (for beginner)

136 views
Skip to first unread message

Aimee Coleman

unread,
Jun 16, 2023, 10:33:30 AM6/16/23
to fityk-users
I am new to coding and looking to export the fit parameters/function variables of two peak fits to a text or CSV file. I want to export height, centre, gwidth1 and 2 and shape 1 and 2 on a split-Voight function fit.

Could someone please explain to me in basic terms how to do this, possibly using the GUI?

I am looking for a way to speed up my data fitting, so I don't have to copy and paste.

Thank you

Guillermo Copello

unread,
Jun 16, 2023, 11:22:14 AM6/16/23
to fityk-users

Hi Aimee,
Once you have fitted your peaks, in the GUI, at the top bar go to "Functions" and select "Export peak parameters".
You will end up with a .peaks file that is basically a txt or csv file that you can open with a simple software such as notepad, xed, kate, etc or even libreoffice calc or excell.
Best regards
Guillermo

Aimee Coleman

unread,
Jun 16, 2023, 11:29:47 AM6/16/23
to fityk-users
Hi Guillermo,

Thank you - that's exactly what I'm looking for.

Best wishes,
Aimee

Jasper Ristkok

unread,
Jun 16, 2023, 12:02:27 PM6/16/23
to fityk-users
Dear Aimee and others with similar task,

In addition to the GUI method I'll share how to do it in code in case somebody has a lot of data. An example can be found here: https://github.com/Tshepajev/fityk-libs-spectra-script/blob/master/analyze_and_plot.lua . More specifically in the function "write_output()" (ctrl + f to find it).

In short the LUA code is off the top of my head:

-- gets table of fitted lines/functions
dataset_index = 0
functions = F:get_components(dataset_index)

-- open file for output (change path)
filename = "/Users/jasper/repos/fityk-libs-spectra-script/Examples/387nm_Mo_example/Output.txt"
file = io.open(filename, "a")
io.output(file)

-- iterate over lines, probably could also use #functions instead of nr_of_lines
nr_of_lines = 2
for  line_index = 1, nr_of_lines, 1 do

-- Reads the variable. Other variables can be accessed by writing their name instead of "height", e.g. "area"
height = functions[line_index]:get_param_value("height")

-- Writes to output file. First fitted line needs special approach
io.write("\t" .. height)

end

-- wrap things up, close file
io.write("\n")
io.close(file)


Cheers!
Jasper
Reply all
Reply to author
Forward
0 new messages