示例#1
0
def test_plotSequence():
# plotSequence
	sp = splat.getSpectrum(lucky=True)[0]
	splot.plotSequence(sp,output=output_folder+'example_plotsequence_dwarf.png')
	sp = splat.getSpectrum(subdwarf=True,lucky=True)[0]
	splot.plotSequence(sp,type='sd',output=output_folder+'example_plotsequence_subdwarf.png')
	sp = splat.getSpectrum(young=True,lucky=True)[0]
	splot.plotSequence(sp,type='lowg',output=output_folder+'example_plotsequence_lowg.png')
	return True
示例#2
0
def app_results():
    mkwargs = {}
    for key in list(request.form.keys()):
        if request.form['shortname'] != '':
            mkwargs['shortname'] = request.form['shortname']
        if request.form['name'] != '':
            mkwargs['name'] = request.form['name']
        if request.form['coordinate'] != '':
            mkwargs['coordinate'] = splut.properCoordinates(
                request.form['coordinate'])
        if request.form['spt'] != '':
            mkwargs['spt'] = request.form['spt']
        if request.form.get('young'):
            mkwargs['young'] = True
        if request.form.get('subdwarf'):
            mkwargs['subdwarf'] = True
        if request.form.get('wd'):
            mkwargs['wd'] = True
        if request.form.get('giant'):
            mkwargs['giant'] = True
        if request.form.get('binary'):
            mkwargs['binary'] = True
        if request.form.get('sbinary'):
            mkwargs['sbinary'] = True
        if request.form.get('lucky'):
            mkwargs['lucky'] = True

#Plotting data
        splist = splat.getSpectrum(**mkwargs)
        n = len(splist)
        number = {'count': n}
        splist = splat.getSpectrum(**mkwargs)[0:20]

        #Error Template
        if n == 0:
            return render_template('zeroerror.html')

#Tabs doesn't support for loops for some reason, so I got desperate
        tabs = []
        for i in range(n):
            sp = splist[i]
            l = Simple(sp)
            tabs.append(Panel(child=l, title=sp.name))
        tabs = Tabs(tabs=tabs)
        div = file_html(tabs, INLINE)

        return render_template('SpectrumResults.html', div=div, number=number)
示例#3
0
 def test_plotSequence():
     sp = splat.Spectrum(10001)
     splat.plotSequence(sp,output=out_folder+'plotSequence_test1.pdf')
     splat.plotSequence(sp,type_range=3,output=out_folder+'plotSequence_test2.png')
     data_folder = '/Users/adam/projects/splat/adddata/done/daniella/'
     files = glob.glob(data_folder+'*.fits')
     splat.plotSequence(files[0],telluric=True,stack=0.7,spt='M0',output=out_folder+'plotSequence_test3.eps')
     sp = splat.getSpectrum(shortname='0415-0935')[0]
     splat.plotSequence(sp,telluric=True,stack=0.3,output=out_folder+'plotSequence_test4.eps')
     splat.plotSequence(sp,telluric=True,stack=0.3)
     return
示例#4
0
def create_wisp_spectrum(filename):
    try:
        splat_spectrum = splat.getSpectrum(filename=filename)[0]
        #put it on the wisp resolution
        splat_spectrum.toInstrument('WFC3-G141')
        s = Spectrum(wave=splat_spectrum.wave.value,
                     flux=splat_spectrum.flux.value,
                     noise=splat_spectrum.noise.value)
        s.classify_by_standard
        return [s, splat_spectrum]
    except:
        return [None, None]
示例#5
0
 def test_plotSequence():
     sp = splat.Spectrum(10001)
     splat.plotSequence(sp, output=out_folder + 'plotSequence_test1.pdf')
     splat.plotSequence(sp,
                        type_range=3,
                        output=out_folder + 'plotSequence_test2.png')
     data_folder = '/Users/adam/projects/splat/adddata/done/daniella/'
     files = glob.glob(data_folder + '*.fits')
     splat.plotSequence(files[0],
                        telluric=True,
                        stack=0.7,
                        spt='M0',
                        output=out_folder + 'plotSequence_test3.eps')
     sp = splat.getSpectrum(shortname='0415-0935')[0]
     splat.plotSequence(sp,
                        telluric=True,
                        stack=0.3,
                        output=out_folder + 'plotSequence_test4.eps')
     splat.plotSequence(sp, telluric=True, stack=0.3)
     return
