:mod:`ocelot.adaptors.genesis` ============================== .. py:module:: ocelot.adaptors.genesis .. autoapi-nested-parse:: interface to genesis Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ocelot.adaptors.genesis.GenesisInput ocelot.adaptors.genesis.GenesisOutput ocelot.adaptors.genesis.GenStatOutput ocelot.adaptors.genesis.GenesisParticlesDump ocelot.adaptors.genesis.GenesisElectronDist ocelot.adaptors.genesis.GenesisRad Functions ~~~~~~~~~ .. autoapisummary:: ocelot.adaptors.genesis.parray2edist ocelot.adaptors.genesis.edist2parray ocelot.adaptors.genesis.run_genesis ocelot.adaptors.genesis.assemble ocelot.adaptors.genesis.create_exp_dir ocelot.adaptors.genesis.generate_input ocelot.adaptors.genesis.get_genesis_launcher ocelot.adaptors.genesis.get_genesis_new_launcher ocelot.adaptors.genesis.read_out_file ocelot.adaptors.genesis.read_out_file_stat ocelot.adaptors.genesis.read_out_file_stat_u ocelot.adaptors.genesis.read_dfl_file_out ocelot.adaptors.genesis.read_dfl_file ocelot.adaptors.genesis.write_dfl_file ocelot.adaptors.genesis.read_dpa_file_out ocelot.adaptors.genesis.read_dpa_file ocelot.adaptors.genesis.write_dpa_file ocelot.adaptors.genesis.max_dpa_dens ocelot.adaptors.genesis.dpa2edist ocelot.adaptors.genesis.read_edist_file_out ocelot.adaptors.genesis.read_edist_file ocelot.adaptors.genesis.cut_edist_std ocelot.adaptors.genesis.cut_edist ocelot.adaptors.genesis.set_edist_energy ocelot.adaptors.genesis.disperse_edist ocelot.adaptors.genesis.repeat_edist ocelot.adaptors.genesis.write_edist_file ocelot.adaptors.genesis.edist2beam ocelot.adaptors.genesis.read_beam_file ocelot.adaptors.genesis.beam_file_str ocelot.adaptors.genesis.zero_wake_at_ipk ocelot.adaptors.genesis.set_beam_energy ocelot.adaptors.genesis.transform_beam_twiss ocelot.adaptors.genesis.cut_beam ocelot.adaptors.genesis.get_beam_s ocelot.adaptors.genesis.get_beam_peak ocelot.adaptors.genesis.find_transform ocelot.adaptors.genesis.write_beam_file ocelot.adaptors.genesis.create_rad_file ocelot.adaptors.genesis.read_rad_file ocelot.adaptors.genesis.adapt_rad_file ocelot.adaptors.genesis.rad_file_str ocelot.adaptors.genesis.generate_lattice ocelot.adaptors.genesis.next_run_id ocelot.adaptors.genesis.get_spectrum ocelot.adaptors.genesis.get_power_exit ocelot.adaptors.genesis.get_power_z ocelot.adaptors.genesis.transform_beam_file ocelot.adaptors.genesis.test_beam_transform ocelot.adaptors.genesis.read_astra_dist ocelot.adaptors.genesis.astra2edist ocelot.adaptors.genesis.astra2edist_ext ocelot.adaptors.genesis.rematch_edist ocelot.adaptors.genesis.cut_lattice ocelot.adaptors.genesis.getAverageUndulatorParameter .. data:: _logger .. data:: _inputTemplate :annotation: = $newrun aw0 = __AW0__ xkx = __XKX__ xky = __XKY__ wcoefz = __WCOEFZ__ xlamd = __XLAMD__ fbess0 = __FBESS0__ delaw = __DELAW__ iertyp = __IERTYP__ iwityp = __IWITYP__ awd = __AWD__ awx = __AWX__ awy = __AWY__ iseed = __ISEED__ npart = __NPART__ gamma0 = __GAMMA0__ delgam = __DELGAM__ rxbeam = __RXBEAM__ rybeam = __RYBEAM__ alphax = __ALPHAX__ alphay = __ALPHAY__ emitx = __EMITX__ emity = __EMITY__ xbeam = __XBEAM__ ybeam = __YBEAM__ pxbeam = __PXBEAM__ pybeam = __PYBEAM__ conditx = __CONDITX__ condity = __CONDITY__ bunch = __BUNCH__ bunchphase = __BUNCHPHASE__ emod = __EMOD__ emodphase = __EMODPHASE__ xlamds = __XLAMDS__ prad0 = __PRAD0__ zrayl = __ZRAYL__ zwaist = __ZWAIST__ ncar = __NCAR__ lbc = __LBC__ rmax0 = __RMAX0__ dgrid = __DGRID__ nscr = __NSCR__ nscz = __NSCZ__ nptr = __NPTR__ nwig = __NWIG__ zsep = __ZSEP__ delz = __DELZ__ nsec = __NSEC__ iorb = __IORB__ zstop = __ZSTOP__ magin = __MAGIN__ magout = __MAGOUT__ quadf = __QUADF__ quadd = __QUADD__ fl = __FL__ dl = __DL__ drl = __DRL__ f1st = __F1ST__ qfdx = __QFDX__ qfdy = __QFDY__ solen = __SOLEN__ sl = __SL__ ildgam = __ILDGAM__ ildpsi = __ILDPSI__ ildx = __ILDX__ ildy = __ILDY__ ildpx = __ILDPX__ ildpy = __ILDPY__ itgaus = __ITGAUS__ nbins = __NBINS__ igamgaus = __IGAMGAUS__ lout = __LOUT__ iphsty = __IPHSTY__ ishsty = __ISHSTY__ ippart = __IPPART__ ispart = __ISPART__ ipradi = __IPRADI__ isradi = __ISRADI__ idump = __IDUMP__ iotail = __IOTAIL__ nharm = __NHARM__ iharmsc = __IHARMSC__ iallharm = __IALLHARM__ curpeak = __CURPEAK__ curlen = __CURLEN__ ntail = __NTAIL__ nslice = __NSLICE__ shotnoise = __SHOTNOISE__ isntyp = __ISNTYP__ iall = __IALL__ __ITDP__ ipseed = __IPSEED__ iscan = __ISCAN__ nscan = __NSCAN__ svar = __SVAR__ isravg = __ISRAVG__ isrsig = __ISRSIG__ cuttail = __CUTTAIL__ eloss = __ELOSS__ version = __VERSION__ ndcut = __NDCUT__ idmpfld = __IDMPFLD__ idmppar = __IDMPPAR__ ilog = __ILOG__ ffspec = __FFSPEC__ convharm = __CONVHARM__ ibfield = __IBFIELD__ imagl = __IMAGL__ idril = __IDRIL__ alignradf = __ALIGNRADF__ offsetradf = __OFFSETRADF__ multconv = __MULTCONV__ trama = __TRAMA__ itram11 = __ITRAM11__ itram12 = __ITRAM12__ itram13 = __ITRAM13__ itram14 = __ITRAM14__ itram15 = __ITRAM15__ itram16 = __ITRAM16__ itram21 = __ITRAM21__ itram22 = __ITRAM22__ itram23 = __ITRAM23__ itram24 = __ITRAM24__ itram25 = __ITRAM25__ itram26 = __ITRAM26__ itram31 = __ITRAM31__ itram32 = __ITRAM32__ itram33 = __ITRAM33__ itram34 = __ITRAM34__ itram35 = __ITRAM35__ itram36 = __ITRAM36__ itram41 = __ITRAM41__ itram42 = __ITRAM42__ itram43 = __ITRAM43__ itram44 = __ITRAM44__ itram45 = __ITRAM45__ itram46 = __ITRAM46__ itram51 = __ITRAM51__ itram52 = __ITRAM52__ itram53 = __ITRAM53__ itram54 = __ITRAM54__ itram55 = __ITRAM55__ itram56 = __ITRAM56__ itram61 = __ITRAM61__ itram62 = __ITRAM62__ itram63 = __ITRAM63__ itram64 = __ITRAM64__ itram65 = __ITRAM65__ itram66 = __ITRAM66__ __OUTPUTFILE__ __BEAMFILE__ __PARTFILE__ __FIELDFILE__ __RADFILE__ __DISTFILE__ __MAGFILE__ filetype ='ORIGINAL' $end .. py:class:: GenesisInput Genesis input files storage object .. method:: input(self) .. method:: __getattr__(self, name) .. method:: copy(self, inp, params) copies list of parameters from another GenesisInput() or GenesisOutput() object .. method:: copymesh(self, inp, expt=()) .. py:class:: GenesisOutput Genesis output *.out files storage object .. method:: fileName(self) .. method:: __call__(self, name) .. method:: calc_spec(self, mode='mid', npad=0) calculates the on-axis spectrum at every position along the undulator and writes it into "spec" attirube if mode = "mid" then on-axis power with on-axis phases is used for calculation if mode = "int" then transversely integrated power with on-axis phases is used (strictly speaking inaccurate, but informative) npad (integer) if > 0 pads the power with zeros in order to increase resolution of spectrum. .. method:: phase_fix(self, wav=None, s=None, **kwargs) the way to display the phase, without constant slope caused by different radiation wavelength from xlamds. phase is set to 0 at maximum power slice .. method:: calc_radsize(self, weigh_transv=1) weigh_transv = True to average the transverse radiation size over slices with radiation power as a weight .. method:: wig(self, z=np.inf, *args, **kwargs) .. method:: re_read(self, read_level=2) .. py:class:: GenStatOutput Genesis statistical output storage object .. method:: zi(self, z) .. method:: si(self, s) .. method:: fi(self, f) .. py:class:: GenesisParticlesDump Genesis particle *.dpa files storage object Each particle record in z starts with the energy of all particles followed by the output of the particle phases, positions in x and y and the momenta in x and y. The momenta are normalized to mc .. method:: fileName(self) .. py:class:: GenesisElectronDist Genesis electron beam distribution *.dat files storage object GENESIS follows the rule that the longitudinal position is reversed if a time is specified by the T column. In this case smaller numbers correspond to particle in the tail of the distribution. .. method:: charge(self) .. method:: fileName(self) .. method:: len(self) .. method:: center(self, s='com') .. method:: s(self) :property: .. method:: twiss(self) .. function:: parray2edist(p_array) .. function:: edist2parray(edist) .. py:class:: GenesisRad Genesis analytical radiation input files storage object? .. function:: run_genesis(inp, launcher, read_level=2, assembly_ver='pyt', dfl_slipage_incl=True, min_phsh=False, debug=1) Main function for executing Genesis code inp - GenesisInput() object with genesis input parameters launcher - MpiLauncher() object obtained via get_genesis_launcher() function read_level - Parameter to read and calculate values from the output: -1 - do not read 0 - read input only (header) 1 - read input and current profile 2 - read all values dfl_slipage_incl - whether to dedicate time in order to keep the dfl slices, slipped out of the simulation window. if zero, reduces assembly time by ~30% assembly_ver - version of the assembly script: 'sys' - system based, 'pyt' - python based, None - assembly with Genesis assumed .. function:: assemble(fileName, remove=1, overwrite=0, ram=1, debug=1) assembles the fileName.slice* files into fileName remove - delete *.slice* files overwrite - writes *.slice* files on top of fileName.slice* starting from the beginning. Applicable for genesis dfl file assembly ram - store the *.slice* files in ram simultaneously .. function:: create_exp_dir(exp_dir, run_ids) creates the folder structure nested in exp_dir folder. run_ids is a list of run numbers. resulting folder structure would be .. ---exp_dir ------run_1 ------run_2 ------run_3 ------... .. function:: generate_input(undulator, beam, E_photon=None, itdp=True, *args, **kwargs) Create Genesis inp object with default input parameters .. function:: get_genesis_launcher(launcher_program=None, launcher_argument='') Returns MpiLauncher() object for given program .. function:: get_genesis_new_launcher(launcher_program=None, mpi_mode=True) tmp for moga, to be solved in the future .. function:: read_out_file(filePath, read_level=2, precision=float, debug=1) reads Genesis output from *.out file. returns GenesisOutput() object thanks gods Genesis3 out will be in hdf5! read_level - 0 = only header is processed. Very fast 1 = slice values are not processed. Current information is obtained, ~2x faster 2 = all contents are read 3 = additional attributed are calculated, like spectrum, transversely averaged radiation size, etc. precision - precision of stored values precision debug - 0 = no messages printed in console 1 = basic info and execution time is printed 2 = most detailed info is printed (real debug) .. function:: read_out_file_stat(proj_dir, stage, run_inp=[], param_inp=[], debug=1) reads statistical info of Genesis simulations, returns GenStatOutput() object proj_dir - project directory of the following structure: proj_dir/run_/run..s.gout* run_inp - list of genesis runs to be looked for [0:1000] by default param_inp - list of genesis output parameters to be processed debug - see read_out_file() .. function:: read_out_file_stat_u(file_tamplate, run_inp=[], param_inp=[], debug=1) reads statistical info of Genesis simulations, universal function for non-standard exp. folder structure returns GenStatOutput() object file_tamplate = template of the .out file path with # denoting run number run_inp - list of genesis runs to be looked for [0:1000] by default param_inp - list of genesis output parameters to be processed debug - see read_out_file() .. function:: read_dfl_file_out(out, filePath=None, debug=1) More compact function than read_dfl_file() to read the file generated with known .out file Returns RadiationField object No need to pass all parameters (Nxy, Lxy, Lz, zsep, xlamds), they are read from GenesisOutput object out - The relevant GenesisOutput object or path to it filePath- Path to *.dfl file. if = None, then it is assumed to be *.out.dfl .. function:: read_dfl_file(filePath, Nxy, Lxy=None, zsep=None, xlamds=None, hist_rec=1, vartype=complex, debug=1) Function to read the Genesis output radiation file "dfl". Returns RadiationField() object filePath - path to *.dfl file Nxy - transverse mesh size, e.g. for 151*151 mesh, Nxy=151 Lxy - transverse mesh size (2*dgrid) zsep - separation between slices in terms of wavelengths xlamds - wavelength of the radiation hist_rec - number of dfl records within a single file (*.fld case), not finished! .. function:: write_dfl_file(dfl, filePath=None, debug=1) Function to write the RadiationField object into filePath file dfl RadiationField object filePath - path top write the file if None then filePath = dfl.filePath .. function:: read_dpa_file_out(out, filePath=None, debug=1) simplifies running the read_dpa_file() function reads GenesisOutput() object returns GenesisParticlesDump() object no need to set nbins and npart parameters as well as file_path (may be overrun) all automatically picked up from GenesisOutput() object .. function:: read_dpa_file(filePath, nbins=4, npart=None, debug=1) reads genesis particle dump file *.dpa returns GenesisParticlesDump() object .. function:: write_dpa_file(dpa, filePath=None, debug=1) .. function:: max_dpa_dens(out, dpa, slice_pos=None, slice_num=None, repeat=1, bins=(50, 50), debug=1) .. function:: dpa2edist(out, dpa, num_part=100000.0, smear=1, debug=1) Convert dpa to edist objects reads GenesisParticlesDump() object returns GenesisElectronDist() object num_part - desired approximate number of particles in edist smear - whether to shuffle macroparticles smearing microbunching .. function:: read_edist_file_out(out, debug=1) .. function:: read_edist_file(filePath, **kwargs) reads particle distribution file (distfile in genesis input) returns GenesisElectronDist() .. function:: cut_edist_std(edist, all_std=None, x_std=4, y_std=4, xp_std=4, yp_std=4) .. function:: cut_edist(edist, t_lim=(-np.inf, np.inf), g_lim=(-np.inf, np.inf), x_lim=(-np.inf, np.inf), xp_lim=(-np.inf, np.inf), y_lim=(-np.inf, np.inf), yp_lim=(-np.inf, np.inf), s_lim=None, debug=1) cuts GenesisElectronDist() in phase space .. function:: set_edist_energy(edist, E_GeV, debug=1) adds energy to the electron beam so that new average energy is E_GeV in [GeV] .. function:: disperse_edist(edist, R56, debug=1) Introduces dispersion (good for simulating weak chicanes) delays or advances time coordinate of the particles depending on ther energy with respect to the averaged energy .. function:: repeat_edist(edist, repeats, smear=0.001, not_smear=[]) dublicates the GenesisElectronDist() by given factor repeats - the number of repetitions smear - smear new particles by x of global standard deviation of parameter .. function:: write_edist_file(edist, filePath=None, debug=1) writes GenesisElectronDist() into filePath folder .. function:: edist2beam(edist, step=2e-07) reads GenesisElectronDist() returns BeamArray() step [m] - long. size ob bin to calculate distribution parameters .. function:: read_beam_file(filePath, *args, **kwargs) reads beam file from filePath folder returns BeamArray() .. function:: beam_file_str(beam) reads BeamArray() returns string of electron beam file, suitable for Genesis .. function:: zero_wake_at_ipk(beam) reads BeamArray() shifts the wake pforile so that at maximum current slice wake is zero returns GenesisBeam() allows to account for wake losses without additional linear undulator tapering .. function:: set_beam_energy(beam, E_GeV_new) reads BeamArray() returns BeamArray() sets the beam energy with peak current to E_GeV_new .. function:: transform_beam_twiss(beam, transform=None, s=None) .. function:: cut_beam(beam=None, cut_s=[-np.inf, np.inf]) cuts BeamArray() object longitudinally cut_z [m] - limits of the cut .. function:: get_beam_s(beam, s=0) obtains values of the beam at s position .. function:: get_beam_peak(beam) obtains values of the beam at s position .. function:: find_transform(g1, g2) find transform from twiss matrix g1 to g2: x -> M x, g -> Mi.T g M .. function:: write_beam_file(filePath, beam, debug=0) .. function:: create_rad_file(p_duration_s=None, p_intensity=None, beam=None, offset=None, out_file='tmp.rad') .. function:: read_rad_file(filePath) reads analyticall radiation seed file from Genesis? .. function:: adapt_rad_file(beam=None, rad_file=None, out_file='tmp.rad') .. function:: rad_file_str(rad) .. function:: generate_lattice(lattice, unit=1.0, energy=None, debug=1, min_phsh=False) .. function:: next_run_id(dir='.') .. function:: get_spectrum(power, phase, smax=1.0) pulse spectrum in eV .. function:: get_power_exit(g) .. function:: get_power_z(g) .. function:: transform_beam_file(beam_file=None, out_file='tmp.beam', s=None, transform=[[25.0, 0.1], [21.0, -0.1]], energy_scale=1, energy_new=None, emit_scale=1, n_interp=None) .. function:: test_beam_transform(beta1=10.0, alpha1=-0.1, beta2=20, alpha2=2.2) .. function:: read_astra_dist(fileName) reading astra distribution parameters Parameter x y z px py pz clock macro_charge particle_index status_flag with units m m m eV/c eV/c eV/c ns nC returns numpy array? .. function:: astra2edist(adist, center=1) converts astra particle distribution into GenesisElectronDist() object center - centers the distribution transversely .. function:: astra2edist_ext(fileName_in, fileName_out='', center=1) .. function:: rematch_edist(edist, tws, s=None) .. function:: cut_lattice(lat, n_cells, elem_in_cell=4) reads MagneticLattice() returns MagneticLattice() without first n_cells*elem_in_cell elements .. function:: getAverageUndulatorParameter(lattice, unit=1.0, energy=17.5)