PropPy package

proppy.comparison module

class proppy.comparison.Comparison(kappa_theory, lambda_theory, step_sizes, l_c, r_g, path_data_raw, path_data, path_figs, proppy_unit='m')

Bases: object

color_bar_invisible()
func_kappa_run(x, kappa, tau)
load_sim_data()
plot_deviation_vs_time_steps(day=True)
plot_kappa_convergence_tests(ylabel='$\\kappa$ [m$^2$/s]', ylabel2='log deviation', lambda_theory=True, kappa_mean_seeds=0, kappa_mean_seeds_err=0)
plot_kappa_vs_time_deviation()
plot_kappa_vs_time_steps()
plot_particle_distributions_crp(file_name, prop_type='BP', unit='m')
plot_particle_distributions_proppy()
plot_running_diffusion_coefficients(d_theory=[1e+17, 4e+17], pp_step_max=0, times=[], kappas_ref=[], show_lambda=True)
plot_time_vs_deviation_steps(day=True)
plot_time_vs_steps_deviation(day=True, lambda_theory=True)

proppy.constants module

proppy.magnetic_field module

Customized ordered magnetic fields.

Ordered magnetic fields determine the directions of the parallel and perpendicular diffusion coefficients of the diffusion tensor. The parallel diffusion coefficient is used for the parallel direction to the ordered background magnetic field. The magnetic fields are used by the propagation class to determine the orientation of the field and how to align the diffusion tensor.

Typical usage example:

import proppy as pp

nr_steps = 10**4 step_size = 10**10 # [m] mfp = np.array([2.13*10**12/2.0, 2.13*10**12/2.0, 2.1078*10**12], dtype=np.float32) # [m] b_rms = 1 # Gaus b_direction = [0,0,1] magnetic_field = pp.OrderedBackgroundField(b_rms, b_direction).magnetic_field

propagator = pp.AnisotropicPropagator(magnetic_field, mfp, nr_steps, step_size) sim = pp.Simulation() sim.add_propagator(propagator) sim.propagator.get_description()

class proppy.magnetic_field.AbstractMagneticField(*args, **kwargs)

Bases: object

Abstract base class for all special magnetic fields.

Functions with the label @abstractmethod have to be implemented in the special magnetic field classes.

Attributes:

rms: A float32 indicating the root-mean square value of the magnetic field. direction: An float32 array indicating the direction of the ordered magnetic field. required_attributes: A list with attributes that have to be implemented in sub classes.

required_attributes = ['rms', 'direction']
class proppy.magnetic_field.AbstractMagneticFieldMeta(name, bases, namespace, **kwargs)

Bases: abc.ABCMeta

Abstract meta class to check if all required attributes are implemented in the sub classes.

required_attributes = []
class proppy.magnetic_field.DefaultBackgroundField(*args, **kwargs)

Bases: proppy.magnetic_field.AbstractMagneticField

Ordered default background magnetic field.

The user can only specify the root-mean-square (rms) value of the ordered magnetic field. The magnetic field is static and points everywhere along the z-axis with the rms value that is specified.

Attributes:

rms: A float32 indicating the root-mean square value of the magnetic field. magnetic_field: An object of the @jitclass MagneticField that can be passed to other jitclasses.

class proppy.magnetic_field.OrderedBackgroundField(*args, **kwargs)

Bases: proppy.magnetic_field.AbstractMagneticField

Ordered background magnetic field.

The user can specify the root-mean-square (rms) value and the direction of the ordered magnetic field. The magnetic field is static and points everywhere in the specified direction with the rms vlaue that is specified.

Attributes:

rms: A float32 indicating the root-mean square value of the magnetic field. direction: An float32 array indicating the direction of the ordered magnetic field. magnetic_field: An object of the @jitclass MagneticField that can be passed to other jitclasses.

proppy.observer module

The Observer determines during the simulation when and what data to write out (observe).

In each simulation step, the current particle state is evaluated by the Observer to check if one of the observing conditions is satisfied. The conditions to observe can be based on the time (-> step) or the coordinates of the particle.

Typical usage example:

import proppy as pp

