示例#1
0
# Run the fitting
fit('data_glimpse',
    filters,
    apertures,
    model_dir,
    'output.fitinfo',
    extinction_law=extinction,
    distance_range=[1., 2.] * u.kpc,
    av_range=[0., 40.])

# For the remaining commands, we always select the models with chi^2-chi_best^2
# per datapoint less than 3.
select_format = ('F', 3)

# Make SED plots
plot('output.fitinfo', 'plots_seds', plot_max=100, select_format=select_format)

# Make histograms of the disk mass
plot_params_1d('output.fitinfo',
               'MDISK',
               'plots_mdisk',
               log_x=True,
               select_format=select_format)

# Make 2-d plots of the envelope infall rate vs disk mass
plot_params_2d('output.fitinfo',
               'MDISK',
               'MDOT',
               'plots_mdot_mdisk',
               log_x=True,
               log_y=True,
示例#2
0
def fit_all_sources(sourcetable):
	'''
	Wrap around Robitaille's fitting routine
	'''

	from sedfitter.extinction import Extinction
	# load up extinction law as suggested by website; might switch over to other dust files
	extinction = Extinction.from_file(SEDfolder+'extinction_law.ascii',columns=[0,1],wav_unit=u.micron,chi_unit=u.cm**2/u.g)

	# only fit the isolated and clustered sources
	types = sourcetable.group_by('Property')
	totsourcetable = vstack([types.groups[0],types.groups[2]])

	# list of columns with fluxes to be used to fit
	columnlist = ['j','h','ks','i1','i2','i3','i4','F11','F19','m1','F31','F37','m2','S450','S850','H70','H160','H250','H350','H500']
	errorlist = ["e_"+col for col in columnlist]
	flaglist = ["flag_"+col for col in columnlist if "flag_"+col in totsourcetable.columns]

	# set up input table to be fed to sedfitter
#	fluxlist = []
#	for col in columnlist:
#		fluxlist.append(col);fluxlist.append('e_'+col)

	# cluster names and distances
	fieldlist = Table(names=["CepA","CepC","IRAS20050","NGC2264","NGC1333","NGC7129","Oph","S140","S171","NGC2071"])
	fieldlist.add_row([730,730,700,760,240,1000,160,900,850,490])

	# for each cluster
	clusters = totsourcetable.group_by('Cluster')

	for key,group in izip(clusters.groups.keys,clusters.groups):

		# isolate source and use only relevant columns
		newsourcetable = group[['SOFIA_name','RA','DEC']+columnlist+errorlist+flaglist]
		print "Working on cluster ",key['Cluster']
		print newsourcetable

		# number of sources in that cluster
		L = len(newsourcetable)
		
		# for each column
		for col in columnlist:
			# re-check that there are no negative fluxes that are not masked
			for i in range(len(newsourcetable)):
				if newsourcetable[col][i]<0:
					newsourcetable.mask[col][i] = True

			# create the flag table based on mask
			newsourcetable["flag"+col] = np.ma.array(~newsourcetable[col].mask).astype(int)

			# make sure the errors are flagged as well
			newsourcetable['e_'+col].mask = newsourcetable[col].mask


		# multiplies the flag by 3 for the Herschel fluxes that we know are taken with a very large aperture
		for col in ['H250','H350','H500']:
			newsourcetable["flag"+col] *= 3

		for col in columnlist:
			for i in range(len(newsourcetable)):
				# if flag string contains a 'U', then the flux is an upper limit
				if 'flag_'+col in newsourcetable.columns:
					if 'U' in newsourcetable['flag_'+col][i] and newsourcetable["flag"+col][i] != 3:
						newsourcetable["flag"+col][i] *= 3

		# convert to mJy
		for col in columnlist:
			newsourcetable[col] *= 1000.0
			newsourcetable['e_'+col] *= 1000.0
		
		# creates the list of columns containing the flags
		newflaglist = ["flag"+col for col in columnlist]

		# create proper flux;error lists
		fluxlist = []
		for col in columnlist:
			fluxlist.append(col);fluxlist.append('e_'+col)
		

		# creates the table in proper format for feeding to sedfitter
		final = newsourcetable[['SOFIA_name','RA','DEC']+newflaglist+fluxlist].filled(-1.0)
		final.write(folder_export+key['Cluster']+'_sedfitter.tab',format='ascii')

		# remove first line (column headers)
		os.system('sed -i -e "1d" %s' % (folder_export+key['Cluster']+'_sedfitter.tab'))

		# name of the filter names for use in sedfitter
		sednamelist = ['2J','2H','2K','I1','I2','I3','I4','F11','F19','M1','F31','F37','M2','W1','W2','H70','H160','H250','H350','H500']

		# list of aperture sizes
		apertures = [8,8,8,12,12,12,12,9,9,35,9,9,45,20,40,12,22,22,30,42] *u.arcsec ### CHECK APERTURE SIZES  ,12,22,22,30,42

		# distance to the current cluster
		distance = fieldlist[key['Cluster']][0]
		
		# cleans up the directories before starting
		os.system('rm -rf %s' % (folder_export+'plot_'+key['Cluster']))
		os.system('rm %s' % (SEDfolder+'output_'+key['Cluster']+'.fitinfo'))

		# fitting routine
		fit(folder_export+key['Cluster']+'_sedfitter.tab',sednamelist,apertures,
			model_dir,SEDfolder+'output_'+key['Cluster']+'.fitinfo',
			extinction_law = extinction,
			distance_range = [distance*0.8,distance*1.2] * u.pc,
			av_range = [0.,10])

		print "Generating some plots"
		plot(SEDfolder+'output_'+key['Cluster']+'.fitinfo',folder_export+'plot_'+key['Cluster'],select_format=('N',10.))
		#plot_params_1d(SEDfolder+'output_'+key['Cluster']+'.fitinfo','MDISK',output_dir=folder_export+'plot_'+key['Cluster']+"/1d",log_x=True,select_format=('F',3.))
		print "Extracting the parameters from the fits"
		write_parameters(SEDfolder+'output_'+key['Cluster']+'.fitinfo',folder_export+'plot_'+key['Cluster']+'/params.txt',select_format=('N',10.))
		write_parameter_ranges(SEDfolder+'output_'+key['Cluster']+'.fitinfo',folder_export+'plot_'+key['Cluster']+'/params_ranges.txt',select_format=('N',10.))
		print "Parsing results..."
		parse_params_table(folder_export+'plot_'+key['Cluster'])
		print "Done parsing results"
示例#3
0
from sedfitter.extinction import Extinction

# Define path to models
model_dir = '/Users/cadeadams/Desktop/PythonPrac/models_kurucz'

# Read in extinction law)
extinction = Extinction.from_file('kmh94.par',
                                  columns=[0, 3],
                                  wav_unit=u.micron,
                                  chi_unit=u.cm**2 / u.g)

# Define filters and apertures
filt = [
    '2H', '2J', '2K', 'S4', 'S1', 'S2', 'S3', 'WISE1', 'WISE2', 'WISE3',
    'WISE4'
]
apertures = [3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.] * u.arcsec

# Run the fitting
fit('V380Ori.dat',
    filt,
    apertures,
    model_dir,
    'output.fitinfo',
    extinction_law=extinction,
    distance_range=[1., 2.] * u.kpc,
    av_range=[0., 40.])

from sedfitter import plot
plot('output.fitinfo', 'plots_seds')
示例#4
0
                output_format=select_format)
        except Exception as e:
            bad.write("%s  %s\n" % (nospacename, e))
            thisbad = True
            print(e)
        #info = fitter.fit(source)
        #FitInfo.write(info,nospacename+'.sedfit')
        if thisbad:
            continue
        else:
            #z = FitInfoFile(outdir+nospacename+'.sedfit',mode="r")
            ##print(type(z))
            #good.append(z)
            write_parameters(outfit,
                             outdir + "/" + nospacename + "_parameters.txt",
                             select_format=select_format)
            write_parameter_ranges(outfit,
                                   outdir + "/" + nospacename +
                                   "_parameters_ranges.txt",
                                   select_format=select_format)
            plot(input_fits=outfit,
                 output_dir=plotdir + nospacename,
                 format='png',
                 plot_mode='A',
                 plot_name=True,
                 select_format=select_format,
                 show_convolved=False,
                 show_sed=True)

