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_range_dsfs.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #! /usr/bin/env python
  2. """
  3. Plot DSF.
  4. Usage: python plot_dsf_k_range.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 K file
  18. kfile = glob.glob('../data/N_%s/c_%s*/K_*' % (N, str(clist[0]).rstrip('.0')[:12]))[0]
  19. k = np.loadtxt(kfile)
  20. # Get the Omega file
  21. omegafile = glob.glob('../data/N_%s/c_%s*/Omega*' % (N, str(clist[0]).rstrip('.0')[:12]))[0]
  22. omega = np.loadtxt(omegafile)
  23. # Load all the available dsfs from the data store
  24. dsfs = {}
  25. for c in clist:
  26. # Do some black magic here: for matching the interaction,
  27. # first try for exact match, stripping '.0' to treat integer values, e.g. 4.0 into 4
  28. # and then (if it doesn't work) use only the first 12 characters, plus wildcard, to cover rounding errors
  29. try:
  30. dsffile = glob.glob('../data/N_%s/c_%s/*_w_%s.dsfs' % (N, str(c).rstrip('.0'), width))[0]
  31. except IndexError:
  32. dsffile = glob.glob('../data/N_%s/c_%s*/*_w_%s.dsfs' % (N, str(c).rstrip('.0')[:12], width))[0]
  33. dsfs[str(c)] = np.loadtxt(dsffile)
  34. # Read some useful parameters from (last) file name:
  35. elements = dsffile.rpartition('/')[2].split('_')
  36. L = elements[5]
  37. #N = elements[7]
  38. iKmax = elements[14]
  39. width = elements[22].rpartition('.')[0]
  40. # which leads to
  41. rho = int(N)/int(L)
  42. #kokF = int(iK)*0.5/int(L)
  43. fig, ax = plt.subplots()
  44. # To determine the y axis limits, we look at the lowest value of c (sharpest peak)
  45. dsfsmax = 0.5
  46. ymax = omega[-1]
  47. xtext = 0.05 * k[-1]
  48. ytext = 0.9 * ymax
  49. ax.text(xtext, ytext, f'c = {clist[0]:10.6f}', color='white', fontsize='large')
  50. pcm = ax.pcolormesh(k, omega, dsfs[str(clist[0])], vmax=dsfsmax)
  51. fig.colorbar(pcm, ax=ax)
  52. def animate(i):
  53. ax.clear()
  54. ax.set_title(f'c scan, rho={rho} (N={N}), w={width}', fontsize='x-large')
  55. ax.text(xtext, ytext, f'c = {clist[i]:10.6f}', color='white', fontsize='x-large')
  56. ax.pcolormesh(k, omega, dsfs[str(clist[i])], vmax=dsfsmax)
  57. ani = animation.FuncAnimation(fig, animate, frames=len(clist), interval=100, repeat=False)
  58. outfilename = (dsffile.partition('_c_')[0].rpartition('/')[2] + '_c_scan_' +
  59. dsffile.partition('_c_')[2].partition('_')[2].partition('.dsfs')[0])
  60. ani.save(outfilename + '.mp4')
  61. with open(outfilename + '.html', 'w') as file:
  62. file.write(ani.to_html5_video())
  63. #plt.show()