<jupyter_start><jupyter_text>---      Load a BAM hdf5 file, and given an inclination value, determine the angle $\theta_{\mathrm{JN}}$---The goal of this script is to take in INCLINATION and then output $\theta_{\mathrm{JN}}$<jupyter_code># Import useful standard things
from os import system, remove, makedirs, path
from os.path import dirname, basename, isdir, realpath
from numpy import array,ones,pi,dot,cos,sin,savetxt
from numpy import arccos as acos
from numpy.linalg import norm
from matplotlib.pyplot import *
from os.path import expanduser
# Import nrutils (See: https://github.com/llondon6/nrutils_dev)
from nrutils import alert,nr2h5,scsearch,gwylm,alert
from nrutils.tools.unit.conversion import *<jupyter_output><empty_output><jupyter_text>Use nrutils to locate the simulation of interest.<jupyter_code>Y = scsearch(keyword='q1.2_dc2dcp2',verbose=True,unique=True)[0]<jupyter_output>[scsearch]>> Found [4mkeyword[0m (='q1.2_dc2dcp2') keyword.
[scsearch]>> Found [4munique[0m (=True) keyword.
[scsearch]>> Found [4mverbose[0m (=True) keyword.
## Found [1m1[0m[92m unique[0m simulations:
[0001] [96mq1.2_dc2dcp2[0m: p-q1.20<jupyter_text>Define function for $\theta_{\mathrm{JN}}$ calculation<jupyter_code>def iota2thetajn(A,                # scnetry object from nrutils
                 IOTA,             # The angle between L and the line of sight 
                 verbose=False):   # be verbose toggle
    
    # Import useful things
    from numpy import array,ones,pi,dot,cos,sin,vstack,hstack
    from numpy import arccos as acos
    from numpy.linalg import norm
    
    # Extract L, S, and J (NOTE: these are after-junk quantities)
    L = A.L1 + A.L2
    S = A.S1 + A.S2 
    J = L + S

    # Calculate the direction of J and L using the loaded information
    info = A.raw_metadata
    L_bbh = array( [ info.initial_angular_momentumx, info.initial_angular_momentumy, info.initial_angular_momentumz ] )
    S1 = array( [ info.after_junkradiation_spin1x, info.after_junkradiation_spin1y, info.after_junkradiation_spin1z ] )
    S2 = array( [ info.after_junkradiation_spin2x, info.after_junkradiation_spin2y, info.after_junkradiation_spin2z ] )
    S = S1+S2
    J_bbh = L_bbh+S

    # The magnitude of For now, apply norm(L_bbh)

    if False: # verbose:
        print 'L from the bbh files is %s' % L_bbh
        print 'L after junk from nrutils is %s' % L
        print 40*'--'

    # Find unit vectors
    L_hat = L / norm(L)
    J_hat = J / norm(J)

    # Extract oribital separation (NOTE: this is also referenced after-junk)
    n_hat = ( A.R1 - A.R2 ) / norm( A.R1 - A.R2 )

    #
    theta = IOTA

    # per LAL convention
    u_hat = [1,0,0]

    #
    phi = acos( dot( n_hat,u_hat ) )

    #
    N_hat = array( [  cos(phi)*sin(theta), sin(phi)*sin(theta), cos(theta)  ] )

    #
    theta_JN = acos( dot(N_hat,J_hat) )
    theta_LN = acos( dot(N_hat,L_hat) )
    theta_JL = acos( dot(J_hat,L_hat) )

    #
    if verbose:
        print '(iota,theta_JN) = (%1.4f,%1.4f)' % (IOTA*180/pi,theta_JN*180/pi)
    if False: # verbose:
        print 'phi = %1.4f' % phi
        print 'n_hat = %s' % n_hat
        print 'N_hat = %s' % N_hat
        print 'L_hat = %s' % L_hat
        print 'J_hat = %s' % J_hat
        print 'theta_JN = %1.4f degrees' % (theta_JN*180/pi)
        print 'theta_LN = %1.4f degrees' % (theta_LN*180/pi)
        print 'theta_JL = %1.4f degrees' % (theta_JL*180/pi)
        print 'theta_JZ = %1.4f degrees' % ( acos(dot(J_hat,[0,0,1])) )
        
    #
    return theta_JN<jupyter_output><empty_output><jupyter_text>Define inclinations of interest.<jupyter_code>NUM = 9 # Number of points in iota to use 
iota = array(  [ (k*pi/(NUM-1.0)) for k in range(0,NUM) ]  )
print iota<jupyter_output>[ 0.          0.39269908  0.78539816  1.17809725  1.57079633  1.96349541
  2.35619449  2.74889357  3.14159265]<jupyter_text>Evaluate above function for the given list of runs (scentry objects).<jupyter_code>theta_JN = array(  [ iota2thetajn(Y,k,verbose=True) for k in iota ]  )<jupyter_output>(iota,theta_JN) = (0.0000,5.3149)
(iota,theta_JN) = (22.5000,24.9079)
(iota,theta_JN) = (45.0000,47.1415)
(iota,theta_JN) = (67.5000,69.5223)
(iota,theta_JN) = (90.0000,91.9350)
(iota,theta_JN) = (112.5000,114.3452)
(iota,theta_JN) = (135.0000,136.7142)
(iota,theta_JN) = (157.5000,158.8802)
(iota,theta_JN) = (180.0000,174.6851)<jupyter_text>Make array of iota and $\theta_{\mathrm{JN}}$ values<jupyter_code>output_data = array( [iota,theta_JN] ).T
print output_data<jupyter_output>[[ 0.          0.09276337]
 [ 0.39269908  0.43472526]
 [ 0.78539816  0.82277365]
 [ 1.17809725  1.2133932 ]
 [ 1.57079633  1.60456847]
 [ 1.96349541  1.99570061]
 [ 2.35619449  2.38611276]
 [ 2.74889357  2.77298228]
 [ 3.14159265  3.04882929]]<jupyter_text>Save the array to a txt file.<jupyter_code>output_file_path = '/Users/book/GARREG/REPOS/cbc_svn_nr_systematics/nr_systematics/scripts/thetaJN_'+Y.setname+'.txt'
savetxt( output_file_path, output_data, fmt='%1.8f', delimiter='\t' )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13337296868806975, 'fraction_numerical': 0.08759413396749902, 'mean_word_length': 3.5715579710144927, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '657578', 'license': 'MIT', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2016, 'n_words': 434, 'path': 'review/notebooks/bam_inclination_to_thetajn.ipynb', 'repo_name': 'Cyberface/nrutils_dev', 'size': '5046'}