Skip to content

Commit 663350e

Browse files
committed
swap orient_stars with orient_component, takes a string now.
valid options are star(s), gas, young_star(s), and cold_gas. extraction now defaults to cold_gas w/i 0.1 rvir
1 parent 7f92471 commit 663350e

2 files changed

Lines changed: 54 additions & 52 deletions

File tree

src/abg_python/galaxy/cosmoExtractor.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def getThetasTaitBryan(angMom):
3232
## RETURNS DEGREES
3333
return theta_TB,phi_TB
3434

35-
def offsetRotateSnapshot(snap,scom,vscom,theta_TB,phi_TB,orient_stars):
35+
def offsetRotateSnapshot(snap,scom,vscom,theta_TB,phi_TB,orient_component):
3636

3737
if 'overwritten' in snap and snap['overwritten']:
3838
if (snap['theta_TB'] == theta_TB and
@@ -61,7 +61,7 @@ def offsetRotateSnapshot(snap,scom,vscom,theta_TB,phi_TB,orient_stars):
6161
'theta_TB':theta_TB,
6262
'phi_TB':phi_TB,
6363
'overwritten':1,
64-
'orient_stars':orient_stars}
64+
'orient_component':orient_component}
6565

6666
## if the snap is already overwritten this info is in there
6767
if 'scom' not in snap:
@@ -102,7 +102,7 @@ def extractDiskFromSnapdicts(
102102
orient_radius,
103103
scom=None,
104104
dark_snap=None,
105-
orient_stars=0,
105+
orient_component='cold_gas',
106106
force_theta_TB=None,
107107
force_phi_TB=None,
108108
loud=True):
@@ -133,7 +133,7 @@ def extractDiskFromSnapdicts(
133133
snap,
134134
orient_radius,
135135
scom=scom,
136-
orient_stars=orient_stars,
136+
orient_component=orient_component,
137137
force_theta_TB=force_theta_TB,
138138
force_phi_TB=force_phi_TB)
139139
if loud: print("Done.")
@@ -144,7 +144,7 @@ def extractDiskFromSnapdicts(
144144
this_snap,
145145
scom,vscom,
146146
theta_TB,phi_TB,
147-
orient_stars)
147+
orient_component)
148148

