File Exchange
Try Origin for Free
The Origin Forum
Home
|
Profile
|
Register
|
Active Topics
|
Members
|
Search
|
FAQ
|
Send File to Tech support
All Forums
Origin Forum for Programming
Forum for Python
Efficient Multiple Peak Decomposition
Note:
Only the poster of this message, and the Moderator can edit the message.
Screensize:
640 x 480
800 x 600
1024 x 768
1280 x 1024
UserName:
Password:
Anti-Spam Code:
Format Mode:
Basic
Help
Prompt
Format:
Font
Andale Mono
Arial
Arial Black
Book Antiqua
Century Gothic
Comic Sans MS
Courier New
Georgia
Impact
Lucida Console
Script MT Bold
Stencil
Tahoma
Times New Roman
Trebuchet MS
Verdana
Size
1
2
3
4
5
6
Color
Black
Red
Yellow
Pink
Green
Orange
Purple
Blue
Beige
Brown
Teal
Navy
Maroon
LimeGreen
Forum:
Forum for Python
Subject:
Message:
* HTML is OFF
*
Forum Code
is ON
Smilies
Origin Ver. and Service Release (Select Help-->About Origin): 10.1.0.170 (Learning Edition) Operating System: windows 11 Hi, I am trying to use the originpro package in the OriginPro embedded Python console to decompose spectroscopy data into 4 curves. Let me start by saying I tried to set this up on my own and there could easily be a problem with how I am using the embedded Python console (I bet something is not installed somewhere or not updated). I have one column of x-data and several y-data columns so I want to set up some way that I can iteratively go about this instead of having to do a lot of clicking each time. Here is an image: [img=800x600]https://my.originlab.com/ftp/forum_and_kbase/Images/ramanDataImage.png[/img] The goal for each column (after the first which is the x data) is to first offset/baseline the data and then fit it to 4 voigt curves. I know this can be done by going through manually and clicking each curve, but we have so much data that I'd love to be able to write a script to go through the motions instead. Here is what the graph looks like after doing it manually: [img=600x450]https://my.originlab.com/ftp/forum_and_kbase/Images/finishedExample.png[/img] I attempted to build my own fitting function and then the idea was to simply call that repeatedly in the script but it had the data being fitted to just one curve with 4 times as many variables. For that function I had the definition written as: "y = nlf_voigt(x, y0, xc1, A1, wG1, wL1) + nlf_voigt(x, y0, xc2, A2, wG2, wL2) + nlf_voigt(x, y0, xc3, A3, wG3, wL3) + nlf_voigt(x, y0, xc4, A4, wG4, wL4);" where the x is always the first column, and then y0 is updated as we go through the data sets. After some research I thought it best to put it under PWF and list the function type as Origin C, I also tried another way with the function still listed under PWF but as a Python Function (Vector) instead which was defined like so: "y = VoigtPython(x, y0, xc1, A1, wG1, wL1, xc2, A2, wG2, wL2, xc3, A3, wG3, wL3, xc4, A4, wG4, wL4);". Neither had much success. In case this is helpful the originpro package I have is 1.1.10, lmfit is 1.3.0. I am obviously open to downloading any other packages that would make this possible, but those are the main two that I really used. Here is the preliminary code I was running in the Code Builder: --------------- import originpro as op import scipy from scipy.optimize import curve_fit import numpy as np # get data from sheet data_raw = op.find_sheet('w', '[convattempt2]converted2') '''cols = data_raw.cols # finds number of cols # converts from worksheet to list of lists (aka basically an array) data = data_raw.to_list2(0, -1, 0, -1) # convergence tolerance tol = 1e-10 # find number of columns in sheet x_data = data[0] y_data = [data[i] for i in range(1, 14)] print(x_data) print("now y") print(y_data)''' # initialize result model = [] iteration = 0 # recursive Voigt fitting for y_curr in range(1, 14): # initial fit and params model.append(op.NLFit("Voigt4")) model[iteration].set_data(data_raw, 0, y_curr) model[iteration].param_box() model[iteration].fit() model[iteration].result() iteration += 1 # print print(model) ------------- The code works in the sense that it goes through all my data and fits them all, but it fits them all to one curve with all four curve variables. I have not been able to find a way to change it so that it makes a new curve for each set of voigt function variables. I was also messing around in solely Python before I tried OriginPro, so there I was not using the originpro embedded package, and I did something similar in that I would build multiple models and then sum them to make the end result but I am not sure how to go about that with this software. Again, somethings may not be installed that would help so if there is anything I should check first that would be instrumental in solving this please let me know and I will check that and/or install it and see how/if that changes things. Thank you! Please let me know if I can do anything to help/clarify. Any help is appreciated! V Hughes
Check here to subscribe to this topic.
The Origin Forum
© 2020 Originlab Corporation
Snitz Forums 2000