fd_orthexp.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python
  2. import os,argparse, ConfigParser
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. from Tools.OrthExp import ExpDecompFn
  6. end = 10 # Maximum value to evaluate
  7. Npt = int(1e6) # Number of points to use
  8. Nbasis = 101 # Number of basis elements to evaluate
  9. toplot = { 1 : {'color': 'green'},
  10. 25 : {'color': 'blue'},
  11. 2 : {'color': 'black'},
  12. 10 : {'color': 'orange'},
  13. 0 : {'color': 'black', 'ls': '--'},
  14. }
  15. np.set_printoptions(precision=3, linewidth=160)
  16. ######
  17. # Parse command line parameters and config files
  18. ######
  19. ArgP = argparse.ArgumentParser(description='=== Functional Decomposition Orthonormal Exponential Plotter ===')
  20. ArgP.add_argument('--base', type=str, default=".", help="FD base directory.")
  21. ArgP.add_argument('--show', action="store_true", help="Display plots interactively.")
  22. ArgP.add_argument('--logx', action="store_true", help="Set x axis to log.")
  23. ArgP.add_argument('--save', type=str, default="Output/orthexp.pdf", help="Filename to save plot.")
  24. ArgC = ArgP.parse_args()
  25. Config = ConfigParser.ConfigParser()
  26. Config.optionxform = str
  27. Config.read( os.path.join(ArgC.base, "base.conf") )
  28. PlotStyle = Config.get("General", "PlotStyle")
  29. try: plt.style.use( PlotStyle )
  30. except IOError: plt.style.use( os.path.join(ArgC.base, PlotStyle) )
  31. x = np.linspace(0.001, end, Npt)
  32. w = np.ones((Npt,)) / Npt
  33. Decomp = ExpDecompFn( x=x, w=w, Nbasis=max(toplot.keys())+1, Lambda=1, x0=0, Alpha=1.0 )
  34. ######
  35. for D in Decomp:
  36. if D.N in toplot:
  37. plt.plot(x, Decomp.Values(), zorder=-D.N, label='$E_{%d}\\left(z\\right)$' % D.N, **toplot[D.N])
  38. print D.Values()
  39. print "%d: %f" % (D.N, Decomp.Moment())
  40. plt.xlabel("z")
  41. plt.ylabel("Arbitrary Units")
  42. plt.xlim( 1e-2, end)
  43. plt.ylim(-2, 2)
  44. if ArgC.logx:
  45. plt.xscale('log')
  46. plt.legend()
  47. plt.tight_layout()
  48. try:
  49. plt.savefig(ArgC.save)
  50. except IOError:
  51. print "Directory for save does not exist or cannot be written to."
  52. if ArgC.show:
  53. plt.show()