Beispiel #1
0
def read_shadow_file(filename, histogram_bins=None):
    if histogram_bins is None:
        raise ValueError("'histogram_bins' kwarg should be specified.")

    beam = sd.Beam()
    beam.load(filename)

    # 1=X spatial coordinate; 3=Z spatial coordinate
    data_dict = beam.histo2(1, 3, nolost=1, nbins=histogram_bins)
    data = data_dict['histogram']

    # This returns a list of N values (N=number of rays)
    photon_energy_list = Shadow.ShadowTools.getshcol(filename,
                                                     col=11)  # 11=Energy [eV]
    photon_energy = np.mean(photon_energy_list)

    return {
        'data': data,
        'shape': data.shape,
        'mean': np.mean(data),
        'photon_energy': photon_energy,
        'horizontal_extent': data_dict['xrange'][:2],
        'vertical_extent': data_dict['yrange'][:2],
        # 'labels': labels,
        # 'units': units,
    }
Beispiel #2
0
def plotxy(beam,col_h,col_v, nofwhm=1, title="", **kwargs):
  """

  plotxy implementation using matplotlib.
  Calculations are done using Shadow.beam.plotxy()

  :param beam: it can be a SHADOW binary file, an instance of Shadow.Beam() or a dictionary from Shadow.Beam.plotxy
  :param col_h: The column for the H coordinate in the plot (irrelevant of beam is a dictionary)
  :param col_v: The column for the H coordinate in the plot (irrelevant of beam is a dictionary)
  :param nofwhm: set to 0 to label the FWHM value in the plot (default do not label)
  :param kwargs: keywrods passed to Shadow.Beam.plotxy
  :return: the dictionary returned by Shadow.beam.plotxy() with some added keys.
  """
  if title == "":
      title = "plotxy"

  if isinstance(beam,dict):
    tkt = beam
    col_h = tkt["col_h"]
    col_v = tkt["col_v"]
  else:
    if isinstance(beam,str):
      beam1 = sd.Beam()
      beam1.load(beam)
      title += " - file: "+beam
      beam = beam1
    tkt = beam.plotxy(col_h,col_v,**kwargs)


  xtitle = "Column %d"%tkt["col_h"]
  ytitle = "Column %d"%tkt["col_v"]

  figure = plt.figure(figsize=(12,8),dpi=96)

  ratio = 8.0/12.0

  rect_scatter = [0.10*ratio, 0.10, 0.65*ratio, 0.65]
  rect_histx =   [0.10*ratio, 0.77, 0.65*ratio, 0.20]
  rect_histy =   [0.77*ratio, 0.10, 0.20*ratio, 0.65]
  rect_text =    [1.00*ratio, 0.10, 1.20*ratio, 0.65]

  #
  #main plot
  #
  axScatter = figure.add_axes(rect_scatter)
  axScatter.set_xlabel(xtitle)
  axScatter.set_ylabel(ytitle)

  # axScatter.set_xlim(tkt["xrange"])
  # axScatter.set_ylim(tkt["yrange"])

  axScatter.axis(xmin=tkt["xrange"][0],xmax=tkt["xrange"][1])
  axScatter.axis(ymin=tkt["yrange"][0],ymax=tkt["yrange"][1])
  #axScatter.pcolor(tkt["bin_h_edges"], tkt["bin_v_edges"], tkt["histogram"].T)
  axScatter.pcolormesh(tkt["bin_h_edges"], tkt["bin_v_edges"], tkt["histogram"].T)

  for tt in axScatter.get_xticklabels():
    tt.set_size('x-small')
  for tt in axScatter.get_yticklabels():
    tt.set_size('x-small')

  #
  #histograms
  #
  axHistx = figure.add_axes(rect_histx, sharex=axScatter)
  axHisty = figure.add_axes(rect_histy, sharey=axScatter)

  #for practical purposes, writes the full histogram path
  tmp_h_b = []
  tmp_h_h = []
  for s,t,v in zip(tkt["bin_h_left"],tkt["bin_h_right"],tkt["histogram_h"]):
    tmp_h_b.append(s)
    tmp_h_h.append(v)
    tmp_h_b.append(t)
    tmp_h_h.append(v)
  tmp_v_b = []
  tmp_v_h = []
  for s,t,v in zip(tkt["bin_v_left"],tkt["bin_v_right"],tkt["histogram_v"]):
    tmp_v_b.append(s)
    tmp_v_h.append(v)
    tmp_v_b.append(t)
    tmp_v_h.append(v)

  axHistx.plot(tmp_h_b,tmp_h_h)
  axHisty.plot(tmp_v_h,tmp_v_b)

  for tl in axHistx.get_xticklabels(): tl.set_visible(False)
  for tl in axHisty.get_yticklabels(): tl.set_visible(False)
  for tt in axHisty.get_xticklabels():
    tt.set_rotation(270)
    tt.set_size('x-small')
  for tt in axHistx.get_yticklabels():
    tt.set_size('x-small')

  if tkt["fwhm_h"] != None:
      hh = 0.5*numpy.max(tkt["histogram_h"])
      lines = [ [ (tkt["fwhm_coordinates_h"][0],hh), \
                  (tkt["fwhm_coordinates_h"][1],hh) ]]
      lc = collections.LineCollection(lines,color='red',linewidths=2)
      axHistx.add_collection(lc)
      if nofwhm != 1:
          if tkt["fwhm_coordinates_h"][0] < 0:
              shift1 = 0.9
          else:
              shift1 = 1.0
          axHistx.annotate('FWHM=%f'%tkt["fwhm_h"], xy=(shift1*tkt["fwhm_coordinates_h"][0],1.01*hh))

  if tkt["fwhm_v"] != None:
      hh = 0.5*numpy.max(tkt["histogram_v"])
      lines = [ [ (hh,tkt["fwhm_coordinates_v"][0]), \
                  (hh,tkt["fwhm_coordinates_v"][1]) ]]
      lc = collections.LineCollection(lines,color='green',linewidths=2)
      axHisty.add_collection(lc)
      if nofwhm != 1:
          if tkt["fwhm_coordinates_v"][0] < 0:
              shift1 = 0.9
          else:
              shift1 = 1.0
          axHisty.annotate('FWHM=%f'%tkt["fwhm_v"], xy=(shift1*tkt["fwhm_coordinates_v"][0],1.01*hh))


  if title!=None:
    axHistx.set_title(title)
  axText = figure.add_axes(rect_text)
  if tkt["nolost"] == 0: axText.text(0.0,0.8,"ALL RAYS")
  if tkt["nolost"] == 1: axText.text(0.0,0.8,"GOOD RAYS")
  if tkt["nolost"] == 2: axText.text(0.0,0.8,"LOST RAYS")

  #tmps = "intensity: %f"%(tkt["intensity"])

  axText.text(0.0,0.7,"intensity: %8.2f"%(tkt["intensity"]))
  axText.text(0.0,0.6,"total number of rays: "+str(tkt["nrays"]))
  axText.text(0.0,0.5,"total good rays: "+str(tkt["good_rays"]))
  axText.text(0.0,0.4,"total lost rays: "+str(tkt["nrays"]-tkt["nrays"]))
  calfwhm = 1
  if tkt["fwhm_h"] != None:
    axText.text(0.0,0.3,"fwhm H: "+str(tkt["fwhm_h"]))
  if tkt["fwhm_v"] != None:
    axText.text(0.0,0.2,"fwhm V: "+str(tkt["fwhm_v"]))

  if isinstance(beam,str): axText.text(0.0,0.1,"FILE: "+beam)
  if isinstance(beam,sd.Beam): axText.text(0.0,0.1,"from Shadow.Beam instance")
  if tkt["ref"] == 0:
    axText.text(0.0,0.0,"WEIGHT: RAYS")
  else:
      axText.text(0.0,0.0,"WEIGHT: INTENSITY")
  axText.set_axis_off()
  plt.show()
  return tkt
