def mass_gradient(r, rho, autoDebug=True): if autoDebug: sam.type_check(r, sam.TYPES_numbers, 'r') sam.type_check(rho, sam.TYPES_numbers, 'rho') dMdr = 4 * np.pi * r**2 * rho return dMdr
def blackbody_fit(wavelengths, emissivity, tempRange=(100, 6500), step=5, rtype="dict", autoDebug=False): #Error Checking if autoDebug == True: sam.type_check(wavelengths, np.ndarray, 'wavelengths') sam.type_check(emissivity, np.ndarray, 'emissivity') sam.value_check(emissivity.shape, (wavelengths.shape, ), 'discrete', 'emissivity') sam.type_check(tempRange, (tuple, list, np.ndarray), 'tempRange') sam.value_check(len(tempRange), (1), 'f', "tempRange") sam.type_check(step, (float, int), 'step') if len(tempRange) <= 2: sam.value_check(step, (tempRange[-1] - tempRange[0]) / 2, 'g', "tempRange") sam.type_check(rtype, str, 'rtype') sam.value_check( rtype, [0, "tuple", "t", "list", 1, "dict", "dictionary", "d"], "d", "rtype") try: #Checking for normalization if np.max(emissivity) > 1.0: emissivity = emissivity / np.max(emissivity) if len(tempRange) == 2: tempRange = range(tempRange[0], tempRange[1], step) RMS = np.zeros(len(tempRange)) for index, temp in enumerate(tempRange): bb = sam.astro.blackbody(T=temp, ranges=wavelengths, normalize=True) rms = sam.sig_proc.rms2(bb, emissivity) RMS[index] = rms bestFitTemp = tempRange[np.argmin(RMS)] bestBlackbody = sam.astro.blackbody(T=bestFitTemp, ranges=wavelengths) if rtype in [0, "tuple", "t", "list"]: return wavelengths, emissivity, bestBlackbody, np.asarray( RMS), bestFitTemp if rtype in [1, "dict", "dictionary", "d"]: return { "wavelengths": wavelengths, "emissivity": emissivity, "bestBlackbody": bestBlackbody, "rms": np.asarray(RMS), "bestFitTemp": bestFitTemp } except Exception as e: sam.debug(e)
def gas_pressure2(T, P, autoDebug=True): """ calculcates gas pressure by subtracting radiation pressure from total pressure in star """ if autoDebug: sam.type_check(T, sam.TYPES_numbers, 'T') sam.type_check(P, sam.TYPES_numbers, 'P') Pg = P - (sam.CONSTANT_third * sam.CONSTANT_a * T**4) return Pg
def luminosity(r,T,autoDebug=True): """ calculates the luminosity based off of the Stefan-Boltzmann law :inputs: r [np.ndarray,int,float] -- radius or radii of star T [np.ndarray,int,float] -- effective temperature or effective temperatures :returns: L [np.ndarray,float] -- effective luminosity or luminosities """ #-----------BEGIN ERROR CHECKING---------- if autoDebug: sam.type_check(r, sam.TYPES_math, "r") sam.type_check(T, sam.TYPES_math, "T") sam.value_check(r,.0,">","r") sam.value_check(T,.0,">","T") #-----------END ERROR CHECKING---------- L = 4 * sam.CONSTANT_pi * r**2 * sam.CONSTANT_SB* T**4 return L
def luminosity_gradient(r, rho, epsilon, autoDebug=True): if autoDebug: sam.type_check(r, sam.TYPES_numbers, 'r') sam.type_check(rho, sam.TYPES_numbers, 'rho') sam.type_check(epsilon, sam.TYPES_numbers, 'epsilon') dLdr = sam.CONSTANT_4pi * r**2 * rho * epsilon return dLdr
def pressure_gradient(r, rho, Mr, autoDebug=True): if autoDebug: sam.type_check(r, sam.TYPES_numbers, 'r') sam.type_check(rho, sam.TYPES_numbers, 'rho') sam.type_check(Mr, sam.TYPES_numbers, 'Mr') dPdr = (-sam.CONSTANT_G * Mr * rho) / (r**2) return dPdr
def rho(T, P, mu, autoDebug=True): if autoDebug: sam.type_check(T, sam.TYPES_numbers, 'T') sam.type_check(P, sam.TYPES_numbers, 'P') sam.type_check(mu, sam.TYPES_numbers, 'mu') Pg = gas_pressure2(T, P) rho = (Pg * mu * sam.CONSTANT_mh) / (sam.CONSTANT_k * T) return rho
def temperature_gradient_adiabatic(r, gamma, mu, Mr, autoDebug=True): if autoDebug: sam.type_check(r, sam.TYPES_numbers, 'gamma') sam.type_check(mu, sam.TYPES_numbers, 'mu') sam.type_check(Mr, sam.TYPES_numbers, 'Mr') mh = sam.CONSTANT_mh k = sam.CONSTANT_k G = sam.CONSTANT_G adiabaticGrad = -1 * (1 - 1 / gamma) * (mu * mh) / k * (G * Mr) / (r**2) return adiabaticGrad