def genPlot(path, teff, logg, metals, am, nm, cm): # Get the model mspec= ferre.interpolate(teff,logg,metals,am,nm,cm) # Plot the model splot.waveregions(mspec, labelID='[N/M]=' + str(nm) + ', [C/M]=' + str(cm), labelTeff=teff, labellogg=logg, labelmetals=metals, labelafe=am) # Format and save the file fig = plot.gcf() fig.set_size_inches(30.0, 15.0, forward=True) plot.draw() if not os.path.exists('model_plots/' + path): os.makedirs('model_plots/' + path) plot.savefig('model_plots/' + path + '/' + str(teff) + '_' + str(logg) + '_' + str(metals) + '_' + str(am) + '_' + str(nm) + '_' + str(cm) + '.png', format='png', dpi=300) plot.clf() plot.close('all');
def binaryModelGen(locationID, apogeeID, params, visit, ipf=None, ipg=None, plot=True): ''' Interpolates the spectra of the individual stars in the binary using some initial parameters and their velocity difference. :param locationID: The location ID of the binary. :param apogeeID: The apogee ID of the binary. :param params: The paramters to test against the observed data. format: [ [Teff1, ...], [logg1, ...], [metals1, ...], [am1, ...], [nm1, ...], [cm1, ...]] :param visit: The visit to test against. :param ip: The interpolator instance that keeps running ferre. Should be faster to keep using this instead. (default=None) :param plot: If true plots each component in the binary in 'plots/model_gen' (default=True) :returns: The binary model flux and the maximum value from the cross correlation function between the modeled totalFlux and the continuum-normalized spectrum. (totalFlux, max) ''' # Generate models (flux1, flux2) if (np.logical_and(ipf == None, ipg == None)): # todo: put in condition for both gk and f libraries mspecs = ferre.interpolate(params[0], params[1], params[2], params[3], params[4], params[5]) else: if (params[0][0] > 6000.): mspec1 = ipf(params[0][0], params[1][0], params[2][0], params[3][0], params[4][0], params[5][0]) else: mspec1 = ipg(params[0][0], params[1][0], params[2][0], params[3][0], params[4][0], params[5][0]) if (params[0][1] > 6000.): mspec2 = ipf(params[0][1], params[1][1], params[2][1], params[3][1], params[4][1], params[5][1]) else: mspec2 = ipg(params[0][1], params[1][1], params[2][1], params[3][1], params[4][1], params[5][1]) mspecs = [ mspec1, mspec2 ] for mspec in mspecs: mspec[np.isnan(mspec)] = 0. # Calculate deltaV RVs = getRVs(locationID, apogeeID, visit) # Generate the wavelength grid restLambda = splot.apStarWavegrid() # Calculates wavelength grid for the second star with a doppler shift shiftLambda = [restLambda * (1. + rv / (const.c / 1000.)) for rv in RVs] # The fluxes of both stars shiftedFlux = np.array([np.interp(restLambda, shiftLambda[i], mspecs[i]) for i in range(len(shiftLambda))]) # The combined flux of the stars in the modeled binary (params[7][1] defined as flux ratio) totalFlux = (shiftedFlux[0] + (shiftedFlux[1] * params[6][1])) / 2.0 # Make the plots if (plot == True): BinPlot.plotDeltaVCheck(locationID, apogeeID, visit, [[ restLambda, mspecs[0], 'blue', 'rest model specA' ], [ restLambda, mspecs[1], 'green', 'rest model specB' ], [ restLambda, shiftedFlux[0], 'orange', 'shift model specA' ], [ restLambda, shiftedFlux[1], 'purple', 'shift model specB' ]], [params[0][0], params[0][1]], 'Binary Model Gen - Prelim. Proc.', folder='model_gen'); return totalFlux
[data["TEFF"][0], 5500.0, 3500.0], # effective temperature [data["LOGG"][0], data["LOGG"][0], data["LOGG"][0]], # surface gravity [data["FEH"][0], data["FEH"][0], data["FEH"][0]], # metal abundance [data["ALPHA"][0], data["ALPHA"][0], data["ALPHA"][0]], # α element [0.0, 0.0, 0.0], # nitrogen relative abundance [data["CARBON"][0], data["CARBON"][0], data["CARBON"][0]], ] # carbon relative abundance if params[0][0] < 3500.0: params[0][0] = 3500.0 if params[0][0] >= 6000.0: params[0][0] = 5500.0 if params[1][0] >= 5.0: params[1][0] = params[1][2] = params[1][1] = 4.9 # Generate models (flux1, flux2) mspecs = ferre.interpolate(params[0], params[1], params[2], params[3], params[4], params[5]) # for mspec in mspecs: # mspec[np.where(np.isnan(mspec))] = 0.0 # prep obs spec """aspec= np.reshape(spec,(1,len(spec))) aspecerr= np.reshape(specerr,(1,len(specerr))) cont= spec / continuum.fit(aspec,aspecerr,type='aspcap')[0]""" """spec[np.where(np.isnan(spec))] = 0.0 cont = spec / max(spec)""" # Generate the wavelength grid restLambda = splot.apStarWavegrid() ccfs = [] velocityShift = 0
for i in range(len(nan_vals_spec) - 1) if nan_vals_spec[i + 1] != nan_vals_spec[i] + 1 ] print(nan_ranges_spec) f.write( "{0}\t{1}\t{2}\t{3}\t{4}".format( locationID, apogeeID, "[" + str(nan_ranges_spec[0][0]) + "," + str(nan_ranges_spec[0][1]) + "]", "[" + str(nan_ranges_spec[1][0]) + "," + str(nan_ranges_spec[1][1]) + "]", "[" + str(nan_ranges_spec[2][0]) + "," + str(nan_ranges_spec[2][1]) + "]\n", ) ) mspec = ferre.interpolate(4500.0, 4.7, 0.0, 0.0, 0.0, 0.0) nan_vals_mspec = np.where(np.isnan(mspec))[0] nan_ranges_mspec = [ (nan_vals_mspec[i] + 1, nan_vals_mspec[i + 1]) for i in range(len(nan_vals_mspec) - 1) if nan_vals_mspec[i + 1] != nan_vals_mspec[i] + 1 ] f.write( "{0}\t{1}\t{2}\t{3}\t{4}".format( "model", "\t\t\t\t", "[" + str(nan_ranges_mspec[0][0]) + "," + str(nan_ranges_mspec[0][1]) + "]", "[" + str(nan_ranges_mspec[1][0]) + "," + str(nan_ranges_mspec[1][1]) + "]", "[" + str(nan_ranges_mspec[2][0]) + "," + str(nan_ranges_mspec[2][1]) + "]\n", ) )