Guest User

Untitled

a guest
Jun 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import numpy as np
  2. try: # numba will provide a ~2x speedup
  3. from numba import jit
  4. except ImportError: # but we can do without it
  5. jit = lambda fn: fn
  6.  
  7. @jit
  8. def massTorres(teff, erteff, logg, erlogg, feh, erfeh,
  9. ntrials=10000, corrected=True, add_intrinsic=True):
  10. """
  11. Calculate stellar mass using the Torres et al. (2010) callibration.
  12.  
  13. Parameters
  14. ----------
  15. teff, erteff : floats
  16. Effective temperature and associated uncertainty.
  17. logg, erlogg : floats
  18. Surface gravity and associated uncertainty.
  19. feh, erfeh : floats
  20. Metallicity [Fe/H] and associated uncertainty.
  21. ntrials : int, optional
  22. Number of Monte Carlo trials for the uncertainty calculation.
  23. corrected : bool, optional
  24. Correct the mass for the offset relative to isochrone-derived masses.
  25. add_intrinsic : bool, optional
  26. Add (quadratically) the intrinsic error of the calibration
  27. (0.027 in log mass).
  28.  
  29. Returns
  30. -------
  31. meanMass, sigMass : floats
  32. Estimate for the stellar mass and associated uncertainty.
  33. """
  34.  
  35. randomteff = teff + erteff * np.random.randn(ntrials)
  36. randomlogg = logg + erlogg * np.random.randn(ntrials)
  37. randomfeh = feh + erfeh * np.random.randn(ntrials)
  38.  
  39. # Parameters for the Torres calibration
  40. a1 = 1.5689
  41. a2 = 1.3787
  42. a3 = 0.4243
  43. a4 = 1.139
  44. a5 = -0.1425
  45. a6 = 0.01969
  46. a7 = 0.1010
  47.  
  48. X = np.log10(randomteff) - 4.1
  49.  
  50. logMass = a1 + a2*X + a3*X**2 + a4*X**3 + a5*randomlogg**2 \
  51. + a6*randomlogg**3 + a7*randomfeh
  52.  
  53. meanlogMass = np.mean(logMass)
  54. siglogMass = np.sum((logMass - meanlogMass)**2) / (ntrials - 1)
  55. if add_intrinsic:
  56. siglogMass = np.sqrt(0.027*0.027 + siglogMass)
  57.  
  58. meanMass = 10**meanlogMass
  59. sigMass = 10**(meanlogMass + siglogMass) - meanMass
  60.  
  61. if corrected:
  62. # correction comes from Santos+(2013), the SWEET-Cat paper
  63. corrected_meanMass = 0.791 * meanMass**2 - 0.575 * meanMass + 0.701
  64. return corrected_meanMass, sigMass
  65. else:
  66. return meanMass, sigMass
Add Comment
Please, Sign In to add comment