Skip to content

Commit

Permalink
finished refactoring *Bunch
Browse files Browse the repository at this point in the history
  • Loading branch information
srio committed Oct 5, 2023
1 parent 97bc450 commit 6474093
Show file tree
Hide file tree
Showing 8 changed files with 541 additions and 90 deletions.
16 changes: 8 additions & 8 deletions crystalpy/util/ComplexAmplitudePhotonBunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy

#todo: replace name "polarized" by "complex_amplitude"
class ComplexAmplitudePhotonBunch(PhotonBunch):
class ComplexAmplitudePhotonBunchOld(PhotonBunch):
"""Constructor.
Parameters
Expand Down Expand Up @@ -106,7 +106,7 @@ def toString(self):
# NEWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
#

class ComplexAmplitudePhotonBunchNew(ComplexAmplitudePhoton):
class ComplexAmplitudePhotonBunch(ComplexAmplitudePhoton):
"""Constructor.
New version that inheritates from ComplexAmplitudePhoton and uses stacks for more effcient stockage.
Expand All @@ -133,15 +133,15 @@ def __init__(self, complex_amplitude_photons=None):
energy[i] = el.energy()
Esigma[i] = el.getComplexAmplitudeS()
Epi[i] = el.getComplexAmplitudeP()
el.unitDirectionVector()
vv = el.unitDirectionVector()
if i == 0:
v = Vector(
el.components()[0],
el.components()[1],
el.components()[2],
vv.components()[0],
vv.components()[1],
vv.components()[2],
)
else:
v.append(el)
v = v.append(vv)
self.setEnergy(energy)
self.setUnitDirectionVector(v)
super().__init__(energy_in_ev=energy, direction_vector=v, Esigma=Esigma, Epi=Epi)
Expand Down Expand Up @@ -210,7 +210,7 @@ def addPhoton(self, to_be_added):
self.setEnergy(numpy.append(self.energy(), to_be_added.energy()))
self.setComplexAmplitudeS(numpy.append(self.getComplexAmplitudeS(), to_be_added.getComplexAmplitudeS()))
self.setComplexAmplitudeP(numpy.append(self.getComplexAmplitudeP(), to_be_added.getComplexAmplitudeP()))
self.setUnitDirectionVector(self.unitDirectionVector().append(to_be_added.unitDirectionVector()))
self.setUnitDirectionVector(self.unitDirectionVector().concatenate(to_be_added.unitDirectionVector()))

def addPhotonsFromList(self, to_be_added):
"""Adds a list of photons to the bunch.
Expand Down
16 changes: 8 additions & 8 deletions crystalpy/util/PhotonBunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from crystalpy.util.ComplexAmplitudePhoton import ComplexAmplitudePhoton
from crystalpy.util.PolarizedPhoton import PolarizedPhoton

class PhotonBunch(object):
class PhotonBunchOld(object):
"""The PhotonBunch is is a collection of Photon instances, making up the photon bunch or beam.
Constructor.
Expand Down Expand Up @@ -48,7 +48,7 @@ def initialize_from_energies_and_directions(cls, energies, V):
if V.nStack() != energies.size:
raise Exception("incompatible inputs")

bunch = PhotonBunch()
bunch = PhotonBunchOld()

for i in range(energies.size):
bunch.addPhoton(Photon(energy_in_ev=energies[i], direction_vector=V.extractStackItem(i)))
Expand Down Expand Up @@ -371,7 +371,7 @@ def __getitem__(self, key):
# NEWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
#

class PhotonBunchNew(Photon):
class PhotonBunch(Photon):
"""The PhotonBunchNew is is a collection of Photon instances, making up the photon bunch or beam.
New version that inheritates from Photon and uses stacks for more effcient stockage.
Expand Down Expand Up @@ -423,7 +423,7 @@ def initialize_from_energies_and_directions(cls, energies, V):
"""
bunch = PhotonBunchNew()
bunch = PhotonBunch()
bunch.setEnergy(energies)
bunch.setUnitDirectionVector(V)
return bunch
Expand Down Expand Up @@ -482,7 +482,7 @@ def addPhoton(self, to_be_added):
"""
self.setEnergy(numpy.append(self.energy(), to_be_added.energy()))
self.setUnitDirectionVector(self.unitDirectionVector().append(to_be_added.unitDirectionVector()))
self.setUnitDirectionVector(self.unitDirectionVector().concatenate(to_be_added.unitDirectionVector()))

def addPhotonsFromList(self, to_be_added):
"""Adds a list of photons to the bunch.
Expand Down Expand Up @@ -651,10 +651,10 @@ def __iter__(self):

energy = numpy.zeros(npoint) + 3000.0

photon_bunch1 = PhotonBunchNew()
photon_bunch2 = PhotonBunchNew()
photon_bunch1 = PhotonBunch()
photon_bunch2 = PhotonBunch()

photons_list = list()
photons_list = []

for i in range(npoint):
photon = Photon(energy_in_ev=energy[i],
Expand Down
4 changes: 1 addition & 3 deletions crystalpy/util/PolarizedPhoton.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class PolarizedPhoton(Photon):
"""
def __init__(self, energy_in_ev, direction_vector, stokes_vector):


self._stokes_vector = stokes_vector
super(PolarizedPhoton, self).__init__(energy_in_ev, direction_vector)
self._stokes_vector = stokes_vector

def duplicate(self):
"""Duplicates a stokes photon.
Expand Down
Loading

0 comments on commit 6474093

Please sign in to comment.