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
 Origin Forum
 Import matrix text file to a matrix object

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
AKazak Posted - 07/19/2021 : 08:45:07 AM
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
10   L A T E S T    R E P L I E S    (Newest First)
AKazak Posted - 07/21/2021 : 12:21:49 PM
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
cpyang Posted - 07/21/2021 : 07:53:53 AM
mb = op.find_book('m')

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

CP
AKazak Posted - 07/21/2021 : 05:51:21 AM
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
YimingChen Posted - 07/20/2021 : 2:05:09 PM
Use this:
mb.add_sheet('sheet2')


James
AKazak Posted - 07/20/2021 : 12:14:56 PM
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
YimingChen Posted - 07/20/2021 : 12:01:10 PM
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
AKazak Posted - 07/20/2021 : 10:31:44 AM
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
YimingChen Posted - 07/19/2021 : 4:48:38 PM
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
AKazak Posted - 07/19/2021 : 2:21:29 PM
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
easwar Posted - 07/19/2021 : 2:04:31 PM
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

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