The Origin Forum
File Exchange
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
 Despecke matrix
 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
584 Posts

Posted - 08/31/2021 :  10:25:39 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2022 (64-bit) Beta2 9.9.0.105
Windows 7 SP1 x64

Greetings!

I have a matrix object and need to replace all the speckles with the missing values. My current thought is to use Python in Set Values dialog.

What Python libraries are available in Origin to find speckles?
How do I set Matrix cells to missing from Python code?

Thank you.

---
Andrey

YimingChen

820 Posts

Posted - 09/01/2021 :  09:36:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
See example below to set missing values:

import numpy as np
import originpro as op

aa = np.array([	[1, np.nan, 3], [np.nan, 5, 6] ])
ma=op.new_sheet('m')
ma.from_np(aa)

You will need to find such Python package to handle the data in Python and then bring it into Origin.

James

Edited by - YimingChen on 09/01/2021 09:36:51 AM
Go to Top of Page

AKazak

Russia
584 Posts

Posted - 09/01/2021 :  1:53:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

See example below to set missing values:

import numpy as np
import originpro as op

aa = np.array([	[1, np.nan, 3], [np.nan, 5, 6] ])
ma=op.new_sheet('m')
ma.from_np(aa)

You will need to find such Python package to handle the data in Python and then bring it into Origin.

James



OK.

How do I get a handle of the existing and currently selected matrix object in Python?

---
Andrey
Go to Top of Page

AKazak

Russia
584 Posts

Posted - 09/01/2021 :  2:09:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is the code I need to use:
from skimage.filters import rank
from skimage.morphology import disk, ball

def remove_outliers(image, radius=2, threshold=50):
    footprint_function = disk if image.ndim == 2 else ball
    footprint = footprint_function(radius=radius)
    median_filtered = rank.median(image, footprint)
    outliers = (
        (image > median_filtered + threshold)
        | (image < median_filtered - threshold)
    )
    output = np.where(outliers, median_filtered, image)
    return output


However, for some unknown reason, I cannot install skimage package.
Origin gives me a bunch of red lines and closes the console windows without a prompt.

Can you help me with this, please?

---
Andrey
Go to Top of Page

easwar

USA
1939 Posts

Posted - 09/01/2021 :  4:04:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

However, for some unknown reason, I cannot install skimage package.
Origin gives me a bunch of red lines and closes the console windows without a prompt.

Can you help me with this, please?

---
Andrey



Hi Andrey,

If you are using the "Python Packages" dialog to install a package (Origin menu: Connectivity->Python Packages), in that dialog, there is a check box named "Pause output window". If you check that, the command window will stay open for you to read the error messages.

To install scikit image, you need to install the package named:
scikit-image

Please try that and see if that succeeds.

In the upcoming 2022 version, we will have methods to get multiframe image from a new image window and process that in Python. I presume you are working with an image stack?

Easwar
OriginLab
Go to Top of Page

AKazak

Russia
584 Posts

Posted - 09/01/2021 :  11:47:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Easwar,

quote:
Originally posted by easwar
If you are using the "Python Packages" dialog to install a package (Origin menu: Connectivity->Python Packages), in that dialog, there is a check box named "Pause output window". If you check that, the command window will stay open for you to read the error messages.

To install scikit image, you need to install the package named:
scikit-image

Please try that and see if that succeeds.


Done!
Please consider implementing an automatic "Pause output window" in case of warnings or errors during installation.
Besides it would be useful if one could use just installed Python packages without restart of Origin.

quote:
Originally posted by easwar
In the upcoming 2022 version, we will have methods to get multiframe image from a new image window and process that in Python. I presume you are working with an image stack?



Currently, I have a matrix object to be processed and plan to use Set values... dialog to paste the Python code.

Can you share an example snippet on processing a data matrix object from the dialog, please?

---
Andrey
Go to Top of Page

easwar

USA
1939 Posts

Posted - 09/02/2021 :  09:24:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrey,

Here is a simple example where matrix object2 is set with flipped values from object 1.



Easwar
OriginLab
Go to Top of Page

AKazak

Russia
584 Posts

Posted - 09/03/2021 :  05:41:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by easwar

Hi Andrey,

Here is a simple example where matrix object2 is set with flipped values from object 1.

Easwar
OriginLab




Dear Easwar,

I your example above, what does F:Fi stand for?

---
Andrey
Go to Top of Page

easwar

USA
1939 Posts

Posted - 09/03/2021 :  08:35:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrey,

Please see:
https://www.originlab.com/doc/python/tools/Set-Column-Values#Specifying_Input_and_Output_Types

Easwar
Go to Top of Page

AKazak

Russia
584 Posts

Posted - 09/04/2021 :  01:48:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by easwar

Hi Andrey,

Please see:
https://www.originlab.com/doc/python/tools/Set-Column-Values#Specifying_Input_and_Output_Types

Easwar



OK, I see that this is a Python syntax.
Where for I find a complete list of types supported in docstring syntax, including F (float) and i (integer)?

---
Andrey
Go to Top of Page

easwar

USA
1939 Posts

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

You can use the menu "Connectivity->Open Examples.py...". This will open the file in code builder and you will see list of supported types plus several examples.

Easwar
Go to Top of Page

AKazak

Russia
584 Posts

Posted - 09/08/2021 :  07:03:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by easwar

Hi Andrey,

You can use the menu "Connectivity->Open Examples.py...". This will open the file in code builder and you will see list of supported types plus several examples.

Easwar



Thank you for the useful suggestion.

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