def random_ebv(tau: float = 0.67, r_v: float = 2.3): # Set up range of x x = np.arange(0, 2, 0.01) # Get curve of PDF. a_exp = st.exponential(x=x, a=0.99, c=r_v / tau, d=0) # Get random E(B-V) value from PDF. ebv = st.value_from_pdf(x, a_exp) return ebv
def random_x1(mu: float = 0.604, sigma_minus: float = 1.029, sigma_plus: float = 0.363): """ Generate a Type Ia supernova SALT2 x1 (stretch) value, using an asymmetric Gaussian distribution, per Scolnic et al, 2016, ApJ 822, L35. Defaults are from PS1 distribution, same paper. :param mu: Mean of the distribution. :param sigma_minus: Sigma of the negative side of the distribution. :param sigma_plus: Sigma of the positive side of the distribution. :return: x1: float """ # Set up range of x x = np.arange(-5, 4, 0.01) # Get curve of PDF. a_gauss = st.asymmetric_gaussian(x=x, mu=mu, sigma_minus=sigma_minus, sigma_plus=sigma_plus) # Get random x1 value from PDF. x1 = st.value_from_pdf(x, a_gauss / max(a_gauss)) return x1
def random_position(image: fits.HDUList, hg_ra: float, hg_dec: float, limit: int = 10, show: bool = False): image, path = ff.path_or_hdu(image) header = image[0].header data = image[0].data # Find host galaxy pixel wcs_info = wcs.WCS(header) hg_x, hg_y = wcs_info.all_world2pix(hg_ra, hg_dec, 0) hg_x = int(np.round(hg_x)) hg_y = int(np.round(hg_y)) image_copy = data.copy()[hg_y - limit:hg_y + limit, hg_x - limit:hg_x + limit] noise = np.median(image_copy) image_copy = image_copy - noise image_flatten = image_copy.flatten(1) i = st.value_from_pdf(np.arange(image_flatten.shape[0]), image_flatten / max(image_flatten)) i = int(i) x, y = np.unravel_index(i, image_copy.shape) if show: plt.imshow(image_copy) plt.scatter(x, y) plt.show() plt.close() plt.plot(image_flatten / max(image_flatten)) plt.show() x += hg_x - limit + np.random.uniform(-0.5, 0.5) y += hg_y - limit + np.random.uniform(-0.5, 0.5) ra, dec = wcs_info.all_pix2world(x, y, 0) if path: image.close() return x, y, ra, dec