[galaxy] use right array to filter in z

This commit is contained in:
Noe Brucy
2021-05-24 16:00:41 +02:00
parent ce5cefa125
commit 6558925b2c
+9 -5
View File
@@ -82,7 +82,7 @@ def extract_polar_region(dset, r=4, dr=0.5, phi=0, dphi=0.125, z=0, dz=0.5):
mask_box = ( mask_box = (
(np.abs(dset["r"] - r) < dr) (np.abs(dset["r"] - r) < dr)
& (np.abs(dset["phi"] - phi) < dphi) & (np.abs(dset["phi"] - phi) < dphi)
& (np.abs(dset["pos"][:, 2] - z) < dz) & (np.abs(dset["pos_kpc"][:, 2] - z) < dz)
) )
return {key: dset[key][mask_box] for key in dset} return {key: dset[key][mask_box] for key in dset}
@@ -143,14 +143,18 @@ def get_time_from_relax(pp):
return tfromrelax return tfromrelax
def get_last_sfr(pp, r=4, dr=0.5): def get_last_sfr(pp, r=4, dr=0.5, z=0, dz=0.5):
pp.load_parts() pp.load_parts()
try: try:
epoch = pp.parts["epoch"].copy() epoch = pp.stars["epoch"].copy()
epoch *= pp.info["unit_time"].express(U.year) epoch *= pp.info["unit_time"].express(U.year)
mass = pp.parts["mass"].copy() mass = pp.stars["mass"].copy()
mass *= pp.info["unit_mass"].express(U.Msun) mass *= pp.info["unit_mass"].express(U.Msun)
mask = (epoch > 0) & (np.abs(pp.parts["r"] - r) < dr) mask = (
(epoch > 0)
& (np.abs(pp.stars["r"] - r) < dr)
& (np.abs(pp.stars["pos_kpc"][:, 2] - z) < dz)
)
masstot, time = np.histogram(epoch[mask], weights=mass[mask], bins=100) masstot, time = np.histogram(epoch[mask], weights=mass[mask], bins=100)
dtime = np.diff(time) dtime = np.diff(time)
sfr = masstot[-1] / dtime[-1] sfr = masstot[-1] / dtime[-1]