-
Notifications
You must be signed in to change notification settings - Fork 0
/
allresults.py
1063 lines (795 loc) · 41.3 KB
/
allresults.py
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
#!/usr/bin/env python
import matplotlib
matplotlib.use('Agg')
import h5py as h5
import numpy as np
import pylab as plt
from random import sample, seed
from os.path import getsize as getFileSize
# ===========================================cd--=====================================
# Basic variables
# ================================================================================
# Set up some basic attributes of the run
whichsimulation = 0
whichimf = 1 # 0=Slapeter; 1=Chabrier
dilute = 7500 # Number of galaxies to plot in scatter plots
sSFRcut = -11.0 # Divide quiescent from star forming galaxies (when plotmags=0)
matplotlib.rcdefaults()
#plt.rc('axes', color_cycle=[
# 'k',
# 'b',
# 'r',
# 'g',
# 'm',
# '0.5',
#f ], labelsize='x-large')
plt.rc('xtick', labelsize='x-large')
plt.rc('ytick', labelsize='x-large')
plt.rc('lines', linewidth='2.0')
# plt.rc('font', variant='monospace')
plt.rc('legend', numpoints=1, fontsize='x-large')
plt.rc('text', usetex=True)
OutputDir = '/home/rdzudzar/sage-model/analysis/plots' # set in main below
OutputFormat = '.png'
TRANSPARENT = False
OutputList = []
class Results:
""" The following methods of this class generate the figures and plot them.
"""
def __init__(self):
"""Here we set up some of the variables which will be global to this
class."""
if whichsimulation == 0: # Mini-Millennium
self.BoxSize = 62.5 # Mpc/h
self.MaxTreeFiles = 8 # FilesPerSnapshot
self.Hubble_h = 0.73
elif whichsimulation == 1: # Millennium
self.BoxSize = 500 # Mpc/h
self.MaxTreeFiles = 512 # FilesPerSnapshot
self.Hubble_h = 0.73
elif whichsimulation == 2: # Bolshoi
self.BoxSize = 250.0 # Mpc/h
self.MaxTreeFiles = 12987 # FilesPerSnapshot
self.Hubble_h = 0.7
elif whichsimulation == 3: # GiggleZ MR
self.BoxSize = 125.0 # Mpc/h
self.MaxTreeFiles = 8 # FilesPerSnapshot
self.Hubble_h = 0.705
else:
print("Please pick a valid simulation!")
exit(1)
def read_gals(self, model_name, first_file, last_file):
# The input galaxy structure:
floattypef = np.float32
Galdesc_full = [
('Type' , np.int32),
('GalaxyIndex' , np.int64),
('HaloIndex' , np.int32),
('SimulationHaloIndex' , np.int32),
('TreeIndex' , np.int32),
('SnapNum' , np.int32),
('CentralGalaxyIndex' , np.int64),
('CentralMvir' , floattypef),
('mergeType' , np.int32),
('mergeIntoID' , np.int32),
('mergeIntoSnapNum' , np.int32),
('dT' , floattypef),
('Pos' , (floattypef, 3)),
('Vel' , (floattypef, 3)),
('Spin' , (floattypef, 3)),
('Len' , np.int32),
('LenMax' , np.int32),
('Mvir' , floattypef),
('Rvir' , floattypef),
('Vvir' , floattypef),
('Vmax' , floattypef),
('VelDisp' , floattypef),
('DiscRadii' , (floattypef, 31)),
('ColdGas' , floattypef),
('StellarMass' , floattypef),
('ClassicalBulgeMass' , floattypef),
('SecularBulgeMass' , floattypef),
('HotGas' , floattypef),
('EjectedMass' , floattypef),
('BlackHoleMass' , floattypef),
('IntraClusterStars' , floattypef),
('DiscGas' , (floattypef, 30)),
('DiscStars' , (floattypef, 30)),
('SpinStars' , (floattypef, 3)),
('SpinGas' , (floattypef, 3)),
('SpinClassicalBulge' , (floattypef, 3)),
('StarsInSitu' , floattypef),
('StarsInstability' , floattypef),
('StarsMergeBurst' , floattypef),
('DiscHI' , (floattypef, 30)),
('DiscH2' , (floattypef, 30)),
('DiscSFR' , (floattypef, 30)),
('MetalsColdGas' , floattypef),
('MetalsStellarMass' , floattypef),
('ClassicalMetalsBulgeMass' , floattypef),
('SecularMetalsBulgeMass' , floattypef),
('MetalsHotGas' , floattypef),
('MetalsEjectedMass' , floattypef),
('MetalsIntraClusterStars' , floattypef),
('DiscGasMetals' , (floattypef, 30)),
('DiscStarsMetals' , (floattypef, 30)),
('SfrDisk' , floattypef),
('SfrBulge' , floattypef),
('SfrDiskZ' , floattypef),
('SfrBulgeZ' , floattypef),
('DiskScaleRadius' , floattypef),
('Cooling' , floattypef),
('Heating' , floattypef),
('LastMajorMerger' , floattypef),
('LastMinorMerger' , floattypef),
('OutflowRate' , floattypef),
('infallMvir' , floattypef),
('infallVvir' , floattypef),
('infallVmax' , floattypef)
]
names = [Galdesc_full[i][0] for i in xrange(len(Galdesc_full))]
formats = [Galdesc_full[i][1] for i in xrange(len(Galdesc_full))]
Galdesc = np.dtype({'names':names, 'formats':formats}, align=True)
# Initialize variables.
TotNTrees = 0
TotNGals = 0
FileIndexRanges = []
print("Determining array storage requirements.")
# Read each file and determine the total number of galaxies to be read in
goodfiles = 0
for fnr in xrange(first_file,last_file+1):
fname = model_name+'_'+str(fnr) # Complete filename
if not os.path.isfile(fname):
# print "File\t%s \tdoes not exist! Skipping..." % (fname)
continue
if getFileSize(fname) == 0:
print("File\t%s \tis empty! Skipping..." % (fname))
continue
fin = open(fname, 'rb') # Open the file
Ntrees = np.fromfile(fin,np.dtype(np.int32),1) # Read number of trees in file
NtotGals = np.fromfile(fin,np.dtype(np.int32),1)[0] # Read number of gals in file.
TotNTrees = TotNTrees + Ntrees # Update total sim trees number
TotNGals = TotNGals + NtotGals # Update total sim gals number
goodfiles = goodfiles + 1 # Update number of files read for volume calculation
fin.close()
print()
print("Input files contain:\t%d trees ;\t%d galaxies ." % (TotNTrees, TotNGals))
print()
# Initialize the storage array
G = np.empty(TotNGals, dtype=Galdesc)
offset = 0 # Offset index for storage array
# Open each file in turn and read in the preamble variables and structure.
print("Reading in files.")
for fnr in xrange(first_file,last_file+1):
fname = model_name+'_'+str(fnr) # Complete filename
if not os.path.isfile(fname):
continue
if getFileSize(fname) == 0:
continue
fin = open(fname, 'rb') # Open the file
Ntrees = np.fromfile(fin, np.dtype(np.int32), 1) # Read number of trees in file
NtotGals = np.fromfile(fin, np.dtype(np.int32), 1)[0] # Read number of gals in file.
GalsPerTree = np.fromfile(fin, np.dtype((np.int32, Ntrees)),1) # Read the number of gals in each tree
print(": Reading N=", NtotGals, " \tgalaxies from file: ", fname)
GG = np.fromfile(fin, Galdesc, NtotGals) # Read in the galaxy structures
FileIndexRanges.append((offset,offset+NtotGals))
# Slice the file array into the global array
# N.B. the copy() part is required otherwise we simply point to
# the GG data which changes from file to file
# NOTE THE WAY PYTHON WORKS WITH THESE INDICES!
G[offset:offset+NtotGals]=GG[0:NtotGals].copy()
del(GG)
offset = offset + NtotGals # Update the offset position for the global array
fin.close() # Close the file
print()
print("Total galaxies considered:", TotNGals)
# Convert the Galaxy array into a recarray
G = G.view(np.recarray)
w = np.where(G.StellarMass > 1.0)[0]
print("Galaxies more massive than 10^10Msun/h:", len(w))
print()
# Calculate the volume given the first_file and last_file
self.volume = self.BoxSize**3.0 * goodfiles / self.MaxTreeFiles
# w = np.where(G.TreeIdx == 8)[0]
# for i in xrange(len(w)):
# print i, G.TreeIdx[w[i]], G.Type[w[i]], G.GalaxyIndex[w[i]], G.mergeType[w[i]], G.mergeIntoID[w[i]], G.mergeIntoSnapNum[w[i]]
return G
# --------------------------------------------------------
def StellarMassFunction(self, G):
print('Plotting the stellar mass function')
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
binwidth = 0.1 # mass function histogram bin width
# calculate all
w = np.where(G.StellarMass > 0.0)[0]
mass = np.log10(G.StellarMass[w] * 1.0e10 / self.Hubble_h)
sSFR = (G.SfrDisk[w] + G.SfrBulge[w]) / (G.StellarMass[w] * 1.0e10 / self.Hubble_h)
mi = np.floor(min(mass)) - 2
ma = np.floor(max(mass)) + 2
NB = (ma - mi) / binwidth
(counts, binedges) = np.histogram(mass, range=(mi, ma), bins=NB)
# Set the x-axis values to be the centre of the bins
xaxeshisto = binedges[:-1] + 0.5 * binwidth
# additionally calculate red
w = np.where(sSFR < 10.0**sSFRcut)[0]
massRED = mass[w]
(countsRED, binedges) = np.histogram(massRED, range=(mi, ma), bins=NB)
# additionally calculate blue
w = np.where(sSFR > 10.0**sSFRcut)[0]
massBLU = mass[w]
(countsBLU, binedges) = np.histogram(massBLU, range=(mi, ma), bins=NB)
# Baldry+ 2008 modified data used for the MCMC fitting
Baldry = np.array([
[7.05, 1.3531e-01, 6.0741e-02],
[7.15, 1.3474e-01, 6.0109e-02],
[7.25, 2.0971e-01, 7.7965e-02],
[7.35, 1.7161e-01, 3.1841e-02],
[7.45, 2.1648e-01, 5.7832e-02],
[7.55, 2.1645e-01, 3.9988e-02],
[7.65, 2.0837e-01, 4.8713e-02],
[7.75, 2.0402e-01, 7.0061e-02],
[7.85, 1.5536e-01, 3.9182e-02],
[7.95, 1.5232e-01, 2.6824e-02],
[8.05, 1.5067e-01, 4.8824e-02],
[8.15, 1.3032e-01, 2.1892e-02],
[8.25, 1.2545e-01, 3.5526e-02],
[8.35, 9.8472e-02, 2.7181e-02],
[8.45, 8.7194e-02, 2.8345e-02],
[8.55, 7.0758e-02, 2.0808e-02],
[8.65, 5.8190e-02, 1.3359e-02],
[8.75, 5.6057e-02, 1.3512e-02],
[8.85, 5.1380e-02, 1.2815e-02],
[8.95, 4.4206e-02, 9.6866e-03],
[9.05, 4.1149e-02, 1.0169e-02],
[9.15, 3.4959e-02, 6.7898e-03],
[9.25, 3.3111e-02, 8.3704e-03],
[9.35, 3.0138e-02, 4.7741e-03],
[9.45, 2.6692e-02, 5.5029e-03],
[9.55, 2.4656e-02, 4.4359e-03],
[9.65, 2.2885e-02, 3.7915e-03],
[9.75, 2.1849e-02, 3.9812e-03],
[9.85, 2.0383e-02, 3.2930e-03],
[9.95, 1.9929e-02, 2.9370e-03],
[10.05, 1.8865e-02, 2.4624e-03],
[10.15, 1.8136e-02, 2.5208e-03],
[10.25, 1.7657e-02, 2.4217e-03],
[10.35, 1.6616e-02, 2.2784e-03],
[10.45, 1.6114e-02, 2.1783e-03],
[10.55, 1.4366e-02, 1.8819e-03],
[10.65, 1.2588e-02, 1.8249e-03],
[10.75, 1.1372e-02, 1.4436e-03],
[10.85, 9.1213e-03, 1.5816e-03],
[10.95, 6.1125e-03, 9.6735e-04],
[11.05, 4.3923e-03, 9.6254e-04],
[11.15, 2.5463e-03, 5.0038e-04],
[11.25, 1.4298e-03, 4.2816e-04],
[11.35, 6.4867e-04, 1.6439e-04],
[11.45, 2.8294e-04, 9.9799e-05],
[11.55, 1.0617e-04, 4.9085e-05],
[11.65, 3.2702e-05, 2.4546e-05],
[11.75, 1.2571e-05, 1.2571e-05],
[11.85, 8.4589e-06, 8.4589e-06],
[11.95, 7.4764e-06, 7.4764e-06],
], dtype=np.float32)
# Finally plot the data
# plt.errorbar(
# Baldry[:, 0],
# Baldry[:, 1],
# yerr=Baldry[:, 2],
# color='g',
# linestyle=':',
# lw = 1.5,
# label='Baldry et al. 2008',
# )
Baldry_xval = np.log10(10 ** Baldry[:, 0] /self.Hubble_h/self.Hubble_h)
if(whichimf == 1): Baldry_xval = Baldry_xval - 0.26 # convert back to Chabrier IMF
Baldry_yvalU = (Baldry[:, 1]+Baldry[:, 2]) * self.Hubble_h*self.Hubble_h*self.Hubble_h
Baldry_yvalL = (Baldry[:, 1]-Baldry[:, 2]) * self.Hubble_h*self.Hubble_h*self.Hubble_h
plt.fill_between(Baldry_xval, Baldry_yvalU, Baldry_yvalL,
facecolor='purple', alpha=0.25, label='Baldry et al. 2008 (z=0.1)')
# This next line is just to get the shaded region to appear correctly in the legend
plt.plot(xaxeshisto, counts / self.volume * self.Hubble_h*self.Hubble_h*self.Hubble_h / binwidth, label='Baldry et al. 2008', color='purple', alpha=0.3)
# # Cole et al. 2001 SMF (h=1.0 converted to h=0.73)
# M = np.arange(7.0, 13.0, 0.01)
# Mstar = np.log10(7.07*1.0e10 /self.Hubble_h/self.Hubble_h)
# alpha = -1.18
# phistar = 0.009 *self.Hubble_h*self.Hubble_h*self.Hubble_h
# xval = 10.0 ** (M-Mstar)
# yval = np.log(10.) * phistar * xval ** (alpha+1) * np.exp(-xval)
# plt.plot(M, yval, 'g--', lw=1.5, label='Cole et al. 2001') # Plot the SMF
# Overplot the model histograms
plt.plot(xaxeshisto, counts / self.volume * self.Hubble_h*self.Hubble_h*self.Hubble_h / binwidth, 'k-', label='Model - All')
plt.plot(xaxeshisto, countsRED / self.volume * self.Hubble_h*self.Hubble_h*self.Hubble_h / binwidth, 'r:', lw=2, label='Model - Red')
plt.plot(xaxeshisto, countsBLU / self.volume * self.Hubble_h*self.Hubble_h*self.Hubble_h / binwidth, 'b:', lw=2, label='Model - Blue')
plt.yscale('log', nonposy='clip')
plt.axis([8.0, 12.5, 1.0e-6, 1.0e-1])
# Set the x-axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.1))
plt.ylabel(r'$\phi\ (\mathrm{Mpc}^{-3}\ \mathrm{dex}^{-1})$') # Set the y...
plt.xlabel(r'$\log_{10} M_{\mathrm{stars}}\ (M_{\odot})$') # and the x-axis labels
plt.text(12.2, 0.03, whichsimulation, size = 'large')
leg = plt.legend(loc='lower left', numpoints=1,
labelspacing=0.1)
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '1.StellarMassFunction' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def BaryonicMassFunction(self, G):
print('Plotting the baryonic mass function')
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
binwidth = 0.1 # mass function histogram bin width
# calculate BMF
w = np.where(G.StellarMass + G.ColdGas > 0.0)[0]
mass = np.log10((G.StellarMass[w] + G.ColdGas[w]) * 1.0e10 / self.Hubble_h)
mi = np.floor(min(mass)) - 2
ma = np.floor(max(mass)) + 2
NB = (ma - mi) / binwidth
(counts, binedges) = np.histogram(mass, range=(mi, ma), bins=NB)
# Set the x-axis values to be the centre of the bins
xaxeshisto = binedges[:-1] + 0.5 * binwidth
# Bell et al. 2003 BMF (h=1.0 converted to h=0.73)
M = np.arange(7.0, 13.0, 0.01)
Mstar = np.log10(5.3*1.0e10 /self.Hubble_h/self.Hubble_h)
alpha = -1.21
phistar = 0.0108 *self.Hubble_h*self.Hubble_h*self.Hubble_h
xval = 10.0 ** (M-Mstar)
yval = np.log(10.) * phistar * xval ** (alpha+1) * np.exp(-xval)
if(whichimf == 0):
# converted diet Salpeter IMF to Salpeter IMF
plt.plot(np.log10(10.0**M /0.7), yval, 'b-', lw=2.0, label='Bell et al. 2003') # Plot the SMF
elif(whichimf == 1):
# converted diet Salpeter IMF to Salpeter IMF, then to Chabrier IMF
plt.plot(np.log10(10.0**M /0.7 /1.8), yval, 'g--', lw=1.5, label='Bell et al. 2003') # Plot the SMF
# Overplot the model histograms
plt.plot(xaxeshisto, counts / self.volume * self.Hubble_h*self.Hubble_h*self.Hubble_h / binwidth, 'k-', label='Model')
plt.yscale('log', nonposy='clip')
plt.axis([8.0, 12.5, 1.0e-6, 1.0e-1])
# Set the x-axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.1))
plt.ylabel(r'$\phi\ (\mathrm{Mpc}^{-3}\ \mathrm{dex}^{-1})$') # Set the y...
plt.xlabel(r'$\log_{10}\ M_{\mathrm{bar}}\ (M_{\odot})$') # and the x-axis labels
leg = plt.legend(loc='lower left', numpoints=1,
labelspacing=0.1)
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '2.BaryonicMassFunction' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def GasMassFunction(self, G):
print('Plotting the cold gas mass function')
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
binwidth = 0.1 # mass function histogram bin width
# calculate all
w = np.where(G.ColdGas > 0.0)[0]
mass = np.log10(G.ColdGas[w] * 1.0e10 / self.Hubble_h)
sSFR = (G.SfrDisk[w] + G.SfrBulge[w]) / (G.StellarMass[w] * 1.0e10 / self.Hubble_h)
mi = np.floor(min(mass)) - 2
ma = np.floor(max(mass)) + 2
NB = (ma - mi) / binwidth
(counts, binedges) = np.histogram(mass, range=(mi, ma), bins=NB)
# Set the x-axis values to be the centre of the bins
xaxeshisto = binedges[:-1] + 0.5 * binwidth
# additionally calculate red
w = np.where(sSFR < 10.0**sSFRcut)[0]
massRED = mass[w]
(countsRED, binedges) = np.histogram(massRED, range=(mi, ma), bins=NB)
# additionally calculate blue
w = np.where(sSFR > 10.0**sSFRcut)[0]
massBLU = mass[w]
(countsBLU, binedges) = np.histogram(massBLU, range=(mi, ma), bins=NB)
# Baldry+ 2008 modified data used for the MCMC fitting
Zwaan = np.array([[6.933, -0.333],
[7.057, -0.490],
[7.209, -0.698],
[7.365, -0.667],
[7.528, -0.823],
[7.647, -0.958],
[7.809, -0.917],
[7.971, -0.948],
[8.112, -0.927],
[8.263, -0.917],
[8.404, -1.062],
[8.566, -1.177],
[8.707, -1.177],
[8.853, -1.312],
[9.010, -1.344],
[9.161, -1.448],
[9.302, -1.604],
[9.448, -1.792],
[9.599, -2.021],
[9.740, -2.406],
[9.897, -2.615],
[10.053, -3.031],
[10.178, -3.677],
[10.335, -4.448],
[10.492, -5.083] ], dtype=np.float32)
ObrRaw = np.array([
[7.300, -1.104],
[7.576, -1.302],
[7.847, -1.250],
[8.133, -1.240],
[8.409, -1.344],
[8.691, -1.479],
[8.956, -1.792],
[9.231, -2.271],
[9.507, -3.198],
[9.788, -5.062 ] ], dtype=np.float32)
ObrCold = np.array([
[8.009, -1.042],
[8.215, -1.156],
[8.409, -0.990],
[8.604, -1.156],
[8.799, -1.208],
[9.020, -1.333],
[9.194, -1.385],
[9.404, -1.552],
[9.599, -1.677],
[9.788, -1.812],
[9.999, -2.312],
[10.172, -2.656],
[10.362, -3.500],
[10.551, -3.635],
[10.740, -5.010] ], dtype=np.float32)
ObrCold_xval = np.log10(10**(ObrCold[:, 0]) /self.Hubble_h/self.Hubble_h)
ObrCold_yval = (10**(ObrCold[:, 1]) * self.Hubble_h*self.Hubble_h*self.Hubble_h)
Zwaan_xval = np.log10(10**(Zwaan[:, 0]) /self.Hubble_h/self.Hubble_h)
Zwaan_yval = (10**(Zwaan[:, 1]) * self.Hubble_h*self.Hubble_h*self.Hubble_h)
ObrRaw_xval = np.log10(10**(ObrRaw[:, 0]) /self.Hubble_h/self.Hubble_h)
ObrRaw_yval = (10**(ObrRaw[:, 1]) * self.Hubble_h*self.Hubble_h*self.Hubble_h)
plt.plot(ObrCold_xval, ObrCold_yval, color='black', lw = 7, alpha=0.25, label='Obr. \& Raw. 2009 (Cold Gas)')
plt.plot(Zwaan_xval, Zwaan_yval, color='cyan', lw = 7, alpha=0.25, label='Zwaan et al. 2005 (HI)')
plt.plot(ObrRaw_xval, ObrRaw_yval, color='magenta', lw = 7, alpha=0.25, label='Obr. \& Raw. 2009 (H2)')
# Overplot the model histograms
plt.plot(xaxeshisto, counts / self.volume * self.Hubble_h*self.Hubble_h*self.Hubble_h / binwidth, 'k-', label='Model - Cold Gas')
plt.yscale('log', nonposy='clip')
plt.axis([8.0, 11.5, 1.0e-6, 1.0e-1])
# Set the x-axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.1))
plt.ylabel(r'$\phi\ (\mathrm{Mpc}^{-3}\ \mathrm{dex}^{-1})$') # Set the y...
plt.xlabel(r'$\log_{10} M_{\mathrm{X}}\ (M_{\odot})$') # and the x-axis labels
leg = plt.legend(loc='lower left', numpoints=1,
labelspacing=0.1)
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '3.GasMassFunction' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def BaryonicTullyFisher(self, G):
print('Plotting the baryonic TF relationship')
seed(2222)
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
# w = np.where((G.Type == 0) & (G.StellarMass + G.ColdGas > 0.0) & (G.Vmax > 0.0))[0]
w = np.where((G.Type == 0) & (G.StellarMass + G.ColdGas > 0.0) &
((G.ClassicalBulgeMass+G.SecularBulgeMass) / G.StellarMass > 0.1) & ((G.ClassicalBulgeMass+G.SecularBulgeMass) / G.StellarMass < 0.5))[0]
if(len(w) > dilute): w = sample(w, dilute)
mass = np.log10((G.StellarMass[w] + G.ColdGas[w]) * 1.0e10 / self.Hubble_h)
vel = np.log10(G.Vmax[w])
plt.scatter(vel, mass, marker='o', s=1, c='k', alpha=0.5, label='Model Sb/c galaxies')
# overplot Stark, McGaugh & Swatters 2009 (assumes h=0.75? ... what IMF?)
w = np.arange(0.5, 10.0, 0.5)
TF = 3.94*w + 1.79
plt.plot(w, TF, 'b-', lw=2.0, label='Stark, McGaugh \& Swatters 2009')
plt.ylabel(r'$\log_{10}\ M_{\mathrm{bar}}\ (M_{\odot})$') # Set the y...
plt.xlabel(r'$\log_{10}V_{max}\ (km/s)$') # and the x-axis labels
# Set the x and y axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.05))
ax.yaxis.set_minor_locator(plt.MultipleLocator(0.25))
plt.axis([1.4, 2.6, 8.0, 12.0])
leg = plt.legend(loc='lower right')
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '4.BaryonicTullyFisher' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def SpecificStarFormationRate(self, G):
print('Plotting the specific SFR')
seed(2222)
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
w = np.where(G.StellarMass > 0.01)[0]
if(len(w) > dilute): w = sample(w, dilute)
mass = np.log10(G.StellarMass[w] * 1.0e10 / self.Hubble_h)
sSFR = np.log10( (G.SfrDisk[w] + G.SfrBulge[w]) / (G.StellarMass[w] * 1.0e10 / self.Hubble_h) )
plt.scatter(mass, sSFR, marker='o', s=1, c='k', alpha=0.5, label='Model galaxies')
# overplot dividing line between SF and passive
w = np.arange(7.0, 13.0, 1.0)
plt.plot(w, w/w*sSFRcut, 'b:', lw=2.0)
plt.ylabel(r'$\log_{10}\ s\mathrm{SFR}\ (\mathrm{yr^{-1}})$') # Set the y...
plt.xlabel(r'$\log_{10} M_{\mathrm{stars}}\ (M_{\odot})$') # and the x-axis labels
# Set the x and y axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.05))
ax.yaxis.set_minor_locator(plt.MultipleLocator(0.25))
plt.axis([8.0, 12.0, -16.0, -8.0])
leg = plt.legend(loc='lower right')
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '5.SpecificStarFormationRate' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def GasFraction(self, G):
print('Plotting the gas fractions')
seed(2222)
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
w = np.where((G.Type == 0) & (G.StellarMass + G.ColdGas > 0.0) &
((G.ClassicalBulgeMass+G.SecularBulgeMass) / G.StellarMass > 0.1) & ((G.ClassicalBulgeMass+G.SecularBulgeMass) / G.StellarMass < 0.5))[0]
if(len(w) > dilute): w = sample(w, dilute)
mass = np.log10(G.StellarMass[w] * 1.0e10 / self.Hubble_h)
fraction = G.ColdGas[w] / (G.StellarMass[w] + G.ColdGas[w])
plt.scatter(mass, fraction, marker='o', s=1, c='k', alpha=0.5, label='Model Sb/c galaxies')
plt.ylabel(r'$\mathrm{Cold\ Mass\ /\ (Cold+Stellar\ Mass)}$') # Set the y...
plt.xlabel(r'$\log_{10} M_{\mathrm{stars}}\ (M_{\odot})$') # and the x-axis labels
# Set the x and y axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.05))
ax.yaxis.set_minor_locator(plt.MultipleLocator(0.25))
plt.axis([8.0, 12.0, 0.0, 1.0])
leg = plt.legend(loc='upper right')
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '6.GasFraction' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def Metallicity(self, G):
print('Plotting the metallicities')
seed(2222)
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
w = np.where((G.Type == 0) & (G.ColdGas / (G.StellarMass + G.ColdGas) > 0.1) & (G.StellarMass > 0.01))[0]
if(len(w) > dilute): w = sample(w, dilute)
mass = np.log10(G.StellarMass[w] * 1.0e10 / self.Hubble_h)
Z = np.log10((G.MetalsColdGas[w] / G.ColdGas[w]) / 0.02) + 9.0
plt.scatter(mass, Z, marker='o', s=1, c='k', alpha=0.5, label='Model galaxies')
# overplot Tremonti et al. 2003 (h=0.7)
w = np.arange(7.0, 13.0, 0.1)
Zobs = -1.492 + 1.847*w - 0.08026*w*w
if(whichimf == 0):
# Conversion from Kroupa IMF to Slapeter IMF
plt.plot(np.log10((10**w *1.5)), Zobs, 'b-', lw=2.0, label='Tremonti et al. 2003')
elif(whichimf == 1):
# Conversion from Kroupa IMF to Slapeter IMF to Chabrier IMF
plt.plot(np.log10((10**w *1.5 /1.8)), Zobs, 'b-', lw=2.0, label='Tremonti et al. 2003')
plt.ylabel(r'$12\ +\ \log_{10}[\mathrm{O/H}]$') # Set the y...
plt.xlabel(r'$\log_{10} M_{\mathrm{stars}}\ (M_{\odot})$') # and the x-axis labels
# Set the x and y axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.05))
ax.yaxis.set_minor_locator(plt.MultipleLocator(0.25))
plt.axis([8.0, 12.0, 8.0, 9.5])
leg = plt.legend(loc='lower right')
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '7.Metallicity' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# ---------------------------------------------------------
def BlackHoleBulgeRelationship(self, G):
print('Plotting the black hole-bulge relationship')
seed(2222)
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
w = np.where(((G.ClassicalBulgeMass+G.SecularBulgeMass) > 0.01) & (G.BlackHoleMass > 0.00001))[0]
if(len(w) > dilute): w = sample(w, dilute)
bh = np.log10(G.BlackHoleMass[w] * 1.0e10 / self.Hubble_h)
bulge = np.log10((G.ClassicalBulgeMass[w]+G.SecularBulgeMass[w]) * 1.0e10 / self.Hubble_h)
plt.scatter(bulge, bh, marker='o', s=1, c='k', alpha=0.5, label='Model galaxies')
# overplot Haring & Rix 2004
w = 10. ** np.arange(20)
BHdata = 10. ** (8.2 + 1.12 * np.log10(w / 1.0e11))
plt.plot(np.log10(w), np.log10(BHdata), 'b-', label="Haring \& Rix 2004")
plt.ylabel(r'$\log\ M_{\mathrm{BH}}\ (M_{\odot})$') # Set the y...
plt.xlabel(r'$\log\ M_{\mathrm{bulge}}\ (M_{\odot})$') # and the x-axis labels
# Set the x and y axis minor ticks
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.05))
ax.yaxis.set_minor_locator(plt.MultipleLocator(0.25))
plt.axis([8.0, 12.0, 6.0, 10.0])
leg = plt.legend(loc='upper left')
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '8.BlackHoleBulgeRelationship' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# --------------------------------------------------------
def MassReservoirScatter(self, G):
print('Plotting the mass in stellar, cold, hot, ejected, ICS reservoirs')
seed(2222)
plt.figure() # New figure
ax = plt.subplot(111) # 1 plot on the figure
w = np.where((G.Type == 0) & (G.Mvir > 1.0) & (G.StellarMass > 0.0))[0]
if(len(w) > dilute): w = sample(w, dilute)
mvir = np.log10(G.Mvir[w] * 1.0e10)
plt.scatter(mvir, np.log10(G.StellarMass[w] * 1.0e10), marker='o', s=0.3, c='k', alpha=0.5, label='Stars')
plt.scatter(mvir, np.log10(G.ColdGas[w] * 1.0e10), marker='o', s=0.3, color='blue', alpha=0.5, label='Cold gas')
plt.scatter(mvir, np.log10(G.HotGas[w] * 1.0e10), marker='o', s=0.3, color='red', alpha=0.5, label='Hot gas')
plt.scatter(mvir, np.log10(G.EjectedMass[w] * 1.0e10), marker='o', s=0.3, color='green', alpha=0.5, label='Ejected gas')
plt.scatter(mvir, np.log10(G.IntraClusterStars[w] * 1.0e10), marker='o', s=10, color='yellow', alpha=0.5, label='Intracluster stars')
plt.ylabel(r'$\mathrm{stellar,\ cold,\ hot,\ ejected,\ ICS\ mass}$') # Set the y...
plt.xlabel(r'$\log\ M_{\mathrm{vir}}\ (h^{-1}\ M_{\odot})$') # and the x-axis labels
plt.axis([10.0, 14.0, 7.5, 12.5])
leg = plt.legend(loc='upper left')
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
plt.text(13.5, 8.0, r'$\mathrm{All}')
outputFile = OutputDir + '9.MassReservoirScatter' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# --------------------------------------------------------
def SpatialDistribution(self, G):
print('Plotting the spatial distribution of all galaxies')
seed(2222)
plt.figure() # New figure
w = np.where((G.Mvir > 0.0) & (G.StellarMass > 0.1))[0]
if(len(w) > dilute): w = sample(w, dilute)
xx = G.Pos[w,0]
yy = G.Pos[w,1]
zz = G.Pos[w,2]
buff = self.BoxSize*0.1
ax = plt.subplot(221) # 1 plot on the figure
plt.scatter(xx, yy, marker='o', s=0.3, c='k', alpha=0.5)
plt.axis([0.0-buff, self.BoxSize+buff, 0.0-buff, self.BoxSize+buff])
plt.ylabel(r'$\mathrm{x}$') # Set the y...
plt.xlabel(r'$\mathrm{y}$') # and the x-axis labels
ax = plt.subplot(222) # 1 plot on the figure
plt.scatter(xx, zz, marker='o', s=0.3, c='k', alpha=0.5)
plt.axis([0.0-buff, self.BoxSize+buff, 0.0-buff, self.BoxSize+buff])
plt.ylabel(r'$\mathrm{x}$') # Set the y...
plt.xlabel(r'$\mathrm{z}$') # and the x-axis labels
ax = plt.subplot(223) # 1 plot on the figure
plt.scatter(yy, zz, marker='o', s=0.3, c='k', alpha=0.5)
plt.axis([0.0-buff, self.BoxSize+buff, 0.0-buff, self.BoxSize+buff])
plt.ylabel(r'$\mathrm{y}$') # Set the y...
plt.xlabel(r'$\mathrm{z}$') # and the x-axis labels
outputFile = OutputDir + '10.SpatialDistribution' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# --------------------------------------------------------
def VelocityDistribution(self, G):
print('Plotting the velocity distribution of all galaxies')
seed(2222)
mi = -40.0
ma = 40.0
binwidth = 0.5
NB = (ma - mi) / binwidth
# set up figure
plt.figure()
ax = plt.subplot(111)
pos_x = G.Pos[:,0] / self.Hubble_h
pos_y = G.Pos[:,1] / self.Hubble_h
pos_z = G.Pos[:,2] / self.Hubble_h
vel_x = G.Vel[:,0]
vel_y = G.Vel[:,1]
vel_z = G.Vel[:,2]
dist_los = np.sqrt(pos_x*pos_x + pos_y*pos_y + pos_z*pos_z)
vel_los = (pos_x/dist_los)*vel_x + (pos_y/dist_los)*vel_y + (pos_z/dist_los)*vel_z
dist_red = dist_los + vel_los/(self.Hubble_h*100.0)
tot_gals = len(pos_x)
(counts, binedges) = np.histogram(vel_los/(self.Hubble_h*100.0), range=(mi, ma), bins=NB)
xaxeshisto = binedges[:-1] + 0.5 * binwidth
plt.plot(xaxeshisto, counts / binwidth / tot_gals, 'k-', label='los-velocity')
(counts, binedges) = np.histogram(vel_x/(self.Hubble_h*100.0), range=(mi, ma), bins=NB)
xaxeshisto = binedges[:-1] + 0.5 * binwidth
plt.plot(xaxeshisto, counts / binwidth / tot_gals, 'r-', label='x-velocity')
(counts, binedges) = np.histogram(vel_y/(self.Hubble_h*100.0), range=(mi, ma), bins=NB)
xaxeshisto = binedges[:-1] + 0.5 * binwidth
plt.plot(xaxeshisto, counts / binwidth / tot_gals, 'g-', label='y-velocity')
(counts, binedges) = np.histogram(vel_z/(self.Hubble_h*100.0), range=(mi, ma), bins=NB)
xaxeshisto = binedges[:-1] + 0.5 * binwidth
plt.plot(xaxeshisto, counts / binwidth / tot_gals, 'b-', label='z-velocity')
plt.yscale('log', nonposy='clip')
plt.axis([mi, ma, 1e-5, 0.5])
# plt.axis([mi, ma, 0, 0.13])
plt.ylabel(r'$\mathrm{Box\ Normalised\ Count}$') # Set the y...
plt.xlabel(r'$\mathrm{Velocity / H}_{0}$') # and the x-axis labels
leg = plt.legend(loc='upper left', numpoints=1, labelspacing=0.1)
leg.draw_frame(False) # Don't want a box frame
for t in leg.get_texts(): # Reduce the size of the text
t.set_fontsize('medium')
outputFile = OutputDir + '11.VelocityDistribution' + OutputFormat
plt.savefig(outputFile) # Save the figure
print('Saved file to', outputFile)
plt.close()
# Add this plot to our output list
OutputList.append(outputFile)
# =================================================================
# 'Main' section of code. This if statement executes if the code is run from the
# shell command line, i.e. with 'python allresults.py'
if __name__ == '__main__':
from optparse import OptionParser