-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhistory_cmc_modified_bss.py
More file actions
1325 lines (1156 loc) · 53.4 KB
/
Copy pathhistory_cmc_modified_bss.py
File metadata and controls
1325 lines (1156 loc) · 53.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/opt/local/bin//python
from numpy import *
import gzip
import scripts
import scripts1
import scripts2
import scripts3
import constants
import subprocess
import sys
def history_maker(ids,positions,file_string,path,binary):
"""creates the full history of interesting stars
ids: array containing the ids of interesting stars
binintfile: binint file
collfile: collision log file
mergefile: merger file
filestring: the filestring from cmc
binary: whether there was any primordial binaries or not -> 0: no binary, 1: yes binary"""
binintfile=path+file_string+'.binint.log'
collfile=path+file_string+'.collision.log'
mergefile=path+file_string+'.semergedisrupt.log'
history_interactions={}
#make the collision dictionary by reading and sorting the collision log file
coll=scripts1.collision(collfile)
#make the pure stellar evolution dictionary
se=scripts2.bse_int(mergefile)
if binary:
#make the binint dictionary by reading from the binint log file
binint=scripts3.read_binint(binintfile)
#now go through the ids of interest and populate the history file with every kind of interactions
for i in range(len(ids)):
if binary:
#read the binint history of the id in this dictionary
binint_id=scripts3.binary_interaction(binint,ids[i])
bininteract={'binint': binint_id,
'binint_coll': {}
}
#cross_correlate with collisions: if binint resulted in a merger this gives if any of the stars had any collisions before this
if len(binint_id.keys())>0:
for j in binint_id.keys():
#print j
if binint_id[j]['merge']==1:
for k in range(len(binint_id[j]['mergeids'])):
cross_id=int(binint_id[j]['mergeids'][k])
#print cross_id
binint_coll=scripts1.call_collision_tree(coll,cross_id)
bininteract['binint_coll'][k]=binint_coll
else:
bininteract = {}
collision=scripts1.call_collision_tree(coll,ids[i])
if se.has_key(ids[i]):
se_id=se[ids[i]]
else:
se_id={}
history_interactions[ids[i]]={'binint': bininteract,
'coll': collision,
'se': se_id,
'position': positions[i]
}
return history_interactions
def print_files_of_history_for_collisions(star_ids, positions, filestring, binary, prefixstring='coll_history'):
"""Takes one star id and finds its dynamical history. Once the history is obtained, it writes this history in a verbose
format in files named as the prefixstring+star id. """
import numpy as np
units = scripts.read_units(filestring)
h = history_maker(star_ids,positions,filestring,binary)
for i in xrange(len(star_ids)):
if len(h[star_ids[i]]['coll'])>0: #some collision did actually take place
pos_end = positions[i] * units[0]['l_pc']
writefilename = filestring+'.'+prefixstring+'.'+str(star_ids[i])+'.dat'
writefile = open(writefilename, 'w')
writefile.write("#1.time(Myr) 2.final_mass(Msun) 3.final_id 4.interaction 5.position_of_interaction(pc) 6.position_at_end_of_sim(pc) 7.parent_masses1(Msun) 8.parent_ids1 9.parent_masses2(Msun) 10.parent_ids2 11.etc.... \n")
t_myr, pos_interaction, interaction, par_masses, par_ids, final_mass,final_id = [], [], [], [], [], [], [],
for j in h[star_ids[i]]['coll'].keys():
t_myr.append( h[star_ids[i]]['coll'][j]['coll_params']['time'] * units[0]['t_myr'] )
print t_myr
pos_interaction.append( h[star_ids[i]]['coll'][j]['coll_params']['position'] * units[0]['l_pc'] )
interaction.append( h[star_ids[i]]['coll'][j]['coll_params']['interaction'] )
par_masses.append( h[star_ids[i]]['coll'][j]['coll_params']['parents']['masses'] )
par_ids.append( h[star_ids[i]]['coll'][j]['coll_params']['parents']['IDs'] )
final_mass.append( h[star_ids[i]]['coll'][j]['coll_params']['mass'] )
final_id.append(j)
sorted = np.argsort(t_myr)
for k in xrange(len(sorted)):
writefile.write("%f %f %ld %s %f %f " %( t_myr[sorted[k]], final_mass[sorted[k]], final_id[sorted[k]], interaction[sorted[k]], pos_interaction[sorted[k]], pos_end, ))
for l in xrange(len(par_masses[sorted[k]])):
writefile.write("%f %ld " %( par_masses[sorted[k]][l], par_ids[sorted[k]][l], ))
writefile.write("\n")
writefile.close()
def print_files_of_history_for_collisions_all_sims(basename, nstring='c'):
import create_table
import glob
dirs = dirs = create_table.get_the_dirs(basename, nstring)
for i in xrange(len(dirs)):
filestring = dirs[i]+'/initial'
print filestring
snapstring = filestring+'.snap*.dat.gz'
snaps = glob.glob(snapstring)
sorted_snaps = sort(snaps)
print sorted_snaps
if len(sorted_snaps)>0:
snapno = sorted_snaps[-1].split('/')[-1].split('snap')[1].split('.dat')[0]
print 'reading snapno', snapno
units = scripts.read_units(filestring)
temp_t_myr = scripts.find_t_myr(filestring, snapno)
if temp_t_myr >= 9000.:
binary = 0
binstring = filestring+'.bin.dat'
binfiles = glob.glob(binstring)
if len(binfiles)>0:
binary = 1
print 'there are binaries: setting binary=', binary
else:
binary=0
print 'all singles: setting binary=', binary
print 't_myr', temp_t_myr
temp_bss = scripts.find_BSS(filestring,snapno, 0.001, 1.1)
ids, pos = temp_bss[3], temp_bss[4]
print 'printing collision history files for BSs in', dirs[i]
print_files_of_history_for_collisions(ids, pos, filestring, binary, 'coll_history_test')
#def classifying_BSS(h, star_id, binary, m_cut, t_now, filestring, z):
# """
# h: history dictionary made by history maker
# star_id: id of the BSS that is of interest
# binary: were their primordial binaries in the simulation?
# m_cut: the mass cut above which we define MS stars to be BSSs for t=t_now
# t_now: last snapshot when BSSs are obtained, t_now is in code units
# divide all of the BSSs in the following categories depending on what made it a BSS:
# All collisions
# SS collision
# SE driven merger or disruption
# binary evolution mass transfer
# note time when it became a BSS and what was the interaction that made it
# to do that:
# find the m_cut at t=t_now
# go back in time and find after what interaction m_star >= m_cut: this is the interaction that
# made the BSS
# get the time and position for the interaction and also the type of the interaction
# When the star is not found to have a binary interaction, collision, or merger and disruption then
# the only other way it can grow in mass is if it had a clean undisturbed mass transfer in a
# binary
# in that case, I need to get these masses and evolve them using BSE to find the onset time
# of the mass transfer. This will be the time when the BSS started to be created.
# """
# print 'star_id', star_id, 't_now', t_now
# units = scripts.read_units(filestring)
# bss_coll, bss_ss_coll, bss_bs_coll, bss_bb_coll = 0, 0, 0, 0
# bss_se, bss_se_merger, bss_se_disruption = 0, 0, 0
# bss_had_binint = 0
# bss_se_binint, bss_mtb_binint = 0, 0
# bss_mtb, bss_mtb_pure = 0, 0
# SS_coll = 0
# BB_coll = 0
# BS_coll = 0
# t_dict = {}
# m_dict = {}
# interaction_dict = {}
# position_dict = {}
# channel_dict = {}
# count = 0
# #first look for collisions
# for i in h[star_id]['coll'].keys():
# m_coll = h[star_id]['coll'][i]['coll_params']['mass']
# t_coll = h[star_id]['coll'][i]['coll_params']['time']
# if m_coll >= m_cut:
# count += 1
# m_dict[count] = m_coll
# t_dict[count] = t_coll
# interaction_dict[count] = h[star_id]['coll'][i]['coll_params']['interaction']
# position_dict[count] = h[star_id]['coll'][i]['coll_params']['position']
# channel_dict[count] = 'collision'
# print channel_dict[count], t_dict[count], star_id
#
# #then for SE merger and disruption
# if len(h[star_id]['se'].keys())>0:
# m_se = h[star_id]['se']['mass']
# t_se = h[star_id]['se']['time']
# if m_se >= m_cut:
# count += 1
# m_dict[count] = m_se
# t_dict[count] = t_se
# interaction_dict[count] = h[star_id]['se']['description']
# position_dict[count] = h[star_id]['se']['position']
# channel_dict[count] = 'se'
# print channel_dict[count], t_dict[count], star_id
#
# #Now figure out which of these interactions actually made the BSS
# print interaction_dict
# t_earliest = t_now+1. #initialization: the plus 1 is to avoid the rare event where on the last timestep
# #the BSS is formed. In that case due to round off, t_now will seem like a later
# #time compared to the BSS formation time
# if len(interaction_dict.keys())>0:
# print 'len', len(interaction_dict.keys()), 't_now', t_now
# for i in interaction_dict.keys():
# if t_dict[i] < t_earliest:
# #finding which interaction first made it a BSS if there were multiple interactions
# actual = i
# t_earliest = t_dict[i]
# else:
# actual = 0 #this should happen for any MTB: no coll/se interaction is found
# print 'actual', actual
#
#
# if actual>0:
# actual_interaction = interaction_dict[actual]
# actual_t = t_dict[actual]
# actual_channel = channel_dict[actual]
# actual_position = position_dict[actual]
# else:
# actual_interaction = 'mtb'
# actual_t = t_now
# actual_channel = 'mtb'
# actual_position = h[star_id]['position']
#
#
# if actual_channel == 'collision':
# bss_coll = 1
# if actual_interaction == 'single-single':
# bss_ss_coll = 1
# elif actual_interaction == 'binary-single':
# bss_bs_coll = 1
# elif actual_interaction == 'binary-binary':
# bss_bb_coll = 1
# if actual_channel == 'se':
# bss_se = 1
# if actual_interaction == 'mergers with one star gone':
# bss_se_merger = 1
# elif actual_interaction == 'both stars intact':
# bss_se_disruption = 1
#
# #check if this star ever had a binary interaction before: may be it is not important
# if binary==1:
# if (h[star_id]['binint']['binint'].keys()) > 0:
# for i in h[star_id]['binint']['binint'].keys():
# t_binint = h[star_id]['binint']['binint'][i]['interaction']['type']['time']
# if t_binint < t_earliest:
# bss_had_binint = 1
#
# #check whether it may have been mass transfer in a binary
# if bss_coll == 0 and bss_se == 0:
# bss_mtb = 1
# ############################################################################
# #now need to find the time when this actually happened if they are pristine
# ############################################################################
# if bss_had_binint == 0:
# bss_mtb_pure = 1
# t_mtb = find_mtb_bss_beginning_time(star_id, z, filestring)
# t_mtb = t_mtb/units[0]['t_myr']
# if t_mtb < actual_t:
# actual_t = t_mtb
#
#
# #mixed with binary interaction before SE or MTB: is it important?
# if bss_se == 1 and bss_had_binint == 1:
# bss_se_binint = 1
# if bss_mtb == 1 and bss_had_binint == 1:
# bss_mtb_binint = 1
#
# return bss_coll, bss_ss_coll, bss_bs_coll, bss_bb_coll, bss_se, bss_se_merger, bss_se_disruption, bss_had_binint, bss_mtb, bss_mtb_pure, bss_se_binint, bss_mtb_binint, actual_t, actual_position, star_id
def classifying_BSS(h, star_id, binary, m_cut, t_now, filestring, z):
"""
h: history dictionary made by history maker
star_id: id of the BSS that is of interest
binary: were their primordial binaries in the simulation?
m_cut: the mass cut above which we define MS stars to be BSSs for t=t_now
t_now: last snapshot when BSSs are obtained, t_now is in code units
divide all of the BSSs in the following categories depending on what made it a BSS:
All collisions
SS collision
SE driven merger or disruption
binary evolution mass transfer
note time when it became a BSS and what was the interaction that made it
to do that:
find the m_cut at t=t_now
go back in time and find after what interaction m_star >= m_cut: this is the interaction that made the BSS
get the time and position for the interaction and also the type of the interaction
When the star is not found to have a binary interaction, collision, or merger and disruption then
the only other way it can grow in mass is if it had a clean undisturbed mass transfer in a binary
in that case, I need to get these masses and evolve them using BSE to find the onset time of the mass transfer. This will be the time when the BSS started to be created.
"""
#print 'star_id', star_id, 't_now', t_now
units = scripts.read_units(filestring)
bss_coll, bss_ss_coll, bss_bs_coll, bss_bb_coll = 0, 0, 0, 0
bss_se, bss_se_merger, bss_se_disruption = 0, 0, 0
bss_had_binint = 0
bss_se_binint, bss_mtb_binint = 0, 0
bss_mtb, bss_mtb_pure = 0, 0
SS_coll = 0
BB_coll = 0
BS_coll = 0
t_dict = {}
m_dict = {}
interaction_dict = {}
position_dict = {}
channel_dict = {}
count = 0
interacted, t_of_interaction1, t_of_interaction2, t_of_interaction3, t_of_interaction = 0, 0., 0., 0., 0.
#first look for collisions
print h[star_id]['coll'].keys()
for i in h[star_id]['coll'].keys():
print i
interacted = 1
m_coll = h[star_id]['coll'][i]['coll_params']['mass']
t_coll = h[star_id]['coll'][i]['coll_params']['time']
t_of_interaction1 = t_coll
if m_coll >= m_cut:
count += 1
m_dict[count] = m_coll
t_dict[count] = t_coll
interaction_dict[count] = h[star_id]['coll'][i]['coll_params']['interaction']
position_dict[count] = h[star_id]['coll'][i]['coll_params']['position']
channel_dict[count] = 'collision'
print channel_dict[count], t_dict[count], star_id
#then for SE merger and disruption
print h[star_id]['se'].keys()
if len(h[star_id]['se'].keys())>0:
interacted = 1
t_of_interaction2 = h[star_id]['se']['time']
m_se = h[star_id]['se']['mass']
t_se = h[star_id]['se']['time']
if m_se >= m_cut:
count += 1
m_dict[count] = m_se
t_dict[count] = t_se
interaction_dict[count] = h[star_id]['se']['description']
position_dict[count] = h[star_id]['se']['position']
channel_dict[count] = 'se'
print channel_dict[count], t_dict[count], star_id
#Now figure out which of these interactions actually made the BSS
#print interaction_dict
t_earliest = t_now+1. #initialization: the plus 1 is to avoid the rare event where on the last timestep the BSS is formed. In that case due to round off, t_now will seem like a later
#time compared to the BSS formation time
if len(interaction_dict.keys())>0:
print 'len', len(interaction_dict.keys()), 't_now', t_now, interaction_dict.keys()
for i in interaction_dict.keys():
if t_dict[i] < t_earliest:
#finding which interaction first made it a BSS if there were multiple interactions
actual = i
t_earliest = t_dict[i]
print actual
else:
actual = 0 #this should happen for any MTB: no coll/se interaction is found
print 'actual', actual
if actual>0:
actual_interaction = interaction_dict[actual]
actual_t = t_dict[actual]
actual_channel = channel_dict[actual]
actual_position = position_dict[actual]
else:
actual_interaction = 'mtb'
actual_t = t_now
actual_channel = 'mtb'
actual_position = h[star_id]['position']
if actual_channel == 'collision':
bss_coll = 1
if actual_interaction == 'single-single':
bss_ss_coll = 1
elif actual_interaction == 'binary-single':
bss_bs_coll = 1
elif actual_interaction == 'binary-binary':
bss_bb_coll = 1
if actual_channel == 'se':
bss_se = 1
if actual_interaction == 'mergers with one star gone':
bss_se_merger = 1
elif actual_interaction == 'both stars intact':
bss_se_disruption = 1
#check if this star ever had a binary interaction before: may be it is not important
if binary==1:
if len(h[star_id]['binint']['binint'].keys()) > 0:
for i in h[star_id]['binint']['binint'].keys():
t_binint = h[star_id]['binint']['binint'][i]['interaction']['type']['time']
t_of_interaction3 = t_binint
if t_binint < t_earliest:
bss_had_binint = 1
#check whether it may have been mass transfer in a binary
t_of_interaction = max([t_of_interaction1, t_of_interaction2, t_of_interaction3])
print 'bss_coll', bss_coll, 'bss_se', bss_se, 'bss_had_binint', bss_had_binint, 'interacted', interacted, 't_of_int', t_of_interaction
try:
if bss_coll == 0 and bss_se == 0:
bss_mtb = 1
actual_t=-100 ##Shi: Because I don't know how to implement bse here
############################################################################
#now need to find the time when this actually happened if they are pristine
############################################################################
if bss_had_binint == 0 and interacted == 0:
bss_mtb_pure = 1
# t_mtb = find_mtb_bss_beginning_time(star_id, z, filestring, t_of_interaction)
# t_mtb = t_mtb/units[0]['t_myr']
# if t_mtb < actual_t:
# actual_t = t_mtb
#else:
# t_mtb = find_mtb_bss_beginning_time(star_id, z, filestring, t_of_interaction)
# t_mtb = t_mtb/units[0]['t_myr']
# if t_mtb < actual_t:
# actual_t = t_mtb
except (UnboundLocalError, IndexError):
print sys.exc_info()[0]
print sys.exc_info()[1]
actual_t = t_now + 1. #these are cases where t_formation is not found so pile them up outside the integration time
#mixed with binary interaction before SE or MTB: is it important?
if bss_se == 1 and bss_had_binint == 1:
bss_se_binint = 1
if bss_mtb == 1 and bss_had_binint == 1:
bss_mtb_binint = 1
return bss_coll, bss_ss_coll, bss_bs_coll, bss_bb_coll, bss_se, bss_se_merger, bss_se_disruption, bss_had_binint, bss_mtb, bss_mtb_pure, bss_se_binint, bss_mtb_binint, actual_t, actual_position, star_id
#def find_mtb_bss_beginning_time(star_id, z, filestring):
# """finds the binary properties"""
# snapfile = filestring+'.snap0000.dat.gz'
# print snapfile
# snapatzero = gzip.open(snapfile,'rb')
# star_id_string = ' '+str(int(star_id))+' '
# print star_id_string
# try:
# for line in snapatzero:
# if line.rfind(star_id_string) > -1:
# values = line.split()
# print values
# #make sure things make sense
# if float(values[7]) == 0.:
# print 'cannot be: supposed to be a binary'
# raise StopIteration()
# else:
# m1, m2 = float(values[8]), float(values[9])
# a = float(values[12])
# e = float(values[13])
# R1, R2 = float(values[21]), float(values[22])
# kstar1, kstar2 = float(values[17]), float(values[18])
# print m1
# raise StopIteration()
# except StopIteration:
# print 'obtained binary properties'
# print m1, m2, a, e, R1, R2, kstar1, kstar2
#
# #now create the binary.in file for this one
# tphysf = 12000.
# tb = scripts.get_period(a*constants.AU, m1*constants.Msun,m2*constants.Msun)
# f=open('binary.in' , 'w')
# f.write("%f %f %f %f %d %d %f %f\n" %(m1, m2, 12000., tb, kstar1, kstar2, z, e))
# #f.write("0.5 0.0 1.0 3.0 0.5 0\n0 1 0 1 0 0 1.8 29769\n0.05 0.01 0.02\n190.0 0.125 1.0 1.5 0.001 10.0 -1.0\n1113.89139868144343\n117.3629102921285 4.94763450979127661 0.0583570371042554659\n-282.92588170378781 9.13749733018044452 1.08589687349379727\n# alternatives for top line ...\n7.816 4.387 15000. 1964.18453 1 1 0.02 0.0\n2.9 0.9 15000. 8.0 1 1 0.02 0.7\n")
# f.write("0.5 0.0 1.0 3.0 0.5 0\n0 1 0 1 0 0 1.8 29769\n0.05 0.01 0.02\n190.0 0.125 1.0 1.5 0.001 10.0 -1.0\n")
# f.close()
# dataout,dataerr=subprocess.Popen([r"./bse"],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
# a = dataout.split('\n')
# for i in range(len(a)):
# if a[i].rfind('BEG RCHE')>-1:
# print a[i]
# t_mtb = float(a[i].split()[0])
# print t_mtb
# return t_mtb
def find_mtb_bss_beginning_time(star_id, z, filestring, t, BSEEXEC='/Users/shiye/Documents/bse/bse'):
"""finds the binary properties"""
from glob import glob
#finding star after it came into being. For non-collisional or non-merger stars it is at t=0
#Otherwise it must be at some later time
#t here is given as the time of collision/merger event that created the star and changed its id
snapstring = filestring+'.snap*.dat.gz'
snaps = glob(snapstring)
print snaps
snapcounter, found_snap = 0, 0
while found_snap==0:
snapfile = snaps[snapcounter]
snap = gzip.open(snapfile,'rb')
line = snap.readline()
t_snap = float(line.split('=')[1].split()[0])
if t_snap>=t:
actual_snapfile = snapfile
found_snap = 1
snapcounter = snapcounter+1
#snapfile = filestring+'.snap0000.dat.gz'
print actual_snapfile
snapatzero = gzip.open(actual_snapfile,'rb')
star_id_string = ' '+str(int(star_id))+' '
print star_id_string
try:
for line in snapatzero:
if line.rfind(star_id_string) > -1:
values = line.split()
print values
#make sure things make sense
if float(values[7]) == 0.:
print 'cannot be: supposed to be a binary'
raise StopIteration()
else:
m1, m2 = float(values[8]), float(values[9])
a = float(values[12])
e = float(values[13])
R1, R2 = float(values[21]), float(values[22])
kstar1, kstar2 = float(values[17]), float(values[18])
print m1
raise StopIteration()
except StopIteration:
print 'obtained binary properties'
print m1, m2, a, e, R1, R2, kstar1, kstar2
#now create the binary.in file for this one
tphysf = 12000.
tb = scripts.get_period(a*constants.AU, m1*constants.Msun,m2*constants.Msun)
f=open('/Users/shiye/Documents/ClusterGroup/BSSproject/bss_binary.in' , 'w')
f.write("%f %f %f %f %d %d %f %f\n" %(m1, m2, 12000., tb, kstar1, kstar2, z, e))
f.write("0.5 0.0 1.0 3.0 0.5\n0 1 0 1 0 0 1.8 29769\n0.05 0.01 0.02\n190.0 0.125 1.0 1.5 0.001 10.0 -1.0\n")
f.close()
dataout,dataerr=subprocess.Popen([BSEEXEC],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
print dataout, dataerr
a = dataout.split('\n')
for i in range(len(a)):
if a[i].rfind('BEG RCHE')>-1:
print a[i]
t_mtb = float(a[i].split()[0])
print t_mtb
return t_mtb
#def classify_all_bss_stars(filestring, snapno, z, mcut):
# #first get time now from the snap
# units = scripts.read_units(filestring)
# snap = filestring+'.snap'+snapno+'.dat.gz'
# f_snap = gzip.open(snap,'rb')
# line_snap = f_snap.readline()
# t_snap = float(line_snap.split()[1].split('=')[1])
# print 't_snap', t_snap
#
# #find rc at t_snap for core population determination
# dynfile = filestring+'.dyn.dat'
# print dynfile
# dyndata = loadtxt(dynfile)
# print dyndata[-1]
# try:
# for i in range(len(dyndata)-1, -1, -1): #start from the last line, it will be quicker
# if dyndata[i,0]==t_snap:
# rc = dyndata[i,7]
# raise StopIteration()
# except StopIteration:
# print 'found rc', rc, 'at time', t_snap
#
# #were there primordial binaries or any binary interactions:
# from glob import glob
# binintstring=filestring+'.binint.log'
# #binint=glob('*.binint.log')
# binint=glob(binintstring)
# binary=1
# if len(binint)==0:
# binary=0
# print 'binary', binary
# BSSs = scripts.find_BSS(filestring,snapno, z, mcut)
#
# bss_ids, bss_positions, m_to = BSSs[3], BSSs[4], BSSs[5]
# h = history_maker(bss_ids, bss_positions, filestring, binary)
# all_bss = len(bss_ids)
# #now classify them one by one
# #how many are in the core
# core_count = 0
# for i in range(len(bss_positions)):
# if bss_positions[i] < rc:
# core_count += 1
# print 'core_count', core_count
# #initialize the arrays
# classified = zeros(( len(bss_ids), 15 ))
# classified_core = zeros(( core_count, 15 ))
# core_count = 0
# m_cutoff = m_to*mcut
# for i in range(len(bss_ids)):
# classified[i] = classifying_BSS(h, bss_ids[i], binary, m_cutoff, t_snap, filestring, z)
# if bss_positions[i]<=rc:
# classified_core[core_count] = classified[i]
# core_count += 1
# print classified_core
#
# file_all = filestring+'.all_bss_formation_properties_one_sim.dat'
# file_all = open(file_all, 'w')
# file_all.write("#1.bss_coll 2.bss_ss_coll 3.bss_bs_coll 4.bss_bb_coll 5.bss_se 6.bss_se_merger 7.bss_se_disruption 8.bss_had_binint 9.bss_mtb 10.bss_mtb_pure 11.bss_se_binint 12.bss_mtb_binint 13.actual_t(Myr) 14.actual_position 15.star_id\n")
# for i in range(len(classified)):
# for j in range(12):
# file_all.write("%d " %(classified[i,j],))
# age = (t_snap-classified[i,12])*units[0]['t_myr']
# file_all.write("%f " %( age ))
# file_all.write("%f " %(classified[i,13],))
# file_all.write("%d\n" %(classified[i,14],))
# file_all.close()
#
# file_core = filestring+'.core_bss_formation_properties_one_sim.dat'
# file_core = open(file_core, 'w')
# file_core.write("#1.bss_coll 2.bss_ss_coll 3.bss_bs_coll 4.bss_bb_coll 5.bss_se 6.bss_se_merger 7.bss_se_disruption 8.bss_had_binint 9.bss_mtb 10.bss_mtb_pure 11.bss_se_binint 12.bss_mtb_binint 13.actual_t(Myr) 14.actual_position 15.star_id\n")
# for i in range(len(classified_core)):
# for j in range(12):
# file_core.write("%d " %(classified_core[i,j],))
# file_core.write("%f " %((t_snap-classified_core[i,12])*units[0]['t_myr'] ))
# file_core.write("%f " %(classified_core[i,13],))
# file_core.write("%d\n" %(classified_core[i,14],))
# file_core.close()
#
#
#
# total_coll = sum(classified[:,0])
# total_ss_coll = sum(classified[:,1])
# total_bs_coll = sum(classified[:,2])
# total_bb_coll = sum(classified[:,3])
# total_se = sum(classified[:,4])
# total_se_merger = sum(classified[:,5])
# total_se_disruption = sum(classified[:,6])
# total_had_binint = sum(classified[:,7])
# total_mtb = sum(classified[:,8])
# total_mtb_pure = sum(classified[:,9])
# total_se_binint = sum(classified[:,10])
# total_mtb_binint = sum(classified[:,11])
# largest_dynamic_t = t_snap - min(classified[:,12])
# median_dynamic_age = t_snap - median(classified[:,12])
# print classified[:,12]
#
# total_core_coll = sum(classified_core[:,0])
# total_core_ss_coll = sum(classified_core[:,1])
# total_core_bs_coll = sum(classified_core[:,2])
# total_core_bb_coll = sum(classified_core[:,3])
# total_core_se = sum(classified_core[:,4])
# total_core_se_merger = sum(classified_core[:,5])
# total_core_se_disruption = sum(classified_core[:,6])
# total_core_had_binint = sum(classified_core[:,7])
# total_core_mtb = sum(classified_core[:,8])
# total_core_mtb_pure = sum(classified_core[:,9])
# total_core_se_binint = sum(classified[:,10])
# total_core_mtb_binint = sum(classified[:,11])
# if total_core_coll > 0:
# largest_dynamic_t_c = t_snap - min(classified_core[:,12])
# median_dynamic_age_c = t_snap - median(classified_core[:,12])
# else:
# largest_dynamic_t_c = -1.
# median_dynamic_age_c = -1.
# print classified_core[:,12]
#
# total = [all_bss, total_coll, total_ss_coll, total_bs_coll, total_bb_coll, total_se, total_se_merger, total_se_disruption, total_had_binint, total_mtb, total_mtb_pure, total_se_binint, total_mtb_binint, largest_dynamic_t, median_dynamic_age]
#
# total_core = [core_count, total_core_coll, total_core_ss_coll, total_core_bs_coll, total_core_bb_coll, total_core_se, total_core_se_merger, total_core_se_disruption, total_core_had_binint, total_core_mtb, total_core_mtb_pure, total_core_se_binint, total_core_mtb_binint, largest_dynamic_t_c, median_dynamic_age_c]
#
# return total, total_core
def classify_all_bss_stars(filestring, snapno, z, mcut):
#first get time now from the snap
units = scripts.read_units(filestring)
snap = filestring+'.snap'+snapno+'.dat.gz'
f_snap = gzip.open(snap,'rb')
line_snap = f_snap.readline()
t_snap = float(line_snap.split()[1].split('=')[1])
print 't_snap', t_snap
#find rc at t_snap for core population determination
dynfile = filestring+'.dyn.dat'
print dynfile
dyndata = loadtxt(dynfile)
print dyndata[-1]
try:
for i in range(len(dyndata)-1, -1, -1): #start from the last line, it will be quicker
if dyndata[i,0]==t_snap:
rc = dyndata[i,7]
raise StopIteration()
except StopIteration:
print 'found rc', rc, 'at time', t_snap
#were there primordial binaries or any binary interactions:
from glob import glob
binintstring=filestring+'.binint.log'
#binint=glob('*.binint.log')
binint=glob(binintstring)
binary=1
if len(binint)==0:
binary=0
print 'binary', binary
print 'calling scripts.find_BSS'
BSSs = scripts.find_BSS(filestring,snapno, z, mcut)
bss_ids, bss_positions, m_to = BSSs[3], BSSs[4], BSSs[5]
print 'calling history_maker'
h = history_maker(bss_ids, bss_positions, filestring, binary)
all_bss = len(bss_ids)
#now classify them one by one
#how many are in the core
core_count = 0
for i in range(len(bss_positions)):
if bss_positions[i] < rc:
core_count += 1
print 'core_count', core_count
#initialize the arrays
classified = zeros(( len(bss_ids), 15 ))
classified_core = zeros(( core_count, 15 ))
core_count = 0
m_cutoff = m_to*mcut
for i in range(len(bss_ids)):
classified[i] = classifying_BSS(h, bss_ids[i], binary, m_cutoff, t_snap, filestring, z)
if bss_positions[i]<=rc:
classified_core[core_count] = classified[i]
core_count += 1
print classified_core
file_all = filestring+'.all_bss_formation_properties_one_sim.dat'
file_all = open(file_all, 'w')
file_all.write("#1.bss_coll 2.bss_ss_coll 3.bss_bs_coll 4.bss_bb_coll 5.bss_se 6.bss_se_merger 7.bss_se_disruption 8.bss_had_binint 9.bss_mtb 10.bss_mtb_pure 11.bss_se_binint 12.bss_mtb_binint 13.actual_t(Myr) 14.actual_position 15.star_id\n")
for i in range(len(classified)):
for j in range(12):
file_all.write("%d " %(classified[i,j],))
age = (t_snap-classified[i,12])*units[0]['t_myr']
file_all.write("%f " %( age ))
file_all.write("%f " %(classified[i,13],))
file_all.write("%d\n" %(classified[i,14],))
file_all.close()
file_core = filestring+'.core_bss_formation_properties_one_sim.dat'
file_core = open(file_core, 'w')
file_core.write("#1.bss_coll 2.bss_ss_coll 3.bss_bs_coll 4.bss_bb_coll 5.bss_se 6.bss_se_merger 7.bss_se_disruption 8.bss_had_binint 9.bss_mtb 10.bss_mtb_pure 11.bss_se_binint 12.bss_mtb_binint 13.actual_t(Myr) 14.actual_position 15.star_id\n")
for i in range(len(classified_core)):
for j in range(12):
file_core.write("%d " %(classified_core[i,j],))
file_core.write("%f " %((t_snap-classified_core[i,12])*units[0]['t_myr'] ))
file_core.write("%f " %(classified_core[i,13],))
file_core.write("%d\n" %(classified_core[i,14],))
file_core.close()
total_coll = sum(classified[:,0])
total_ss_coll = sum(classified[:,1])
total_bs_coll = sum(classified[:,2])
total_bb_coll = sum(classified[:,3])
total_se = sum(classified[:,4])
total_se_merger = sum(classified[:,5])
total_se_disruption = sum(classified[:,6])
total_had_binint = sum(classified[:,7])
total_mtb = sum(classified[:,8])
total_mtb_pure = sum(classified[:,9])
total_se_binint = sum(classified[:,10])
total_mtb_binint = sum(classified[:,11])
largest_dynamic_t = t_snap - min(classified[:,12])
median_dynamic_age = t_snap - median(classified[:,12])
print classified[:,12]
total_core_coll = sum(classified_core[:,0])
total_core_ss_coll = sum(classified_core[:,1])
total_core_bs_coll = sum(classified_core[:,2])
total_core_bb_coll = sum(classified_core[:,3])
total_core_se = sum(classified_core[:,4])
total_core_se_merger = sum(classified_core[:,5])
total_core_se_disruption = sum(classified_core[:,6])
total_core_had_binint = sum(classified_core[:,7])
total_core_mtb = sum(classified_core[:,8])
total_core_mtb_pure = sum(classified_core[:,9])
total_core_se_binint = sum(classified[:,10])
total_core_mtb_binint = sum(classified[:,11])
if total_core_coll > 0:
largest_dynamic_t_c = t_snap - min(classified_core[:,12])
median_dynamic_age_c = t_snap - median(classified_core[:,12])
else:
largest_dynamic_t_c = -1.
median_dynamic_age_c = -1.
print classified_core[:,12]
total = [all_bss, total_coll, total_ss_coll, total_bs_coll, total_bb_coll, total_se, total_se_merger, total_se_disruption, total_had_binint, total_mtb, total_mtb_pure, total_se_binint, total_mtb_binint, largest_dynamic_t, median_dynamic_age]
total_core = [core_count, total_core_coll, total_core_ss_coll, total_core_bs_coll, total_core_bb_coll, total_core_se, total_core_se_merger, total_core_se_disruption, total_core_had_binint, total_core_mtb, total_core_mtb_pure, total_core_se_binint, total_core_mtb_binint, largest_dynamic_t_c, median_dynamic_age_c]
return total, total_core
def classify_all_bss_stars_all_sims(basename, z, mcut, writefile, problemfile):
import create_table
import glob
dirs = create_table.get_the_dirs(basename, 'c4-')
writefile = open(writefile, 'a')
problemfile = open(problemfile, 'a')
writefile.write("#1.all_bss 2.total_coll 3.total_ss_coll 4.total_bs_coll 5.total_bb_coll 6.total_se 7.total_se_merger 8.total_se_disruption 9.total_had_binint 10.total_mtb 11.total_mtb_pure 12.total_se_binint 13.total_mtb_binint 14.age_oldest 15.age_median 16.core_count 17.total_core_coll 18.total_core_ss_coll 19.total_core_bs_coll 20.total_core_bb_coll 21.total_core_se 22.total_core_se_merger 23.total_core_se_disruption 24.total_core_had_binint 25.total_core_mtb 26.total_core_mtb_pure 27.total_core_se_binint 28.total_core_mtb_binint 29.age_oldest_core 30.age_median_core 31.run\n")
for i in range(len(dirs)):
string = dirs[i]+'/initial'
print 'string'
snapstring = string+'.snap*.dat.gz'
snaps = glob.glob(snapstring)
sorted_snaps = sort(snaps)
print sorted_snaps
if len(snaps)>0:
snapno = sorted_snaps[-1].split('/')[-1].split('snap')[1].split('.dat')[0]
print snapno
try:
units = scripts.read_units(string)
temp_t_myr = scripts.find_t_myr(string, snapno)
if temp_t_myr >= 9000.:
print 't_myr', temp_t_myr
total, total_core = classify_all_bss_stars(string, snapno, z, mcut)
all_bss = total[0]
total_coll, total_ss_coll, total_bs_coll, total_bb_coll = total[1], total[2], total[3], total[4]
total_se, total_se_merger, total_se_disruption = total[5], total[6], total[7]
total_had_binint = total[8]
total_mtb, total_mtb_pure = total[9], total[10]
total_se_binint, total_mtb_binint = total[11], total[12]
age_oldest, age_median = total[13]*units[0]['t_myr'], total[14]*units[0]['t_myr']
writefile.write( "%d " %(all_bss,) )
writefile.write( "%d %d %d %d " %(total_coll, total_ss_coll, total_bs_coll, total_bb_coll,) )
writefile.write( "%d %d %d " %(total_se, total_se_merger, total_se_disruption,) )
writefile.write( "%d " %(total_had_binint,) )
writefile.write( "%d %d " %(total_mtb, total_mtb_pure,) )
writefile.write( "%d %d " %(total_se_binint, total_mtb_binint,) )
writefile.write( "%f %f " %(age_oldest, age_median,) )
core_count = total_core[0]
total_core_coll, total_core_ss_coll, total_core_bs_coll, total_core_bb_coll = total_core[1], total_core[2], total_core[3], total_core[4]
total_core_se, total_core_se_merger, total_core_se_disruption = total_core[5], total_core[6], total_core[7]
total_core_had_binint = total_core[8]
total_core_mtb, total_core_mtb_pure = total_core[9], total_core[10]
total_core_se_binint, total_core_mtb_binint = total_core[11], total_core[12]
age_oldest_core, age_median_core = total_core[13]*units[0]['t_myr'], total_core[14]*units[0]['t_myr']
writefile.write( "%d " %(core_count,))
writefile.write( "%d %d %d %d " %(total_core_coll, total_core_ss_coll, total_core_bs_coll, total_core_bb_coll,))
writefile.write( "%d %d %d " %(total_core_se, total_core_se_merger, total_core_se_disruption,))
writefile.write( "%d " %(total_core_had_binint,))
writefile.write( "%d %d " %(total_core_mtb, total_core_mtb_pure,) )
writefile.write( "%d %d " %(total_core_se_binint, total_core_mtb_binint,) )
writefile.write( "%f %f " %(age_oldest_core, age_median_core,) )
writefile.write( "%s\n" %(dirs[i],) )
else:
problemfile.write("%s: ran only upto %f Myr. Discarded.snapno %s\n" %(dirs[i], temp_t_myr, snapno))
except (ValueError, IOError):
problemfile.write("%s\n" %(dirs[i],))
writefile.close()
problemfile.close()
def just_print(total, total_core, directorystring, writefilename):
"""If I want to run only one directory to extract the BS info and then want to print them in the same BS files that gets created after running
classify_all_bss_stars_all_sims, then use this nifty routine.
1. run classify_all_bss_stars first to obtain total, and total_core
2. run just_print after supplying the file this line needs to be printed to and the directory specifying the model.
"""
convstring = directorystring+'/initial'
units = scripts.read_units(convstring)
writefile = open(writefilename, 'a') #Note that this is appending to the file. Be careful
writefile.write("#1.all_bss 2.total_coll 3.total_ss_coll 4.total_bs_coll 5.total_bb_coll 6.total_se 7.total_se_merger 8.total_se_disruption 9.total_had_binint 10.total_mtb 11.total_mtb_pure 12.total_se_binint 13.total_mtb_binint 14.age_oldest 15.age_median 16.core_count 17.total_core_coll 18.total_core_ss_coll 19.total_core_bs_coll 20.total_core_bb_coll 21.total_core_se 22.total_core_se_merger 23.total_core_se_disruption 24.total_core_had_binint 25.total_core_mtb 26.total_core_mtb_pure 27.total_core_se_binint 28.total_core_mtb_binint 29.age_oldest_core 30.age_median_core 31.run\n")
all_bss = total[0]
total_coll, total_ss_coll, total_bs_coll, total_bb_coll = total[1], total[2], total[3], total[4]
total_se, total_se_merger, total_se_disruption = total[5], total[6], total[7]
total_had_binint = total[8]
total_mtb, total_mtb_pure = total[9], total[10]
total_se_binint, total_mtb_binint = total[11], total[12]
age_oldest, age_median = total[13]*units[0]['t_myr'], total[14]*units[0]['t_myr']
writefile.write( "%d " %(all_bss,) )
writefile.write( "%d %d %d %d " %(total_coll, total_ss_coll, total_bs_coll, total_bb_coll,) )
writefile.write( "%d %d %d " %(total_se, total_se_merger, total_se_disruption,) )
writefile.write( "%d " %(total_had_binint,) )
writefile.write( "%d %d " %(total_mtb, total_mtb_pure,) )
writefile.write( "%d %d " %(total_se_binint, total_mtb_binint,) )
writefile.write( "%f %f " %(age_oldest, age_median,) )
core_count = total_core[0]
total_core_coll, total_core_ss_coll, total_core_bs_coll, total_core_bb_coll = total_core[1], total_core[2], total_core[3], total_core[4]
total_core_se, total_core_se_merger, total_core_se_disruption = total_core[5], total_core[6], total_core[7]
total_core_had_binint = total_core[8]
total_core_mtb, total_core_mtb_pure = total_core[9], total_core[10]
total_core_se_binint, total_core_mtb_binint = total_core[11], total_core[12]
age_oldest_core, age_median_core = total_core[13]*units[0]['t_myr'], total_core[14]*units[0]['t_myr']
writefile.write( "%d " %(core_count,))
writefile.write( "%d %d %d %d " %(total_core_coll, total_core_ss_coll, total_core_bs_coll, total_core_bb_coll,))
writefile.write( "%d %d %d " %(total_core_se, total_core_se_merger, total_core_se_disruption,))
writefile.write( "%d " %(total_core_had_binint,))
writefile.write( "%d %d " %(total_core_mtb, total_core_mtb_pure,) )
writefile.write( "%d %d " %(total_core_se_binint, total_core_mtb_binint,) )
writefile.write( "%f %f " %(age_oldest_core, age_median_core,) )
writefile.write( "%s\n" %(directorystring,) )
#def extract_cluster_properties_for_classified_bss(bssfilename, writefilename):
# """Once classify_all_bss_stars_all_sims has finished running, each simulation directory should
# have a file where the branching ratios are already calculated. Also the full paths of the simulation
# files are there. This is just a conenient routine to extract some cluster global properties and write
# another file with that data also. Now only interested in rhoc, rc, vcrms to calculate Gamma. """
# from glob import glob
# import create_table as table
# writefile = open(writefilename, 'w')
# writefile.write("#1.all_bss 2.total_coll 3.total_ss_coll 4.total_bs_coll 5.total_bb_coll 6.total_se 7.total_se_merger 8.total_se_disruption 9.total_had_binint 10.total_mtb 11.total_mtb_pure 12.total_se_binint 13.total_mtb_binint 14.age_oldest(Myr) 15.age_median(Myr) 16.core_count 17.total_core_coll 18.total_core_ss_coll 19.total_core_bs_coll 20.total_core_bb_coll 21.total_core_se 22.total_core_se_merger 23.total_core_se_disruption 24.total_core_had_binint 25.total_core_mtb 26.total_core_mtb_pure 27.total_core_se_binint 28.total_core_mtb_binint 29.age_oldest_core(Myr) 30.age_median_core(Myr) 31.rc(pc) 32.rhoc(Msun/pc^3) 33.vcrms(km/s) 34.Gamma 35.fbf 36.fbcf 37.tf(Myr) 37.run\n")
# bssfile = open(bssfilename, 'r')
# bssfile.seek(0)
# bssfile.readline()
# for line in bssfile:
# a=line.split()
# datafilestring=a[-1]
# dynfile=datafilestring+'/initial.dyn.dat'
# data = loadtxt(dynfile)
# convstring=datafilestring+'/initial'
# units=scripts.read_units(convstring)
# print units
# rc = mean(data[-10:-1,7])*units[0]['l_pc']
# rhoc = mean(data[-10:-1,21])*units[0]['m_msun']/(units[0]['l_pc'])**3.
# vcrms = mean(data[-10:-1,23])*units[0]['l_cgs']/units[0]['nbt_cgs']/10.**5.
# Gamma = rhoc**2. * rc**3. / vcrms
# print 'rc, rhoc, vcrms, Gamma', rc, rhoc, vcrms, Gamma
# fbi, fbf = table.get_fb_sim(datafilestring, 'initial')
# fbci, fbcf = table.get_fbc_sim(datafilestring, 'initial')
# tf = table.get_tf_sim(datafilestring, 'initial')
#
# for j in range(30):
# writefile.write("%s " %(a[j],))
# writefile.write("%f %f %f %f %f %f %f %s\n" %(rc, rhoc, vcrms, Gamma, fbf, fbcf, tf, datafilestring,))
#
# #bssfile=datafilestring+'/initial.all_bss_formation_properties_one_sim.dat'
# #allbssdata=loadtxt(allbssfile)
# #print allbssdata, len(allbssdata)
# #try:
# # oldest_all = max(allbssdata[:,12])
# #except IndexError:
# # print 'only one BSS'
# # oldest_all = allbssdata[12]
#
#
# #corebssfile=datafilestring+'/initial.core_bss_formation_properties_one_sim.dat'
# #corebssdata=loadtxt(corebssfile)
# #try:
# # oldest_core = max(corebssdata[:,12])
# #except IndexError:
# # print 'only one BSSc'
# # oldest_core = corebssdata[12]
#
# #for i in range(13):
# # writefile.write("%s " %(a[i],))
# #writefile.write("%f " %(oldest_all,))
# #for i in range(13):
# # writefile.write("%s " %(a[i+13]))
# #writefile.write("%f " %(oldest_core))
# #writefile.write("%f %f %f %f " %(rc, rhoc, vcrms, Gamma,))
# #writefile.write("%s\n" %(datafilestring))
#
# writefile.close()
def extract_cluster_properties_for_classified_bss(bssfilename, writefilename):
"""Once classify_all_bss_stars_all_sims has finished running, each simulation directory should
have a file where the branching ratios are already calculated. Also the full paths of the simulation
files are there. This is just a conenient routine to extract some cluster global properties and write
another file with that data also. Now only interested in rhoc, rc, vcrms to calculate Gamma. """
from glob import glob
import create_table as table
writefile = open(writefilename, 'w')