substeps = [False, False, True] # observe only steps (no substeps) spheres = [1*10**13, 5*10**12]

observer = pp.SphericalObserver(substeps, spheres)

sim = pp.Simulation() sim.add_observer(observer) sim.observer.get_description()

class proppy.observer.AbstractSpecialObserver(*args, **kwargs)

Bases: object

Abstract base class for all special observers.

Functions with the label @abstractmethod have to be implemented in the special observer classes.

Attributes:
substeps_bool: An b1 array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

steps: A float32 array specifying all steps that should be observed. spheres: A float32 array for specifying the radii of the observer spheres. column: A float32 array for specifying the column names of the data output. observer: The special observer. on_detection_deactivate: A bool to check if particle should be deactivated after observing it.

get_column_names()

Gets called in the simulation script and returns the column names of the data output.

get_description()

Prints a description of the observer with the status of all attributes.

abstract get_description_observer_type()

Gives the name of each special observer.

init_observer(substeps, spheres, on_detection_deactivate=False)

Initialize the Observer

Sets the important parameters and calls the @abstractmethods that are implemented in each special observer class that are derived from the current abstract base class.

Args:

substeps (float32[:]): Specifying which substeps need to be observed. spheres (float32[:]): Specifying the radii of the observer spheres.

required_attributes = ['steps', 'substeps_bool', 'spheres', 'on_detection_deactivate']
abstract set_steps()

Sets the number of steps that should be observed.

set_steps_int()

Converts list of steps to np array of ints that is known in the @jitclass Observer().

class proppy.observer.AbstractSpecialObserverMeta(name, bases, namespace, **kwargs)

Bases: abc.ABCMeta

Abstract meta class to check if all required attributes are implemented in the sub classes.

required_attributes = []
class proppy.observer.ObserverAllSteps(*args, **kwargs)

Bases: proppy.observer.AbstractSpecialObserver

Observes particles in all propagation steps.

Attributes:
substeps: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

steps_input: A float array specifying all steps that should be observed.

get_description_observer_type()

Gives the name of each special observer.

set_steps()

Sets the number of steps that should be observed.

class proppy.observer.SphericalObserver(*args, **kwargs)

Bases: proppy.observer.AbstractSpecialObserver

Observes particles on a spheres with given radii.

When particles pass through the sphere, they will be observed.

Attributes:
substeps: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

spheres: A float array for specifying the radii of the observer spheres.

get_description_observer_type()

Gives the name of each special observer.

set_steps()

No steps needed.

class proppy.observer.TimeEvolutionObserver(*args, **kwargs)

Bases: proppy.observer.AbstractSpecialObserver

Observes particles at the user specified step numbers.

The user passes the list of steps to the TimeEvolutionObserver.

Attributes:
substeps: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

steps_input: A float array specifying all steps that should be observed.

get_description_observer_type()

Gives the name of each special observer.

set_steps()

Sets the number of steps that should be observed.

class proppy.observer.TimeEvolutionObserverLin(*args, **kwargs)

Bases: proppy.observer.AbstractSpecialObserver

Observes particles at the user specified step numbers.

The user only gives the minimum, the maximum and the total step numbers. The TimeEvolutionObserverLin computes the list (linearly).

Attributes:
substeps: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

min_steps: An int that gives the minimal step number that should be observed. max_steps: An int that gives the maximal step number that should be observed. nr_steps: An int that gives the number of steps that should be observed. steps_input: A float array specifying all steps that should be observed.

get_description_observer_type()

Gives the name of each special observer.

set_steps()

Sets the number of steps that should be observed.

Takes the minimum and maximum step numbers into account to generate the list of step numbers based on the given number of steps. Here, the steps are spaced linearly.

class proppy.observer.TimeEvolutionObserverLog(*args, **kwargs)

Bases: proppy.observer.AbstractSpecialObserver

Observes particles at the user specified step numbers.

The user only gives the minimum, the maximum and the total step numbers. The TimeEvolutionObserverLog computes the list (logarithmically).

Attributes:
substeps: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

