Exemple #1
0
def run_tlinear(loc, region, scol=True):
    """Runs ``IRAF/TLINEAR`` (linear fit) on data in file ``tcreate.tab``.
    
    Parameters:
        scol : {True, False}
            True by default. Set False if don't want to weight the fit
            by the deltaflux error.
           
    Returns:
        nothing       
                    
    Outputs:
        text file. The linear fit stored in 
        ``<filtername>_<amp><outfilemark>_tlinear.dat``.
        text file. The parameters of the fit stored in
        ``<filtername>_<amp><outfilemark>_tlinear.hdr.dat``
    """
    if scol:
        iraf.tlinear(loc+'tcreate.tab', loc+'tlinear.tab', \
                     xcol='x', ycol='y', scol='yerror' )
    else:
        iraf.tlinear(loc+'tcreate.tab', loc+'tlinear.tab', \
                     xcol='x', ycol='y')

    # Convert IRAF table to ascii file.
    iraf.tdump(loc+'tlinear.tab', \
                datafile = loc + region + '_tlinear.dat', \
                pfile = loc + region + '_tlinear.hdr.dat')

    # Delete the IRAF tables.
    os.remove(loc + 'tcreate.tab')
    os.remove(loc + 'tlinear.tab')
Exemple #2
0
def getBgrd(tablename):
    iraf.tables()
    dumpfile = tablename + '_dump.txt'

    try:
        os.remove(dumpfile)
    except OSError:
        pass

    iraf.tdump(table=tablename, columns='INTENS', datafile=dumpfile)

    file = open(dumpfile, "r")
    lineList = file.readlines()
    lastLine = lineList[-1]
    lastLine = lastLine.replace('\t', '')
    lastLine = lastLine.replace('\s', '')
    lastLine = lastLine.replace('\n', '')
    bg = float(lastLine)
    file.close()

    os.remove(dumpfile)

    print(bg)
Exemple #3
0
iraf.ellipse.geompar.step = 0.01
iraf.ellipse.geompar.linear = False
iraf.ellipse.geompar.recenter = True
# iraf.ellipse.geompar.saveParList(filename="ellipse.par")

# samplepar
iraf.ellipse.samplepar.nclip = 1
iraf.ellipse.samplepar.sdevice = "stdgraph"
# iraf.ellipse.samplepar.saveParList(filename="ellipse.par")

# magpar    : zero point photometry
iraf.ellipse.magpar.mag0 = 20.3

# ellipse parameters
iraf.ellipse(input=input_filename, output=output_bin)
iraf.tdump(table=output_bin, datafile=output_table, cdfile=output_cdf)

# model image construction
iraf.bmodel.unlearn()
iraf.bmodel(table=output_bin, output=model_image)

# subtraction
image = fits.open(input_filename)[0].data
model = fits.open(model_image)[0].data

fn = lambda x: np.nanmean((image - x[0] * model - np.nanmedian(image))**2)

res = minimize(fn, (0.1, ), method="Nelder-Mead")

iraf.imarith.unlearn()
iraf.imarith.operand1 = model_image
Exemple #4
0
    def getMeaningfulColumns(self, input, columns, output):
        '''
		Uses IRAF task tdump for parsing columns from a table.
		'''
        I.tdump(input, colum=columns, datafil=output)
Exemple #5
0
    elif pa > 90:
        pa = pa - 180.0
#	iraf.ellipse.controlpar.minit = 10
#	iraf.ellipse.controlpar.maxit = 100
#	iraf.ellipse.controlpar.olthresh = 0.0