149149
## dictionary to add to extracted snapshot
150150
add_to_dict = {
@@ -166,10 +166,10 @@ def extractDiskFromSnapdicts(
166166

167167
def orientDiskFromSnapdicts(
168168
star_snap,
169-
snap,
169+
gas_snap,
170170
radius,
171171
scom,
172-
orient_stars=0,
172+
orient_component='cold_gas',
173173
force_theta_TB=None,
174174
force_phi_TB=None):
175175
""" Takes arrays from a snapshot and returns orientation.
@@ -179,23 +179,27 @@ def orientDiskFromSnapdicts(
179179
radius - radius to extract particles from
180180
"""
181181

182-
if orient_stars:
183-
if star_snap is None:
184-
raise ValueError("Can't orient on stars if stars are not passed")
185-
186-
these_rs = star_snap['Coordinates']
187-
these_vs = star_snap['Velocities']
188-
these_masses = star_snap['Masses']
189-
else:
190-
if snap is None:
191-
raise ValueError("Can't orient on gas if gas is not passed")
192-
193-
these_rs = snap['Coordinates']
194-
these_vs = snap['Velocities']
195-
these_masses = snap['Masses']
196-
197-
mask = sphericalVolumeMask(
198-
these_rs,radius,scom)
182+
if 'star' in orient_component: which_snap = star_snap
183+
elif 'gas' in orient_component: which_snap = gas_snap
184+
else: raise KeyError(
185+
f"Can't understand orient_component:{orient_component}")
186+
187+
these_rs = which_snap['Coordinates']
188+
these_vs = which_snap['Velocities']
189+
these_masses = which_snap['Masses']
190+
191+
mask = sphericalVolumeMask(these_rs,radius,scom)
192+
193+
if '_' in orient_component:
194+
## hardcode in my definition of "cold", 1e3 K
195+
if orient_component == 'cold_gas':
196+
mask = np.logical_and(mask,which_snap['Temperature']<1e3)
197+
## hardcode in my definition of "young", 25 Myr
198+
elif orient_component in ['young_star','young_stars']:
199+
mask = np.logical_and(mask,which_snap['AgeGyr']<0.025)
200+
## catch for everything else
201+
else: raise NotImplementedError(
202+
f"Orient component {orient_component} is not implemented.")
199203

200204
if not np.sum(mask):
201205
print(scom,radius)

src/abg_python/galaxy/gal_utils.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def saveHeaderToCatalog(
809809
def extractMainHalo(
810810
self,
811811
save_meta=False,
812-
orient_stars=True, ## which angular momentum axis to orient along
812+
orient_component='cold_gas', ## which angular momentum axis to orient along
813813
overwrite_full_snaps_with_rotated_versions=False,
814814
free_mem=True, ## delete the full snapshot from RAM
815815
extract_DM=True, ## do we want the DM particles?
@@ -828,15 +828,12 @@ def extractMainHalo(
828828
force_phi_TB = None -- force orientation
829829
"""
830830

831-
if orient_stars:
832-
group_name = 'star_extract'
833-
else:
834-
group_name = 'gas_extract'
831+
group_name = f"{orient_component}_extract"
835832

836833
@metadata_cache(
837834
group_name,
838835
['sub_radius',
839-
'orient_stars',
836+
'orient_component',
840837
'theta_TB',
841838
'phi_TB',
842839
'rvir',
@@ -847,7 +844,7 @@ def extractMainHalo(
847844
loud=loud)
848845
def extract_halo_inner(
849846
self,
850-
orient_stars=True,
847+
orient_component='cold_gas',
851848
radius=None,
852849
use_saved_subsnapshots=True,
853850
force=False,
@@ -863,19 +860,20 @@ def extract_halo_inner(
863860
self.star_snap['Masses'],
864861
n=4)
865862

866-
if radius is None:
867-
radius = self.rvir ## radius of the sub-snapshot
863+
## calculate the stellar half-mass radius to have--
864+
## some analyses require 5rstar_half
865+
if self.rstar_half is None: self.get_rstar_half(
866+
save_meta=save_meta,
867+
force_from_file=True,
868+
loud=False,
869+
within_radius=0.2*self.rvir)
868870

869-
## manually calcualte rstar half using the star particles
870-
## rather than relying on the output of AHF
871-
if self.rstar_half is None: self.get_rstar_half(
872-
save_meta=save_meta,
873-
force_from_file=True,
874-
loud=False)
871+
if radius is None: radius = self.rvir ## radius of the sub-snapshot
875872

876-
## radius to calculate angular momentum
877-
## to orient on
878-
orient_radius = 5*self.rstar_half
873+
## radius to calculate angular momentum to orient on
874+
#orient_radius = 5*self.rstar_half
875+
## switched on 1/16/2023 for paper 3, also orient on cold_gas
876+
orient_radius = 0.1 * self.rvir
879877

880878
## if this is not the first time extract_halo_inner has been
881879
## called these properties may or may not exist
@@ -1005,7 +1003,7 @@ def extract_halo_inner(
10051003
orient_radius, ## radius to orient on
10061004
scom=self.scom,
10071005
dark_snap=which_dark_snap, ## dark_snap = None will ignore dark matter particles
1008-
orient_stars=orient_stars,
1006+
orient_component=orient_component,
10091007
force_theta_TB=force_theta_TB,
10101008
force_phi_TB=force_phi_TB,
10111009
loud=loud)
@@ -1022,7 +1020,7 @@ def extract_halo_inner(
10221020
self.sub_radius = orient_radius
10231021
## denote whether the most recent extraction was
10241022
## oriented on stars or gas
1025-
self.orient_stars = orient_stars
1023+
self.orient_component = orient_component
10261024

10271025
if compute_stellar_hsml and 'SmoothingLength' not in self.sub_star_snap:
10281026
already_saved=False
@@ -1042,7 +1040,7 @@ def extract_halo_inner(
10421040

10431041

10441042
return (self.sub_radius,
1045-
self.orient_stars,
1043+
self.orient_component,
10461044
self.sub_snap['theta_TB'],
10471045
self.sub_snap['phi_TB'],
10481046
self.rvir,
@@ -1051,7 +1049,7 @@ def extract_halo_inner(
10511049

10521050
return_value = extract_halo_inner(
10531051
self,
1054-
orient_stars=orient_stars,
1052+
orient_component=orient_component,
10551053
**kwargs)
10561054

10571055
## this should happen by default when you do an extraction but if you are
@@ -1103,10 +1101,10 @@ def get_rstar_half(self,
11031101
loud=loud,
11041102
assert_cached=assert_cached,
11051103
force_from_file=force_from_file)
1106-
def compute_rstar_half(self):
1104+
def compute_rstar_half(self,within_radius=None):
11071105
self.load_stars()
1108-
return self.calculate_half_mass_radius(),
1109-
return compute_rstar_half(self)
1106+
return self.calculate_half_mass_radius(within_radius=within_radius),
1107+
return compute_rstar_half(self,**kwargs)
11101108

11111109
def get_HSML(
11121110
self,
@@ -1266,10 +1264,10 @@ def overwrite_full_snaps_with_rotated_versions(self,extract_DM):
12661264
snaps += [self.dark_snap]
12671265

12681266
## get the extraction parameters
1269-
theta_TB,phi_TB,scom,vscom,orient_stars = (
1267+
theta_TB,phi_TB,scom,vscom,orient_component = (
12701268
self.sub_snap['theta_TB'],self.sub_snap['phi_TB'],
12711269
self.sub_snap['scom'],self.sub_snap['vscom'],
1272-
self.sub_snap['orient_stars'])
1270+
self.sub_snap['orient_component'])
12731271

12741272
## if snaps doesn't have dark snap then zipped will stop at [0,4]
12751273
for ptype,snap in zip([0,4,1],snaps):
@@ -1279,7 +1277,7 @@ def overwrite_full_snaps_with_rotated_versions(self,extract_DM):
12791277
snap,
12801278
scom,vscom,
12811279
theta_TB,phi_TB,
1282-
orient_stars)
1280+
orient_component)
12831281

12841282
## snapdict holds ptype -> "snap"/"star_snap"/"dark_snap"
12851283
setattr(self,snap_dict[ptype],snap)

0 commit comments

Comments
 (0)