Browse Source

Add histogram-making functions and plotting scripts

master
J.-S. Caux 4 years ago
parent
commit
15e9fdb5d4
5 changed files with 236 additions and 0 deletions
  1. 1
    0
      Makefile
  2. 20
    0
      scripts/DSF_iK.py
  3. 21
    0
      scripts/Histograms.py
  4. 38
    0
      scripts/Histograms_Animated.py
  5. 156
    0
      src/EXECS/Histogram_RAW_File.cc

+ 1
- 0
Makefile View File

@@ -123,6 +123,7 @@ EXECS = $(BINDIR)LiebLin_DSF $(BINDIR)LiebLin_Data_Daemon $(BINDIR)LiebLin_RAW_F
123 123
 lib$(VERSION).a : $(Objects_ALL)
124 124
 	ar -cru lib$(VERSION).a $(Objects_ALL)
125 125
 	mv lib$(VERSION).a $(BASEDIR)lib/
126
+	$(COMPILE) $(EXECSDIR)Histogram_RAW_File.cc -o $(BINDIR)Histogram_RAW_File -l$(VERSION)
126 127
 	$(COMPILE) $(EXECSDIR)LiebLin_DSF.cc -o $(BINDIR)LiebLin_DSF -l$(VERSION)
127 128
 	$(COMPILE) $(EXECSDIR)LiebLin_Data_Daemon.cc -o $(BINDIR)LiebLin_Data_Daemon -l$(VERSION)
128 129
 	$(COMPILE) $(EXECSDIR)LiebLin_Data_Daemon_Nscaling.cc -o $(BINDIR)LiebLin_Data_Daemon_Nscaling -l$(VERSION)

+ 20
- 0
scripts/DSF_iK.py View File

@@ -0,0 +1,20 @@
1
+import argparse
2
+import plotly.graph_objects as go
3
+import numpy
4
+
5
+parser = argparse.ArgumentParser()
6
+parser.add_argument('omegafile', help='Omega filename')
7
+parser.add_argument('dsffile', help='DSF filename')
8
+args = parser.parse_args()
9
+
10
+omega = numpy.loadtxt(args.omegafile)
11
+dsf = numpy.loadtxt(args.dsffile)
12
+
13
+x = [o for o in omega]
14
+y = [d for d in dsf]
15
+
16
+fig = go.Figure(data=go.Scatter(x=x, y=y))
17
+fig.update_layout(title=args.dsffile.rpartition('/')[2])
18
+fig.show()
19
+
20
+

+ 21
- 0
scripts/Histograms.py View File

@@ -0,0 +1,21 @@
1
+import argparse
2
+import plotly.graph_objects as go
3
+import numpy
4
+
5
+parser = argparse.ArgumentParser()
6
+parser.add_argument('filenames', nargs='*')
7
+args = parser.parse_args()
8
+
9
+print(args)
10
+
11
+fig = go.Figure()
12
+
13
+for datafilename in args.filenames:
14
+	data = numpy.loadtxt(datafilename, delimiter="\t", usecols=[0,1,2,3])
15
+	x = [line[0] for line in data]
16
+	y = [line[3] for line in data]
17
+	fig.add_trace(go.Bar(x=x, y=y))
18
+
19
+fig.show()
20
+
21
+

+ 38
- 0
scripts/Histograms_Animated.py View File

@@ -0,0 +1,38 @@
1
+import argparse
2
+import plotly.graph_objects as go
3
+import numpy
4
+
5
+parser = argparse.ArgumentParser()
6
+parser.add_argument('filename', help='Enter the sliced data filename')
7
+args = parser.parse_args()
8
+
9
+data = numpy.loadtxt(args.filename, delimiter="\t")
10
+# The data is in row format
11
+x = [i for i in range(len(data[0]))]
12
+
13
+fig = go.Figure()
14
+
15
+for line in data:
16
+	fig.add_trace(go.Bar(x=x, y=[d for d in line]))
17
+
18
+steps = []
19
+for i in range(len(fig.data)):
20
+	step = dict(
21
+		method="update",
22
+		args=[{'visible': [False] * len(fig.data)},
23
+			{'title': "Slider switched to step: " + str(i)}],)
24
+	step["args"][0]["visible"][i] = True
25
+	steps.append(step)
26
+
27
+sliders = [dict(
28
+	active=0,
29
+	currentvalue={"prefix": "bin box "},
30
+	pad={"t": 50},
31
+	steps=steps)]
32
+
33
+fig.update_yaxes(range=[0,0.2])
34
+fig.update_layout(
35
+	sliders=sliders
36
+)
37
+fig.show()
38
+

+ 156
- 0
src/EXECS/Histogram_RAW_File.cc View File