Beispiel #3
0
def plotxy_gnuplot(beam,col_h,col_v,execute=1,ps=0,pdf=0,title="",viewer='okular',**kwargs):
  """
  A plotxy implemented for gnuplot.
  It uses Shadow.beam.plotxy() for calculations.
  It creates files for gnuplot (plotxy.gpl and plotxy_*.dat)
  It can run gnuplot (system call) and display ps or pdf outputs

  :param beam: it can be a SHADOW binary file, an instance of Shadow.Beam() or a dictionary from Shadow.Beam.plotxy
  :param col_h: the H column for the plot. Irrelevant if beam is a dictionary
  :param col_v: the V column for the plot. Irrelevant if beam is a dictionary
  :param execute: set to 1 to make a system call to execute gnuplot (default=1)
  :param ps: set to 1 to get postscript output (irrelevant if pdf=1
  :param pdf: set to 1 for pdf output (prioritaire over ps)
  :param viewer: set to the ps or pdf viewer (default='okular')
  :param kwargs: keywords to be passed to Shadow.beam.plotxy()
  :return: the dictionary produced by Shadow.beam.plotxy with some keys added
  """
  if title == "":
      title = "plotxy"

  if isinstance(beam,dict):
    tkt = beam
    col_h = tkt["col_h"]
    col_v = tkt["col_v"]
  else:
    if isinstance(beam,str):
      beam1 = sd.Beam()
      beam1.load(beam)
      title += " - file: "+beam
      beam = beam1
    tkt = beam.plotxy(col_h,col_v,**kwargs)

  f = open("plotxy_histtop.dat",'w')
  for i in range(tkt["nbins_h"]):
      f.write("%12.5f  %12.5f \n"%( tkt["bin_h_left"][i], tkt["histogram_h"][i] ))
      f.write("%12.5f  %12.5f \n"%( tkt["bin_h_right"][i], tkt["histogram_h"][i] ))
  f.close()
  print("File written to disk: plotxy_histside.dat")

  f = open("plotxy_histside.dat",'w')
  for i in range(tkt["nbins_v"]):
      f.write("%12.5f  %12.5f \n"%( tkt["histogram_v"][i], tkt["bin_v_left"][i]  ))
      f.write("%12.5f  %12.5f \n"%( tkt["histogram_v"][i], tkt["bin_v_right"][i]  ))
  f.close()

  print("File written to disk: plotxy_histtop.dat")

  f = open("plotxy_grid.dat",'w')
  f.write(" # plotxy grid data for plotxy.gpl\n")
  f.write(" # Xbin Ybin Weight\n")
  for i in range(tkt["nbins_h"]):
    for j in range(tkt["nbins_v"]):
        f.write("%25.20f  %25.20f  %25.20f\n"%(tkt["bin_h_center"][i],tkt["bin_v_center"][j], tkt["histogram"][i,j] ))
    f.write("\n")
  f.close()
  print("File written to disk: plotxy_grid.dat")

  txt = """
    #GnuPlot command file for PLOTXY
    #Minimum version: gnuplot 4.2 patchlevel 6
    #
    {set_terminal}

    set multiplot

    #
    # top histogram
    #
    set lmargin screen 0.2125
    set rmargin screen 0.70
    set bmargin screen 0.75
    set tmargin screen 0.90
    unset xtics
    unset x2tics
    unset ytics
    unset y2tics
    unset key
    unset xlabel
    unset ylabel
    unset x2label
    unset y2label

    set x2tics mirror
    set x2label "  {title} "
     set xrange[  {xrange[0]} :  {xrange[1]} ]
     set yrange[*:*]
    plot "plotxy_histtop.dat" u 1:2 w lines lt -1 notitle


    #
    # side histogram
    #
    set lmargin screen 0.10
    set rmargin screen 0.2125
    set bmargin screen 0.10
    set tmargin screen 0.75
    unset xtics
    unset x2tics
    unset ytics
    unset y2tics
    unset key
    unset xlabel
    unset ylabel
    unset x2label
    unset y2label

    set ytics
    set ylabel "Column  {col_v}"

    set xrange[*:*]
    set yrange[  {yrange[0]} :  {yrange[1]} ]
    plot "plotxy_histside.dat" u (-$1):2 w lines lt -1 notitle

    #
    # scattered/contour plot
    #
    set lmargin screen 0.2125
    set rmargin screen 0.70
    set bmargin screen 0.10
    set tmargin screen 0.75
    unset xtics
    unset x2tics
    unset ytics
    unset y2tics
    unset key
    unset xlabel
    unset ylabel
    unset x2label
    unset y2label

    set xlabel "Column  {col_h}"

    set xrange[  {xrange[0]} :   {xrange[1]} ]
    set yrange[  {yrange[0]} :   {yrange[1]} ]
    #
    # IF PIXEL UNCOMMENT THIS
    #
    set pm3d map
    set palette gray
    splot "./plotxy_grid.dat" u 1:2:3 notitle

    #
    # info column
    #
    set obj 10 rect from graph 1.20, graph 1 to graph 1.61, graph 0
    set label "{label_id}"       at graph 1.21, graph 0.9
    set label "{label_good}"       at graph 1.21, graph 0.5
    set label "TOT  =    {nrays}"    at graph 1.21, graph 0.30
    set label "LOST =    {lost_rays}"    at graph 1.21, graph 0.25
    set label "GOOD =    {good_rays}"    at graph 1.21, graph 0.20
    set label "INTENS =  {intensity}" at graph 1.21, graph 0.15
    set label "{label_weight}"      at graph 1.21, graph 0.10
    replot

    unset multiplot

    {set_pause}

    """
  #add kws to dictionnary to be used in the template

  tkt["set_terminal"] = "set terminal x11 size 900,600"
  tkt["set_pause"] = "pause -1 'Press <Enter> to end graphic '"
  if ps:
      tkt["set_terminal"] = "set terminal postscript \n    set output 'plotxy.ps' "
      tkt["set_pause"] = ""
  if pdf:
      tkt["set_terminal"] = "set terminal pdf \n    set output 'plotxy.pdf' "
      tkt["set_pause"] = ""

  tkt["title"] = title
  tkt["lost_rays"] = tkt["nrays"] - tkt["good_rays"]
  tkt["label_id"] = os.getenv("USER")+"@"+os.getenv("HOST")
  if tkt["ref"] == 0:
      tkt["label_weight"] = "WEIGHT: RAYS"
  else:
      if tkt["ref"] == 1 or tkt["ref"] == 23:
        tkt["label_weight"] = "WEIGHT: INTENSITY"
      else:
        tkt["label_weight"] = "WEIGHT: COLUMN %d"%(tkt["ref"])

  if tkt["nolost"] == 0:
      tkt["label_good"] = "--ALL RAYS"
  elif tkt["nolost"] == 1:
      tkt["label_good"] = "--GOOD ONLY"
  else:
      tkt["label_good"] = "--ONLY LOSSES"

  txt2 = txt.format_map(tkt)

  f = open("plotxy.gpl",'w')
  f.write(txt2)
  f.close()

  print("File written to disk: plotxy.gpl")

  if execute:
      os.system("gnuplot plotxy.gpl")
      if ps:
          os.system(viewer+" plotxy.ps")
      if pdf:
        os.system(viewer+" plotxy.pdf")

  return tkt
