-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenCDF.py
More file actions
157 lines (135 loc) · 3.22 KB
/
genCDF.py
File metadata and controls
157 lines (135 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import argparse
import numpy as np
# Local imports
import plot
def computeStats(input_data):
np_data = np.array(input_data)
print('DATA STATS')
print('-------------------------')
print('\tMin:', np.min(np_data))
print('\tMedian:', np.median(np_data))
print('\tMax:', np.max(np_data), '\n')
print('\tP10:', np.percentile(np_data, 10))
print('\tP20:', np.percentile(np_data, 20))
print('\tP30:', np.percentile(np_data, 30))
print('\tP40:', np.percentile(np_data, 40))
print('\tP50:', np.percentile(np_data, 50))
print('\tP60:', np.percentile(np_data, 60))
print('\tP70:', np.percentile(np_data, 70))
print('\tP80:', np.percentile(np_data, 80))
print('\tP90:', np.percentile(np_data, 90))
print('\tP95:', np.percentile(np_data, 95))
print('\tP99:', np.percentile(np_data, 99))
print('-------------------------')
"""
Main entry point for stats and cdf.
Requires input file path, output plot.
Optional labels.
"""
def main(
input_data,
output_plot_file,
plot_title,
xlabel,
ylabel,
):
# Input format one number per line.
with open(input_data, 'r') as inf:
print('Reading:', input_data)
data = inf.read().split('\n')
# Remove empty strings from list
sanitizedList = list(filter(None, data))
# Convert data to float
floatData = [float(x) for x in sanitizedList]
# Print data stats
computeStats(floatData)
# CDFify
cdfData = plot.CDFify(floatData)
# Add a starting 0 to the x and y axis
cdfData[0] = [0] + cdfData[0]
cdfData[1] = [0] + cdfData[1]
plotData = []
plotData.append(cdfData)
labels = []
labels.append('CDF data')
# Plot the data, and save results.
plt = plot.drawPlot(
r=plotData,
xlabel=xlabel,
ylabel=ylabel,
title=plot_title,
set_logx=0,
set_logy=0,
labels=labels,
leg_loc='best',
time_plot=False,
return_plt=True,
above_legend=True,
outside_legend=True,
special_line=False,
marker=False,
trend=False,
yhline=None,
text=None,
)
# Save the figure
plt.savefig(
output_plot_file,
bbox_inches='tight',
)
print('Saved plot for {} in {}'.format(input_data, output_plot_file))
# Clear the figure
plt.clf()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'-if',
'--input_data_file',
help='Relative path to input data file for CDF',
type=str,
required=True,
)
parser.add_argument(
'-of',
'--output_plot_file',
help='Location and name of where to save plot',
type=str,
required=True,
)
parser.add_argument(
'-t',
'--plot_title',
help='Plot title, otherwise default',
type=str,
required=False,
default='CDF Plot',
)
parser.add_argument(
'-xl',
'--xlabel',
help='X-label caption',
type=str,
required=False,
default='X-data',
)
parser.add_argument(
'-yl',
'--ylabel',
help='Y-label caption',
type=str,
required=False,
default='Proportion',
)
args = parser.parse_args()
input_data_file = args.input_data_file
output_plot_file = args.output_plot_file
plot_title = args.plot_title
xlabel = args.xlabel
ylabel = args.ylabel
main(
input_data_file,
output_plot_file,
plot_title,
xlabel,
ylabel,
)