min_steps: An int that gives the minimal step number that should be observed. max_steps: An int that gives the maximal step number that should be observed. nr_steps: An int that gives the number of steps that should be observed. steps_input: A float array specifying all steps that should be observed.

get_description_observer_type()

Gives the name of each special observer.

set_steps()

Sets the number of steps that should be observed.

Takes the minimum and maximum step numbers into account to generate the list of step numbers based on the given number of steps. Here, the steps are spaced logarithmically.

proppy.particle module

Individual particles will be simulated here.

By calling the particles simulate function, the particle will be propagated completely and observed as specified in the observer.

proppy.particle_state module

The Particle State keeps track of all relevant particle properties.

In each simulation step, the particle state gets updated. It can be passed to observers to easily write out the current particle state for analysis.

proppy.propagator module

The Source initializes the particles in the beginning of the simulation.

Background information:

Current simulation codes propagate charged particles through magnetic fields either by ballistic codes solving the Lorentz force at each step or by using particle distributions arising from the solution of the classical diffusion equation. Whereas the former method provides an accurate description of the particle trajectories using small step sizes, this method is computationally expensive, especially for low particle energies. The method based on the diffusion equation, on the other hand, is extremely fast since the particle distribution is analytically given at each time point, but by the nature of the method, particles can only be described statistically. Even using quasi- particles, the individual trajectories are useless. For applications in which statistical statements and averaging over many particles are intended, this method is preferred in many areas of astronomy because of the short simulation times. It is important to note, however, that the diffusion equation guarantees an adequate description of the particles only in the limit of infinitely large times. Numerically, however, this approach can also be used starting from times for which a diffusive behavior occurs. This typically happens after a simulation time which is in the order of magnitude of the mean free path length. Consequently, the use of propagation codes based on the diffusion equation is not suitable in compact objects. Examples include AGNs, supernovas, pulsars, etc.

Explanation:

In analogy to existing diffusion codes, the following routine requires the information of the diffusion coefficients. Here, however, we do not use the solution of the diffusion equation, since this only provides a particle distribution and makes statistical statements about individual particle trajectories. Instead, we propagate particles according to the two-step propagation routine. For strong turbulence levels we use the correlated random walk (CRW) in Cartesian coordinates and for weak turbulence levels the CRW in cylindrical coordinates.

Typical usage example:

import proppy as pp

nr_steps = 1*10**4 step_size = 0.5*10**10 # [m] mfp = np.array([2.13*10**12/2.0, 2.13*10**12/2.0, 2.1078*10**12], dtype=np.float32) # [m] rms = 1 # Gaus magnetic_field = pp.OrderedBackgroundField(rms, [0,0,1]).magnetic_field

propagator = pp.AnisotropicPropagator(magnetic_field, mfp, nr_steps, step_size)

sim = pp.Simulation() sim.add_propagator(propagator) sim.propagator.get_description()

class proppy.propagator.AbstractPropagator(*args, **kwargs)

Bases: object

Abstract base class for all special propagator.

Functions with the label @abstractmethod have to be implemented in the special propagator classes.

Attributes:

propagator: The special propagator. dimensions: Number of dimensions. speed: Speed of the particles in [m/s]. mfp: Mean free paths of particles in each direction in [m]. nr_steps: Number of steps for each particle in simulation. magnetic_field: The magnetic field. step_size: Size of the steps in [m]. isotropic_diffusion: Is the particle diffusion isotropic?

convert_mfp_input(mfp_input)

Check the input of the mean free paths.

get_description()

Description.

Print the information of the relevant parameters and the description of the special propagation type that was chosen.

get_description_general()

Called by all special propagator classes below. Introduction of the description output.

get_description_parameters()

Called by all special propagator classes below. Print out all relevant instance parameters.

abstract get_description_propagator_type()
init_jitclass_propagator()

Initialize the Propagator.

Sets the important parameters and calls the @abstractmethods that are implemented in each special propagator class that are derived from the current abstract base class.

required_attributes = ['propagator', 'dimensions', 'speed', 'mfp', 'nr_steps', 'magnetic_field', 'step_size', 'isotropic_diffusion', 'cartesian', 'cylindrical']
set_basic_parameters()
set_cartesian_coords(cartesian_bool)

