def __init__(self, callback, top, filepath, chage_mass_ratio, weight, loader=phase_volume_pickle_loader,flags={},**kwargs): """ The init method captures what happens when instance = ElectronInjector() is called. This passes the callback function and the arguments for this callback function, namely top, phase_volume, electrons, and flags, to the UserEvent.__init__ method. Args: self: The ElectronInjector object --- standard notation for object oriented python. callback: The function to that will be called when injection is called. top: The top object from warp. This is passed so that it is accessible by the callback function for electron injecton. phase_volume: A timed phase volume object containing the injection time and the x, y, z an px, py, pz coordinates of the N particles. A phase volume can be found in my coordinates package. This is assumed to be in \ Cosy dump format. flags: A dictionary of additional terms that can be passed to the callback function. This is meant to hold True/False flags. """ self.callback = callback t, x, y, z, px, py, pz = loader(filepath,**kwargs) self.n = len(x) electrons = Species(type=Electron,weight=weight,name="Electron") args=[top, t, x, y, z, px, py, pz, chage_mass_ratio, electrons, flags] UserEvent.__init__(self,callback,args) #This partially freezes the attributes
def __init__(self, dt, filepath, onset, offset, n, electrons): """ The init method captures what happens when instance = DiagnosticsBySteps() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The RecordTransitionTime object --- standard notation for object oriented python. onset: The begining of the region offset: the ending of the region """ self.complete = False self.states = [] self.time_in = [] self.time_out = [] for i in range(0, n): self.states.append("before") self.time_in.append(0) self.time_out.append(0) self.states = np.array(self.states) #self.time_in = np.array(self.time_in) #self.time_out = np.array(self.time_out) self.onset = onset self.offset = offset self.electrons = electrons self.time = [0, dt] self.filepath = filepath args = [] additional_attr = {} UserEvent.__init__( self, None, args, additional_attr) #This partially freezes the attributes
def __init__(self, callback, top, filepath, chage_mass_ratio, weight, flags={},**kwargs): """ The init method captures what happens when instance = ElectronInjector() is called. This passes the callback function and the arguments for this callback function, namely top, phase_volume, electrons, and flags, to the UserEvent.__init__ method. Args: self: The ElectronInjector object --- standard notation for object oriented python. callback: The function to that will be called when injection is called. top: The top object from warp. This is passed so that it is accessible by the callback function for electron injecton. phase_volume: A timed phase volume object containing the injection time and the x, y, z an px, py, pz coordinates of the N particles. A phase volume can be found in my coordinates package. flags: A dictionary of additional terms that can be passed to the callback function. This is meant to hold True/False flags. """ self.callback = callback t, x, y, z, px, py, pz = phase_volume_pickle_loader(filepath,**kwargs) electrons = Species(type=Electron,weight=weight,name="Electron") args=[top, t, x, y, z, px, py, pz, chage_mass_ratio, electrons, flags] UserEvent.__init__(self,callback,args) #This partially freezes the attributes
def __init__(self, callback, obj, mass, location_keys, location_values): """ The init method captures what happens when instance = DiagnosticsBySteps() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The DiagnosticsBySteps object --- standard notation for object oriented python. callback: The function to that will be called when DiagnosticsBySteps.callFunction is called. obj: to be passed to function and which contains z data mass: The mass of the macroparticle used to do momentum conversion. locations: A dictionary of locations (z-position) at which the diagnostics will be launched. The key will be used for saving the data. """ args = [obj, mass] additional_attr = { "obj": obj, "file_prenames": deque(location_keys), "locations": deque(location_values) } UserEvent.__init__( self, callback, args, additional_attr) #This partially freezes the attributes
def __init__(self,top,particles): """ The init method captures what happens when instance = SyncToCOM() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The SyncToCOM object --- standard notation for object oriented python. top: The top object from warp particles: A species container from warp """ args = [top, particles] UserEvent.__init__(self,sync_grid_to_com,args) #This partially freezes the attributes
def __init__(self, callback, top, filepath, weight, input_format=None, sigma_r = None, N=None, w3d=None, **kwargs): """ The init method captures what happens when instance = ElectronInjector() is called. This passes the callback function and the arguments for this callback function, namely top, phase_volume, electrons, and flags, to the UserEvent.__init__ method. Args: self: The ElectronInjector object --- standard notation for object oriented python. callback: The function to that will be called when injection is called. filepath: Contains the file with particle coordinates in it in ascii format. The filepath is assumed to have warp dumped format. """ self.callback = callback if input_format is None: try: [x, y, z, px, py, pz, vx, vy, vz] = getdatafromtextfile(filepath,nskip=0,dims=[9,None]) except AssertionError: clight = constants.physical_constants["speed of light in vacuum"][0] emass = constants.physical_constants["electron mass"][0] [x, y, z, px, py, pz] = getdatafromtextfile(filepath,nskip=0,dims=[6,None]) gamma = sqrt(1. + (px**2 + py**2 + pz**2)/(emass*clight)**2 ) gamma_inv = 1./gamma vx = gamma_inv*px/emass vy = gamma_inv*py/emass vz = gamma_inv*pz/emass self.n = len(x) elif input_format == "xv": [x, y, z, vx, vy, vz] = getdatafromtextfile(filepath,nskip=0,dims=[6,None]) self.n = len(x) elif input_format == "generate_3d_normal": if sigma_r is None: raise Exception("A sigma_r needs to be provided to generate macroparticle positions.") if N is None: raise Exception("The number of particles needs to be supplied to generate macroparticle positions.") x, y, z = np.random.multivariate_normal([0,0,0], sigma_r**2*np.identity(3), N).T vx = np.zeros(x.size) vy = np.zeros(y.size) vz = np.zeros(z.size) self.n = N self.w3d = w3d #To pass the argument to partiallyPeriodic electrons = Species(type=Electron,weight=weight,name="Electron") args=[top, x, y, z, vx, vy, vz, electrons] self.injected = False UserEvent.__init__(self,callback,args) #This partially freezes the attributes
def __init__(self, callback, top, filepath, weight, **kwargs): """ The init method captures what happens when instance = ElectronInjector() is called. This passes the callback function and the arguments for this callback function, namely top, phase_volume, electrons, and flags, to the UserEvent.__init__ method. Args: self: The ElectronInjector object --- standard notation for object oriented python. callback: The function to that will be called when injection is called. filepath: Contains the file with particle coordinates in it in ascii format. """ self.callback = callback [x, y, z, px, py, pz, vx, vy, vz] = getdatafromtextfile(filepath,nskip=0,dims=[9,None]) electrons = Species(type=Electron,weight=weight,name="Electron") args=[top, x, y, z, vx, vy, vz, electrons] self.injected = False UserEvent.__init__(self,callback,args) #This partially freezes the attributes
def __init__(self,callback,obj,mass,top,steps): """ The init method captures what happens when instance = DiagnosticsBySteps() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The DiagnosticsBySteps object --- standard notation for object oriented python. callback: The function to that will be called when DiagnosticsBySteps.callFunction is called. obj: to be passed to function mass: The mass of the macroparticle used to do momentum conversion. top: The top object from warp steps: A list of steps (iterations) at which the diagnostics will be launched. """ args = [obj,mass] additional_attr = {"top": top, "steps": list(steps)} UserEvent.__init__(self,callback,args,additional_attr) #This partially freezes the attributes
def __init__(self,callback,obj,top,times): """ The init method captures what happens when instance = DiagnosticsBySteps() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The DiagnosticsBySteps object --- standard notation for object oriented python. callback: The function to that will be called when DiagnosticsBySteps.callFunction is called. obj: to be passed to function top: The top object from warp times: A list of approximate times at which the diagnostics will be launched. The program will launch the diagnostic at the first time that is equal or greater than the provided time. """ args = [obj] additional_attr = {"top": top, "times": list(times)} UserEvent.__init__(self,callback,args,additional_attr) #This partially freezes the attributes
def __init__(self, callback, obj, mass, top, steps, **kwargs): """ The init method captures what happens when instance = DiagnosticsBySteps() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The DiagnosticsBySteps object --- standard notation for object oriented python. callback: The function to that will be called when DiagnosticsBySteps.callFunction is called. obj: to be passed to function mass: The mass of the macroparticle used to do momentum conversion. top: The top object from warp steps: A list of steps (iterations) at which the diagnostics will be launched. """ args = [obj, mass] additional_attr = {"top": top, "steps": list(steps)} self.keywordargs = kwargs UserEvent.__init__( self, callback, args, additional_attr) #This partially freezes the attributes
def __init__(self, callback, obj, top, times): """ The init method captures what happens when instance = DiagnosticsBySteps() is called. This passes the callback function and the arguments for this callback function, namely top and steps, to the UserEvent.__init__ method. Args: self: The DiagnosticsBySteps object --- standard notation for object oriented python. callback: The function to that will be called when DiagnosticsBySteps.callFunction is called. obj: to be passed to function top: The top object from warp times: A list of approximate times at which the diagnostics will be launched. The program will launch the diagnostic at the first time that is equal or greater than the provided time. """ args = [obj] additional_attr = {"top": top, "times": list(times)} UserEvent.__init__( self, callback, args, additional_attr) #This partially freezes the attributes