forked from jchelly/SOAP
-
Notifications
You must be signed in to change notification settings - Fork 3
/
subhalo_properties.py
2314 lines (2077 loc) · 78.7 KB
/
subhalo_properties.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
#!/bin/env python
"""
subhalo_properties.py
Halo properties for VR subhalo groups.
Subhalos are identified by VR as substructures of 3D FOF groups. They are found
by first running a 3D FOF algorithm and then subdividing the resulting 3D FOF
groups using a 6D phase space FOF algorithm. The 6D FOF subhalo groups come in
two flavours: a version that includes all the particles within the 6D FOF group
(simply called the FOFSubhalo), and a version that only includes the particles
that are also gravitationally bound to the subhalo (the BoundSubhalo). The union
of all the FOFSubhalo groups is the original 3D FOF group (which can be useful
to recover e.g. the FOF mass or CoM of the 3D FOF group).
Note that all the membership information used to determine which particles are
a member of the FOFSubhalo and the BoundSubhalo comes directly from VR, i.e. we
do not perform any FOF algorithm or boundedness calculation in SOAP.
Just like the other HaloProperty implementations, the calculation of the
properties is done lazily: only calculations that are actually needed are
performed. See aperture_properties.py for a fully documented example.
"""
import numpy as np
import unyt
from halo_properties import HaloProperty, SearchRadiusTooSmallError
from dataset_names import mass_dataset
from half_mass_radius import get_half_mass_radius
from kinematic_properties import (
get_angular_momentum,
get_angular_momentum_and_kappa_corot,
get_vmax,
get_inertia_tensor,
get_velocity_dispersion_matrix,
)
from recently_heated_gas_filter import RecentlyHeatedGasFilter
from stellar_age_calculator import StellarAgeCalculator
from property_table import PropertyTable
from lazy_properties import lazy_property
from category_filter import CategoryFilter
from parameter_file import ParameterFile
from snapshot_datasets import SnapshotDatasets
from swift_cells import SWIFTCellGrid
from typing import Dict, List
from numpy.typing import NDArray
class SubhaloParticleData:
"""
Halo calculation class.
All properties we want to compute in apertures are implemented as lazy
methods of this class.
Note that unlike aperture-based halo property calculations, subhalo calculations
only require a single mask, since their membership is purely based on VR
membership information and is irrespective of the particle position.
That said, we still require a types==PartTypeX mask
(see aperture_properties.py) to access some arrays that have been
precomputed for all particles.
"""
def __init__(
self,
input_halo: Dict,
data: Dict,
types_present: List[str],
grnr: int,
stellar_age_calculator: StellarAgeCalculator,
recently_heated_gas_filter: RecentlyHeatedGasFilter,
snapshot_datasets: SnapshotDatasets,
softening_of_parttype: unyt.unyt_array,
):
"""
Constructor.
Parameters:
- input_halo: Dict
Dictionary containing properties of the halo read from the VR catalogue.
- data: Dict
Dictionary containing particle data.
- types_present: List
List of all particle types (e.g. 'PartType0') that are present in the data
dictionary.
- grnr: int
VR index of this particular subhalo. Used to match particles to this
subhalo.
- stellar_age_calculator: StellarAgeCalculator
Object used to compute stellar ages from the current cosmological scale factor
and the birth scale factors of star particles.
- recently_heated_gas_filter: RecentlyHeatedGasFilter
Filter used to mask out gas particles that were recently heated by
AGN feedback.
- snapshot_datasets: SnapshotDatasets
Object containing metadata about the datasets in the snapshot, like
appropriate aliases and column names.
"""
self.input_halo = input_halo
self.data = data
self.types_present = types_present
self.grnr = grnr
self.stellar_age_calculator = stellar_age_calculator
self.recently_heated_gas_filter = recently_heated_gas_filter
self.snapshot_datasets = snapshot_datasets
self.softening_of_parttype = softening_of_parttype
self.compute_basics()
def get_dataset(self, name: str) -> unyt.unyt_array:
"""
Local wrapper for SnapshotDatasets.get_dataset().
"""
return self.snapshot_datasets.get_dataset(name, self.data)
def compute_basics(self):
"""
Compute some properties that are always needed, regardless of which
properties we actually want to compute.
"""
self.centre = self.input_halo["cofp"]
self.index = self.input_halo["index"]
mass = []
position = []
radius = []
velocity = []
types = []
softening = []
for ptype in self.types_present:
grnr = self.get_dataset(f"{ptype}/{self.grnr}")
in_halo = grnr == self.index
mass.append(self.get_dataset(f"{ptype}/{mass_dataset(ptype)}")[in_halo])
pos = (
self.get_dataset(f"{ptype}/Coordinates")[in_halo, :]
- self.centre[None, :]
)
position.append(pos)
r = np.sqrt(pos[:, 0] ** 2 + pos[:, 1] ** 2 + pos[:, 2] ** 2)
radius.append(r)
velocity.append(self.get_dataset(f"{ptype}/Velocities")[in_halo, :])
typearr = int(ptype[-1]) * np.ones(r.shape, dtype=np.int32)
types.append(typearr)
s = np.ones(r.shape, dtype=np.float64) * self.softening_of_parttype[ptype]
softening.append(s)
self.mass = np.concatenate(mass)
self.position = np.concatenate(position)
self.radius = np.concatenate(radius)
self.velocity = np.concatenate(velocity)
self.types = np.concatenate(types)
self.softening = np.concatenate(softening)
@lazy_property
def gas_mask_sh(self) -> NDArray[bool]:
"""
Mask used to mask out gas particles that belong to this subhalo in
arrays containing all particles, e.g. self.mass.
"""
return self.types == 0
@lazy_property
def dm_mask_sh(self) -> NDArray[bool]:
"""
Mask used to mask out dark matter particles that belong to this subhalo in
arrays containing all particles, e.g. self.mass.
"""
return self.types == 1
@lazy_property
def star_mask_sh(self) -> NDArray[bool]:
"""
Mask used to mask out star particles that belong to this subhalo in
arrays containing all particles, e.g. self.mass.
"""
return self.types == 4
@lazy_property
def bh_mask_sh(self) -> NDArray[bool]:
"""
Mask used to mask out black hole particles that belong to this subhalo in
arrays containing all particles, e.g. self.mass.
"""
return self.types == 5
@lazy_property
def baryons_mask_sh(self) -> NDArray[bool]:
"""
Mask used to mask out baryon (gas + star) particles that belong to this subhalo in
arrays containing all particles, e.g. self.mass.
"""
return self.gas_mask_sh | self.star_mask_sh
@lazy_property
def Ngas(self) -> int:
"""
Number of gas particles in the subhalo.
"""
return self.gas_mask_sh.sum()
@lazy_property
def Ndm(self) -> int:
"""
Number of dark matter particles in the subhalo.
"""
return self.dm_mask_sh.sum()
@lazy_property
def Nstar(self) -> int:
"""
Number of star particles in the subhalo.
"""
return self.star_mask_sh.sum()
@lazy_property
def Nbh(self) -> int:
"""
Number of black hole particles in the subhalo.
"""
return self.bh_mask_sh.sum()
@lazy_property
def mass_gas(self) -> unyt.unyt_array:
"""
Masses of the gas particles in the subhalo.
"""
return self.mass[self.gas_mask_sh]
@lazy_property
def mass_dm(self) -> unyt.unyt_array:
"""
Masses of the dark matter particles in the subhalo.
"""
return self.mass[self.dm_mask_sh]
@lazy_property
def mass_star(self) -> unyt.unyt_array:
"""
Masses of the star particles in the subhalo.
"""
return self.mass[self.star_mask_sh]
@lazy_property
def mass_baryons(self) -> unyt.unyt_array:
"""
Masses of the baryon (gas + star) particles in the subhalo.
"""
return self.mass[self.baryons_mask_sh]
@lazy_property
def pos_gas(self) -> unyt.unyt_array:
"""
Positions of the gas particles in the subhalo.
"""
return self.position[self.gas_mask_sh]
@lazy_property
def pos_dm(self) -> unyt.unyt_array:
"""
Positions of the dark matter particles in the subhalo.
"""
return self.position[self.dm_mask_sh]
@lazy_property
def pos_star(self) -> unyt.unyt_array:
"""
Positions of the star particles in the subhalo.
"""
return self.position[self.star_mask_sh]
@lazy_property
def pos_baryons(self) -> unyt.unyt_array:
"""
Positions of the baryon (gas + star) particles in the subhalo.
"""
return self.position[self.baryons_mask_sh]
@lazy_property
def vel_gas(self) -> unyt.unyt_array:
"""
Velocities of the gas particles in the subhalo.
"""
return self.velocity[self.gas_mask_sh]
@lazy_property
def vel_dm(self) -> unyt.unyt_array:
"""
Velocities of the dark matter particles in the subhalo.
"""
return self.velocity[self.dm_mask_sh]
@lazy_property
def vel_star(self) -> unyt.unyt_array:
"""
Velocities of the star particles in the subhalo.
"""
return self.velocity[self.star_mask_sh]
@lazy_property
def vel_baryons(self) -> unyt.unyt_array:
"""
Velocities of the baryon (gas + star) particles in the subhalo.
"""
return self.velocity[self.baryons_mask_sh]
@lazy_property
def Mtot(self) -> unyt.unyt_quantity:
"""
Total mass of the particles in the subhalo.
"""
return self.mass.sum()
@lazy_property
def Mgas(self) -> unyt.unyt_quantity:
"""
Total mass of the gas particles in the subhalo.
"""
return self.mass_gas.sum()
@lazy_property
def Mdm(self) -> unyt.unyt_quantity:
"""
Total mass of the dark matter particles in the subhalo.
"""
return self.mass_dm.sum()
@lazy_property
def Mstar(self) -> unyt.unyt_quantity:
"""
Total mass of the star particles in the subhalo.
"""
return self.mass_star.sum()
@lazy_property
def Mbh_dynamical(self) -> unyt.unyt_quantity:
"""
Total dynamical mass of the black hole particles in the subhalo.
"""
return self.mass[self.bh_mask_sh].sum()
@lazy_property
def star_mask_all(self) -> NDArray[bool]:
"""
Mask that can be used to filter out star particles belonging to this
subhalo in raw particle arrays, e.g. PartType4/Masses.
"""
if self.Nstar == 0:
return None
return self.get_dataset(f"PartType4/{self.grnr}") == self.index
@lazy_property
def mass_star_init(self) -> unyt.unyt_array:
"""
Initial stellar masses of star particles in the subhalo.
"""
if self.Nstar == 0:
return None
return self.get_dataset("PartType4/InitialMasses")[self.star_mask_all]
@lazy_property
def Mstar_init(self) -> unyt.unyt_quantity:
"""
Total initial stellar mass of star particles in the subhalo.
"""
if self.Nstar == 0:
return None
return self.mass_star_init.sum()
@lazy_property
def stellar_luminosities(self) -> unyt.unyt_array:
"""
Stellar luminosities of star particles in the subhalo.
"""
if self.Nstar == 0:
return None
return self.get_dataset("PartType4/Luminosities")[self.star_mask_all]
@lazy_property
def StellarLuminosity(self) -> unyt.unyt_array:
"""
Total stellar luminosity of star particles in the subhalo.
Note that this is an array, since there are multiple luminosity bands.
"""
if self.Nstar == 0:
return None
return self.stellar_luminosities.sum(axis=0)
@lazy_property
def starmetalfrac(self) -> unyt.unyt_quantity:
"""
Total metal mass fraction in star particles in the subhalo.
Given as a fraction of the total mass in star particles.
"""
if self.Nstar == 0:
return None
return (
self.mass_star
* self.get_dataset("PartType4/MetalMassFractions")[self.star_mask_all]
).sum() / self.Mstar
@lazy_property
def stellar_ages(self) -> unyt.unyt_array:
"""
Stellar ages of star particles.
Uses the StellarAgeCalculator to convert the stellar birth scale factor
into a stellar age.
"""
if self.Nstar == 0:
return None
birth_a = self.get_dataset("PartType4/BirthScaleFactors")[self.star_mask_all]
return self.stellar_age_calculator.stellar_age(birth_a)
@lazy_property
def stellar_age_mw(self) -> unyt.unyt_quantity:
"""
Mass-weighted average stellar age of star particles in the subhalo.
"""
if self.Nstar == 0:
return None
return ((self.mass_star / self.Mstar) * self.stellar_ages).sum()
@lazy_property
def stellar_age_lw(self) -> unyt.unyt_array:
"""
R-band luminosity weighted average stellar age of star particles in the
subhalo.
This assumes that the Luminosities have a named column with the name
"GAMA_r".
"""
if self.Nstar == 0:
return None
Lr = self.stellar_luminosities[
:, self.snapshot_datasets.get_column_index("Luminosities", "GAMA_r")
]
Lrtot = Lr.sum()
return ((Lr / Lrtot) * self.stellar_ages).sum()
@lazy_property
def bh_mask_all(self) -> NDArray[bool]:
"""
Mask that can be used to filter out black hole particles belonging to this
subhalo in raw particle arrays, e.g. PartType5/DynamicalMasses.
"""
if self.Nbh == 0:
return None
return self.get_dataset(f"PartType5/{self.grnr}") == self.index
@lazy_property
def Mbh_subgrid(self) -> unyt.unyt_quantity:
"""
Total sub-grid mass of black hole particles in the subhalo.
"""
if self.Nbh == 0:
return None
return self.BH_subgrid_masses.sum()
@lazy_property
def agn_eventa(self) -> unyt.unyt_array:
"""
Last AGN feedback scale factor of black hole particles in the subhalo.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/LastAGNFeedbackScaleFactors")[
self.bh_mask_all
]
@lazy_property
def BHlasteventa(self) -> unyt.unyt_quantity:
"""
Maximum AGN feedback scale factor among all BH particles.
"""
if self.Nbh == 0:
return None
return np.max(self.agn_eventa)
@lazy_property
def BH_subgrid_masses(self) -> unyt.unyt_array:
"""
Sub-grid masses of black hole particles in the subhalo.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/SubgridMasses")[self.bh_mask_all]
@lazy_property
def BlackHolesTotalInjectedThermalEnergy(self) -> unyt.unyt_quantity:
"""
Total thermal energy injected into gas particles by all BH particles.
"""
if self.Nbh == 0:
return None
return np.sum(
self.get_dataset("PartType5/AGNTotalInjectedEnergies")[self.bh_mask_all]
)
@lazy_property
def BlackHolesTotalInjectedJetEnergy(self) -> unyt.unyt_quantity:
"""
Total jet energy injected into gas particles by all BH particles.
"""
if self.Nbh == 0:
return None
return np.sum(
self.get_dataset("PartType5/InjectedJetEnergies")[self.bh_mask_all]
)
@lazy_property
def iBHmax(self) -> int:
"""
Index of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return np.argmax(self.BH_subgrid_masses)
@lazy_property
def BHmaxM(self) -> unyt.unyt_quantity:
"""
Sub-grid mass of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.BH_subgrid_masses[self.iBHmax]
@lazy_property
def BHmaxID(self) -> int:
"""
ID of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/ParticleIDs")[self.bh_mask_all][self.iBHmax]
@lazy_property
def BHmaxpos(self) -> unyt.unyt_array:
"""
Position of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/Coordinates")[self.bh_mask_all][self.iBHmax]
@lazy_property
def BHmaxvel(self) -> unyt.unyt_array:
"""
Velocity of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/Velocities")[self.bh_mask_all][self.iBHmax]
@lazy_property
def BHmaxAR(self) -> unyt.unyt_quantity:
"""
Accretion rate of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/AccretionRates")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleAveragedAccretionRate(self) -> unyt.unyt_quantity:
"""
Averaged accretion rate of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/AveragedAccretionRates")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleInjectedThermalEnergy(self) -> unyt.unyt_quantity:
"""
Total thermal energy injected into gas particles by the most massive
BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/AGNTotalInjectedEnergies")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleAccretionMode(self) -> unyt.unyt_quantity:
"""
Accretion flow regime of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/AccretionModes")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleGWMassLoss(self) -> unyt.unyt_quantity:
"""
Cumulative mass lost to GW of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/GWMassLosses")[self.bh_mask_all][self.iBHmax]
@lazy_property
def MostMassiveBlackHoleInjectedJetEnergyByMode(self) -> unyt.unyt_quantity:
"""
Total energy injected in the kinetic jet AGN feedback mode, split by accretion mode,
of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/InjectedJetEnergiesByMode")[
self.bh_mask_all
][self.iBHmax]
@lazy_property
def MostMassiveBlackHoleLastJetEventScalefactor(self) -> unyt.unyt_quantity:
"""
Scale-factor of last jet event of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/LastAGNJetScaleFactors")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleNumberOfAGNEvents(self) -> unyt.unyt_quantity:
"""
Number of AGN events the most massive black hole has had so far.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/NumberOfAGNEvents")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleNumberOfAGNJetEvents(self) -> unyt.unyt_quantity:
"""
Number of jet events the most massive black hole has had so far.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/NumberOfAGNJetEvents")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleNumberOfMergers(self) -> unyt.unyt_quantity:
"""
Number of mergers the most massive black hole has had so far.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/NumberOfMergers")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleRadiatedEnergyByMode(self) -> unyt.unyt_quantity:
"""
The total energy launched into radiation by the most massive black hole, split by accretion mode.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/RadiatedEnergiesByMode")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleTotalAccretedMassesByMode(self) -> unyt.unyt_quantity:
"""
The total mass accreted by the most massive black hole, split by accretion mode.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/TotalAccretedMassesByMode")[
self.bh_mask_all
][self.iBHmax]
@lazy_property
def MostMassiveBlackHoleWindEnergyByMode(self) -> unyt.unyt_quantity:
"""
The total energy launched into accretion disc winds by the most massive black hole, split by accretion mode.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/WindEnergiesByMode")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleSpin(self) -> unyt.unyt_quantity:
"""
The spin of the most massive black hole.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/Spins")[self.bh_mask_all][self.iBHmax]
@lazy_property
def MostMassiveBlackHoleTotalAccretedMass(self) -> unyt.unyt_quantity:
"""
The total mass accreted by the most massive black hole.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/TotalAccretedMasses")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def MostMassiveBlackHoleFormationScalefactor(self) -> unyt.unyt_quantity:
"""
The formation scale factor of the most massive black hole.
"""
if self.Nbh == 0:
return None
return self.get_dataset("PartType5/FormationScaleFactors")[self.bh_mask_all][
self.iBHmax
]
@lazy_property
def BHmaxlasteventa(self) -> unyt.unyt_quantity:
"""
Last feedback scale factor of the most massive BH particle (largest sub-grid mass).
"""
if self.Nbh == 0:
return None
return self.agn_eventa[self.iBHmax]
@lazy_property
def total_mass_fraction(self) -> unyt.unyt_array:
"""
Fractional mass of all particles.
Used to avoid numerical overflow in calculations like
com = (mass * position).sum() / Mtot
by rewriting it as
com = ((mass / Mtot) * position).sum()
= (mass_fraction * position).sum()
This is more accurate, since the mass fractions are numbers
of the order of 1e-5 or so, while the masses themselves can be much
larger, if expressed in the wrong units (and that is up to unyt).
"""
if self.Mtot == 0:
return None
return self.mass / self.Mtot
@lazy_property
def com(self) -> unyt.unyt_array:
"""
Centre of mass of all particles in the subhalo.
"""
if self.Mtot == 0:
return None
return (self.total_mass_fraction[:, None] * self.position).sum(
axis=0
) + self.centre
@lazy_property
def vcom(self) -> unyt.unyt_array:
"""
Centre of mass velocity of all particles in the subhalo.
"""
if self.Mtot == 0:
return None
return (self.total_mass_fraction[:, None] * self.velocity).sum(axis=0)
@lazy_property
def R_vmax_unsoft(self) -> unyt.unyt_quantity:
"""
Radius at which the maximum circular velocity of the halo is reached.
Particles are not constrained to be at least one softening length away
from the centre.
This includes contributions from all particle types.
"""
if self.Mtot == 0:
return None
if not hasattr(self, "r_vmax_unsoft"):
self.r_vmax_unsoft, self.vmax_unsoft = get_vmax(
self.mass, self.radius, nskip=1
)
return self.r_vmax_unsoft
@lazy_property
def Vmax_unsoft(self) -> unyt.unyt_quantity:
"""
Maximum circular velocity of the halo.
Particles are not constrained to be at least one softening length away
from the centre.
This includes contributions from all particle types.
"""
if self.Mtot == 0:
return None
if not hasattr(self, "vmax_unsoft"):
self.r_vmax_unsoft, self.vmax_unsoft = get_vmax(
self.mass, self.radius, nskip=1
)
return self.vmax_unsoft
@lazy_property
def R_vmax_soft(self) -> unyt.unyt_quantity:
"""
Radius at which the maximum circular velocity of the halo is reached.
Particles are set to have minimum radius equal to their softening length.
This includes contributions from all particle types.
"""
if self.Mtot == 0:
return None
if not hasattr(self, "vmax_soft"):
soft_r = np.maximum(self.softening, self.radius)
self.r_vmax_soft, self.vmax_soft = get_vmax(self.mass, soft_r)
return self.r_vmax_soft
@lazy_property
def Vmax_soft(self):
"""
Maximum circular velocity of the halo.
Particles are set to have minimum radius equal to their softening length.
This includes contributions from all particle types.
"""
if self.Mtot == 0:
return None
if not hasattr(self, "vmax_soft"):
soft_r = np.maximum(self.softening, self.radius)
self.r_vmax_soft, self.vmax_soft = get_vmax(self.mass, soft_r)
return self.vmax_soft
@lazy_property
def spin_parameter(self) -> unyt.unyt_quantity:
"""
Spin parameter of all particles in the subhalo.
Computed as in Bullock et al. (2021):
lambda = |Ltot| / (sqrt(2) * M * v_max * R)
Since a subhalo does not have a characteristic radius, R, we instead use
the radius at which v_max is reached (and the corresponding mass).
"""
if self.Mtot == 0:
return None
if self.R_vmax_soft > 0 and self.Vmax_soft > 0:
mask_r_vmax = self.radius <= self.R_vmax_soft
vrel = self.velocity[mask_r_vmax, :] - self.vcom[None, :]
Ltot = np.linalg.norm(
(
self.mass[mask_r_vmax, None]
* np.cross(self.position[mask_r_vmax, :], vrel)
).sum(axis=0)
)
M_r_vmax = self.mass[mask_r_vmax].sum()
if M_r_vmax > 0:
return Ltot / (
np.sqrt(2.0) * M_r_vmax * self.Vmax_soft * self.R_vmax_soft
)
return None
@lazy_property
def TotalInertiaTensor(self) -> unyt.unyt_array:
"""
Inertia tensor of the total mass distribution.
Computed iteratively using an ellipsoid with volume equal to that of
a sphere with radius HalfMassRadiusTot. Only considers bound particles.
"""
if self.Mtot == 0:
return None
return get_inertia_tensor(self.mass, self.position, self.HalfMassRadiusTot)
@lazy_property
def TotalInertiaTensorReduced(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the total mass distribution.
Computed iteratively using an ellipsoid with volume equal to that of
a sphere with radius HalfMassRadiusTot. Only considers bound particles.
"""
if self.Mtot == 0:
return None
return get_inertia_tensor(
self.mass, self.position, self.HalfMassRadiusTot, reduced=True
)
@lazy_property
def TotalInertiaTensorNoniterative(self) -> unyt.unyt_array:
"""
Inertia tensor of the total mass distribution.
Computed using all bound particles within HalfMassRadiusTot.
"""
if self.Mtot == 0:
return None
return get_inertia_tensor(
self.mass, self.position, self.HalfMassRadiusTot, max_iterations=1
)
@lazy_property
def TotalInertiaTensorReducedNoniterative(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the total mass distribution.
Computed using all bound particles within HalfMassRadiusTot.
"""
if self.Mtot == 0:
return None
return get_inertia_tensor(
self.mass,
self.position,
self.HalfMassRadiusTot,
reduced=True,
max_iterations=1,
)
@lazy_property
def gas_mass_fraction(self) -> unyt.unyt_array:
"""
Mass fractions of gas particles in the subhalo.
See total_mass_fraction() for the rationale behind this function.
"""
if self.Mgas == 0:
return None
return self.mass_gas / self.Mgas
@lazy_property
def vcom_gas(self) -> unyt.unyt_array:
"""
Centre of mass velocity of gas particles in the subhalo.
"""
if self.Mgas == 0:
return None
return (self.gas_mass_fraction[:, None] * self.vel_gas).sum(axis=0)
def compute_Lgas_props(self):
"""
Auxiliary function used to compute a number of properties that depend
on Lgas. It is more efficient to compute these properties together.
"""
(
self.internal_Lgas,
self.internal_kappa_gas,
self.internal_Mcountrot_gas,
) = get_angular_momentum_and_kappa_corot(
self.mass_gas,
self.pos_gas,
self.vel_gas,
ref_velocity=self.vcom_gas,
do_counterrot_mass=True,
)
@lazy_property
def Lgas(self) -> unyt.unyt_array:
"""
Total angular momentum of gas particles in the subhalo.
Calls compute_Lgas_props() if required.
"""
if self.Mgas == 0:
return None
if not hasattr(self, "internal_Lgas"):
self.compute_Lgas_props()
return self.internal_Lgas
@lazy_property
def kappa_corot_gas(self) -> unyt.unyt_quantity:
"""
Ratio of the kinetic energy in counter-rotating rotation to the total
kinetic energy for gas particles in the subhalo.
Calls compute_Lgas_props() if required.
"""
if self.Mgas == 0:
return None
if not hasattr(self, "internal_kappa_gas"):
self.compute_Lgas_props()
return self.internal_kappa_gas
@lazy_property
def DtoTgas(self) -> unyt.unyt_quantity:
"""
Disc to total mass ratio for gas particles in the subhalo.
Calls compute_Lgas_props() if required.
"""
if self.Mgas == 0:
return None
if not hasattr(self, "internal_Mcountrot_gas"):
self.compute_Lgas_props()
return 1.0 - 2.0 * self.internal_Mcountrot_gas / self.Mgas