Commit bae90753 authored by Zoheyr Doctor's avatar Zoheyr Doctor 🔭
Browse files

added support for text files of data for animate_binaries_from_file

parent ee43ce0e
......@@ -14,7 +14,7 @@ def make_parser():
parser.add_argument(
"file",
type=str,
help='json file with median values',
help='json file with median values or gwosc text catalog',
)
parser.add_argument(
......@@ -44,17 +44,49 @@ def make_parser():
return parser
def file_handler(filename):
""" spits out a dictionary of events mapping
to m1 and m2 values
"""
events2masses = {}
if filename.endswith('.json'):
with open(filename,'r') as json_file:
data = json.load(json_file)
for event in list(data.keys()):
events2masses[event] = {
'm1': data[event]['mass_1_source']['med'],
'm2': data[event]['mass_2_source']['med']
}
elif filename.endswith('.txt'):
data = np.genfromtxt(filename,names=True,encoding='UTF-8',dtype=None)
sel = data['mass_1_source']=='None'
data = data[~sel]
for event in data['id']:
print(event)
event_sel = data['id'] == event
events2masses[event] = {
'm1': float(data[event_sel]['mass_1_source'][0]),
'm2': float(data[event_sel]['mass_2_source'][0])
}
else:
print('bad file name. Must be .json or .txt')
return events2masses
def main():
import json
import sys
# parse arguments
parser = make_parser()
args = parser.parse_args()
with open(args.file,'r') as json_file:
data = json.load(json_file)
events2masses = file_handler(args.file)
# get number of events and hence number of axes needed
events = list(data.keys())
events = list(events2masses.keys())
n_events = len(events)
n_side = int(np.ceil(np.sqrt(n_events)))
n_side2 = int(np.ceil(n_events/float(n_side)))
......@@ -72,18 +104,17 @@ def main():
# determine orbital frequencies
if args.round:
omegas = np.array([1./(data[event]['mass_1_source']['med']
+ data[event]['mass_2_source']['med']
) for event in events
omegas = np.array([1./(
masses['m1'] + masses['m2']
) for event, masses in events2masses.items()
])
omegas = np.round(omegas/np.amin(omegas),0)
omegas = {event : omegas[i]/length for i,event in enumerate(events)}
else:
omegas = {event : 20./(data[event]['mass_1_source']['med']
+ data[event]['mass_2_source']['med']
) for event in events
omegas = {event: 20./(
masses['m1'] + masses['m2']
) for event, masses in events2masses.items()
}
pos_dict = {} # dictionary for all compact object positions
bbh_dict = {} # dictionary for all BinaryBlackHole objects
# loop over all events
......@@ -91,8 +122,8 @@ def main():
print('evolving ',event)
event_pos_dict = {} # dictionary for positions of this event
m1 = data[event]['mass_1_source']['med']
m2 = data[event]['mass_2_source']['med']
m1 = events2masses[event]['m1']
m2 = events2masses[event]['m2']
# create a Binary instance for the event
binary = Binary(
m1 = m1,
......
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