示例#6
0
文件: web.py 项目: dhomeier/splat
def load_spectra():
	#'/Users/guillaumeshippee/Desktop/splat-master/reference/Spectra/10001_10443.fits' #change
	if request.method == 'GET':
		return render_template('input.html', error='')
	else:
#		for k in list(request.form.keys()):
#			print(k,request.form[k])

# search by file "upload"	
		if request.form['submit'] == 'Load File':
			try:
				path = request.form['path']
				sp = splat.Spectrum(file=str(path))
				sp = [sp]
			except:
				return render_template('input.html',  error = "\n\nProblem with file upload button")
		
# search by file path specification	
		if request.form['submit'] == 'Load File ':
			try:
				path = request.form['path']
				sp = splat.Spectrum(file=str(path))
				sp = [sp]
			except:
				return render_template('input.html',  error = "\n\nProblem with file path specification")
		
# search by spectrum key	
		if request.form['submit'] == 'Load by ID':
			try:
				sp = splat.Spectrum(int(str(request.form['key'])))
				sp = [sp]
			except:
				return render_template('input.html',  error = "\n\nProblem with key specification")
		
# search by date observed	
		if request.form['submit'] == 'Load by Date':
			try:
				sp = splat.getSpectrum(date = str(request.form['date']))
			except:
				return render_template('input.html',  error = "\n\nProblem with key specification")
		
# search by shortname	
		elif request.form['submit'] == 'Load by Shortname':
			try:
				sp = splat.getSpectrum(shortname = str(request.form['shortname']))
			except:
				return render_template('input.html',  error = "\n\nProblem with specifying file by shortname")
	
# search by name	
		elif request.form['submit'] == 'Load by Name':
			try:
				sp = splat.getSpectrum(name = str(request.form['name']))
			except:
				return render_template('input.html',  error = "\n\nProblem with specifying file by name")
	
			
# search by options
		elif request.form['submit'] == 'Load by Options':
			sp1 = request.form['sp1']
			sp2 = request.form['sp2']
			mag1 = request.form['mag1']
			mag2 =  request.form['mag2']


			if sp2 == '':
				sp = sp1
			elif sp1 == '':
				sp2 = sp1
			elif sp1 == '' and sp2 == '':
				sp = ''
			else:
				sp = [sp1, sp2]

			if mag2 == '':
				mag = mag1
			elif sp1 == '':
				mag2 = mag1
			elif sp1 == '' and sp2 == '':
				mag = ''
			else:
				mag = [mag1, mag2]

			kwargs = {'spt': sp, 'jmag' : mag, 'snr' : request.form['snr'], 'date' : request.form['date'] }
			kwargs = {k: v for k, v in kwargs.items() if v}

			try:
				sp = splat.getSpectrum(**kwargs)
			except:
				return render_template('input.html', error = "\n\nProblem with option search")
			
# lucky pull	
		elif request.form['submit'] == 'Get Lucky!':
			sp = splat.getSpectrum(lucky=True)

		if len(sp) == 0:
			return render_template('input.html', error = "\n\nNo spectra matched search constratins")

		try:
			tab = []

			for s in sp:
				spectral_type = splat.classifyByStandard(s)[0]
				mpl_fig = splat.plotSpectrum(s, web=True, uncertainty = True, mdwarf=True)[0]
				bokehfig = mpl.to_bokeh(fig=mpl_fig)
				bokehfig.set(x_range=Range1d(.8,2.4),y_range=Range1d(0,s.fluxMax().value*1.2))
#				sys.stdout = open("out1.txt", "w") 
#				sys.stdout = sys.__stdout__
#				with open("out1.txt", "r") as f:
#					content = f.read() 
				content = s.info(printout=False)
#				print(content)
				p = Paragraph(text=content)
				widget = VBox(bokehfig, p)
				tab.append(Panel(child=widget, title=str(s.name)))
