### Introduction

MUDI is a kit used to measure uniformity of the distribution.It can compute standard deviation and plot "heat map". It is demended to separate the input file into two csv files.The value of standard deviation is acquired by normalizing the distribution and it creates possibilities to compare these data having diffrerent total numbers.

### Code

#!/usr/bin/env python
# MUDI v1.0
# measure uniformity of the distribution
# University of science and technology Beijing
import csv
import math
import numpy as np
from sklearn import preprocessing
from numpy import float64
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import seaborn as sns
print("------------MUDI v1.0------------")
#input data file
fileName1 = input()
fileName2 = input()
x1 = []
y1 = []
x2 = []
y2 = []
for content in csv_file1:
content = list(map(float,content))
x1.append(content[0])
y1.append(content[1])
for content in csv_file2:
content = list(map(float,content))
x2.append(content[0])
y2.append(content[1])
#calculate the maximum, minimum
x1Max = max(x1)
x1Min = min(x1)
y1Max = max(y1)
y1Min = min(y1)
x2Max = max(x2)
x2Min = min(x2)
y2Max = max(y2)
y2Min = min(y2)
num1 = len(x1)
num2 = len(x2)
print("Numbers of data1 points:"+str(num1))
print("Data1 point distribution range:"+'\n'+"("+str(x1Min)+","+str(y1Min)+")"+"~"+"("+str(x1Max)+","+str(y1Max)+")")
print("Numbers of data2 points:"+str(num2))
print("Data2 point distribution range:"+'\n'+"("+str(x2Min)+","+str(y2Min)+")"+"~"+"("+str(x2Max)+","+str(y2Max)+")")
#meshing
print("------------Meshing module------------")
stepSize = float(input())
if x1Max >= x2Max:
xMax = x2Max
else:
xMax = x1Max
if x1Min >= x2Min:
xMin = x2Min
else:
xMin = x1Min
if y1Max >= y2Max:
yMax = y2Max
else:
yMax = y1Max
if y1Min >= y2Min:
yMin = y2Min
else:
yMin = y1Min
numx = int(xMax / stepSize)
numy = int(yMax / stepSize)
print("Mesh Result:"+str(numy)+" X "+str(numx))
#count
print("------------Start counting------------")
countNum1 = []
countNum2 = []
meshX = np.arange(xMin,xMax,stepSize)
print(meshX)
meshX[-1] = xMax
print(meshX)
meshY = np.arange(yMin,yMax,stepSize)
meshY[-1] = yMax
print(meshY)
yFormer = meshY[0] - 0.1
for myy in range(1,len(meshY)):
my = meshY[myy]
xFormer = meshX[0] - 0.1
for mxx in range(1,len(meshX)):
mx = meshX[mxx]
n1 = 0
n2 = 0
for a in range(0,len(x1)):
i = x1[a]
j = y1[a]
if i  xFormer:
if j  yFormer:
n1 = n1 +1
countNum1.append(n1)
for a in range(0,len(x2)):
i = x2[a]
j = y2[a]
if i  xFormer:
if j  yFormer:
n2 = n2 +1
countNum2.append(n2)
xFormer = mx
yFormer = my
c1 = np.array(countNum1,dtype=float64).reshape(numy,numx)
c2 = np.array(countNum2,dtype=float64).reshape(numy,numx)
min_max_scaler = preprocessing.MinMaxScaler()
cN1 = min_max_scaler.fit_transform(c1)
cN2 = min_max_scaler.fit_transform(c2)
std1 = np.std(cN1, ddof = 1)
std2 = np.std(cN2, ddof = 1)
print("Amount of data1:"+str(sum(countNum1)))
print("Amount of data2:"+str(sum(countNum2)))
print("Standard deviation")
print("data1: "+str(std1))
print("data2: "+str(std2))
#plot
print("------------Save images of distribution------------")
plt.figure(figsize=(15, 15))
sns.set()
sns.heatmap(c1,cmap="Blues",annot=True,linewidths=.5)
plt.xlabel('Direction-x')
plt.ylabel('Direction-y')
plt.title('Amount of data1')
plt.savefig('data1.png')
plt.figure(figsize=(15, 15))
sns.set()
sns.heatmap(c2,cmap="Blues",annot=True,linewidths=.5)
plt.xlabel('Direction-x')
plt.ylabel('Direction-y')
plt.title('Amount of data2')
plt.savefig('data2.png')
print("Images of distribution have been saved!")

### Instruction

Anaconda is an useful software, it can save your time to install and configurate packages needed. Namely, you can run this program in your personal compute via Anaconda easily.

python3 mudi.py