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
 Linear Fit with external Python

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
TorbenS Posted - 03/24/2021 : 3:08:09 PM
Hello,
I am trying to do a linear Fit with external Python. As far as I understood I need to execute a Labtalk Command via obj.LT_execute().
My first question is on which object I need to execute the command. Since I want to fit the data in the plot my first suggestion was to use
plot.obj.LT_execute('fitLR'). But this did not worked out. Did I choose the wrong object or the wrong command or maybe both.
My second question would be if there is a list containing the correct Synthax for such Labtalk commands.

Thanks in advance and best regards!
Torben
6   L A T E S T    R E P L I E S    (Newest First)
TorbenS Posted - 03/26/2021 : 05:19:17 AM
Hello,

thank you for your suggestions. @ Chris D your solution worked fine for me.

Best regards,
TorbenS
Chris D Posted - 03/25/2021 : 08:53:57 AM
Hi,

Currently it is not really possible in pure Python to create a complete linear fit report and fitted curve like the one produced in the Origin GUI.

Your best bet is to create an analysis template with a data sheet, embedded graph, and a fitting from the graph using Origin itself. Then load this analysis template in Python and populate the data sheet.

I assume that you know how to add data to a worksheet. There is an example of a linear fit analysis template here:

C:\Program Files\OriginLab\Origin2021\Samples\Batch Processing\Sensor Analysis.ogwu

In Python, you'd load the analysis template book like this:

# Load analysis template book that ships with Origin.
at = op.load_book(op.path('e') + r'Samples\Batch Processing\Sensor Analysis.ogwu')

# Get 1st worksheet in book.
wks = at[0]

// Populate worksheet

# Wait for analysis operation to complete.
op.wait()



Please let us know if you need more information or help on this.

Thanks,
Chris Drozdowski
Originlab Technical Support
TorbenS Posted - 03/25/2021 : 05:40:41 AM
Hello,
first if all thanks for the fast answers. I will try your different suggestion.

@Chris D: I want generate a fitted curve and a data sheet.

Best regards
TorbenS
cpyang Posted - 03/24/2021 : 6:46:09 PM
See if the following is useful,

import originpro as op
wb = op.new_book()
wks = wb[0]
fn=op.path('e') + 'Samples\Curve Fitting\Linear Fit.dat'
wks.from_file(fn,False)
wb.lt_exec('fitlr (A,D)')
intercept=op.lt_float('fitlr.a')
slope=op.lt_float('fitlr.b')
print(f'slope={slope} intercept={intercept}')


It will fit A(x) D(y).
To find details on the FitLR X-Function, you type into Origin script window

fitlr -h

Any XF execution will create a LabTalk Tree of the same name, so after the fit, you can find the full tree by

firlr.=

from script window.

CP
Chris D Posted - 03/24/2021 : 4:52:14 PM
Hi,

Are you trying to generate a fitted curve and report sheet or do you just want to do a fit and get back slope and intercept.

Thanks,
Chris Drozdowski
Originlab Technical Support
一击爆裂陈子豪 Posted - 03/24/2021 : 4:25:37 PM
It is not LT_execute(), but lt_exec().
https://www.originlab.com/python/doc/originpro/classoriginpro_1_1base_1_1_base_page.html#a178a2d564ef0e68f140f65e5d5cf0cf5

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