issim.galgen package
Submodules
issim.galgen.galgen module
- class issim.galgen.galgen.Galaxy(N, mass, radius, scaleheight, randvel, G=0.00019160287, k=4e-06, n=3, nu=3e-06)[source]
Bases:
objectA class for generating the initial conditions for a spiral galaxy, running simulations, and generating animations of those simulations.
- plot(time, orientation='top', xlim=None, ylim=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.25, s=10, **kwargs)[source]
Plot the galaxy at a specific time.
Parameters: - time: The time at which to plot the galaxy. - orientation: The orientation of the plot (‘top’ or ‘side’, default is ‘top’). - xlim: The x-axis limits of the plot (default is None). - ylim: The y-axis limits of the plot (default is None). - cmap: The colormap for density plotting (default is plt.cm.autumn). - alpha: The transparency of points (default is 0.25). - s: The size of points (default is 10).
- plot3d(time, xlim=None, ylim=None, zlim=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.2, s=10, **kwargs)[source]
Plot the galaxy at a specific time.
Parameters: - time: The time at which to plot the galaxy. - orientation: The orientation of the plot (‘top’ or ‘side’, default is ‘top’). - xlim: The x-axis limits of the plot (default is None). - ylim: The y-axis limits of the plot (default is None). - zlim: The y-axis limits of the plot (default is None). - cmap: The colormap for density plotting (default is plt.cm.autumn). - alpha: The transparency of points (default is 0.25). - s: The size of points (default is 10).
- plot3dvid(downsampling=1, interval=50, xlim=None, ylim=None, zlim=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.2, s=10, **kwargs)[source]
Create a 3D video of the galaxy’s movement.
Parameters: - downsampling: The downsampling factor for the video (default is 1). - orientation: The orientation of the plot (‘top’ or ‘side’, default is ‘top’). - xlim: The x-axis limits of the plot (default is None). - ylim: The y-axis limits of the plot (default is None). - zlim: The z-axis limits of the plot (default is None). - cmap: The colormap for density plotting (default is plt.cm.autumn). - alpha: The transparency of points (default is 0.25). - s: The size of points (default is 10).
- plotvid(downsampling=1, interval=50, orientation='top', xlim=None, ylim=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.25, s=10, **kwargs)[source]
Create a video of the galaxy’s movement.
Parameters: - downsampling: The downsampling factor for the video (default is 1). - orientation: The orientation of the plot (‘top’ or ‘side’, default is ‘top’). - xlim: The x-axis limits of the plot (default is None). - ylim: The y-axis limits of the plot (default is None). - cmap: The colormap for density plotting (default is plt.cm.autumn). - alpha: The transparency of points (default is 0.25). - s: The size of points (default is 10).
- quadplot(time, xlim1=None, ylim1=None, xlim2=None, ylim2=None, xlim3=None, ylim3=None, xlim4=None, ylim4=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.25, s=10, **kwargs)[source]
Plot the galaxy in four different orientations at a specific time.
Parameters: - time: The time at which to plot the galaxy. - xlim1, ylim1: The x-axis and y-axis limits for the first subplot (default is None). - xlim2, ylim2: The x-axis and y-axis limits for the second subplot (default is None). - xlim3, ylim3: The x-axis and y-axis limits for the third subplot (default is None). - xlim4, ylim4: The x-axis and y-axis limits for the fourth subplot (default is None). - cmap: The colormap for density plotting (default is plt.cm.autumn). - alpha: The transparency of points (default is 0.25). - s: The size of points (default is 10).
- quadplotvid(downsampling=1, interval=50, xlim1=None, ylim1=None, xlim2=None, ylim2=None, xlim3=None, ylim3=None, xlim4=None, ylim4=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.25, s=10, **kwargs)[source]
Create a quad-view video of the galaxy’s movement.
Parameters: - downsampling: The downsampling factor for the video (default is 1). - orientation: The orientation of the plot (‘top’ or ‘side’, default is ‘top’). - xlim1, ylim1: The x-axis and y-axis limits for the first subplot (default is None). - xlim2, ylim2: The x-axis and y-axis limits for the second subplot (default is None). - xlim3, ylim3: The x-axis and y-axis limits for the third subplot (default is None). - xlim4, ylim4: The x-axis and y-axis limits for the fourth subplot (default is None). - cmap: The colormap for density plotting (default is plt.cm.autumn). - alpha: The transparency of points (default is 0.25). - s: The size of points (default is 10).
- saveanim(name='ISsiManim', writer='ffmpeg', fps=24, dpi=100)[source]
Save the generated animation as an MP4 file.
Parameters: - name: The base name of the MP4 file (default is ‘ISsiManim’). - writer: The name of the video writer to use (default is ‘ffmpeg’). - fps: The frames per second of the animation (default is 24). - dpi: The resolution of the animation in dots per inch (default is 100).
- simulate(smoothinglength, tstep, tEnd, tStart=0)[source]
Simulate the movement of particles in the galaxy.
Parameters: - smoothinglength: The smoothing length for SPH calculations. - tstep: The time step for integration. - tEnd: The end time of the simulation. - tStart: The start time of the simulation (default is 0).
Returns: - simulation: A tuple containing positions, colors, and times of the simulation.
- issim.galgen.galgen.exponentialdiskvelocity(G, M, Rdisk, R)[source]
Calculates the angular velocity of an object at a certain radial distance within an exponential disk galaxy using a simplified model. This function assumes an exponential disk mass distribution and utilizes specific Bessel functions to estimate the velocity.
Parameters: - G (float): Gravitational constant. Ensure consistent units are used
throughout all parameters.
- M (float): Total mass of the galaxy or the mass enclosed within a certain
radius. Again, consistent units with G are essential.
- Rdisk (float): Scale length of the galaxy’s exponential disk. This parameter
defines how rapidly the disk’s density decreases with radius from the center of the galaxy.
- R (float or array_like): Radial distance(s) from the center of the galaxy
at which to calculate the angular velocity. Can be a single value or an array of values for calculating velocities at multiple radii simultaneously.
Returns: - vels (float or ndarray): The angular velocity (or velocities if R is an array)
at the specified radial distance(s) from the galaxy’s center. The return type matches the input type of R.
Notes: - This function uses the special.iv (modified Bessel function of the first kind)
and special.kv (modified Bessel function of the second kind) from the SciPy library to compute the velocities. Ensure SciPy is installed and imported correctly in your environment.
Example:
>>> import numpy as np >>> from scipy import special >>> G = 6.67430e-11 # Gravitational constant in m^3 kg^-1 s^-2 >>> M = 1e11 # Mass of the galaxy in kg >>> Rdisk = 3.5e3 # Scale length of the galaxy's disk in light-years >>> R = np.array([8000, 15000]) # Radial distances in light-years >>> velocities = exponentialdiskvelocity(G, M, Rdisk, R) >>> print(velocities)
The output will be the angular velocities at the specified radial distances.
- issim.galgen.galgen.generate_3d_exponential_cylindrical(n, radius, height)[source]
Generate 3D coordinates in cylindrical space where the radial distance follows a radial exponential distribution and z-coordinates are uniformly distributed.
Parameters: - n: Number of points to generate. - lambda_r: Rate parameter (λ) for the radial distance’s exponential distribution. - z_min: Minimum z-coordinate. - z_max: Maximum z-coordinate.
Returns: - A numpy array of shape (n, 3) containing the 3D coordinates.
Example:
>>> import numpy as np >>> from issim.galgen import generate_3d_exponential_cylindrical
>>> # Generating 1000 points with a radius of 2 units and a height of 5 units >>> points = generate_3d_exponential_cylindrical(1000, 2, 5)
>>> # Check the shape of the generated points >>> points.shape (1000, 3)
>>> # Visualize the generated points in 3D space >>> import matplotlib.pyplot as plt >>> from mpl_toolkits.mplot3d import Axes3D
>>> fig = plt.figure() >>> ax = fig.add_subplot(111, projection='3d') >>> ax.scatter(points[:,0], points[:,1], points[:,2]) >>> ax.set_xlabel('X') >>> ax.set_ylabel('Y') >>> ax.set_zlabel('Z') >>> plt.show()
- issim.galgen.galgen.normalize_vectors(vectors)[source]
Normalize a list or array of 3D vectors to their unit vectors.
Parameters: - vectors: A list or a numpy array of shape (n, 3) where n is the number of vectors
Returns: - A numpy array of shape (n, 3) containing the unit vectors.
Example: >>> import numpy as np >>> from issim.galgen import normalize_vectors
>>> # Define some 3D vectors >>> vectors = np.array([[1, 2, 2], [3, 4, 5], [6, 7, 8]])
>>> # Normalize the vectors >>> normalized_vectors = normalize_vectors(vectors)
>>> # Check the normalized vectors >>> normalized_vectors array([[0.33333333, 0.66666667, 0.66666667], [0.42426407, 0.56568542, 0.70710678], [0.46666667, 0.54772256, 0.6289709 ]])
>>> # Check if the magnitudes of the normalized vectors are approximately 1 >>> np.linalg.norm(normalized_vectors, axis=1) array([1., 1., 1.])
- issim.galgen.galgen.radiuscalc2Dcylinder(vectors)[source]
Calculate the radial positions of 3D vectors projected onto a 2D cylindrical space.
Parameters: - vectors: A numpy array of shape (n, 3) containing the 3D vectors.
Returns: - A numpy array of shape (n,) containing the radial positions of the vectors in 2D cylindrical space.
The radial position of a vector in cylindrical coordinates is calculated as the Euclidean distance from the origin to the projection of the vector onto the xy-plane.
Example: >>> import numpy as np >>> from issim.galgen import radiuscalc2Dcylinder
>>> # Define some 3D vectors >>> vectors = np.array([[1, 2, 2], [3, 4, 5], [6, 7, 8]])
>>> # Calculate the radial positions of the vectors in 2D cylindrical space >>> radial_positions = radiuscalc2Dcylinder(vectors)
>>> # Check the radial positions >>> radial_positions array([2.23606798, 5. , 9.21954446])
- issim.galgen.galgen.timepull(simulation, time)[source]
Find the index of the closest time in a simulation to a given time.
Parameters: - simulation: A tuple containing positions, colors, and times of the simulation. - time: The time to find in the simulation.
Returns: - index: The index of the closest time in the simulation.