Commit a38f9cec authored by Marc Arene's avatar Marc Arene
Browse files

Preparing for injection_file.

parent 41167e76
# Import such a file using the following lines in a python script
# from configparser import ConfigParser
# config = ConfigParser()
# config.read('ThisFile.ini')
[parameters]
mass_1=1.47
mass_2=1.27
chi_1=0.0
chi_2=0.0
luminosity_distance=40
# iota=146*np.pi/180
iota=2.81
theta_jn=2.81
psi=2.21
phase=5.497787143782138
geocent_time=1187008882.43
# value from fixed skyposition run
ra=3.44616
# value from fixed skyposition run
dec=-0.408084
lambda_1=0
lambda_2=0
tilt_1=0
tilt_2=0
{
"mass_1":1.47,
"mass_2":1.27,
"chi_1":0.0,
"chi_2":0.0,
"luminosity_distance":40,
"iota":2.81,
"theta_jn":2.81,
"psi":2.21,
"phase":5.497787143782138,
"geocent_time":1187008882.43,
"ra":3.44616,
"dec":-0.408084,
"lambda_1":0.0,
"lambda_2":0.0,
"tilt_1":0,
"tilt_2":0,
"meta": {
"minimum_frequency":40
}
}
......@@ -124,9 +124,38 @@ def loadtxt_complex(path):
"""
return np.loadtxt(path).view(complex)
def config_parser_to_dict(config):
"""
Converts a configparser comming from an ini file to a python dictionary. Inputs will try to be converted into floats, and will be treated as text inputs if that fails.
Parameters:
-----------
config: configparser.ConfigParser()
Contains the content of the ini file through `config.read('file.ini')`
Returns:
--------
dictionary: dict
A dictionary containing one primary key per section in the ini file. Each of these keys is itself another dictionary with the section options as keys.
"""
dictionary = {}
for section in config.sections():
dictionary[section] = {}
for option in config.options(section):
try:
dictionary[section][option] = config.getfloat(section, option)
except ValueError:
dictionary[section][option] = config.get(section, option)
return dictionary
# def as_dict(config):
# d = dict(config._sections)
# for k in d:
# d[k] = dict(config._defaults, **d[k])
# d[k].pop('__name__', None)
# return d
def binaryFile_to_sigpar(binary_file_name):
......
import sys
# cf https://docs.python.org/3/tutorial/modules.html
sys.path.append('../')
import numpy as np
import bilby.gw.conversion as conv
from Headers.PN_Coefficients import * # Headers.Constants already imported in PN_Coeff
# import sys
# # cf https://docs.python.org/3/tutorial/modules.html
# sys.path.append('../')
# import Library.bilby_waveform as bilby_wv
import json
# from configparser import ConfigParser
# import Library.Python_Utility as pu
def ComputeChirpTime3p5PN(f_low, m1, m2):
......@@ -53,26 +54,31 @@ def Compute_fmax(Rmin, m1, m2):
injection_parameters = dict(
mass_1=1.47,
mass_2=1.27,
chi_1=0.0,
chi_2=0.0,
luminosity_distance=40,
# iota=146*np.pi/180,
iota=2.81,
theta_jn=2.81,
psi=2.21,
phase=5.497787143782138,
geocent_time=1187008882.43,
ra=3.44616, # value from fixed skyposition run
dec=-0.408084, # value from fixed skyposition run
lambda_1=0.,
lambda_2=0.,
tilt_1=0,
tilt_2=0
)
with open('../Codes/GW170817.json') as inj_file:
injection_parameters = json.load(inj_file)
inj_file.close
# config = ConfigParser()
# config.read('../Codes/GW170817.ini')
# injection_parameters = pu.config_parser_to_dict(config)
# injection_parameters = dict(
# mass_1=1.47,
# mass_2=1.27,
# chi_1=0.0,
# chi_2=0.0,
# luminosity_distance=40,
# # iota=146*np.pi/180,
# iota=2.81,
# theta_jn=2.81,
# psi=2.21,
# phase=5.497787143782138,
# geocent_time=1187008882.43,
# ra=3.44616, # value from fixed skyposition run
# dec=-0.408084, # value from fixed skyposition run
# lambda_1=0.,
# lambda_2=0.,
# tilt_1=0,
# tilt_2=0
# )
injection_parameters = conv.generate_mass_parameters(injection_parameters)
injection_parameters['reduced_mass'] = (injection_parameters['mass_1'] * injection_parameters['mass_2']) / (injection_parameters['mass_1'] + injection_parameters['mass_2'])
......
......@@ -782,3 +782,14 @@ Next Meeting with Ed:
- [1,2,3]: better acceptance rate but oscillatory behavior is here
- [1,3]: no oscillatory behavior
- [1,2]: oscillatory behavior !
#### Refactorization before chile
- make dynamical injection parameters from a file
- remove the `GW170817` name in files:
- `GW170817` shouldn't appear anymore
- these modules shouldn't be in a directory called `Tests` if I keep importing them in the main script => create a directory called: `intermediate scripts` ?
- have the `verbose` option really control the prints.
- simplify the call to bilby's waveform generation
- remove `import bilby` from `Python_Utility`
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment