def main(): @dispatch @predicate(lambda x: x >= 0) @refine(Out=lambda res: res >= 0) def abs(x: int): return x @dispatch @predicate(lambda x: x < 0) @refine(Out=lambda res: res >= 0) def abs(x: int): return -x assert abs(10) == 10 assert abs(-10) == 10 assert (-10 | e / abs) == 10 assert when(lambda s: s | case(lambda: False) >> value(1) | case(lambda: False) >> value(2) | otherwise >> value(3)) == 3 assert when( "abc", lambda s: s | value("Hello") >> value(1) | value("abc") >> value(2) | otherwise >> value(3)) == 2
def __init__(self, z, name, position, LIR, cosmo=const.riechers2011, fee=value(0.0, 1e-10), sil=0.0, fagn=None): self.add_basics(z, name, position, LIR, cosmo=const.riechers2011) self.cubes = [] self.z = z # valiur + uncertainity self.position = position self.name = name self.scale = ut.CC_dl.main(z.value, const.riechers2011, wantscale=True) self.DL = ut.CC_dl.main( z.value, cosmo) * const.Mpc_to_kpc * const.kpc_to_m * const.m_to_cm self.LIR = LIR * (1.0 - fee.value) self.LIR_to_SFR = 1e-10 self.fee = fee self.sil = sil self.fagn = fagn self.LIR_SFR = self.LIR * (1.0 - self.fagn.value) self.LIR_AGN = self.LIR * (self.fagn.value)
def calc_Mdyn(self, vel, radius, vel_circ=False): # can pass it either the FWHM velocity or the circular velocity, radius should be kpc ' vel_fwhm, radius' self.vcirc = vel if not vel_circ: self.vcirc.mult(1/(2 * (np.log(2))**0.5)) self.Mdyn = value() self.Mdyn.value = (self.vcirc.value *1e3)**2 * radius.value * const.kpc_to_m / const.G_si /const.Msun_to_kg self.Mdyn.error = self.Mdyn.value * ((2 * self.vcirc.frac)**2 + radius.frac**2)**0.5 self.Mdyn.unit = 'Msun'
def simplify(s) -> "permutaram": q = [ac.simplify() for ac in s.q] s = s._copywithparam(*q).deeplevel() q = s.q evy = [ac for ac in q if ac.evaluable()] evn = [ac for ac in q if not ac.evaluable()] if len(evy) > 1: zx = s._copywithparam(*evy) evn.append(value(zx.eval())) if len(evn) == 1: return evn[0] ret = s._copywithparam(*evn) if ret.evaluable(): return value(ret.eval()) return ret.deeplevel() else: ret = s._copywithparam(*q) if ret.evaluable(): return value(ret.eval()) return ret.deeplevel()
def diff(s,by)->"fobj": if by==s.q: return value(1.0) else: return value(0.0)
def huntident(s) -> "fobj": if len(s.q) == 0: return value(0.0) if len(s.q) == 1: return s.q[0].huntident() return s._copywithparam(*[ac.huntident() for ac in s.q])
def dust_props(self, nu_obs, flux, semiMaj, semiMin, Td=25, listem=False): # all the dust observations should be from " The function expects the continuum flux, the size of the source, the dust temperature : alternative functionality will include fitting an image cube with the flux" self.FluxDust = flux self.semiMaj_arcsec = semiMaj self.semiMin_arcsec = semiMin self.semiMaj_kpc = deepcopy(semiMaj) self.semiMin_kpc = deepcopy(semiMin) self.semiMaj_kpc.mult(self.scale, unit='kpc') self.semiMin_kpc.mult(self.scale, unit='kpc') self.Td = Td # this is the most recent calculation Td - the one that was used to calculate the dust mass self.Mism = value() self.Mism.value = fd.Mism( nu_obs=nu_obs, Snu=self.FluxDust.value, Td=self.Td, z=self.z.value) ## need to propagate error here. self.Mism.error = fd.Mism( nu_obs=nu_obs, Snu=self.FluxDust.error, Td=self.Td, z=self.z.value) ## need to propagate error here. print('Mism-error not propagated yet - dont trust it.') self.area = value() self.area.value = np.pi * self.semiMaj_kpc.value * self.semiMin_kpc.value / ( 4 * np.log10(2)) self.area.error = self.area.value * (self.semiMaj_kpc.frac**2 + self.semiMin_kpc.frac**2)**0.5 self.radDust = value() self.radDust.value = np.sqrt(self.area.value / np.pi) self.radDust.error = self.area.error / (2 * np.pi * self.radDust.value) self.sf_density = value() self.sf_density.value = self.LIR * self.LIR_to_SFR / self.area.value self.sf_density.error = self.sf_density.value * (self.area.error / self.area.value) self.sf_density.unit = 'Msun/yr/kpc^2' if listem: print "Flux density (mJy): ", np.round(self.FluxDust.value, 2), '+/-', np.round( self.FluxDust.error, 2) print "size (arcs): ", np.round( self.semiMaj_arcsec.value, 2), '+/-', np.round(self.semiMaj_arcsec.error, 2), np.round( self.semiMin_arcsec.value, 2), '+/-', np.round(self.semiMin_arcsec.error, 2) print "size (kpc) : ", np.round( self.semiMaj_kpc.value, 2), '+/-', np.round( self.semiMaj_kpc.error, 2), np.round(self.semiMin_kpc.value, 2), '+/-', np.round(self.semiMin_kpc.error, 2) #print "Radius (kpc) : ", np.round(self.radDust.value,2), '+/-',np.round(self.radDust.error, 2) print "Td (K): ", np.round(self.Td, 2) print "Area (kpc^2): ", np.round(self.area.value, 2), '+/-', np.round( self.area.error, 2) print "Mism (Msun): ", np.round(self.Mism.value, 2), '+/-', np.round( self.Mism.error, 2) print "sf density (Msun/yr/kpc^{2}): ", np.round( self.sf_density.value, 2), '+/-', np.round(self.sf_density.error, 2)