#				tab.append(Panel(child=widget, title=str(spectral_type)+ " Star"))
				
			plottabs = Tabs(tabs= tab)
			script, div_dict = components({"plot" : plottabs})
		except:
				return render_template('input.html', error = "\n\nProblem Plotting Spectra")
		
		return render_template('out.html', star_type = spectral_type, script=script,  div=div_dict)	
示例#7
0
	sp2.flux = sp2.flux+anoise
	sp2.variance = sp2.variance+bnoise**2
	sp2.noise = sp2.variance**0.5
	sp2.snr = sp2.computeSN()
	sp2.history.append('Added spectral noise based on Euclid sensitivity')
	return sp2


if __name__ == '__main__':
	'''
	Test function for splat_euclid functions, taking an 0559-1404 spectrum and plotting a 3 
	apparent magnitudes with corresponding distances
	'''

	ofold = '/Users/adam/projects/splat/euclid/'
	sp = splat.getSpectrum(shortname='J0559-1404')[0]
	spt = 'T4.5'
	filter = 'MKO H'
	m1 = splat.typeToMag(spt,filter)[0]
	m2 = 21
	d2 = splat.estimateDistance(sp,spt=spt,mag=m2, absmag=m1)[0]
	m3 = 19
	d3 = splat.estimateDistance(sp,spt=spt,mag=m3, absmag=m1)[0]

	spexToEuclid(sp)
	sp.normalize()
	sp.fluxCalibrate(filter,m2)
	print(sp.snr)
	sp2 = addEuclidNoise(sp)
	print(sp2.snr)
	sp.fluxCalibrate(filter,m3)
from matplotlib import pyplot as plt
import splat
import splat.model as spmdl
import math
plt.matplotlib.use('Qt5Agg')  #Important!

name = input(
    "Enter the shortname of the desired spectra: ")  #Take in user input
spectra = splat.getSpectrum(shortname=name)  #0949+0806 is a good example
sp = spectra[0]
sp.plot()  #Plot users spectra

#Uncomment these lines to compare models and fit models

#spmdl.modelFitGrid(sp)
#mdl = spmdl.loadModel(teff=2400,logg=5.0, Z=0.5, modelset='btsettl08')
#splat.compareSpectra(sp, mdl, plot = True)

plt.show()

#Take user input
starMass = float(input("Enter the Mass of the star (kg): "))
planetMass = float(
    input("Enter the mass of the planet (0 if unknown or incosenquential): "))
innerBound = float(
    input("Enter the inner boundary of the Habitable Zone (Meters): "))
outerBound = float(
    input("Enter the outer boundary of the Habitable Zone (Meters): "))