Choose Cartesian coords or not.

There are cartesian or cylindrical coordinates available. cylindrical coordinates activated lead to the usage of move_phi, move_rho and move_cartesian for the z-direction

set_cylindrical_coords(cylindrical)

Choose cylindrical coords or not.

There are cartesian or cylindrical coordinates available. Cylindrical coordinates activated lead to the usage of move_phi, move_rho and move_cartesian for the z-direction

set_dimensions(dimensions)

Default is 3d -> dimensions = 3. More than 3 dimensions are not supported.

set_magnetic_field(magnetic_field)

Allow to set the propagator magnetic field.

set_nr_steps(nr_steps)

Change number of steps.

set_pitch_angle_const(const_bool)

Keep the pitch angle either constant or allow for changes during each propagation step.

set_prob(mean_free_path)
set_speed(speed)

Set particle speed.

units = [m/s] change the speed of the particles. The default speed is the speed of light that is valid for relativistic particles.

set_step_size(step_size)

Change distance of each step that particles travel.

units = [m]

class proppy.propagator.AbstractPropagatorMeta(name, bases, namespace, **kwargs)

Bases: abc.ABCMeta

Abstract meta class to check if all required attributes are implemented in the sub classes.

required_attributes = []
class proppy.propagator.AnisotropicPropagator(*args, **kwargs)

Bases: proppy.propagator.AbstractPropagator

Anisotropic propagator with user-specified parameters.

Usage of a background magnetic field and a turbulent one. Anisotropic diffusion coefficients and therefore anisotropic mfp. Propagating with Cylindircal coordinates. User can specify mfp, nr steps and step size, as well as magnetic field.

Attributes:

nr_steps: Number of steps for each particle in simulation. step_size: Size of the steps in [m]. mfp: Mean free paths of particles in each direction in [m]. magnetic_field: The magnetic field. isotropic_diffusion: Is the particle diffusion isotropic?

get_description_propagator_type()
class proppy.propagator.IsotropicPropagator(*args, **kwargs)

Bases: proppy.propagator.AbstractPropagator

Isotropic propagator with user-specified parameters.

Usage of no background magnetic field with only a turbulent one. Isotropic diffusion coefficients and therefore isotropic mfp. Propagating with Cartesian coordinates. User can specify mfp, nr steps and step size.

Attributes:

nr_steps: Number of steps for each particle in simulation. step_size: Size of the steps in [m]. mfp: Mean free paths of particles in each direction in [m]. magnetic_field: The magnetic field. isotropic_diffusion: Is the particle diffusion isotropic?

get_description_propagator_type()
class proppy.propagator.IsotropicPropagatorDefault(*args, **kwargs)

Bases: proppy.propagator.AbstractPropagator

Default isotropic propagator.

Usage of no background magnetic field with only a turbulent one. Isotropic diffusion coefficients with corresponding mfp = 10**12 m. Propagating with Cartesian coordinates.

Attributes:

nr_steps: Number of steps for each particle in simulation. step_size: Size of the steps in [m]. mfp: Mean free paths of particles in each direction in [m]. magnetic_field: The magnetic field. isotropic_diffusion: Is the particle diffusion isotropic?

get_description_propagator_type()

proppy.simulation module

Central simulation file.

This file serves with providing the Simulation class where the modules are defined and set for the simulation, such as the source, the observer, and the propagator.

Typical usage example:

import proppy as pp

nr_steps = 10**4 step_size = 10**10 # [m] mfp = np.array([2.13*10**12/2.0, 2.13*10**12/2.0, 2.1078*10**12], dtype=np.float32) # [m] b_rms = 1 # Gaus b_direction = [0,0,1] magnetic_field = pp.OrderedBackgroundField(b_rms, b_direction).magnetic_field

propagator = pp.AnisotropicPropagator(magnetic_field, mfp, nr_steps, step_size) sim = pp.Simulation() sim.add_propagator(propagator) sim.propagator.get_description() . . . sim.run_simulation() sim.save_data(‘data/data_sim’)

