fit_d_param.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. from matplotlib import pyplot as plt
  4. import numpy as np
  5. import cma
  6. from eval_spectra import multi_lorentzian, params_count as pc
  7. import sys
  8. from_disk = np.loadtxt('rs4-d_perp_interpolated.txt')
  9. # from_disk = from_disk[:,
  10. # from_disk[0, :] > 0.4
  11. # ]
  12. # from_disk = from_disk[:,
  13. # from_disk[0, :] < 0.8
  14. # ]
  15. step = 5
  16. omega_ratio = np.copy(from_disk[0, ::step])
  17. d_rs4 = from_disk[1, ::step] + 1j*from_disk[2, ::step]
  18. def rms(x0):
  19. d_fit = multi_lorentzian(omega_ratio, x0)
  20. diff_re = np.real(d_rms - d_fit)
  21. diff_im = np.imag(d_rms - d_fit)
  22. # rms = np.sqrt(np.sum(np.abs(diff_re)**2))
  23. # rms += np.sqrt(np.sum(np.abs(diff_im)**2))
  24. rms = (np.sum(np.abs(diff_re)**2))
  25. rms += (np.sum(np.abs(diff_im)**2))
  26. return rms
  27. x0 = np.random.random(pc)
  28. d_rms = d_rs4
  29. x, es = cma.fmin2(rms, x0, sigma0=0.2)
  30. # x = np.array([0.1332754793043937, 0.8248539955310855, -
  31. # 0.5024906405674647, -0.08076797734842008])
  32. x1 = np.copy(x)
  33. x0 = np.random.random(pc)
  34. d_rms = d_rs4 - multi_lorentzian(omega_ratio, x1)
  35. x, es = cma.fmin2(rms, x0, sigma0=2)
  36. # x = np.array([0.0019369902204593222, 0.9978752165162739,
  37. # 0.05801769075873917, -0.032110084386726336])
  38. x2 = np.copy(x)
  39. x0 = np.hstack((x1, x2))
  40. d_rms = d_rs4
  41. x, es = cma.fmin2(rms, x0, sigma0=0.02)
  42. # x = np.array([0.11878109939932953, 0.8142072049467617, -0.43466301805510305, -0.012772472816983446,
  43. # 0.012573279034397847, 1.0010563127596699, 0.07665592968844606, -0.07679477702750433])
  44. x12 = x
  45. x0 = np.random.random(pc)
  46. d_rms = d_rs4 - multi_lorentzian(omega_ratio, x12)
  47. x, es = cma.fmin2(rms, x0, sigma0=0.2)
  48. # x = np.array([0.1434266344187499, 0.5188802822956783, -
  49. # 0.00950433613285183, 0.013585684987833985])
  50. x3 = np.copy(x)
  51. x0 = np.hstack((x1, x2, x3))
  52. d_rms = d_rs4
  53. x, es = cma.fmin2(rms, x0, sigma0=0.02)
  54. # x = np.array([0.09914803, 0.81158511, -0.34941712, 0.01388308,
  55. # 0.01560184, 1.00551237, 0.11006553, -0.09818891,
  56. # 0.34432793, 0.64182428, -0.0803532, 0.04641341])
  57. x123 = x
  58. # [ 0.09349663 -0.8188804 -0.36874431 -0.08079194
  59. # 0.25712096 0.56012451 -0.02089828 0.03133694]
  60. # [ 0.09391149 0.81234806 -0.30526326 -0.01044856
  61. # 0.3121473 0.55333457 -0.01684191 0.04727765
  62. # 0.11249052 0.88368699 -0.04680872 -0.10982548]
  63. print(x)
  64. d_fit = multi_lorentzian(omega_ratio, x)
  65. plt.figure('rs4')
  66. plt.plot(omega_ratio, np.real(d_rms), label='re d')
  67. plt.plot(omega_ratio, np.imag(d_rms), label='im d')
  68. plt.plot(omega_ratio, np.real(d_fit), label='re d fit', alpha=0.2, lw=3)
  69. plt.plot(omega_ratio, np.imag(d_fit), label='im d fit', alpha=0.2, lw=3)
  70. plt.axhline(y=0.0, color='black', linestyle='-', lw=1, alpha=0.2)
  71. plt.legend()
  72. plt.show()