The Origin Forum
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: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
vrh25 Posted - 05/18/2024 : 3:09:40 PM
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:


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:


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
1   L A T E S T    R E P L I E S    (Newest First)
ChaoC Posted - 05/20/2024 : 10:30:30 AM
Hello,

You can call the LabTalk X-function pa.
See: https://my.originlab.com/forum/topic.asp?TOPIC_ID=48306

Best,
Chao

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000