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
 Origin Forum
 Import matrix text file to a matrix object
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AKazak

Russia
1205 Posts

Posted - 07/19/2021 :  08:45:07 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2021b (64-bit) SR2 9.8.5.212
Windows 10 21H1 x64

Greetings!

The laboratory setup generates the following text file in a matrix format. Each file holds a separate data map.
https://my.originlab.com/ftp/forum_and_kbase/Images/AlK_1.csv

What is the suggested way to import each file from the set to the individual matrix object?
Can Single/Multi ASCII Import Wizard handle this file structure?

Thank you.

---
Andrey

Edited by - AKazak on 07/19/2021 09:59:29 AM

easwar

USA
1965 Posts

Posted - 07/19/2021 :  2:04:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrey,

Currently the GUI does not support this. We can however provide Python code to import the data.

Can you send us a set of files or a link to a zip file for a set of files?

If sending the files, you can attach to a new ticket as a zip file:
https://www.originlab.com/restricted/support/newticket.aspx?c=3

Thank you,

Easwar
OriginLab
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/19/2021 :  2:21:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by easwar

Hi Andrey,

Currently the GUI does not support this. We can however provide Python code to import the data.

Can you send us a set of files or a link to a zip file for a set of files?

If sending the files, you can attach to a new ticket as a zip file:
https://www.originlab.com/restricted/support/newticket.aspx?c=3

Thank you,

Easwar
OriginLab



Dear Easwar,

Done!
Ticket ID is Originlab_REQ00018442_20210719.
It would be great to name matrix objects as per file name without extension.
By the way, please note that matrix should be transposed before import. The correct image dimensions are 512 columns and 400 rows.

---
Andrey
Go to Top of Page

YimingChen

1640 Posts

Posted - 07/19/2021 :  4:48:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you try the Python code below?

import originpro as op
import pandas as pd
import numpy as np


fileList = ['AlK_1','AlK_2']
data = None
for file in fileList:
    df = pd.read_csv(f'C:\\Users\\yiming\\Documents\\OriginLab\\User Files\\{file}.csv', index_col=0, header=3)
    dt = np.transpose(df.values)
    dd = np.expand_dims(dt, axis=0)
    if data is None:
        data = dd
    else:
        data = np.concatenate((data,dd), axis=0)  

print(data.shape)
ws=op.new_sheet('m','[Book1]BTest')
ws.from_np(data)

for i, nm in enumerate(fileList):
    ws.set_label(i, nm)


James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/20/2021 :  10:31:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Can you try the Python code below?

import originpro as op
import pandas as pd
import numpy as np


fileList = ['AlK_1','AlK_2']
data = None
for file in fileList:
    df = pd.read_csv(f'C:\\Users\\yiming\\Documents\\OriginLab\\User Files\\{file}.csv', index_col=0, header=3)
    dt = np.transpose(df.values)
    dd = np.expand_dims(dt, axis=0)
    if data is None:
        data = dd
    else:
        data = np.concatenate((data,dd), axis=0)  

print(data.shape)
ws=op.new_sheet('m','[Book1]BTest')
ws.from_np(data)

for i, nm in enumerate(fileList):
    ws.set_label(i, nm)


James



Dear James,

I see few issues.

1) The core returns matrix 512 by 401, that is one row more than it should be; the additional row is full of NaN values.

2) How do I specify Short and Long book Names in op.new_sheet('m','...') command?

3) How do I command to show Image Selector from the Python code?

4) How do I transpose the final matrix sheet instead of transposing each input matrix object?

Thank you.

---
Andrey
Go to Top of Page

YimingChen

1640 Posts

Posted - 07/20/2021 :  12:01:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please see the code below that has addressed question 1,2,3. For 4) what do you mean by transpose the sheet? Current code transposes the matrix of each file before being put to a matrix object.

import originpro as op
import pandas as pd
import numpy as np


fileList = ['AlK_1','AlK_2']
data = None
for file in fileList:
    df = pd.read_csv(f'C:\\Users\\yiming\\Documents\\OriginLab\\User Files\\{file}.csv', index_col=0, header=3)
    df = df.dropna(axis=1)
    
    # get x range
    xvals = [int(i) for i in df.columns.tolist()]
    x1 = xvals[0]
    x2 = xvals[len(xvals)-1]
    
    # get y range
    yvals = [int(j) for j in df.index.tolist()]
    y1 = yvals[0]
    y2 = yvals[len(yvals)-1]
    
    # build input 2D array    
    dt = np.transpose(df.values)
    dd = np.expand_dims(dt, axis=0)
    if data is None:
        data = dd
    else:
        data = np.concatenate((data,dd), axis=0)  

mb = op.new_book('m','Long_Name')
mb.name = 'Short_Name'
ms = mb[0]

ms.from_np(data.astype('float'))
ms.xymap = y1, y2, x1, x2
ms.show_thumbnails()

for i, nm in enumerate(fileList):
    ms.set_label(i, nm)


James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/20/2021 :  12:14:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Please see the code below that has addressed question 1,2,3. For 4) what do you mean by transpose the sheet? Current code transposes the matrix of each file before being put to a matrix object.

import originpro as op
import pandas as pd
import numpy as np


fileList = ['AlK_1','AlK_2']
data = None
for file in fileList:
    df = pd.read_csv(f'C:\\Users\\yiming\\Documents\\OriginLab\\User Files\\{file}.csv', index_col=0, header=3)
    df = df.dropna(axis=1)
    
    # get x range
    xvals = [int(i) for i in df.columns.tolist()]
    x1 = xvals[0]
    x2 = xvals[len(xvals)-1]
    
    # get y range
    yvals = [int(j) for j in df.index.tolist()]
    y1 = yvals[0]
    y2 = yvals[len(yvals)-1]
    
    # build input 2D array    
    dt = np.transpose(df.values)
    dd = np.expand_dims(dt, axis=0)
    if data is None:
        data = dd
    else:
        data = np.concatenate((data,dd), axis=0)  

mb = op.new_book('m','Long_Name')
mb.name = 'Short_Name'
ms = mb[0]

ms.from_np(data.astype('float'))
ms.xymap = y1, y2, x1, x2
ms.show_thumbnails()

for i, nm in enumerate(fileList):
    ms.set_label(i, nm)


James



Dear James,

Great code!
Thank you.

Can you suggest a way to create a new matrix sheet in an active matrixbook instead of creating a new matrixbook, please?

---
Andrey

Edited by - AKazak on 07/20/2021 12:55:59 PM
Go to Top of Page

YimingChen

1640 Posts

Posted - 07/20/2021 :  2:05:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Use this:
mb.add_sheet('sheet2')


James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/21/2021 :  05:51:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Use this:
mb.add_sheet('sheet2')


James



Dear James,

Got it!

Is this the correct command to get a handle of the active matrix book?
MatrixBook = op.find_book('m')


---
Andrey
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/21/2021 :  07:53:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
mb = op.find_book('m')

will give the the object for the active window if it is a matrix book, yes.

CP
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/21/2021 :  12:21:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

mb = op.find_book('m')

will give the the object for the active window if it is a matrix book, yes.

CP




Got it!
Thanks

---
Andrey
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