Using Geodesics (Back-ends & Plotting)¶
[12]:
import numpy as np
from einsteinpy.geodesic import Geodesic, Timelike, Nulllike
from einsteinpy.plotting import GeodesicPlotter, StaticGeodesicPlotter, InteractiveGeodesicPlotter
Example 1: Exploring Schwarzschild Time-like Spiral Capture, using Python Backend and GeodesicPlotter¶
Defining initial conditions¶
[13]:
# Initial Conditions
position = [4., np.pi / 3, 0.]
momentum = [0., 0., -1.5]
a = 0. # Schwarzschild Black Hole
Calculating Geodesic¶
[14]:
geod = Timelike(
metric = "Schwarzschild",
metric_params = (a,),
position=position,
momentum=momentum,
steps=15543, # As close as we can get before the integration becomes highly unstable
delta=0.0005,
return_cartesian=True,
omega=0.01, # Small omega values lead to more stable integration
suppress_warnings=True, # Uncomment to view the tolerance warning
)
geod
[14]:
Geodesic Object:(
Type : (Time-like),
Metric : (Schwarzschild),
Metric Parameters : ((0.0,)),
Initial 4-Position : ([0. 4. 1.04719755 0. ]),
Initial 4-Momentum : ([-0.77055175 0. 0. -1.5 ]),
Trajectory = (
(array([ 0, 1, 2, ..., 15540, 15541, 15542]), array([[ 7.70551750e-04, 3.46410160e+00, -2.16506351e-04, ...,
-5.07812502e-05, 5.41265877e-05, -1.50000000e+00],
[ 1.54110350e-03, 3.46410157e+00, -4.33012700e-04, ...,
-1.01562501e-04, 1.08253176e-04, -1.50000000e+00],
[ 2.31165526e-03, 3.46410152e+00, -6.49519046e-04, ...,
-1.52343754e-04, 1.62379763e-04, -1.50000000e+00],
...,
[ 2.10892615e+01, 5.06915642e-01, -1.93331152e+00, ...,
-7.67875285e+01, 8.37708122e-01, -1.50000000e+00],
[ 2.11285953e+01, 5.06465005e-01, -1.93307239e+00, ...,
-7.82825155e+01, 8.37749353e-01, -1.50000000e+00],
[ 2.11686915e+01, 5.06014321e-01, -1.93283308e+00, ...,
-7.98370238e+01, 8.37790569e-01, -1.50000000e+00]]))
),
Output Position Coordinate System = (Cartesian)
))
Plotting using GeodesicPlotter
¶
Note that GeodesicPlotter
automatically switches between “Static” and “Interactive” plots. Since we are in a Jupyter Notebook or Interactive Environment, it uses the “Interactive” backend.
[15]:
gpl = GeodesicPlotter()
[16]:
gpl.plot(geod, color="green", title="Geodesic Plot", aspect="auto")
gpl.show()
Data type cannot be displayed: application/vnd.plotly.v1+json
[17]:
gpl.clear() # In Interactive mode, `clear()` must be called before drawing another plot, to avoid overlap
gpl.plot2D(geod, coordinates=(1, 2), color="green", title="Top/Bottom View") # "top" / "bottom" view
gpl.show()
Data type cannot be displayed: application/vnd.plotly.v1+json
[18]:
gpl.clear()
gpl.plot2D(geod, coordinates=(1, 3), color="green", title="Face-On View") # "face-on" view
gpl.show()
Data type cannot be displayed: application/vnd.plotly.v1+json
Each interactive plot instance (gpl
) has a fig
attribute that is a plotly.graph_objs._figure.Figure
object. So, one can easily make modifications to the plots as they would to any plotly figure. For instance, we can update the title to clarify that the plot above is showing a face-on view.
[19]:
gpl.fig.layout.title = {
'text': 'Face-On View', 'x': 0.46, 'xanchor': 'center', 'y': 0.9, 'yanchor': 'top'
}
gpl.show()
Data type cannot be displayed: application/vnd.plotly.v1+json
[20]:
gpl.clear()
gpl.parametric_plot(geod, colors=("red", "green", "blue"))
gpl.show()
Data type cannot be displayed: application/vnd.plotly.v1+json