class proppy.simulation.AnisotropicSimulation(nr_particles=100, energy=1000000000000000, nr_steps=100000, diffusion_coefficient_para=1.3999999999999998e+20, nr_obs_steps=600)

Bases: object

get_simulation_info()
simulate(file_name='anisotropic')
class proppy.simulation.IsotropicSimulation(nr_particles=1000, energy=1000000000000000, nr_steps=10000, diffusion_coefficient_para=1e+21, nr_obs_steps=600, step_size=1000000000000, constants=<numba.experimental.jitclass.boxing.Constants object>)

Bases: object

get_simulation_info()
simulate(file_name='isotropic')
class proppy.simulation.IsotropicSphereSimulation(nr_particles=1000, energy=1000000000000000, nr_steps=10000, diffusion_coefficient_para=1e+21, nr_obs_steps=600)

Bases: object

get_simulation_info()
simulate(file_name='isotropic')
class proppy.simulation.PlasmoidSimulation(nr_particles=10000, radius=100000000000000, energy=1000000000000000, nr_steps=3000, diffusion_coefficient=1e+21, step_size=1000000000000, step_size_diff_factor=1.0)

Bases: object

get_simulation_info()
plot_arrival_times(bins_log=20, bins_lin=50, d_max=None)
simulate(file_name='plasmoid')
class proppy.simulation.Simulation(constants=<numba.experimental.jitclass.boxing.Constants object>)

Bases: object

Remove all step number duplicates.

Special observer such as the TimeEvolutionObserverLog() may introduce duplicate step numbers [1,1,1,…] that lead to a wrong number of steps during the description output because the step 1 will be only observed once, while it is counted several times in the description output.

Attributes:

data: Matrix of observed data. source: Object of a special source type set by the user. observer: Object of a special observer type set by the user. propagator: Object of a special propagator type set by the user.

add_observer(observer)
add_propagator(propagator)
add_source(source)
init_data()
run_simulation()
save_data(file_name)

proppy.source module

The Source initializes the particles in the beginning of the simulation.

There are different sources available that can be customized by the user. The source specifies the initial state of the particles.

Typical usage example:

import proppy as pp

nr_particles = 1*10**3 source_pos = np.array([0.0, 0.0, 0.0], dtype=np.float32) delta_rho_div_phi = 1 #1/2**0.5 # (delta_r_rho / delta_r_phi) energy = 3*10**15 # eV phi = 0.0 pitch_angle = 2*np.pi * 54.74/360 # pitch angle for equal components in all directions

sim = pp.Simulation() source = pp.PointSourceOriented(energy, source_pos, nr_particles, pitch_angle, phi) sim.add_source(source) sim.source.get_description()

class proppy.source.PointSourceIsotropic(*args, **kwargs)

Bases: proppy.source.Source

A point source that emits particles isotropically.

All particles start from a single point defined by the source position in the user-defined direction. All particles have the exact same state in the beginning, except for the direction, which is isotropic.

Attributes:
energy: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

pos: A list that specify the source position. nr_particles: An int that defines how many particles should be emited. particles: List of particles in the source. This list will be used in the simulation.

get_description_source_type()
inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

sample_isotropic_vecotrs()

Samlpe correct isotropic vectors.

See discussion in https://mathworld.wolfram.com/SpherePointPicking.html.

class proppy.source.PointSourceIsotropicPhi(*args, **kwargs)

Bases: proppy.source.Source

A point source that emits particles isotropically in phi.

All particles start from a single point defined by the source position in the user-defined direction. All particles have the exact same state in the beginning, except for the direction, which is isotropic in phi.

Attributes:
energy: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

pos: A list that specify the source position. nr_particles: An int that defines how many particles should be emited. particles: List of particles in the source. This list will be used in the simulation.

get_description_source_type()
inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

class proppy.source.PointSourceOriented(*args, **kwargs)

Bases: proppy.source.Source

A point source that emits particles into a user-defined direction.

All particles start from a single point defined by the source position in the user-defined direction. All particles have the exact same state in the beginning.

Attributes:
energy: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