@@ -0,0 +1,156 @@
1
+/**********************************************************
2
+
3
+This software is part of J.-S. Caux's ABACUS library.
4
+
5
+Copyright (c) J.-S. Caux.
6
+
7
+-----------------------------------------------------------
8
+
9
+File:  Histogram_RAW_File.cc
10
+
11
+Purpose:  Produce a histogram of matrix elements from a RAW file.
12
+
13
+***********************************************************/
14
+
15
+#include "ABACUS.h"
16
+
17
+using namespace std;
18
+using namespace ABACUS;
19
+
20
+
21
+int main(int argc, char* argv[])
22
+{
23
+  if (argc != 7) {
24
+    cout << "Argument needed: rawfile, iKmin, iKmax, omega, domega, logscale_int" << endl;
25
+    ABACUSerror("");
26
+  }
27
+
28
+  int n = 1;
29
+  const char* rawfilename = argv[n++];
30
+  int iKmin = atoi(argv[n++]);
31
+  int iKmax = atoi(argv[n++]);
32
+  DP om = atof(argv[n++]);
33
+  DP dom = atof(argv[n++]);
34
+  int logscale_int = atoi(argv[n++]); // see below for meaning
35
+
36
+  ifstream RAW_infile;
37
+  RAW_infile.open(rawfilename);
38
+  if (RAW_infile.fail()) {
39
+    cout << rawfilename << endl;
40
+    ABACUSerror("Could not open RAW_infile... ");
41
+  }
42
+
43
+  stringstream outfilename;
44
+  string outfilename_string;
45
+  outfilename << rawfilename << "_hist";
46
+  if (iKmin != iKmax) outfilename << "_iKmin_" << iKmin << "_iKmax_" << iKmax;
47
+  outfilename << "_om_" << om << "_dom_" << dom << "_li_" << logscale_int;
48
+  outfilename_string = outfilename.str();
49
+  const char* outfilename_c_str = outfilename_string.c_str();
50
+
51
+  ofstream outfile;
52
+  outfile.open(outfilename_c_str);
53
+  outfile.precision(16);
54
+
55
+
56
+
57
+  // Use the binning in current ABACUS version's threads,
58
+  // with logscale unit = 2^{1/64} \simeq 1.01
59
+  int npts = 6400/logscale_int;
60
+  DP logscale_used = logscale_int * (1.0/64) * log(2.0);
61
+
62
+  DP omega_min = om - 0.5* dom;
63
+  DP omega_max = om + 0.5* dom;
64
+
65
+  DP omega;
66
+  int iK;
67
+  DP FF;
68
+  DP dev;
69
+  string label;
70
+
71
+  Vect<int> nFF (0, npts);
72
+
73
+  int nread = 0;
74
+  int nfound = 0;
75
+  int il = 0;
76
+
77
+  while (RAW_infile.peek() != EOF) {
78
+    RAW_infile >> omega >> iK >> FF >> dev >> label;
79
+
80
+    nread++;
81
+
82
+    if (iK >= iKmin && iK <= iKmax && omega > omega_min && omega < omega_max) {
83
+      nfound++;
84
+      il = int(-log(FF*FF)/logscale_used);
85
+      if (il < 0) il=0;
86
+      if (il > npts) continue;
87
+      nFF[il] += 1;
88
+    }
89
+  }
90
+  RAW_infile.close();
91
+
92
+  if (nfound == 0) {
93
+    cout << "Didn't find any contributing state." << endl;
94
+    return(1)
95
+  }
96
+
97
+  for (int i = 0; i < npts; ++i) {
98
+    if (i > 0) outfile << endl;
99
+    outfile << i << "\t" << exp(-i * logscale_used) << "\t" << nFF[i] << "\t" << DP(nFF[i])/nfound;
100
+  }
101
+  outfile.close();
102
+
103
+
104
+  // Now that we know the total number of entries, produce animated data:
105
+  // the total number of entries is sliced into 100 pieces
106
+  // and binned in the same way as before
107
+
108
+  int stepsize = nfound/100;
109
+
110
+  outfilename << "_sliced";
111
+  outfilename_string = outfilename.str();
112
+  const char* sliced_c_str = outfilename_string.c_str();
113
+
114
+  ofstream sliced_file;
115
+  sliced_file.open(sliced_c_str);
116
+  sliced_file.precision(16);
117
+
118
+  RAW_infile.open(rawfilename);
119
+  if (RAW_infile.fail()) {
120
+    cout << rawfilename << endl;
121
+    ABACUSerror("Could not open RAW_infile... ");
122
+  }
123
+
124
+  nread = 0;
125
+  nfound = 0;
126
+  int nsteps = 0;
127
+  for (int i = 0; i < npts; ++i) nFF[i] = 0;
128
+
129
+  while (RAW_infile.peek() != EOF) {
130
+    RAW_infile >> omega >> iK >> FF >> dev >> label;
131
+
132
+    nread++;
133
+
134
+    if (iK >= iKmin && iK <= iKmax && omega > omega_min && omega < omega_max) {
135
+      nfound++;
136
+      il = int(-log(FF*FF)/logscale_used);
137
+      if (il < 0) il=0;
138
+      if (il > npts) continue;
139
+      nFF[il] += 1;
140
+    }
141
+
142
+    if (nfound == stepsize) {// || RAW_infile.peek() == EOF) {
143
+      if (nsteps++ > 0) sliced_file << endl;
144
+      sliced_file << DP(nFF[0])/stepsize;
145
+      for (int i = 1; i < npts; ++i) sliced_file << "\t" << DP(nFF[i])/stepsize;
146
+      for (int i = 0; i < npts; ++i) nFF[i] = 0;
147
+      nfound = 0;
148
+    }
149
+  }
150
+
151
+  RAW_infile.close();
152
+
153
+  sliced_file.close();
154
+
155
+  return(0);
156
+}

Loading…
Cancel
Save