#Calculate and print periods
innerPeriod = math.sqrt(
    (4.0 * (3.141592**2)) / ((6.67e-11) *
示例#9
0
    sp2.flux = sp2.flux + anoise
    sp2.variance = sp2.variance + bnoise**2
    sp2.noise = sp2.variance**0.5
    sp2.snr = sp2.computeSN()
    sp2.history.append('Added spectral noise based on Euclid sensitivity')
    return sp2


if __name__ == '__main__':
    '''
	Test function for splat_euclid functions, taking an 0559-1404 spectrum and plotting a 3 
	apparent magnitudes with corresponding distances
	'''

    ofold = '/Users/adam/projects/splat/euclid/'
    sp = splat.getSpectrum(shortname='J0559-1404')[0]
    spt = 'T4.5'
    filter = 'MKO H'
    m1 = splat.typeToMag(spt, filter)[0]
    m2 = 21
    d2 = splat.estimateDistance(sp, spt=spt, mag=m2, absmag=m1)[0]
    m3 = 19
    d3 = splat.estimateDistance(sp, spt=spt, mag=m3, absmag=m1)[0]

    spexToEuclid(sp)
    sp.normalize()
    sp.fluxCalibrate(filter, m2)
    print(sp.snr)
    sp2 = addEuclidNoise(sp)
    print(sp2.snr)
    sp.fluxCalibrate(filter, m3)
示例#10
0
def load_spectra():
    #'/Users/guillaumeshippee/Desktop/splat-master/reference/Spectra/10001_10443.fits' #change
    if request.method == 'GET':
        return render_template('input.html', error='')
    else:
        #		for k in list(request.form.keys()):
        #			print(k,request.form[k])

        # search by file "upload"
        if request.form['submit'] == 'Load File':
            try:
                path = request.form['path']
                sp = splat.Spectrum(file=str(path))
                sp = [sp]
            except:
                return render_template(
                    'input.html', error="\n\nProblem with file upload button")

# search by file path specification
        if request.form['submit'] == 'Load File ':
            try:
                path = request.form['path']
                sp = splat.Spectrum(file=str(path))
                sp = [sp]
            except:
                return render_template(
                    'input.html',
                    error="\n\nProblem with file path specification")

# search by spectrum key
        if request.form['submit'] == 'Load by ID':
            try:
                sp = splat.Spectrum(int(str(request.form['key'])))
                sp = [sp]
            except:
                return render_template(
                    'input.html', error="\n\nProblem with key specification")

# search by date observed
        if request.form['submit'] == 'Load by Date':
            try:
                sp = splat.getSpectrum(date=str(request.form['date']))
            except:
                return render_template(
                    'input.html', error="\n\nProblem with key specification")

# search by shortname
        elif request.form['submit'] == 'Load by Shortname':
            try:
                sp = splat.getSpectrum(
                    shortname=str(request.form['shortname']))
            except:
                return render_template(
                    'input.html',
                    error="\n\nProblem with specifying file by shortname")

# search by name
        elif request.form['submit'] == 'Load by Name':
            try:
                sp = splat.getSpectrum(name=str(request.form['name']))
            except:
                return render_template(
                    'input.html',
                    error="\n\nProblem with specifying file by name")

# search by options
        elif request.form['submit'] == 'Load by Options':
            sp1 = request.form['sp1']
            sp2 = request.form['sp2']
            mag1 = request.form['mag1']
            mag2 = request.form['mag2']

            if sp2 == '':
                sp = sp1
            elif sp1 == '':
                sp2 = sp1
            elif sp1 == '' and sp2 == '':
                sp = ''
            else:
                sp = [sp1, sp2]

            if mag2 == '':
                mag = mag1
            elif sp1 == '':
                mag2 = mag1
            elif sp1 == '' and sp2 == '':
                mag = ''
            else:
                mag = [mag1, mag2]

            kwargs = {
                'spt': sp,
                'jmag': mag,
                'snr': request.form['snr'],
                'date': request.form['date']
            }
            kwargs = {k: v for k, v in kwargs.items() if v}

            try:
                sp = splat.getSpectrum(**kwargs)
            except:
                return render_template('input.html',
                                       error="\n\nProblem with option search")

# lucky pull
        elif request.form['submit'] == 'Get Lucky!':
            sp = splat.getSpectrum(lucky=True)

        if len(sp) == 0:
            return render_template(
                'input.html',
                error="\n\nNo spectra matched search constratins")

        try:
            tab = []

            for s in sp:
                spectral_type = splat.classifyByStandard(s)[0]
                mpl_fig = splot.plotSpectrum(s, web=True, uncertainty=True)[0]
                bokehfig = mpl.to_bokeh(fig=mpl_fig)
                bokehfig.set(x_range=Range1d(.8, 2.4),
                             y_range=Range1d(0,
                                             s.fluxMax().value * 1.2))
                #				sys.stdout = open("out1.txt", "w")
                #				sys.stdout = sys.__stdout__
                #				with open("out1.txt", "r") as f:
                #					content = f.read()
                content = s.info(printout=False)
                #				print(content)
                p = Paragraph(text=content)
                widget = VBox(bokehfig, p)
                tab.append(Panel(child=widget, title=str(s.name)))


#				tab.append(Panel(child=widget, title=str(spectral_type)+ " Star"))

            plottabs = Tabs(tabs=tab)
            script, div_dict = components({"plot": tab})
        except:
            return render_template('input.html',
                                   error="\n\nProblem Plotting Spectra")

        return render_template('output.html',
                               star_type=spectral_type,
                               script=script,
                               div=div_dict)