pos: A list that specify the source position. nr_particles: An int that defines how many particles should be emitted. pitch_angle: The initial pitch angle of the particle -> angle between B-field and particle direction. phi: The initial angle between the particle direction in the xy-plane and the x-axis. particles: List of particles in the source. This list will be used in the simulation.

get_description_source_type()
inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

class proppy.source.QubicSourceIsotropic(*args, **kwargs)

Bases: proppy.source.Source

A quibic source that emits particles isotropically from within its volume.

All particles start from a random point from the 3d cube of a user defined width. All particles have the exact same state in the beginning, except for the position and the direction, which is isotropic.

Attributes:
energy: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

pos: A list that specify the source position. nr_particles: An int that defines how many particles should be emited. particles: List of particles in the source. This list will be used in the simulation.

get_description_source_type()
inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

sample_isotropic_vecotrs()

Samlpe correct isotropic vectors.

See discussion in https://mathworld.wolfram.com/SpherePointPicking.html.

class proppy.source.Source(*args, **kwargs)

Bases: object

Abstract base class for all special sources.

Functions with the label @abstractmethod have to be implemented in the special observer classes.

Attributes:

energy: Initial energy of the particle. nr_particles: Number of particles emitted from the source. dimensions: Number of dimensions. particles: Particles with the initial particle state. source: Special source.

empty_source()

Remove all particles in the source.

get_description()

Print the information of the relevant parameters and the description of the special source type that was chosen

get_description_general()

Called by all special observer classes below. Introduction of the description output.

get_description_parameters()

Called by all special observer classes below. print out all relevant instance parameters.

abstract get_description_source_type()
init_source()

Initialize parameters that are common for all special source classes.

abstract inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

required_attributes = ['energy', 'nr_particles', 'dimensions', 'particles']
reset_source()

Reset source after simulation in order to repeat the simulation afterwards.

set_dimensions(dimensions)
class proppy.source.SourceMeta(name, bases, namespace, **kwargs)

Bases: abc.ABCMeta

Abstract meta class to check if all required attributes are implemented in the sub classes.

required_attributes = []
class proppy.source.SphereSourceIsotropic(*args, **kwargs)

Bases: proppy.source.Source

A spherical source that emits particles isotropically.

All particles start from a random point within a user defined sphere. All particles have the exact same state in the beginning, except for the position and the direction, which is isotropic.

Attributes:
energy: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

pos: A list that specify the source position. nr_particles: An int that defines how many particles should be emited. particles: List of particles in the source. This list will be used in the simulation.

get_description_source_type()
inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

sample_isotropic_vecotrs()

Samlpe correct isotropic vectors.

See discussion in https://mathworld.wolfram.com/SpherePointPicking.html.

class proppy.source.SphereSourceSurfaceIsotropic(*args, **kwargs)

Bases: proppy.source.Source

A spherical source that emits particles isotropically from its surface.

All particles start from a random point from the surface of a user defined sphere. All particles have the exact same state in the beginning, except for the position and the direction, which is isotropic.

Attributes:
energy: An b array specifying observed substeps [1_substep,2_substep,3_substep].

Only observing once per step: substeps = [False, False, True].

pos: A list that specify the source position. nr_particles: An int that defines how many particles should be emited. particles: List of particles in the source. This list will be used in the simulation.

get_description_source_type()
inject_particles()

Each sub class (special source) has to implement how particles should be injected. Here, self.particles will be filled.

sample_isotropic_vecotrs()

Samlpe correct isotropic vectors.

See discussion in https://mathworld.wolfram.com/SpherePointPicking.html.

proppy.statistics module

Scripts to compute statistical quantities of the particles.

As the particles propagate via a random walk, statistical properties of many particles are interesting, such as the diffusion coefficients and particle distributions. These quantities can be compared to analytical predictions.

Typical usage example:

import proppy as pp

df = pd.read_pickle(“data/data_sim.pkl”) df_time_evolution_observer = df.loc[df[‘radius’] == -1.0] sta = pp.Statistics(df_time_evolution_observer) errors = False df_kappas = sta.plot_diffusion_coefficients(errors)