Beispiel #4
0
def getshonecol(beam,col):
  '''
  Extract a column from a shadow file (eg. begin.dat) or a Shadow.Beam instance. 
  The column are numbered in the fortran convention, i.e. starting from 1.
  It returns a numpy.array filled with the values of the chosen column.
  
  Inumpy.ts:
     beam     : str instance with the name of the shadow file to be loaded. OR
                Shadow.Beam initialized instance.
     col      : int for the chosen columns.
     
  Outputs:
     numpy.array 1-D with length numpy.INT.
     
  Error:
     if an error occurs an ArgsError is raised.
     
  Possible choice for col are:
           1   X spatial coordinate [user's unit]
           2   Y spatial coordinate [user's unit]
           3   Z spatial coordinate [user's unit]
           4   Xp direction or divergence [rads]
           5   Yp direction or divergence [rads]
           6   Zp direction or divergence [rads]
           7   X component of the electromagnetic vector (s-polariz)
           8   Y component of the electromagnetic vector (s-polariz)
           9   Z component of the electromagnetic vector (s-polariz)
          10   Lost ray flag
          11   Energy [eV]
          12   Ray index
          13   Optical path length
          14   Phase (s-polarization)
          15   Phase (p-polarization)
          16   X component of the electromagnetic vector (p-polariz)
          17   Y component of the electromagnetic vector (p-polariz)
          18   Z component of the electromagnetic vector (p-polariz)
          19   Wavelength [A]
          20   R= SQRT(X^2+Y^2+Z^2)
          21   angle from Y axis
          22   the magnituse of the Electromagnetic vector
          23   |E|^2 (total intensity)
          24   total intensity for s-polarization
          25   total intensity for p-polarization
          26   K = 2 pi / lambda [A^-1]
          27   K = 2 pi / lambda * col4 [A^-1]
          28   K = 2 pi / lambda * col5 [A^-1]
          29   K = 2 pi / lambda * col6 [A^-1]
          30   S0-stokes = |Es|^2 + |Ep|^2
          31   S1-stokes = |Es|^2 - |Ep|^2
          32   S2-stokes = 2 |Es| |Ep| cos(phase_s-phase_p)
          33   S3-stokes = 2 |Es| |Ep| sin(phase_s-phase_p)
  '''
  try: stp.getshonecol_CheckArg(beam,col)
  except stp.ArgsError as e: raise e
  col=col-1
  if isinstance(beam,sd.Beam):
    ray = beam.rays
  else:
    bm = sd.Beam()
    bm.load(beam)
    ray = bm.rays
  if col>=0 and col<18 and col!=10:  column =  ray[:,col]
  if col==10: column =  ray[:,col]/A2EV
  if col==18: column =  2*numpy.pi*1.0e8/ray[:,10]
  if col==19: column =  numpy.sqrt(ray[:,0]*ray[:,0]+ray[:,1]*ray[:,1]+ray[:,2]*ray[:,2])
  if col==20: column =  numpy.arccos(ray[:,4])
  if col==21: column =  numpy.sqrt(numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8,15,16,17] ]),axis=0))
  if col==22: column =  numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8,15,16,17] ]),axis=0)
  if col==23: column =  numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8] ]),axis=0)
  if col==24: column =  numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [15,16,17] ]),axis=0)
  if col==25: column =  ray[:,10]*1.0e8
  if col==26: column =  ray[:,3]*ray[:,10]*1.0e8
  if col==27: column =  ray[:,4]*ray[:,10]*1.0e8
  if col==28: column =  ray[:,5]*ray[:,10]*1.0e8
  if col==29:
    E2s = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8] ]),axis=0)
    E2p = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [15,16,17] ]),axis=0)
    column =  E2p+E2s    
  if col==30:
    E2s = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8] ]),axis=0)
    E2p = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [15,16,17] ]),axis=0)
    column =  E2p-E2s
  if col==31:
    E2s = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8] ]),axis=0)
    E2p = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [15,16,17] ]),axis=0)
    Cos = numpy.cos(ray[:,13]-ray[:,14])
    column =  2*E2s*E2p*Cos
  if col==32:
    E2s = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [6,7,8] ]),axis=0)
    E2p = numpy.sum(numpy.array([ ray[:,i]*ray[:,i] for i in [15,16,17] ]),axis=0)
    Sin = numpy.sin(ray[:,13]-ray[:,14])
    column =  2*E2s*E2p*Sin
  return column
