forked from kunyuan/FeynCalc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.py
More file actions
142 lines (110 loc) · 4.2 KB
/
IO.py
File metadata and controls
142 lines (110 loc) · 4.2 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
from color import *
import numpy as np
import glob
import re
import sys
import os
# import seaborn as sns
# import matplotlib as mat
# mat.use("agg")
# import matplotlib.pyplot as plt
# mat.rcParams.update({'font.size': 16})
# mat.rcParams["font.family"] = "Times New Roman"
# size = 12
# sns.set_style("whitegrid")
# sns.set_palette("colorblind", n_colors=16)
def GetLine(file):
while True:
line = file.readline().strip()
if len(line) > 0 and line[0] != "#":
return line
def getListOfFiles(dirName):
listOfFiles = list()
for (dirpath, dirnames, filenames) in os.walk(dirName):
listOfFiles += [os.path.join(dirpath, file) for file in filenames]
return listOfFiles
class param:
# Order, Beta, Rs, Mass2, Lambda, Charge2, TotalStep = [None, ]*7
# kF, Nf, EF, Bubble = [0.0, ]*4
def __init__(self, D, Spin):
self.DataFolder = "Data"
self.InputFile = "parameter"
self.Dim = D
self.Spin = Spin
with open(self.InputFile, "r") as file:
para = file.readline().split(" ")
self.Order = int(para[0])
self.Beta = float(para[1])
self.Rs = float(para[2])
self.Mass2 = float(para[3])
self.Lambda = float(para[4])
self.MaxExtMom = float(para[5])
self.TotalStep = int(para[6])
if self.Dim == 3:
self.kF = (9.0*np.pi/4.0)**(1.0/3.0)/self.Rs
self.Nf = self.kF/4.0/np.pi**2*self.Spin
elif self.Dim == 2:
self.kF = np.sqrt(2.0)/self.Rs # 2D
self.Nf = 1.0/4.0/np.pi*self.Spin
else:
print "Not Implemented for Dimension {0}".format(self.Dim)
sys.exit(0)
self.EF = self.kF**2
self.Beta /= self.EF
self.MaxExtMom *= self.kF
print yellow("Parameters:")
print "Rs={0}, kF={1}, EF={2}, Beta={3}, Mass2={4}, Lambda={5}\n".format(
self.Rs, self.kF, self.EF, self.Beta, self.Mass2, self.Lambda)
# For the given path, get the List of all files in the directory tree
def LoadFile(Folder, FileName):
Groups = []
ReWeight = []
Step = []
Data = []
Grid = {}
for f in getListOfFiles(Folder):
if re.search(FileName, f):
print "Loading ", f
try:
with open(f, "r") as file:
line = file.readline().strip().split(":")[1]
Step.append(float(line))
line = file.readline().strip().split(":")[1]
if len(Groups) == 0:
for e in [e for e in line.split(",") if len(e) > 0]:
Groups.append(tuple([int(o)
for o in e.split("_")]))
line = file.readline().strip().split(":")[1]
ReWeight = [float(e)
for e in line.split(",") if len(e) > 0]
while True:
g = file.readline().split(":")
if g[0].find("Grid") != -1:
key = g[0].strip(" #")
Grid[key] = np.fromstring(g[1], sep=' ')
else:
break
data = np.loadtxt(f)
# print Groups[-1], data[2, 0]
Data.append(data)
except Exception as e:
print "Failed to load {0}".format(f)
print str(e)
Data = np.array(Data)
DataDict = {}
for (idx, g) in enumerate(Groups):
DataDict[g] = np.array(Data[:, idx, :])
return DataDict, np.array(Step), Groups, np.array(ReWeight), Grid
def ErrorPlot(p, x, d, color='k', marker='s', label=None, size=4, shift=False):
p.plot(x, d, marker=marker, c=color, label=label,
lw=1, markeredgecolor="None", linestyle="--", markersize=size)
ColorList = ['k', 'r', 'b', 'g', 'm', 'c', 'navy',
'y', 'cyan', 'darkgreen', 'violet', 'lime', 'purple']
ColorList = ColorList*40
if __name__ == '__main__':
Para = param(3, 2)
dirName = "./data"
filename = "pid[0-9]+.dat"
LoadFile(dirName, filename)
# for elem in getListOfFiles(dirName):
# print(elem)