You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plot_c_scan_k_fixed_dsfs.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #! /usr/bin/env python
  2. """
  3. Plot fixed momentum DSF.
  4. Usage: python plot_dsf_k_fixed.py [omega file] [dsf file]
  5. """
  6. import glob
  7. import matplotlib.pyplot as plt
  8. import matplotlib.animation as animation
  9. import numpy as np
  10. import os
  11. import sys
  12. N = str(sys.argv[1])
  13. width = str(sys.argv[2])
  14. # Get the list of interactions which have been computed
  15. dirlist = os.listdir('../data/N_%s' % N)
  16. clist = sorted([float(c.lstrip('c_')) for c in dirlist])
  17. # Get the Omega file
  18. omegafile = glob.glob('../data/N_%s/c_%s*/Omega*' % (N, str(clist[0]).rstrip('.0')[:12]))[0]
  19. omega = np.loadtxt(omegafile)
  20. # Load all the available dsfs from the data store
  21. dsfs = {}
  22. for c in clist:
  23. # Do some black magic here: for matching the interaction,
  24. # first try for exact match, stripping '.0' to treat integer values, e.g. 4.0 into 4
  25. # and then (if it doesn't work) use only the first 12 characters, plus wildcard, to cover rounding errors
  26. try:
  27. dsffile = glob.glob('../data/N_%s/c_%s/*_w_%s.dsfs' % (N, str(c).rstrip('.0'), width))[0]
  28. except IndexError:
  29. dsffile = glob.glob('../data/N_%s/c_%s*/*_w_%s.dsfs' % (N, str(c).rstrip('.0')[:12], width))[0]
  30. dsfs[str(c)] = np.loadtxt(dsffile)
  31. # Read some useful parameters from (last) file name:
  32. elements = dsffile.rpartition('/')[2].split('_')
  33. L = elements[5]
  34. #N = elements[7]
  35. iK = elements[12]
  36. width = elements[20].rpartition('.')[0]
  37. # which leads to
  38. rho = int(N)/int(L)
  39. kokF = int(iK)*0.5/int(L)
  40. fig, ax = plt.subplots()
  41. ax.set_xlim(omega[0], omega[-1])
  42. # To determine the y axis limits, we look at the lowest value of c (sharpest peak)
  43. dsfsmax = max(dsfs[str(clist[0])])
  44. ymax = 1.01 * dsfsmax
  45. ymax=4
  46. xtext = 0.6 * omega[-1]
  47. ytext = 0.9 * ymax
  48. ax.set_ylim([0, ymax])
  49. ax.text(xtext, ytext, f'c = {clist[0]}')
  50. ax.plot(omega, dsfs[str(clist[0])])
  51. def animate(i):
  52. ax.clear()
  53. ax.set_xlim(omega[0], omega[-1])
  54. ax.set_ylim([0, ymax])
  55. ax.set_title(f'c scan, rho={rho} (N={N}), k={kokF}k_F, w={width}')
  56. ax.text(xtext, ytext, f'c = {clist[i]:10.6f}')
  57. ax.plot(omega, dsfs[str(clist[i])])
  58. ani = animation.FuncAnimation(fig, animate, frames=len(clist), interval=100, repeat=False)
  59. outfilename = (dsffile.partition('_c_')[0].rpartition('/')[2] + '_c_scan_' +
  60. dsffile.partition('_c_')[2].partition('_')[2].partition('.dsfs')[0])
  61. ani.save(outfilename + '.mp4')
  62. with open(outfilename + '.html', 'w') as file:
  63. file.write(ani.to_html5_video())
  64. #plt.show()