Beispiel #5
0
def histo1(beam, col, notitle=0, nofwhm=0,  bar=0,  **kwargs):
    """
    Plot the histogram of a column, as calculated by Shadow.Beam.histo1 using matplotlib

    NOTE: This will replaces the old histo1 still available as histo1_old

    :param beam: a Shadow.Beam() instance, or a file name with Shadow binary file
    :param col: the Shadow column number (start from 1)
    :param notitle: set to 1 to avoid displaying title
    :param nofwhm: set to 1 to avoid labeling FWHM value
    :param bar: 1=bar plot, 0=line plot
    :param kwargs: keywords accepted by Shadow.Beam.histo1()
    :return: the dictionary returned by Shadow.beam.histo1() with some keys added.
    """

    title = "histo1"

    if isinstance(beam,str):
        beam1 = sd.Beam()
        beam1.load(beam)
        title += " - file: "+beam
        beam = beam1

    tk2 = beam.histo1(col, **kwargs)



    h = tk2["histogram"]
    bins = tk2["bin_left"]
    xrange = tk2["xrange"]
    yrange = [0,1.1*numpy.max(h)]
    fwhm = tk2["fwhm"]

    xtitle = "column %d"%tk2["col"]
    ytitle = "counts ("

    if tk2["nolost"] == 0:
        ytitle += " all rays"
    if tk2["nolost"] == 1:
        ytitle += " good rays"
    if tk2["nolost"] == 2:
        ytitle += " lost rays"

    if tk2["ref"] == 0:
        ytitle += " = weight: number of rays"
    else:
        if tk2["ref"] == 23:
            ytitle += " - weight: intensity"
        else:
            ytitle += " - weight column: %d"%(tk2["ref"])

    ytitle += ")"


    if fwhm != None: print ("fwhm = %g" % fwhm)

    fig0 = plt.figure()
    ax = fig0.add_subplot(111)

    ax.set_xlabel(xtitle)
    ax.set_ylabel(ytitle)
    if notitle != 1: ax.set_title(title)
    ax.set_xlim(xrange[0],xrange[1])
    ax.set_ylim(yrange[0],yrange[1])
    ax.grid(True)

    if bar:
        l = ax.bar(bins, h, 1.0*(bins[1]-bins[0]),color='blue') #,error_kw=dict(elinewidth=2,ecolor='red'))
    else:
        l = plt.plot(tk2["bin_path"], tk2["histogram_path"], color='blue') #,error_kw=dict(elinewidth=2,ecolor='red'))

    if tk2["fwhm"] != None:
        hh = 0.5*numpy.max(tk2["histogram"])
        lines = [ [ (tk2["fwhm_coordinates_h"][0],hh), \
                    (tk2["fwhm_coordinates_h"][1],hh) ]]
        print(lines)
        lc = collections.LineCollection(lines,color='red',linewidths=2)
        ax.add_collection(lc)
        if nofwhm != 1:
            if tk2["fwhm_coordinates_h"][0] < 0:
                shift1 = 0.9
            else:
                shift1 = 1.0
            ax.annotate('FWHM=%f'%tk2["fwhm"], xy=(shift1*tk2["fwhm_coordinates_h"][0],1.01*tk2["fwhm_coordinates_v"][0]))

    plt.show()
    return tk2