#	iraf.ellipse(input=cur_dir+'tmp_V.fits',output=cur_dir+'tmp_V.tab',inter='no',x0=i,y0=j,ellip0=ellip,pa0=pa,sma0=thumb/10.0, \
#		minsma=1,maxsma=thumb,linear='no',recenter='no',hcenter='yes',hellip='yes',hpa='yes',integrmode='median',refer=1.0, \
#		zerolevel=0.0,mag0=22.5,nclip=0,step=0.3)

    iraf.ellipse(input=cur_dir+'tmp_V.fits',output=cur_dir+'tmp_V.tab',inter='no',x0=i,y0=j,ellip0=ellip,pa0=pa,sma0=thumb/10.0, \
            minsma=1,maxsma=thumb,linear='no',recenter='yes',hcenter='no',hellip='no',hpa='no',integrmode='median',refer=1.0, \
            zerolevel=0.0,mag0=22.5,nclip=0,step=0.3)

    iraf.tdump(table=cur_dir + 'tmp_V.tab',
               datafile='/Users/dhk/work/data/NGC_IC/ellipse/pa_ellip/' +
               name + '.txt',
               columns='@colnames.lis')
    copyfile(cur_dir + 'tmp_V.tab',
             '/Users/dhk/work/data/NGC_IC/ellipse/pa_ellip/' + name + '.tab')

    iraf.ellipse(input=work_dir + 'SHA/SHA_NGC_IC_LONG_mean/' + name + '.fits',
                 output=cur_dir + 'tmp_I1.tab',
                 inter='no',
                 inellip=cur_dir + 'tmp_V.tab',
                 mag0=21.5814)
    iraf.tdump(table=cur_dir + 'tmp_I1.tab',
               datafile='/Users/dhk/work/data/NGC_IC/ellipse/pa_ellip/' +
               name + '_I1.txt',
               columns='@colnames.lis')
    copyfile(
        cur_dir + 'tmp_I1.tab',
iraf.ellipse.controlpar.maxit = 100
# 9. Threshold for the object locator algorithm
#    By lowering this value, the locator become less strict.
iraf.ellipse.controlpar.olthresh = 1.00000
# 10. Make sure the Interactive Mode is turned off
iraf.ellipse.controlpar.interactive = "no"

# Check and remove outputs from the previous Ellipse run, or Ellipse will report
# error (Quite stupid!)
if os.path.exists(outBin):
	os.remove(outBin)
if os.path.exists(outTab):
	os.remove(outTab)
if os.path.exists(outCdf):
	os.remove(outCdf)

# Start the fitting
iraf.ellipse(input=inputImg, output=outTab)
# TODO: Demonstrate the direct photometry mode using input catalog
# inBin = input_bin_file
## The inBin is a Binary result from previous Ellipse run, and the isophote
## stored in it will overwrite all the above settings. Ellipse will simply
## extract surface brightness profile using these isophote instead of doing any
## fitting
# iraf.ellipse(input=inputImg, output=outBin, inellip=inBin)

# The Ellipse output is a binary table file, which is very hard to deal with
#  "Dump" it into a nice ASCII table
iraf.tdump(table=outBin, datafile=outTab, cdfile=outCdf)
os.remove(outCdf)
				if os.path.exists('tmp7.dqf'):
					os.remove('tmp7.dqf')

				hdu7 = fits.PrimaryHDU(betav_seg)
				hdu7.writeto('tmp7.fits')

				mask = betav_seg
				mask[np.isnan(mask)] = int(32)
				mask[np.where(mask != 32)] = int(0)

				hdu7pl = fits.PrimaryHDU(mask)
				hdu7pl.writeto('tmp7.dqf')

				#iraf.ellipse(input='tmp7.fits',output='tmp7.tab',inter='no',inellip=work_dir+'ellipse/pa_ellip/'+name+'_I1.tab',dqf='.c1h')
				iraf.ellipse(input='tmp7.fits',output='tmp7.tab',inter='no',x0=i,y0=j,dqf='.dqf')
                	        iraf.tdump(table='tmp7.tab',datafile=work_dir+'ellipse/pa_ellip/'+name+'_bv_pl9.txt',columns='@colnames.lis')
		
		if AV_fit:
			if os.path.exists('tmp.fits'):
        	                os.remove('tmp.fits')

			if os.path.exists('tmp1.fits'):
				os.remove('tmp1.fits')
	                if os.path.exists('tmp2.fits'):
        	                os.remove('tmp2.fits')
	                if os.path.exists('tmp3.fits'):
        	                os.remove('tmp3.fits')
	                if os.path.exists('tmp4.fits'):
        	                os.remove('tmp4.fits')
	                if os.path.exists('tmp5.fits'):
        	                os.remove('tmp5.fits')
Exemple #8
0
## ====>>>>  Constroi um modelo baseado no ellipse
iraf.bmodel(table=tab, output=model)
iraf.imarith(operand1=fich_comb, op="-", operand2=model, result=resid)

## ====>>>> Faz o grafico mag X R^(1/4) (perfil de de Vaucouleurs)
# iraf.isoplot(input=tab, xaxis="RSMA", yaxis="INTENS")

### ------  Saida de uma tabela ascii (.txt) para ajuste em outro programa

colunas = "SMA,RSMA,INTENS,INT_ERR,RMS,MAG,MAG_LERR,MAG_UERR"
colunas_2 = [
    'SMA', 'RSMA', 'INTENS', 'INT_ERR', 'RMS', 'MAG', 'MAG_LERR', 'MAG_UERR'
]

iraf.tdump(table=tab, datafile=fich4, columns=colunas)

#ACABA AQUI

data = pd.read_csv(fich4, sep="\s+", header=None)
data.columns = colunas_2
data.to_csv(tabcsv)

### Apaga arquivos temporarios

# os.remove(fich2)
os.remove(fich4)
os.remove(tab)

print('Terminou. Veja os arquivos ', nome, ' Model e Resid.fits')
Exemple #9
0
	def getMeaningfulColumns(self, input, columns, output):
		'''
		Uses IRAF task tdump for parsing columns from a table.
		'''
		I.tdump(input, colum=columns, datafil=output)