iagapov / ocelot

Main repository moved to https://github.com/ocelot-collab/ocelot
GNU General Public License v3.0
8 stars 11 forks source link

FEL simulations: hxrss_common.py - consider change in update_beam #44

Closed ggeloni closed 8 years ago

ggeloni commented 8 years ago

Consider deleting the line

beam_new.z = beam_new.z[:-i_diff]

in the update_beam function in hxrss_common.py

The number of slices in the radiation file is larger than the original one in the beam file. i_diff is defined as such difference. If you redefine beam_new.z with beam_new.z = beam_new.z[:-i_diff] you actually cut the original beamfile, ending up with less slices than in the original beamfile. Deleting this line you end up with a number of slices in the beam file equal to the original one.

iagapov commented 8 years ago

it seems to be so. Did you test that deleting this works? Then I can fix that.

iagapov commented 8 years ago

commented out

ggeloni commented 8 years ago

...actually the fix does not fully solve the Problem. g0 and dg will still have a number of components larger than beam_new.z. However, the abscissa in g0 and dg are just re-scaled with respect to the beam, so cutting does not work when the difference in length is large. I suggest the following mor radical fix (which seems to work). In this case I only Need two arguments: a 'new_beam' which will be updated, and g.

def update_beam_2(beam_new, g): beam = deepcopy(beam_new) g0 = np.array(map(lambda x : g.sliceValues[x]['energy'][-1], xrange(1,g.nSlices+1)) ) dg = np.array(map(lambda x : g.sliceValues[x]['e-spread'][-1], xrange(1,g.nSlices+1)) )

print len(g0)
print g.nSlices

print len(beam_new.z)

I = np.array(g.I)

n_interp = g.nSlices
'''
plt.figure()
plt.plot(beam_new.g0)
plt.plot(g0 + beam.gamma_rel)
plt.figure()
plt.plot(beam_new.dg)
plt.plot(dg)
plt.figure()
plt.plot(I)
plt.plot(beam_new.I)
plt.show()
'''
beam_new.z = np.linspace(beam.z[0], beam.z[-1], n_interp) 
beam_new.I = np.interp(beam_new.z, beam.z, beam.I)

zmax, Imax = peaks(beam_new.z, beam_new.I, n=1)
beam_new.idx_max = np.where(beam_new.z == zmax)[0][0]

beam_new.ex = np.interp(beam_new.z, beam.z, beam.ex) 
beam_new.ey = np.interp(beam_new.z, beam.z, beam.ey) 
beam_new.zsep = beam.zsep * len(beam.z) / len(beam_new.z)
#beam_new.g0 = np.interp(beam_new.z, beam.z, beam.g0) 
beam_new.g0 = g0 + beam.gamma_rel
beam_new.dg = np.interp(beam_new.z, beam.z, beam.dg)
beam_new.dg = dg   

beam_new.eloss = np.interp(beam_new.z, beam.z, beam.eloss)

beam_new.betax = np.interp(beam_new.z, beam.z, beam.betax)
beam_new.betay = np.interp(beam_new.z, beam.z, beam.betay)
beam_new.alphax = np.interp(beam_new.z, beam.z, beam.alphax)
beam_new.alphay = np.interp(beam_new.z, beam.z, beam.alphay)

beam_new.x = np.interp(beam_new.z, beam.z, beam.x) 
beam_new.px = np.interp(beam_new.z, beam.z, beam.px) 
beam_new.y = np.interp(beam_new.z, beam.z, beam.y)
beam_new.py = np.interp(beam_new.z, beam.z, beam.py)
'''
plt.figure()
plt.plot(beam_new.g0)
plt.plot(g0 + beam.gamma_rel)
plt.figure()
plt.plot(beam_new.dg)
plt.plot(dg)
plt.figure()
plt.plot(I)
plt.plot(beam_new.I)
plt.show()
'''