[galaxy] deal with simulation without epoch field
This commit is contained in:
@@ -133,23 +133,29 @@ def ring_analysis(pp, r=4, dr=0.5, dphi=0.125, z=0, dz=0.5, do_mean=True):
|
|||||||
|
|
||||||
def get_time_from_relax(pp):
|
def get_time_from_relax(pp):
|
||||||
pp.load_parts()
|
pp.load_parts()
|
||||||
epoch = pp.parts["epoch"].copy()
|
try:
|
||||||
epoch *= pp.info["unit_time"].express(U.Myr)
|
epoch = pp.parts["epoch"].copy()
|
||||||
trelax = np.min(epoch[epoch > 0])
|
epoch *= pp.info["unit_time"].express(U.Myr)
|
||||||
tfromrelax = np.max(epoch - trelax)
|
trelax = np.min(epoch[epoch > 0])
|
||||||
|
tfromrelax = np.max(epoch - trelax)
|
||||||
|
except KeyError:
|
||||||
|
tfromrelax = 0.0
|
||||||
return tfromrelax
|
return tfromrelax
|
||||||
|
|
||||||
|
|
||||||
def get_last_sfr(pp):
|
def get_last_sfr(pp):
|
||||||
pp.load_parts()
|
pp.load_parts()
|
||||||
epoch = pp.parts["epoch"].copy()
|
try:
|
||||||
epoch *= pp.info["unit_time"].express(U.year)
|
epoch = pp.parts["epoch"].copy()
|
||||||
mass = pp.parts["mass"].copy()
|
epoch *= pp.info["unit_time"].express(U.year)
|
||||||
mass *= pp.info["unit_mass"].express(U.Msun)
|
mass = pp.parts["mass"].copy()
|
||||||
mask = epoch > 0
|
mass *= pp.info["unit_mass"].express(U.Msun)
|
||||||
masstot, time = np.histogram(epoch[mask], weights=mass[mask], bins=100)
|
mask = epoch > 0
|
||||||
dtime = np.diff(time)
|
masstot, time = np.histogram(epoch[mask], weights=mass[mask], bins=100)
|
||||||
sfr = masstot[-1] / dtime[-1]
|
dtime = np.diff(time)
|
||||||
|
sfr = masstot[-1] / dtime[-1]
|
||||||
|
except KeyError:
|
||||||
|
sfr = 0.0
|
||||||
return sfr
|
return sfr
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user