-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerlaw.py
57 lines (45 loc) · 1.27 KB
/
powerlaw.py
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
import argparse
import os
import glob
import numpy as np
import matplotlib.pyplot as plt
opt = argparse.ArgumentParser(
description='Evaluate fracture power law.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
opt.add_argument(
'-s', '--source',
type=str
)
def fit(data, alfa, beta, L):
V = data['V']
I = data['I']
vlb = V / (L**beta)
ilb = I / (L**alfa)
return ilb, vlb
def sort_files(path):
filename = os.path.basename(path)
length = filename.split('.')[0]
return int(length)
args = opt.parse_args()
files = sorted(glob.glob(args.source + "/*.csv"), key=sort_files)
print('\n'.join(files))
sizes = [7, 14, 20, 28]
data = [np.genfromtxt(path, delimiter=',', skip_header=1, names=['V', 'I'])
for path in files]
while True:
try:
alfa = float(input('\nalfa: '))
beta = float(input('beta: '))
except ValueError:
break
fitresult = [(L, fit(d, alfa, beta, L)) for L, d in zip(sizes, data)]
for L, (ilb, vlb) in fitresult:
plt.plot(vlb, ilb, label=f'L = {L}')
plt.legend(loc='upper left')
plt.grid(True)
plt.axis('equal')
plt.xlabel(r'$V/L^\beta$')
plt.ylabel(r'$I/L^\alpha$')
plt.title(f'$D = 0$, $\\alpha = {alfa}$ e $\\beta = {beta}$')
plt.show()