Statistics in ZEN OAD (method to calculate median?)

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
user-64
Posts: 22
Joined: Thu Jan 01, 1970 1:00 am

Statistics in ZEN OAD (method to calculate median?)

Post by user-64 »

Support,

I am attempting to find an easy way to calculate the median value of a number array.

From most of my Google search attempts I have come up with various libraries that I understand are not available for use in ZEN OAD. I base this on the following old post

http://forums.zeiss.com/microscopy/comm ... .php?t=967

I have worked around the problem, but for future is there any way to calculate Median, Standard Deviation, Mean within the ZEN OAD environment?

Regards,

Dan
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

Hi,

One option is to download and install Math.Net. Import MathNet.Numerics.Statistics and there you have plenty of different tools available. You may add the dlls in a folder and then use clr.addreferencetofile("Your dll") before you import the namespace. As array you can either import Array from System or use Vectors from MathNet.Numerics.LinearAlgebra. The functions expects double so use float, Arr = Array[float]([1.5,3.5,4]). I have used it within Zen.


BR
Fredrik
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Hello Fredrik,

Thank you for your contribution! This is exactly how OAD is meant to be.
As we do not intend to ‘reinvent the wheel’, the suggestion is to use libraries whenever it is possible.

In this special case it is not trivial, as Math.NET Numerics comes as a nuget package and there are not so many examples that can be transferred directly to IronPython.

Therefore I think it is a good idea to explain the installation and coding in more details.

1. How to get the library

On numerics.mathdotnet.com
you will find a link to the nuget distribution
nuget.org/packages/MathNet.Numerics
where the newest version is preselected.
On the right side, you find ‘download package

2. Installation

After downloading the package you get something like ‘mathnet.numerics.X.X.X.nupkg’ where X.X.X stands for the version number.
Now rename ‘mathnet.numerics.X.X.X.nupkg’ to ‘mathnet.numerics.X.X.X.zip’.
Open and extract the ‘package’. After extracting you will find a lib folder with various .Net versions like 1.3, 2.0 4.0 and 461 inside.
As Zen is written in .Net 4.6.1 the last folder is the correct one.
Open the folder and copy the MathNet.Numerics.dll to the folder where ZEN resides!
(Something like "C:\Program Files\Carl Zeiss\ZEN 2\ZEN 2 (blue edition)")

3. Using the lib

Start Zen and open the OAD-IDE (Python Editor)

Code: Select all

from System import Array  

import clr
clr.AddReference("MathNet.Numerics.dll")
import MathNet.Numerics.Statistics

arr = Array[float]([1.5,3.5,4])

median = MathNet.Numerics.Statistics.Statistics.Median(arr)

print median
You can find 'the other functions' on
numerics.mathdotnet.com/api/MathNet.Numerics.Statistics/Statistics.htm


I hope this helps!
user-64
Posts: 22
Joined: Thu Jan 01, 1970 1:00 am

thanks

Post by user-64 »

Thank you Fredrik, and Admin,

This works perfectly, and eliminates a good deal of code.

D
Post Reply