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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 Linear Fit with external Python
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

TorbenS

Germany
12 Posts

Posted - 03/24/2021 :  3:08:09 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

一击爆裂陈子豪

Taiwan
41 Posts

Posted - 03/24/2021 :  4:25:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It is not LT_execute(), but lt_exec().
https://www.originlab.com/python/doc/originpro/classoriginpro_1_1base_1_1_base_page.html#a178a2d564ef0e68f140f65e5d5cf0cf5
Go to Top of Page

Chris D

428 Posts

Posted - 03/24/2021 :  4:52:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 03/24/2021 :  6:46:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

TorbenS

Germany
12 Posts

Posted - 03/25/2021 :  05:40:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Chris D

428 Posts

Posted - 03/25/2021 :  08:53:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

TorbenS

Germany
12 Posts

Posted - 03/26/2021 :  05:19:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

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

Best regards,
TorbenS
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000