Beispiel #6
0
def getshcol(beam,col):
  '''
  Extract multiple columns from a shadow file (eg.'begin.dat') or a Shadow.Beam instance. 
  The column are numbered in the fortran convention, i.e. starting from 1.
  It returns a numpy.array filled with the values of the chosen column.
  
  Inumpy.ts:
     beam     : str instance with the name of the shadow file to be loaded. OR
                Shadow.Beam initialized instance.
     col      : tuple or list instance of int with the number of columns chosen.
     
  Outputs:
     numpy.array 2-D with dimension R x numpy.INT. Where R is the total number of column chosen
     
  Error:
     if an error occurs an ArgsError is raised.      

  Possible choice for col are:
           1   X spatial coordinate [user's unit]
           2   Y spatial coordinate [user's unit]
           3   Z spatial coordinate [user's unit]
           4   X' direction or divergence [rads]
           5   Y' direction or divergence [rads]
           6   Z' direction or divergence [rads]
           7   X component of the electromagnetic vector (s-polariz)
           8   Y component of the electromagnetic vector (s-polariz)
           9   Z component of the electromagnetic vector (s-polariz)
          10   Lost ray flag
          11   Energy [eV]
          12   Ray index
          13   Optical path length
          14   Phase (s-polarization)
          15   Phase (p-polarization)
          16   X component of the electromagnetic vector (p-polariz)
          17   Y component of the electromagnetic vector (p-polariz)
          18   Z component of the electromagnetic vector (p-polariz)
          19   Wavelength [A]
          20   R= SQRT(X^2+Y^2+Z^2)
          21   angle from Y axis
          22   the magnituse of the Electromagnetic vector
          23   |E|^2 (total intensity)
          24   total intensity for s-polarization
          25   total intensity for p-polarization
          26   K = 2 pi / lambda [A^-1]
          27   K = 2 pi / lambda * col4 [A^-1]
          28   K = 2 pi / lambda * col5 [A^-1]
          29   K = 2 pi / lambda * col6 [A^-1]
          30   S0-stokes = |Es|^2 + |Ep|^2
          31   S1-stokes = |Es|^2 - |Ep|^2
          32   S2-stokes = 2 |Es| |Ep| cos(phase_s-phase_p)
          33   S3-stokes = 2 |Es| |Ep| sin(phase_s-phase_p)
  '''
  try: stp.getshcol_CheckArg(beam,col)
  except stp.ArgsError as e: raise e
  if isinstance(beam,sd.Beam):
    bm = beam
  else:
    bm = sd.Beam()
    bm.load(beam)  
  ret = []
  if isinstance(col, int): return getshonecol(bm,col)
  for c in col:
    ret.append(getshonecol(bm,c))
  return tuple(ret)