forked from jchelly/SOAP
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprojected_aperture_properties.py
1892 lines (1710 loc) · 65.5 KB
/
projected_aperture_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
"""
projected_aperture_properties.py
Halo properties within projected 2D apertures. These only include
the gravitionally bound particles (the equivalent of the exclusive
3D apertures) of a subhalo, within a fixed physical radius.
Just like the other HaloProperty implementations, the calculation of the
properties is done lazily: only calculations that are actually needed are
performed. A fully documented explanation can be found in
aperture_properties.py.
Note that for the projected apertures we use a design that adds another
level of complexity: apart from the ProjectedApertureParticleData equivalent
of ApertureParticleData, we now also need a
SingleProjectionProjectedApertureParticleData object to deal with individual
projections. Besides this difference, the approach is very similar.
"""
import numpy as np
import unyt
from swift_cells import SWIFTCellGrid
from halo_properties import HaloProperty, SearchRadiusTooSmallError
from dataset_names import mass_dataset
from half_mass_radius import get_half_mass_radius
from property_table import PropertyTable
from kinematic_properties import get_projected_inertia_tensor
from lazy_properties import lazy_property
from category_filter import CategoryFilter
from parameter_file import ParameterFile
from snapshot_datasets import SnapshotDatasets
from typing import Dict, List
from numpy.typing import NDArray
class ProjectedApertureParticleData:
"""
Halo calculation class.
Only used to obtain some basic particle properties; actual property
calculations are done by SingleProjectionProjectedApertureParticleData
objects based on this object.
"""
def __init__(
self,
input_halo: Dict,
data: Dict,
types_present: List[str],
aperture_radius: unyt.unyt_quantity,
snapshot_datasets: SnapshotDatasets,
):
"""
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.
- aperture_radius: unyt.unyt_quantity
Aperture radius.
- 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.aperture_radius = aperture_radius
self.snapshot_datasets = snapshot_datasets
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 and projection we actually want to compute.
"""
self.centre = self.input_halo["cofp"]
self.index = self.input_halo["index"]
mass = []
position = []
radius_projx = []
radius_projy = []
radius_projz = []
velocity = []
types = []
for ptype in self.types_present:
grnr = self.get_dataset(f"{ptype}/GroupNr_bound")
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)
rprojx = np.sqrt(pos[:, 1] ** 2 + pos[:, 2] ** 2)
radius_projx.append(rprojx)
rprojy = np.sqrt(pos[:, 0] ** 2 + pos[:, 2] ** 2)
radius_projy.append(rprojy)
rprojz = np.sqrt(pos[:, 0] ** 2 + pos[:, 1] ** 2)
radius_projz.append(rprojz)
velocity.append(self.get_dataset(f"{ptype}/Velocities")[in_halo, :])
typearr = int(ptype[-1]) * np.ones(rprojx.shape, dtype=np.int32)
types.append(typearr)
self.mass = np.concatenate(mass)
self.position = np.concatenate(position)
self.radius_projx = np.concatenate(radius_projx)
self.radius_projy = np.concatenate(radius_projy)
self.radius_projz = np.concatenate(radius_projz)
self.velocity = np.concatenate(velocity)
self.types = np.concatenate(types)
self.mask_projx = self.radius_projx <= self.aperture_radius
self.mask_projy = self.radius_projy <= self.aperture_radius
self.mask_projz = self.radius_projz <= self.aperture_radius
class SingleProjectionProjectedApertureParticleData:
"""
Halo calculation class for individual projections.
All properties we want to compute in apertures are implemented as lazy
methods of this class.
Note that the aperture is applied in projection, which means that there
is no restriction on the coordinates of the particles parallel to the
projection axis.
Note that this class internally uses and requires two different masks:
- *_mask_all: Mask that masks out particles belonging to this halo:
gravitationally bound particles. This mask needs to be
applied _first_ to raw "PartTypeX" datasets.
- *_mask_ap: Mask that masks out particles that are inside the projected aperture
radius. This mask can only be applied after *_mask_all has been applied.
compute_basics() of ProjectedApertureParticleData furthermore defines
some arrays that contain variables (e.g. masses, positions) for all
particles that belong to the halo (so after applying *_mask_all, but before
applying *_mask_ap). To retrieve the variables for a single particle type,
these have to be masked with "PartTypeX == 'type'".
All of these masks have different lengths, so using the wrong mask will
lead to errors. Those are captured by the unit tests, so make sure to run
those after you implement a new property!
"""
def __init__(self, part_props: ProjectedApertureParticleData, projection: str):
"""
Constructor.
Parameters:
- part_props: ProjectedApertureParticleData
ProjectedApertureParticleData object that precomputed some quantities
for this halo.
- projection: str
Projection axis for this particular projection. Needs to be one of
"projx", "projy", "projz".
"""
self.part_props = part_props
self.index = part_props.index
self.centre = part_props.centre
self.types = part_props.types
self.aperture_radius = part_props.aperture_radius
self.iproj = {"projx": 0, "projy": 1, "projz": 2}[projection]
self.projmask = getattr(part_props, f"mask_{projection}")
self.projr = getattr(part_props, f"radius_{projection}")
self.proj_mass = part_props.mass[self.projmask]
self.proj_position = part_props.position[self.projmask]
self.proj_velocity = part_props.velocity[self.projmask]
self.proj_radius = self.projr[self.projmask]
self.proj_type = part_props.types[self.projmask]
@lazy_property
def gas_mask_ap(self) -> NDArray[bool]:
"""
Mask that filters out gas particles that are inside the aperture radius.
This mask can be used on arrays of all gas particles that are included
in the calculation (so either the raw "PartType0" array for inclusive
apertures, or only the bound particles in that array for exclusive
apertures).
"""
return self.projmask[self.types == 0]
@lazy_property
def dm_mask_ap(self) -> NDArray[bool]:
"""
Mask that filters out DM particles that are inside the aperture radius.
This mask can be used on arrays of all DM particles that are included
in the calculation (so either the raw "PartType1" array for inclusive
apertures, or only the bound particles in that array for exclusive
apertures).
"""
return self.projmask[self.types == 1]
@lazy_property
def star_mask_ap(self) -> NDArray[bool]:
"""
Mask that filters out star particles that are inside the aperture radius.
This mask can be used on arrays of all star particles that are included
in the calculation (so either the raw "PartType4" array for inclusive
apertures, or only the bound particles in that array for exclusive
apertures).
"""
return self.projmask[self.types == 4]
@lazy_property
def bh_mask_ap(self) -> NDArray[bool]:
"""
Mask that filters out BH particles that are inside the aperture radius.
This mask can be used on arrays of all BH particles that are included
in the calculation (so either the raw "PartType5" array for inclusive
apertures, or only the bound particles in that array for exclusive
apertures).
"""
return self.projmask[self.types == 5]
@lazy_property
def baryon_mask_ap(self) -> NDArray[bool]:
"""
Mask that filters out baryon particles that are inside the aperture radius.
This mask can be used on arrays of all baryon particles that are included
in the calculation. Note that baryons are gas and star particles,
so "PartType0" and "PartType4".
"""
return self.projmask[(self.types == 0) | (self.types == 4)]
@lazy_property
def Ngas(self) -> int:
"""
Number of gas particles in the aperture.
"""
return self.gas_mask_ap.sum()
@lazy_property
def Ndm(self) -> int:
"""
Number of DM particles in the aperture.
"""
return self.dm_mask_ap.sum()
@lazy_property
def Nstar(self) -> int:
"""
Number of star particles in the aperture.
"""
return self.star_mask_ap.sum()
@lazy_property
def Nbh(self) -> int:
"""
Number of BH particles in the aperture.
"""
return self.bh_mask_ap.sum()
@lazy_property
def proj_mass_gas(self) -> unyt.unyt_array:
"""
Mass of the gas particles.
"""
return self.proj_mass[self.proj_type == 0]
@lazy_property
def proj_mass_dm(self) -> unyt.unyt_array:
"""
Mass of the DM particles.
"""
return self.proj_mass[self.proj_type == 1]
@lazy_property
def proj_mass_star(self) -> unyt.unyt_array:
"""
Mass of the star particles.
"""
return self.proj_mass[self.proj_type == 4]
@lazy_property
def proj_mass_baryons(self) -> unyt.unyt_array:
"""
Mass of the baryon particles (gas + stars).
"""
return self.proj_mass[(self.proj_type == 0) | (self.proj_type == 4)]
@lazy_property
def proj_pos_gas(self) -> unyt.unyt_array:
"""
Projected position of the gas particles.
"""
return self.proj_position[self.proj_type == 0]
@lazy_property
def proj_pos_dm(self) -> unyt.unyt_array:
"""
Projected position of the DM particles.
"""
return self.proj_position[self.proj_type == 1]
@lazy_property
def proj_pos_star(self) -> unyt.unyt_array:
"""
Projected position of the star particles.
"""
return self.proj_position[self.proj_type == 4]
@lazy_property
def proj_pos_baryons(self) -> unyt.unyt_array:
"""
Projected position of the baryon (gas + stars) particles.
"""
return self.proj_position[(self.proj_type == 0) | (self.proj_type == 4)]
@lazy_property
def Mtot(self) -> unyt.unyt_quantity:
"""
Total mass of all particles.
"""
return self.proj_mass.sum()
@lazy_property
def Mgas(self) -> unyt.unyt_quantity:
"""
Total mass of gas particles.
"""
return self.proj_mass_gas.sum()
@lazy_property
def Mdm(self) -> unyt.unyt_quantity:
"""
Total mass of DM particles.
"""
return self.proj_mass_dm.sum()
@lazy_property
def Mstar(self) -> unyt.unyt_quantity:
"""
Total mass of star particles.
"""
return self.proj_mass_star.sum()
@lazy_property
def Mbh_dynamical(self) -> unyt.unyt_quantity:
"""
Total dynamical mass of BH particles.
"""
return self.proj_mass[self.proj_type == 5].sum()
@lazy_property
def Mbaryons(self) -> unyt.unyt_quantity:
"""
Total mass of baryon (gas+star) particles.
"""
return self.proj_mass_baryons.sum()
@lazy_property
def star_mask_all(self) -> NDArray[bool]:
"""
Mask for masking out star particles in raw PartType4 arrays.
This is the mask that masks out unbound particles.
"""
if self.Nstar == 0:
return None
return self.part_props.get_dataset("PartType4/GroupNr_bound") == self.index
@lazy_property
def Mstar_init(self) -> unyt.unyt_quantity:
"""
Total initial mass of star particles.
"""
if self.Nstar == 0:
return None
return self.part_props.get_dataset("PartType4/InitialMasses")[
self.star_mask_all
][self.star_mask_ap].sum()
@lazy_property
def stellar_luminosities(self) -> unyt.unyt_array:
"""
Stellar luminosities.
"""
if self.Nstar == 0:
return None
return self.part_props.get_dataset("PartType4/Luminosities")[
self.star_mask_all
][self.star_mask_ap]
@lazy_property
def StellarLuminosity(self) -> unyt.unyt_array:
"""
Total luminosity of star particles.
Note that this returns an array with total luminosities in multiple
bands.
"""
if self.Nstar == 0:
return None
return self.stellar_luminosities.sum(axis=0)
@lazy_property
def bh_mask_all(self) -> NDArray[bool]:
"""
Mask for masking out BH particles in raw PartType5 arrays.
This is the mask that masks out unbound particles.
"""
if self.Nbh == 0:
return None
return self.part_props.get_dataset("PartType5/GroupNr_bound") == self.index
@lazy_property
def BH_subgrid_masses(self) -> unyt.unyt_array:
"""
Subgrid masses of BH particles.
"""
if self.Nbh == 0:
return None
return self.part_props.get_dataset("PartType5/SubgridMasses")[self.bh_mask_all][
self.bh_mask_ap
]
@lazy_property
def Mbh_subgrid(self) -> unyt.unyt_quantity:
"""
Total subgrid mass of BH particles.
"""
if self.Nbh == 0:
return None
return self.BH_subgrid_masses.sum()
@lazy_property
def agn_eventa(self) -> unyt.unyt_array:
"""
Last AGN feedback event scale factors for BH particles.
"""
if self.Nbh == 0:
return None
return self.part_props.get_dataset("PartType5/LastAGNFeedbackScaleFactors")[
self.bh_mask_all
][self.bh_mask_ap]
@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 BlackHolesTotalInjectedThermalEnergy(self) -> unyt.unyt_quantity:
"""
Thermal energy injected into gas particles by all BH particles.
"""
if self.Nbh == 0:
return None
return np.sum(
self.part_props.get_dataset("PartType5/AGNTotalInjectedEnergies")[
self.bh_mask_all
][self.bh_mask_ap]
)
@lazy_property
def BlackHolesTotalInjectedJetEnergy(self) -> unyt.unyt_quantity:
"""
Jet energy injected into gas particles by all BH particles.
"""
if self.Nbh == 0:
return None
return np.sum(
self.part_props.get_dataset("PartType5/InjectedJetEnergies")[
self.bh_mask_all
][self.bh_mask_ap]
)
@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.part_props.get_dataset("PartType5/ParticleIDs")[self.bh_mask_all][
self.bh_mask_ap
][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.part_props.get_dataset("PartType5/Coordinates")[self.bh_mask_all][
self.bh_mask_ap
][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.part_props.get_dataset("PartType5/Velocities")[self.bh_mask_all][
self.bh_mask_ap
][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.part_props.get_dataset("PartType5/AccretionRates")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/AveragedAccretionRates")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/AGNTotalInjectedEnergies")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/AccretionModes")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/GWMassLosses")[self.bh_mask_all][
self.bh_mask_ap
][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.part_props.get_dataset("PartType5/InjectedJetEnergiesByMode")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/LastAGNJetScaleFactors")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/NumberOfAGNEvents")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/NumberOfAGNJetEvents")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/NumberOfMergers")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/RadiatedEnergiesByMode")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/TotalAccretedMassesByMode")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/WindEnergiesByMode")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/Spins")[self.bh_mask_all][
self.bh_mask_ap
][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.part_props.get_dataset("PartType5/TotalAccretedMasses")[
self.bh_mask_all
][self.bh_mask_ap][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.part_props.get_dataset("PartType5/FormationScaleFactors")[
self.bh_mask_all
][self.bh_mask_ap][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 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.proj_mass / self.Mtot
@lazy_property
def com(self) -> unyt.unyt_array:
"""
Centre of mass of all particles in the projected aperture.
"""
if self.Mtot == 0:
return None
return (self.mass_fraction[:, None] * self.proj_position).sum(
axis=0
) + self.centre
@lazy_property
def vcom(self) -> unyt.unyt_array:
"""
Centre of mass velocity of all particles in the projected aperture.
"""
if self.Mtot == 0:
return None
return (self.mass_fraction[:, None] * self.proj_velocity).sum(axis=0)
@lazy_property
def ProjectedTotalInertiaTensor(self) -> unyt.unyt_array:
"""
Inertia tensor of the total mass distribution in projection.
Computed iteratively using an ellipse with area equal to that of a circle with radius
equal to the aperture radius.
"""
if self.Mtot == 0:
return None
return get_projected_inertia_tensor(
self.part_props.mass,
self.part_props.position,
self.iproj,
self.aperture_radius,
)
@lazy_property
def ProjectedTotalInertiaTensorReduced(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the total mass distribution in projection.
Computed iteratively using an ellipse with area equal to that of a circle with radius
equal to the aperture radius.
"""
if self.Mtot == 0:
return None
return get_projected_inertia_tensor(
self.part_props.mass,
self.part_props.position,
self.iproj,
self.aperture_radius,
reduced=True,
)
@lazy_property
def ProjectedTotalInertiaTensorNoniterative(self) -> unyt.unyt_array:
"""
Inertia tensor of the total mass distribution in projection.
Computed using all bound particles within the projected aperture.
"""
if self.Mtot == 0:
return None
return get_projected_inertia_tensor(
self.proj_mass,
self.proj_position,
self.iproj,
self.aperture_radius,
max_iterations=1,
)
@lazy_property
def ProjectedTotalInertiaTensorReducedNoniterative(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the total mass distribution in projection.
Computed using all bound particles within the projected aperture.
"""
if self.Mtot == 0:
return None
return get_projected_inertia_tensor(
self.proj_mass,
self.proj_position,
self.iproj,
self.aperture_radius,
reduced=True,
max_iterations=1,
)
@lazy_property
def gas_mass_fraction(self) -> unyt.unyt_array:
"""
Fractional mass of gas particles. See the documentation of mass_fraction
for the rationale behind this.
"""
if self.Mgas == 0:
return None
return self.proj_mass_gas / self.Mgas
@lazy_property
def proj_veldisp_gas(self) -> unyt.unyt_quantity:
"""
Projected velocity dispersion of gas particles along the projection
axis. Unlike the 3D aperture counterpart, the velocity dispersion
along the projection axis is a single number.
"""
if self.Mgas == 0:
return None
proj_vgas = self.proj_velocity[self.proj_type == 0, self.iproj]
vcom_gas = (self.gas_mass_fraction * proj_vgas).sum()
return np.sqrt((self.gas_mass_fraction * (proj_vgas - vcom_gas) ** 2).sum())
def gas_inertia_tensor(self, **kwargs) -> unyt.unyt_array:
"""
Helper function for calculating projected gas inertia tensors
"""
mass = self.part_props.mass[self.part_props.types == 0]
position = self.part_props.position[self.part_props.types == 0]
return get_projected_inertia_tensor(
mass, position, self.iproj, self.aperture_radius, **kwargs
)
@lazy_property
def ProjectedGasInertiaTensor(self) -> unyt.unyt_array:
"""
Inertia tensor of the gas mass distribution in projection.
Computed iteratively using an ellipse with area equal to that of a circle with radius
equal to the aperture radius. Only considers bound particles within the projected aperture.
"""
if self.Mgas == 0:
return None
return self.gas_inertia_tensor()
@lazy_property
def ProjectedGasInertiaTensorReduced(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the gas mass distribution in projection.
Computed iteratively using an ellipse with area equal to that of a circle with radius
equal to the aperture radius. Only considers bound particles within the projected aperture.
"""
if self.Mgas == 0:
return None
return self.gas_inertia_tensor(reduced=True)
@lazy_property
def ProjectedGasInertiaTensorNoniterative(self) -> unyt.unyt_array:
"""
Inertia tensor of the gas mass distribution in projection.
Computed using all bound gas particles within the projected aperture.
"""
if self.Mgas == 0:
return None
return get_projected_inertia_tensor(
self.proj_mass_gas,
self.proj_pos_gas,
self.iproj,
self.aperture_radius,
max_iterations=1,
)
@lazy_property
def ProjectedGasInertiaTensorReducedNoniterative(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the gas mass distribution in projection.
Computed using all bound gas particles within the projected aperture.
"""
if self.Mgas == 0:
return None
return get_projected_inertia_tensor(
self.proj_mass_gas,
self.proj_pos_gas,
self.iproj,
self.aperture_radius,
reduced=True,
max_iterations=1,
)
@lazy_property
def dm_mass_fraction(self) -> unyt.unyt_array:
"""
Fractional mass of DM particles. See the documentation of mass_fraction
for the rationale behind this.
"""
if self.Mdm == 0:
return None
return self.proj_mass_dm / self.Mdm
@lazy_property
def proj_veldisp_dm(self) -> unyt.unyt_quantity:
"""
Projected velocity dispersion of DM particles along the projection
axis. Unlike the 3D aperture counterpart, the velocity dispersion
along the projection axis is a single number.
"""
if self.Mdm == 0:
return None
proj_vdm = self.proj_velocity[self.proj_type == 1, self.iproj]
vcom_dm = (self.dm_mass_fraction * proj_vdm).sum()
return np.sqrt((self.dm_mass_fraction * (proj_vdm - vcom_dm) ** 2).sum())
@lazy_property
def star_mass_fraction(self) -> unyt.unyt_array:
"""
Fractional mass of star particles. See the documentation of mass_fraction
for the rationale behind this.
"""
if self.Mstar == 0:
return None
return self.proj_mass_star / self.Mstar
@lazy_property
def proj_veldisp_star(self) -> unyt.unyt_quantity:
"""
Projected velocity dispersion of star particles along the projection
axis. Unlike the 3D aperture counterpart, the velocity dispersion
along the projection axis is a single number.
"""
if self.Mstar == 0:
return None
proj_vstar = self.proj_velocity[self.proj_type == 4, self.iproj]
vcom_star = (self.star_mass_fraction * proj_vstar).sum()
return np.sqrt((self.star_mass_fraction * (proj_vstar - vcom_star) ** 2).sum())
def stellar_inertia_tensor(self, **kwargs) -> unyt.unyt_array:
"""
Helper function for calculating projected stellar inertia tensors
"""
mass = self.part_props.mass[self.part_props.types == 4]
position = self.part_props.position[self.part_props.types == 4]
return get_projected_inertia_tensor(
mass, position, self.iproj, self.aperture_radius, **kwargs
)
@lazy_property
def ProjectedStellarInertiaTensor(self) -> unyt.unyt_array:
"""
Inertia tensor of the stellar mass distribution in projection.
Computed iteratively using an ellipse with area equal to that of a circle with radius
equal to the aperture radius. Only considers bound particles within the projected aperture.
"""
if self.Mstar == 0:
return None
return self.stellar_inertia_tensor()
@lazy_property
def ProjectedStellarInertiaTensorReduced(self) -> unyt.unyt_array:
"""
Reduced inertia tensor of the stellar mass distribution in projection.
Computed iteratively using an ellipse with area equal to that of a circle with radius
equal to the aperture radius. Only considers bound particles within the projected aperture.
"""
if self.Mstar == 0:
return None
return self.stellar_inertia_tensor(reduced=True)
@lazy_property
def ProjectedStellarInertiaTensorNoniterative(self) -> unyt.unyt_array:
"""
Inertia tensor of the stellar mass distribution in projection.