bad.close()
示例#5
0
labels = []
labels.append(
    "Best Fit: A$_{\\rm V}=9.7$, M$_{\\rm disk}=1.4\\times 10^{-4} {\\rm M}_{\\odot}$, $\\dot{{\\rm M}}=0$, T$_{\\rm eff}=4000$, L$= 0.5{\\rm L_{\odot}}$"
)
labels.append(
    "w/Optical+M24 data: A$_{\\rm V}\\sim 2$, M$_{\\rm disk}\\sim 10^{-6} {\\rm M}_{\\odot}$, $\dot{{\\rm M}}\\sim 5\\times 10^{-8}$, T$_{\\rm eff}=4000$, L$= 0.25{\\rm L_{\\odot}}$"
)
outfile = data_dir + 'one_source_sedfit_output.info' + ext
plot(outfile,
     'plots_seds' + ext,
     plot_max=100,
     select_format=select_format,
     mysources=mysources,
     myfilters=myfilters,
     y_mode='M',
     y_range=(6E-14, 5E-10),
     x_mode='M',
     x_range=(2E-1, 80),
     plot_info=False,
     plot_name=False,
     mylabels=labels)

ext = "onesource+mips"

labels = []
labels.append(
    "Best Fit: A$_{\\rm V}=0$, M$_{\\rm disk}=5\\times 10^{-3} {\\rm M}_{\\odot}$, $\\dot{{\\rm M}}=2\\times 10^{-7}$, T$_{\\rm eff}=4000$, L$= 3.0{\\rm L_{\\odot}}$"
)
labels.append(
    "w/Optical+M24 data: A$_{\\rm V}\\sim 2$, M$_{\\rm disk}\\sim 10^{-6} {\\rm M}_{\\odot}$, $\\dot{{\\rm M}}\\sim 5\\times 10^{-8}$, T$_{\\rm eff}=4000$, L$= 0.25{\\rm L_{\\odot}}$"
示例#6
0
def fit_all_sources(sourcetable):
    '''
	Wrap around Robitaille's fitting routine
	'''

    from sedfitter.extinction import Extinction
    # load up extinction law as suggested by website; might switch over to other dust files
    extinction = Extinction.from_file(SEDfolder + 'extinction_law.ascii',
                                      columns=[0, 1],
                                      wav_unit=u.micron,
                                      chi_unit=u.cm**2 / u.g)

    # only fit the isolated and clustered sources
    types = sourcetable.group_by('Property')
    totsourcetable = vstack([types.groups[0], types.groups[2]])

    # list of columns with fluxes to be used to fit
    columnlist = [
        'j', 'h', 'ks', 'i1', 'i2', 'i3', 'i4', 'F11', 'F19', 'm1', 'F31',
        'F37', 'm2', 'S450', 'S850', 'H70', 'H160', 'H250', 'H350', 'H500'
    ]
    errorlist = ["e_" + col for col in columnlist]
    flaglist = [
        "flag_" + col for col in columnlist
        if "flag_" + col in totsourcetable.columns
    ]

    # set up input table to be fed to sedfitter
    #	fluxlist = []
    #	for col in columnlist:
    #		fluxlist.append(col);fluxlist.append('e_'+col)

    # cluster names and distances
    fieldlist = Table(names=[
        "CepA", "CepC", "IRAS20050", "NGC2264", "NGC1333", "NGC7129", "Oph",
        "S140", "S171", "NGC2071"
    ])
    fieldlist.add_row([730, 730, 700, 760, 240, 1000, 160, 900, 850, 490])

    # for each cluster
    clusters = totsourcetable.group_by('Cluster')

    for key, group in izip(clusters.groups.keys, clusters.groups):

        # isolate source and use only relevant columns
        newsourcetable = group[['SOFIA_name', 'RA', 'DEC'] + columnlist +
                               errorlist + flaglist]
        print "Working on cluster ", key['Cluster']
        print newsourcetable

        # number of sources in that cluster
        L = len(newsourcetable)

        # for each column
        for col in columnlist:
            # re-check that there are no negative fluxes that are not masked
            for i in range(len(newsourcetable)):
                if newsourcetable[col][i] < 0:
                    newsourcetable.mask[col][i] = True

            # create the flag table based on mask
            newsourcetable["flag" + col] = np.ma.array(
                ~newsourcetable[col].mask).astype(int)

            # make sure the errors are flagged as well
            newsourcetable['e_' + col].mask = newsourcetable[col].mask

        # multiplies the flag by 3 for the Herschel fluxes that we know are taken with a very large aperture
        for col in ['H250', 'H350', 'H500']:
            newsourcetable["flag" + col] *= 3

        for col in columnlist:
            for i in range(len(newsourcetable)):
                # if flag string contains a 'U', then the flux is an upper limit
                if 'flag_' + col in newsourcetable.columns:
                    if 'U' in newsourcetable[
                            'flag_' +
                            col][i] and newsourcetable["flag" + col][i] != 3:
                        newsourcetable["flag" + col][i] *= 3

        # convert to mJy
        for col in columnlist:
            newsourcetable[col] *= 1000.0
            newsourcetable['e_' + col] *= 1000.0

        # creates the list of columns containing the flags
        newflaglist = ["flag" + col for col in columnlist]

        # create proper flux;error lists
        fluxlist = []
        for col in columnlist:
            fluxlist.append(col)
            fluxlist.append('e_' + col)

        # creates the table in proper format for feeding to sedfitter
        final = newsourcetable[['SOFIA_name', 'RA', 'DEC'] + newflaglist +
                               fluxlist].filled(-1.0)
        final.write(folder_export + key['Cluster'] + '_sedfitter.tab',
                    format='ascii')

        # remove first line (column headers)
        os.system('sed -i -e "1d" %s' %
                  (folder_export + key['Cluster'] + '_sedfitter.tab'))

        # name of the filter names for use in sedfitter
        sednamelist = [
            '2J', '2H', '2K', 'I1', 'I2', 'I3', 'I4', 'F11', 'F19', 'M1',
            'F31', 'F37', 'M2', 'W1', 'W2', 'H70', 'H160', 'H250', 'H350',
            'H500'
        ]

        # list of aperture sizes
        apertures = [
            8, 8, 8, 12, 12, 12, 12, 9, 9, 35, 9, 9, 45, 20, 40, 12, 22, 22,
            30, 42
        ] * u.arcsec  ### CHECK APERTURE SIZES  ,12,22,22,30,42

        # distance to the current cluster
        distance = fieldlist[key['Cluster']][0]

        # cleans up the directories before starting
        os.system('rm -rf %s' % (folder_export + 'plot_' + key['Cluster']))
        os.system('rm %s' %
                  (SEDfolder + 'output_' + key['Cluster'] + '.fitinfo'))

        # fitting routine
        fit(folder_export + key['Cluster'] + '_sedfitter.tab',
            sednamelist,
            apertures,
            model_dir,
            SEDfolder + 'output_' + key['Cluster'] + '.fitinfo',
            extinction_law=extinction,
            distance_range=[distance * 0.8, distance * 1.2] * u.pc,
            av_range=[0., 10])

        print "Generating some plots"
        plot(SEDfolder + 'output_' + key['Cluster'] + '.fitinfo',
             folder_export + 'plot_' + key['Cluster'],
             select_format=('N', 10.))
        #plot_params_1d(SEDfolder+'output_'+key['Cluster']+'.fitinfo','MDISK',output_dir=folder_export+'plot_'+key['Cluster']+"/1d",log_x=True,select_format=('F',3.))
        print "Extracting the parameters from the fits"
        write_parameters(SEDfolder + 'output_' + key['Cluster'] + '.fitinfo',
                         folder_export + 'plot_' + key['Cluster'] +
                         '/params.txt',
                         select_format=('N', 10.))
        write_parameter_ranges(
            SEDfolder + 'output_' + key['Cluster'] + '.fitinfo',
            folder_export + 'plot_' + key['Cluster'] + '/params_ranges.txt',
            select_format=('N', 10.))
        print "Parsing results..."
        parse_params_table(folder_export + 'plot_' + key['Cluster'])
        print "Done parsing results"
示例#7
0
filters = ['2J', '2H', '2K', 'I1', 'I2', 'I3', 'I4']
apertures = [3., 3., 3., 3., 3., 3., 3.] * u.arcsec

# Run the fitting
fit('data_glimpse', filters, apertures, model_dir,
    'output.fitinfo',
    extinction_law=extinction,
    distance_range=[1., 2.] * u.kpc,
    av_range=[0., 40.])

# For the remaining commands, we always select the models with chi^2-chi_best^2
# per datapoint less than 3.
select_format = ('F', 3)

# Make SED plots
plot('output.fitinfo', 'plots_seds', plot_max=100, select_format=select_format)

# Make histograms of the disk mass
plot_params_1d('output.fitinfo', 'MDISK', 'plots_mdisk',
               log_x=True, select_format=select_format)

# Make 2-d plots of the envelope infall rate vs disk mass
plot_params_2d('output.fitinfo', 'MDISK', 'MDOT', 'plots_mdot_mdisk',
               log_x=True, log_y=True, select_format=select_format)

# Write out all models with a delta chi^2-chi_best^2 per datapoint < 3
write_parameters('output.fitinfo', 'parameters.txt',
                 select_format=select_format)

# Write out the min/max ranges corresponding to the above file
write_parameter_ranges('output.fitinfo', 'parameter_ranges.txt',