def computemag(z, l, limb, L, tau, omega, inc, M, Z, av, bands): # array of magnitudes shape = tuple((len(omega), len(inc), len(M), len(bands), len(av))) # use a less memory intensive data type result = np.full(shape, np.nan, dtype=np.float32) for m in np.arange(len(M)): for o in np.arange(len(omega)): try: # pre-calculate inclination-independent quantities st = star.Star(omega[o], L[l], M[m], 1, ut.D10, 100, ld=limb) for i in np.arange(len(inc)): # calculate the magnitudes at this inclination; # these should be a 1D array, corresponding to bands and reddenings as follows: # (b0, av0), (b0, av1), ..., (b0, avm), (b1, av0), ..., (bn, avm) mags = st.integrate(inc[i]) result[o, i, m, :, :] = mags.reshape(len(bands), len(av)) except mp.InterpolationError as err: pass print('.', end='', flush=True) return result
k = (4 * math.pi * ut.sigma * ut.G * ut.Msun / (g * ut.Lsun))**(7. / 5) # the stars' luminosities in solar luminosities L = k * temp**m # the stars' masses in solar masses M = L**(2. / 7) # radii of the stars in solar radii R = L**(1. / 7) * np.sqrt(ut.G * ut.Msun / g) / ut.Rsun print('Non-rotating stars') print('Temperatures in Kelvin ' + str(temp)) print('Luminosities in solar luminosities ' + str(L)) print('Masses in solar masses ' + str(M)) print('Radii in solar radii ' + str(R)) # stars with linear temperature interpolaion and full limb darkening information stars = [st.Star(omega, l, m, r, ut.D10, n, ld=ld) for l, m, r in zip(L, M, R)] # the light from such stars light = np.array([s.integrate(inclination) for s in stars]) # remove the limb darkening information at the gravity of the stars ind_g = np.searchsorted(ld.g, logg) print('Gravity removed from intensity information: ' + str(ld.g[ind_g]) + \ '. \nThese should be the same as the star gravity.') print('Gravities between which we are interpolating: ' + str(ld.g[ind_g - 1]) +\ ' and ' + str(ld.g[ind_g + 1]) ) ld.fit_params = np.delete(ld.fit_params, ind_g, axis=1) ld.g = np.delete(ld.g, ind_g) # stars with missing limb darkening information and log gravity interpolation stars = [st.Star(omega, l, m, r, ut.D10, n, ld=ld) for l, m, r in zip(L, M, R)] # the light from such stars
ld = pickle.load(f) iV = ld.bands.index('V') iB = ld.bands.index('B') # star parameters omega, luminosity, mass, Req, distance = [ 0.6151, 40.346, 2.165, 2.815, 2.3694e19 ] # vega n_z = 100 incs = np.arccos(np.linspace(1, 0, 50)) # inclinations, equally spaced in cos(i) # the observed inclination and record the index iobs = 0.08683 # create star star = st.Star(omega, luminosity, mass, Req, distance, n_z, ld) # compute its magnitudes at both filters at all inclinations V = [] B = [] for i in incs: mags = star.integrate(i) V.append(mags[iV]) B.append(mags[iB]) V = np.array(V) B = np.array(B) # colors color = B - V # compute the observed values mags = star.integrate(iobs) Vobs = mags[iV] Bobs = mags[iB]
k = (4 * math.pi * ut.sigma * ut.G * ut.Msun / (g * ut.Lsun))**(7. / 5) # the stars' luminosities in solar luminosities L = k * temp**m # the stars' masses in solar masses M = L**(2. / 7) # radii of the stars in solar radii R = L**(1. / 7) * np.sqrt(ut.G * ut.Msun / g) / ut.Rsun print('Non-rotating stars') print('Temperatures in Kelvin ' + str(temp)) print('Luminosities in solar luminosities ' + str(L)) print('Masses in solar masses ' + str(M)) print('Radii in solar radii ' + str(R)) # stars with linear temperature interpolaion and full limb darkening information stars = [st.Star(omega, l, m, r, ut.D10, n, ld=ld) for l, m, r in zip(L, M, R)] # the light from such stars light = np.array([s.integrate(inclination) for s in stars]) # remove the limb darkening information at the temperatures of the stars ind_temp = np.searchsorted(ld.T, temp) print('Temperatures removed from intensity information: ' + str(ld.T[ind_temp]) + \ '. \n\t These should be the same as the star temperatures.') print('Temperatures between we are interpolating: ' + str(ld.T[ind_temp - 1]) +\ ' and ' + str(ld.T[ind_temp + 1]) ) ld.fit_params = np.delete(ld.fit_params, ind_temp, axis=0) ld.T = np.delete(ld.T, ind_temp) # stars with linear temperature interpolaion and missing limb darkening information stars = [ st.Star(omega, l, m, r, ut.D10, n, ld=ld, temp_method='linear')
Req = np.float(line.split()[-1]) elif 'inclination' in line: inclination = np.float(line.split()[-1]) if 'z values' in line: nz = np.int(line.split()[-1]) f.close() # the wavelengths and the synthetic spectrum wl_syn, I_syn = np.loadtxt(iodir + 'data/vega/vega0_088418.txt').T m = wl_syn < w wl_syn = wl_syn[m] I_syn = I_syn[m] # a star without limb darkening information for the temperature plot star = st.Star(omega, luminosity, mass, Req, nz) # observed spectrum wl_obs, I_obs = np.loadtxt(iodir + 'data/vega/vega2.dat').T m = wl_obs < w wl_obs = wl_obs[m] I_obs = I_obs[m] # spectrum at inclination = pi/2 wl_inc, I_inc = np.loadtxt(iodir + 'data/vega/vega1_570796.txt').T m = wl_inc < w wl_inc = wl_inc[m] I_inc = I_inc[m] ## plot rc('font', **{'family': 'serif', 'serif': ['Computer Modern'], 'size': 18})
def run(): parser = argparse.ArgumentParser(description="Examples: \n" +\ "calc_star data/limbdark_m01.pkl data/vega.pkl 0.6151 40.346 2.165 2.815 2.3694e19 100; " +\ "calc_star data/limbdark/limbdark_p02f.pkl data/altair.pkl 0.744 10.6 1.86 2.008 1.583e19 100; " +\ "calc_star data/limbdark/limbdark_m01f.pkl data/achernar.pkl 0.838 3020 6.1 9.16 1.319e20 100") parser.add_argument("ld_file", help="the limb darkening .pkl file to access") parser.add_argument("output", help="an output file containing the pickled star") parser.add_argument( "omega", help="rotation speed divided by its Keplerian value at the equator", type=float) parser.add_argument("luminosity", help="luminosity in solar luminosities", type=float) parser.add_argument("mass", help="mass in solar masses", type=float) parser.add_argument("Req", help="equatorial radius in solar radii", type=float) parser.add_argument("d", help="distance in cm", type=float) parser.add_argument( "nz", help="number of z coordinates in the upper hemisphere (normally 100)", type=int) parser.add_argument("-t", help="temperature interpolation: 0=planck(default), 1=linear, 2=log", type=int, \ default=0) parser.add_argument("-n", help="number of steps in the Newton's method for temperature calculation (default is 15)", type=int, \ default=15) args = parser.parse_args() ## input files pkl_sfile = args.output # star pickle file pkl_lfile = args.ld_file # limb darkening file ## star parameter inputs omega = args.omega # dimensionless rotation speed luminosity = args.luminosity # luminosity of the star in solar luminosities mass = args.mass # mass of the star in solar masses Req = args.Req # equatorial radius of the star in solar radii distance = args.d # distance to the star in cm # integration parameter nz = args.nz # temperature interpolation parameter if args.t == 0: tm = 'planck' if args.t == 1: tm = 'linear' elif args.t == 2: tm = 'log' # Newton's method parameter nm = args.n ## unpickle the limb darkening information with open(pkl_lfile, 'rb') as f: ld = pickle.load(f) # print a message ut.printf ("Mass: " + str(mass) + " sun(s)\nLuminosity: "+ str(luminosity) + " sun(s)\n" +\ "Equatorial radius: " + str(Req) + " solar radi(i/us)\nRotation speed: " + str(omega) +\ " of the Keplerian angular velocity at the equator\n") ## For a star with given physical parameters, resolution of map, ## and limb darkening information, pre-compute quantities that are needed for ## integrating the starlight and are independent of the inclination st = star.Star(omega, luminosity, mass, Req, distance, nz=nz, ld=ld, temp_method=tm, nm=nm) ### Pickle the star with open(pkl_sfile, 'wb') as f: pickle.dump(st, f)
wl = 511. ind = np.where(lam == wl)[0][0] # number of z values: log2 scale low, high = [3, 13] m = high - low + 1 n_z = np.logspace(low, high, num=m, base=2.) diff_trap = [] diff_cubic = [] omega, luminosity, mass, Req, distance, inclination = [ 0.6151, 40.346, 2.165, 2.815, 2.3694e19, math.pi / 4 ] print("calculating the etalon spectrum with N = 10,000...") st = star.Star(omega, luminosity, mass, Req, distance, 1e4, ld=ld) ref = st.integrate(inclination, method='cubic') mask = ref > 0 print("calculating the flux at the indicator wavelength") for i, n in np.ndenumerate(n_z): st = star.Star(omega, luminosity, mass, Req, distance, n, ld=ld) light = st.integrate(inclination, method='cubic') sd = np.abs(1 - light[ind] / ref[ind]) diff_cubic.append(sd) light = st.integrate(inclination, method='trapezoid') sd = np.abs(1 - light[ind] / ref[ind]) diff_trap.append(sd)