GPUE  v1.0
GPU Gross-Pitaevskii Equation numerical solver for Bose-Einstein condensates
plot.py
Go to the documentation of this file.
1 # Simple script to plot variables. Will grow with time.
2 import numpy as np
3 import matplotlib.pyplot as plt
4 import matplotlib.cm as cm
5 import argparse
6 
7 parser = argparse.ArgumentParser(description='reading strings for plotting')
8 parser.add_argument('strings', metavar='ID', nargs='+', help='string to plot')
9 
10 args = parser.parse_args()
11 print(args.strings)
12 
13 #class for all variables with initial definitions
14 class params:
15 
16  # Defining static / default values
17  xDim = 512
18  yDim = 512
19 
20  # data_dir is assumed to be in the previous directory
21  data_dir = "data"
22 
23  # Defaulting to first element after imaginary time evolution
24  start = 0
25  end = 1
26  incr = 1
27 
28  # item to work with
29  item = "wfc"
30 
31 # Function to plot specific variable
32 def plot_var(xDim, yDim, data_dir, pltval):
33  if data_dir[0] != "/":
34  data_dir = "../" + data_dir
35  data = data_dir + "/" + pltval
36  lines = np.loadtxt(data)
37  val = np.reshape(lines, (xDim,yDim))
38  '''
39  val = -np.log(val) * 1E4 * 1.0545718E-34
40  data_V = "../data/K_0"
41  lines_V = np.loadtxt(data_V)
42  V_val = np.reshape(lines_V, (xDim, yDim))
43  final_val = V_val - val
44  '''
45  plt.imshow(val, extent=(1,xDim,1,yDim), interpolation='nearest',
46  cmap = cm.jet)
47  plt.colorbar()
48  fig = plt.gcf()
49  #plt.clim(0,1)
50  plt.show()
51 
52 # function to plot a variable with a range
53 def plot_var_range(xDim, yDim, data_dir, pltval, start, end, incr):
54  if data_dir[0] != "/":
55  data_dir = "../" + data_dir
56  for i in range(start, end, incr):
57  print(i)
58  output = pltval + "%s" % i
59  data = data_dir + "/" + output
60  lines = np.loadtxt(data)
61  val = np.reshape(lines, (xDim,yDim))
62  plt.imshow(val, extent=(1,xDim,1,yDim), interpolation='nearest',
63  cmap = cm.jet)
64  plt.colorbar()
65  fig = plt.gcf()
66  #plt.show()
67  plt.draw()
68  num_str = "%s" % i
69  output_str = pltval + num_str.rjust(5,'0') + ".png"
70  fig.savefig(output_str)
71  plt.clf()
72 
73 
74 # Function to plot wfc with pltvar as a variable to modify the type of plot
75 def plot_wfc(xDim, yDim, data_dir, pltval, start, end, incr):
76  if data_dir[0] != "/":
77  data_dir = "../" + data_dir
78  for i in range(start,end,incr):
79  print(i)
80  data_real = data_dir + "/wfc_0_const_%s" % i
81  data_im = data_dir + "/wfc_0_consti_%s" % i
82  #data_real = data_dir + "/wfc_ev_%s" % i
83  #data_im = data_dir + "/wfc_evi_%s" % i
84  #data_x = data_dir + "x_0" % i
85  #data_y = data_dir + "y_0" % i
86 
87 
88  #print(i)
89 
90  lines_real = np.loadtxt(data_real)
91  lines_im = np.loadtxt(data_im)
92  wfc_real = np.reshape(lines_real, (xDim,yDim));
93  wfc_im = np.reshape(lines_im, (xDim,yDim));
94 
95  wfc = abs(wfc_real + 1j * wfc_im)
96  wfc = wfc * wfc
97 
98  #wfc_k = np.fft.fft2(wfc)
99  #wfc_k_plot = np.abs(np.fft.fftshift(wfc_k))
100  #wfc_k_plot = wfc_k_plot**2
101 
102  plt.imshow(wfc, extent=(-6.9804018707623236e-04,6.9804018707623236e-04,-6.9804018707623236e-04,6.9804018707623236e-04), interpolation='nearest',
103  cmap = cm.jet)
104  plt.colorbar()
105  plt.show()
106  #fig = plt.figure()
107  #fig.savefig('wfc.png')
108 
109 # Function to plot complex vals with pltvar as the variable
110 def plot_complex(xDim, yDim, data_dir, pltval, start, end, incr):
111  if data_dir[0] != "/":
112  data_dir = "../" + data_dir
113 
114  data_real = data_dir + "/" + pltval + "_0"
115  data_im = data_dir + "/" + pltval + "i_0"
116 
117  lines_real = np.loadtxt(data_real)
118  lines_im = np.loadtxt(data_im)
119  wfc_real = np.reshape(lines_real, (xDim,yDim));
120  wfc_im = np.reshape(lines_im, (xDim,yDim));
121 
122  wfc = abs(wfc_real + 1j * wfc_im)
123  wfc = wfc * wfc
124 
125  plt.imshow(wfc, extent=(1,xDim,1,yDim), interpolation='nearest',
126  cmap = cm.jet)
127  plt.colorbar()
128  plt.show()
129  #fig = plt.figure()
130  #fig.savefig('wfc.png')
131 
132 # Function to plot wfc with pltvar as a variable to modify the type of plot
133 def plot_wfc_k(xDim, yDim, data_dir, pltval, start, end, incr):
134  if data_dir[0] != "/":
135  data_dir = "../" + data_dir
136 
137  for i in range(start,end,incr):
138  print(i)
139  data_real = data_dir + "/wfc_0_const_%s" % i
140  data_im = data_dir + "/wfc_0_consti_%s" % i
141  #data_real = data_dir + "/wfc_ev_%s" % i
142  #data_im = data_dir + "/wfc_0_evi_%s" % i
143 
144  lines_real = np.loadtxt(data_real)
145  lines_im = np.loadtxt(data_im)
146  wfc_real = np.reshape(lines_real, (xDim,yDim));
147  wfc_im = np.reshape(lines_im, (xDim,yDim));
148 
149  wfc = (wfc_real + 1j * wfc_im)
150 
151  wfc_k = np.fft.fft2(wfc)
152  wfc_k_plot = np.abs(np.fft.fftshift(wfc_k))
153  wfc_k_plot = wfc_k_plot**2
154 
155  plt.imshow(wfc_k_plot, extent=(1,xDim,1,yDim), interpolation='nearest',
156  cmap = cm.jet)
157  plt.colorbar()
158  plt.show()
159  #fig = plt.figure()
160  #fig.savefig('wfc.png')
161 
162 # Function to plot wfc with pltvar as a variable to modify the type of plot
163 def plot_wfc_phase(xDim, yDim, data_dir, pltval, start, end, incr):
164  if data_dir[0] != "/":
165  data_dir = "../" + data_dir
166  for i in range(start,end,incr):
167  print(i)
168  data_real = data_dir + "/wfc_0_const_%s" % i
169  data_im = data_dir + "/wfc_0_consti_%s" % i
170  #data_real = data_dir + "/wfc_ev_%s" % i
171  #data_im = data_dir + "/wfc_evi_%s" % i
172 
173  lines_real = np.loadtxt(data_real)
174  lines_im = np.loadtxt(data_im)
175  wfc_real = np.reshape(lines_real, (xDim,yDim));
176  wfc_im = np.reshape(lines_im, (xDim,yDim));
177 
178  wfc = (wfc_real + 1j * wfc_im)
179 
180  wfc = np.angle(wfc)
181  plt.imshow(wfc, extent=(1,xDim,1,yDim), interpolation='nearest',
182  cmap = cm.jet)
183  plt.colorbar()
184  plt.show()
185  #fig = plt.figure()
186  #fig.savefig('wfc.png')
187 
188 
189 # Function to parse arguments for plotting
190 # Note: We assume that the parameters come in sets
191 def parse_args(string_list):
192  i = 0
193  par = params()
194  print(string_list[i])
195  while i < len(string_list):
196  # -d for "data_dir"
197  if (string_list[i] == "d"):
198  par.data_dir = string_list[i+1]
199  i += 2
200  # -i for "item" -- The thing to plot
201  elif (string_list[i] == "i"):
202  par.item = string_list[i+1]
203  i += 2
204  # -r for "range"
205  elif (string_list[i] == "r"):
206  par.start = int(string_list[i+1])
207  par.end = int(string_list[i+2]) + 1
208  par.incr = int(string_list[i+3])
209  par.range = True
210  i+= 4
211  # -g for "grid"
212  elif (string_list[i] == "g"):
213  par.xDim = int(string_list[i+1])
214  par.yDim = int(string_list[i+2])
215  i += 3
216  return par
217 
218 def plot(par):
219  if (par.item == "wfc"):
220  plot_wfc(par.xDim, par.yDim, par.data_dir, par.item,
221  par.start, par.end, par.incr)
222  elif (par.item == "wfc_k"):
223  plot_wfc_k(par.xDim, par.yDim, par.data_dir, par.item,
224  par.start, par.end, par.incr)
225  elif (par.item == "wfc_phase"):
226  plot_wfc_phase(par.xDim, par.yDim, par.data_dir, par.item,
227  par.start, par.end, par.incr)
228  elif (par.item == "GK" or par.item == "GV"):
229  plot_complex(par.xDim, par.yDim, par.data_dir, par.item,
230  par.start, par.end, par.incr)
231  elif (par.end != 1):
232  plot_var_range(par.xDim, par.yDim, par.data_dir, par.item,
233  par.start, par.end, par.incr)
234  else:
235  plot_var(par.xDim, par.yDim, par.data_dir, par.item)
236 
237 par = parse_args(args.strings)
238 plot(par)
def plot_wfc_k(xDim, yDim, data_dir, pltval, start, end, incr)
Definition: plot.py:133
def parse_args(string_list)
Definition: plot.py:191
def plot(par)
Definition: plot.py:218
def plot_wfc(xDim, yDim, data_dir, pltval, start, end, incr)
Definition: plot.py:75
def plot_wfc_phase(xDim, yDim, data_dir, pltval, start, end, incr)
Definition: plot.py:163
def plot_complex(xDim, yDim, data_dir, pltval, start, end, incr)
Definition: plot.py:110
def plot_var(xDim, yDim, data_dir, pltval)
Definition: plot.py:32
def plot_var_range(xDim, yDim, data_dir, pltval, start, end, incr)
Definition: plot.py:53
Definition: plot.py:1
Latin Modern latex print('-dpng','-r300', ['./Comp_CBAR_', int2str(iii),'.png'])