-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerlaw2.py
83 lines (64 loc) · 1.73 KB
/
powerlaw2.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
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
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
)
opt.add_argument(
'-l', '--length',
type=int
)
opt.add_argument(
'-g', '--geometry',
type=str,
choices=['t', 'h', 's']
)
def convert_geometry(initial):
return {
't': '45 graus',
'h': 'hexagonal',
's': 'quadrada'
}[initial]
def fit(data, eta, nu, D):
V = data['V']
I = data['I']
vlb = V * (1 + D)**nu
ilb = I * (1 + D)**eta
return ilb, vlb
def sort_files(path):
filename = os.path.basename(path)
disorder = filename.split('.')[2]
disorder = disorder.replace(',', '.')
return float(disorder)
args = opt.parse_args()
files = sorted(glob.glob(args.source + "/*.csv"), key=sort_files)
disorders = [0, 0.2, 0.4, 0.6, 0.8, 1.0]
data = [np.genfromtxt(path, delimiter=',', skip_header=1, names=['V', 'I'])
for path in files]
while True:
try:
eta = float(input('\neta: '))
nu = float(input('nu: '))
except ValueError:
break
fitresult = [(D, fit(d, eta, nu, D)) for D, d in zip(disorders, data)]
for D, (ilb, vlb) in fitresult:
plt.plot(vlb, ilb, label=f'D = {D}')
plt.legend(loc='upper left')
plt.grid(True)
#plt.axis('equal')
plt.xlabel(r'$V(1+D)^{\nu}$')
plt.ylabel(r'$I(1+D)^{\eta}$')
#plt.gca().set_adjustable("box")
#plt.gca().set_ylim(bottom=0.0)
length = args.length
geometry = convert_geometry(args.geometry)
plt.title(f'$L = {length}$, G = {geometry}, $\\eta = {eta}$ e $\\nu = {nu}$')
plt.show()