class proppy.statistics.Statistics(df)

Bases: object

Statistics class for visualizing statistical properties of particle transport.

After loading the simulation data, distributions of particles and running diffusion coefficients can be plotted.

Attributes:

dimensions: An int for defining the dimensions. df: A pandas dataftrame with the simulation data.

get_diffusion_coefficients(speed_light=300000000)
plot_arrival_times(radius, nr_particles, diffusion_coefficient, file_name, bins_log=20, bins_lin=50, d_max=None)

Plotting the histograms for arrival times on a sphere.

Two plots are created that show the number of particles arriving the sphere as a function of time: - in lin-lin representation to resolve later times - in log-log representation to resolve initial times

Args:

radius: A double that defines the radius of the sphere. nr_particles: An int only relevant for the title of the plots. diffusion_coefficient: A float only relevant for the title of the plots. file_name: A string that points to the source of the data that should be plotted. bins_log: An int that defines the number of bins for the lin-lin hist. bins_lin: An int that defines the number of bins for the log-log hist. d_max: An float that defines the maximum trajectory length that is shown.

plot_diffusion_coefficients(isotropic=True, error=False, file_name=None, plot=True, n_points_plateau=100)

Plotting the running diffusion coefficients.

The computation is described in: [1]Reichherzer, P., Becker Tjus, J., Zweibel, E. G., Merten, L., and Pueschel, M. J., “Turbulence-level dependence of cosmic ray parallel diffusion”, Monthly Notices of the Royal Astronomical Society, vol. 498, no. 4, pp. 5051–5064, 2020. doi:10.1093/mnras/staa2533.

Args:

isotropic: A bool to define if the diffusion is isotropic. error: A bool to define if the error bars should be plotted.

plot_distribution(column, step, bins, file_name)

Plotting particle distributions at a given step number.

The column of the df that should be plotted can be choosen freely. Possible is to plot the particle distribution along directions, but also all other dataframe (df) columns are possible and sometimes usefull.

Args:

column: An int that specifies which column to plot. step: An int that defines the step number -> row of the df. bins: An int that defines the number of bins in the plotted histogram. file_name: String or None. If not None, the plot will be saved with the given String as a name.

set_dimensions(dimensions)

proppy.trajectory module

Scripts to visualize simulated particle trajectories.

The simulated particles can be visualized here by showing their trajectories or other properties.

Typical usage example:

import proppy as pp

df = pd.read_pickle(“data.pkl”) df_time_evolution_observer = df.loc[df[‘radius’] == -1.0] tra = pp.Trajectory(df_time_evolution_observer) particle_ids = tra.get_particle_ids()

nr_steps = 2*10**2 tra.plot_trajectory(‘x’, ‘y’, ‘d’, particle_ids[0], nr_steps, None) tra.plot_trajectory(‘d’, ‘z’, ‘d’, particle_ids[0], nr_steps, None)

class proppy.trajectory.Trajectory(df)

Bases: object

Trajectory class for visualizing particle trajectories.

After loading the simulation data, the simulated particles can be visualized here by showing their trajectories or other properties.

Attributes:

dimensions: An int for defining the dimensions. df: A pandas dataftrame with the simulation data.

get_label(axis)

If the axis shows a distance, add the unit [m] to the label.

get_particle_ids()
plot_trajectory(x, y, c, particle_ids, nr_steps, file_name)

Plot the particle trajectory.

Args:

x: A String that specifies which column to plot on the x-axis. y: A String that specifies which column to plot on the y-axis. c: A String that specifies which column to use for color-coding the plot and the color-bar. particle_ids: List of particle ids that should be plotted. nr_steps: An int tha defines the number of steps to be plotted. file_name: String or None. If not None, the plot will be saved with the given String as a name.

plot_trjectory_substeps(substep_0, substep_1, particle_ids, number_steps, file_name)

Function to visualize substeps. Two substeps can be passed, which are visualized in the x-y plane. The lines from substep_0 to substep_1 as well as the lines substep_1 to aubstep_0 are marked in color

set_dimensions(dimensions)

Module contents