Professional Documents
Culture Documents
Python and NR Data Intro
Python and NR Data Intro
Dibrugarh University
2-4.11.16
Python basics
Now enter
>>> print(Hello World!)
All you need to enter is the same command as before, save, and enter python
helloworld.py in the command line.
# This is a comment.
"""
This is also a comment.
"""
Arithmetic in Python
numpy is the standard numerical package for Python, though there are
also some useful mathematica things in scipy, notably special functions.
Well see how to import these (and how to import things in general).
Of course
>>> from numpy import *
imports everything, but is generally frowned upon in Python circles as polluting
namespaces.
Numpy arrays
One can also easily find out where an arrays elements satisfy some
condition, e.g.,
>>> idx = np.where(b < 0.4)
>>> idx
Now one can use this array of indices to select out the elements of this
array that satisfy the condition and perform some other operation, e.g.,
>>> np.cos(a[idx]*b[idx])
Numpy arrays (cont.)
a = 5
if a > 1:
print(a)
Then one can create a figure and then create 3d axes (gca = get current axes,
creating them if necessary)
>>> fig = plt.figure()
>>> ax = plt.gca(projection=3d')
Try to plot the final mass and spin fits versus eta in 3d.
Data reading
There are various ways of reading data into Python.
If one has a table with headers, np.genfromtxt is a very convenient way of reading in data.
Lets see this with a simple example where we make our own data.
Note that you will need to normalize the final mass by the sum of the initial masses and the
final spin by the final mass squared (since it is the fully dimensionful final spin).
You may also want to check that adding in spins introduces features in the final mass and
spin that are not captured by these nonspinning fits (as expected). You can even restrict to
just nonprecessing, aligned-spin cases (with x- and y-components close to 0) and find that
this is still the case.
You can at least look at the final masses and spins for high spin simulations (either
selecting them in Python or via the web interface to the SXS catalogue) and see that these
are not accurately captured by this nonspinning fit.
You can also experiment with plotting the residual of this fit versus spin quantitiesthe
dominant effect comes from the spins along the orbital angular momentum.
Looking at BBH data
We will now plot some BBH waveforms and coordinate tracks.
First well have a look at the metadata file, which tells you lots about
the simulation.
This just shows the top directories. To access a given directory, just
use data_file[directory name]; this also works for subdirectories.
Now one can pick an extrapolation order (or use the outermost
extraction radius) and plot the dominant quadrupolar part of
the waveform (l = m = 2 in this [spin-weighted] spherical
harmonic decomposition). You want Y_l2_m2.dat
You can pick out all the time values using [:,0], and the real and
imaginary parts similarly.
To get the phase, youll want to use np.arctan2(real, imaginary) and unwrap the
phase with np.unwrap.
You can also check that the initial angular velocity (after the junk) is twice the initial
orbital frequency given in the metadata using np.gradient (which youll need to apply
to both phase and time).
Also, you can try to find the minimum mass needed such that the minimum 2,2
mode frequency in this waveform is above LIGOs (current) minimum frequency of
20 Hz; note that 1 solar mass is ~5 s.
You can also look at the higher modesthe nonzero ones in this simple nonspinning
equal mass case are the ones with even m. You should try at least 3, 2 and 4, 4.
(The negative m modes are the same as the corresponding positive m modes up to
a sign in this simple case; this is not true in more complicated precessing cases.)
Analyzing a BBH waveform
You can also compute the radiated energy and see how much
2
comes from each mode. The expression is dElm/dt = |r dhlm/dt| /16.
np.cumsum can be used to integrate to get the total energy radiated
in each mode (making sure to include the gradient of the time in the
integrand).
Here you can see if you can reproduce (to good accuracy) the final
mass given in the metadata by subtracting off the radiated energy
from the initial ADM energy. [The expressions for the angular and
linear momentum radiated are rather more complicated but can be
found in Ruiz et al. GRG (2008).]
You can also check the peak luminosity from the 2,2 and 2,-2 modes
dominates and is very close to the value obtained for GW150914.
Plotting the trajectory
You can look at the trajectory of one of the black holes. This
is in Horizons.h5, where you want to look at
CoordCenterInertial.dat in AhA.dir or AhB.dir.