polarplot.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. # Copyright (C) 2013-2015 Konstantin Ladutenko <kostyfisik@gmail.com>
  6. #
  7. # This file is part of python-scattnlay
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # The only additional remark is that we expect that all publications
  20. # describing work using this software, or all commercial products
  21. # using it, cite the following reference:
  22. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  23. # a multilayered sphere," Computer Physics Communications,
  24. # vol. 180, Nov. 2009, pp. 2348-2354.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. from scattnlay import scattnlay
  29. import numpy as np
  30. import cmath
  31. import matplotlib.pyplot as plt
  32. import matplotlib as mp
  33. import math as m
  34. import sys,os,shutil,glob,subprocess
  35. def polarplot(x, m, fname, plot_type="unpolarized", mode_n = -1, mode_type = -1):
  36. theta = np.linspace(0,2*np.pi, 360*4)
  37. theta = theta[:-1]
  38. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  39. np.array([x]), np.array([m]), theta = theta, mode_n = mode_n, mode_type = mode_type)
  40. S = 1.0/2.0*( np.abs(S1[0])**2 + np.abs(S2[0])**2 )
  41. print(S)
  42. font = {'family' : 'monospace',
  43. 'weight' : 'bold',
  44. 'size' : '20'}
  45. mp.rc('font', **font)
  46. mp.rcParams['axes.linewidth'] = 2
  47. #mp.rcParams['grid.linewidth'] = 1.5
  48. mp.rcParams['legend.fontsize'] = 20
  49. mp.rcParams['axes.labelweight'] = 'bold'
  50. #mp.rcParams['lines.linewidth'] = 1.5
  51. ax = plt.subplot(111, polar=True)
  52. # low_lim = np.min(S)
  53. # hi_lim = np.max(S)
  54. # ax.set_ylim(low_lim, hi_lim)
  55. # yticks = np.arange(low_lim,hi_lim, 5)
  56. # ax.set_yticks(yticks)
  57. # ax.set_yticklabels(yticks,fontsize='18')
  58. for lb in ax.get_yticklabels():
  59. lb.set_fontsize(15)
  60. # # ax.plot(theta, r, color='r', linewidth=3)
  61. # # ax.set_rmax(2.0)
  62. ax.grid(linestyle="--")
  63. # ax.set_ylabel("dBsm",rotation='horizontal');
  64. #ax.yaxis.set_label_coords(1.05, .7)
  65. # # ax.set_title("dBsm", loc=[0.78,0.97])
  66. # # tick locations
  67. # thetaticks = np.arange(0,360,45)
  68. # # set ticklabels location at 1.3 times the axes' radius
  69. # ax.set_thetagrids(thetaticks)# The frac parameter was deprecated in version
  70. # # 2.1. Use tick padding via Axes.tick_params
  71. # # instead. , frac=1.15)
  72. # ax.xaxis.label.set_visible(False)
  73. # ax.tick_params(pad=15)
  74. # plt.setp(ax.get_xticklabels(), visible=False)
  75. # plt.setp(ax.get_yticklabels(), visible=False)
  76. #plt.setp(ax.get_xticklines()[-2:], visible=False)
  77. #ax.grid()
  78. # Init line data structure, will be rewritten before real plotting.
  79. #line_tscs, = ax.plot(theta, np.log(S), 'r', linewidth=3, label=r"$S_{11}$")
  80. line_tscs, = ax.plot(theta, (S), 'r', linewidth=3, label=r"$S_{11}$")
  81. # handles, labels = ax.get_legend_handles_labels()
  82. # #lg = ax.legend(handles, labels, loc=[0.74,0.97])
  83. # #lg = ax.legend(handles, labels, loc=[-0.24,-0.12])
  84. # lg = ax.legend(handles, labels, loc=[-0.36,0.9])
  85. # lg.draw_frame(False)
  86. # #two curves per figure
  87. # line_bar.set_ydata(data_dBsm[i])
  88. plt.savefig(fname) #"RCS-"+description[i]+"-"+description[i+num_of_plots]+".svg", format="svg")
  89. plt.clf()
  90. plt.close()