def run_ell(file_in, file_tab, file_dat, mag, **ellipse_par):    

    # prochaine etape : mettre en argument sous une certaine forme les parametres associes epar des taches 1) strict minimum sous forme de dico fixe 2) tout pouvoir changer sous forme de dictionnaire et tester les cles ...

    # import iraf packages
 
    iraf.stsdas()
    iraf.analysis()
    iraf.isophote()

    p = Popen("ds9", shell = True)
    time.sleep(5)

    iraf.display(file_in, 1)  

    set_iraf_param(ellipse_par)

    # iraf.lpar(iraf.geompar)

    iraf.ellipse(file_in, file_tab, mag0 = str(mag), verbose = "no")
    
    # iraf.lpar(iraf.isoimap)
    
    iraf.isoimap(file_in, file_tab)

    iraf.tproject(file_tab, "temp.fits", "SMA,INTENS,INT_ERR,ELLIP,ELLIP_ERR, PA, PA_ERR, X0, Y0, TFLUX_C, TMAG_E,NPIX_E")
    
    iraf.tprint("temp.fits", pwidth = 200, Stdout = file_dat)
    
    iraf.imdel("temp.fits")

    p.kill()
Ejemplo n.º 2
0
def run(args):
    """Generate the residual image using Ellipse run."""
    """Call the STSDAS.ANALYSIS.ISOPHOTE package"""
    if args.isophote is None:
        if args.verbose:
            print '\n' + SEP
            print "##       Call STSDAS.ANALYSIS.ISOPHOTE() "
            print SEP
        iraf.stsdas()
        iraf.analysis()
        iraf.isophote()
        iraf.ttools()
Ejemplo n.º 3
0
def run(args):
    """Generate the residual image using Ellipse run."""
    """Call the STSDAS.ANALYSIS.ISOPHOTE package"""
    if args.isophote is None:
        if args.verbose:
            print '\n' + SEP
            print "##       Call STSDAS.ANALYSIS.ISOPHOTE() "
            print SEP
        iraf.stsdas()
        iraf.analysis()
        iraf.isophote()
        iraf.ttools()
Ejemplo n.º 4
0
def pyraf_bmodel(binary,
                 parent,
                 output=None,
                 highar=False,
                 verbose=False,
                 interp='spline',
                 backgr=0.0):
    """Wrapper of the `Pyraf` `bmodel` function to build 2-D model.

    For details about the `bmodel` task, please see:
        http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?bmodel

    Parameters
    ----------
    binary: str
        Location of the output binary file from `ellipse` task.
    parent: str
        Location of the input image that `ellipse` run is based on.
    output: str, optional
        Name of the output FITS image
    highar: boolen, optional
        Whether to include the higher-order Fourier component. Default: False.
    verbose: boolen, optional
        Verbose mode. Default: False.
    interp: str, optional
        The interpolation mode used by the `trebin` task.
        Allowed values are: nearest | linear | poly3 | spline. Default: spline.

    Returns
    -------
    model: ndarray
        2-D model image of the `ellipse` results.

    """
    # Initiate the isophote module in IRAF/STSDAS
    try:
        from pyraf import iraf
        iraf.stsdas()
        iraf.analysis()
        iraf.isophote()
    except ImportError:
        raise Exception("# Unfortunately, you need to install pyraf first.")

    # Make sure the files are available
    if not os.path.isfile(binary):
        raise FileNotFoundError(
            "# Can not find the binary output file: {}".format(binary))
    if not os.path.isfile(parent):
        raise FileNotFoundError(
            "# Can not find the input image: {}".format(parent))

    # Name of the output FITS file
    if output is None:
        output = os.path.splitext(binary)[0] + '_model.fits'

    # Remove the output file if it exists
    if os.path.isfile(output):
        os.remove(output)

    # Check the interpolation method
    if interp not in PYRAF_INTERP:
        raise Exception("# Wrong interpolation method! Choices are {}".format(
            PYRAF_INTERP))

    # Higher-order harmonic modes
    highar_str = "yes" if highar else "no"
    verbose_str = "yes" if verbose else "no"

    try:
        iraf.bmodel(binary,
                    output,
                    parent=parent,
                    interp=interp,
                    highar=highar_str,
                    backgr=backgr,
                    verbose=verbose_str)
    except Exception:
        warnings.warn("# Something is wrong with the Bmodel task!")
        return None

    if not os.path.isfile(output):
        raise FileNotFoundError(
            "# Cannot find the output file: {}".format(output))
    else:
        model = fits.open(output)[0].data
        return model
Ejemplo n.º 5
0
import numpy as np
from scipy.optimize import minimize
import pandas as pd

# input images
input_filename = "small.fits"
output_table = input_filename.replace(".fits", ".tab")
output_bin = input_filename.replace(".fits", ".bin")
output_cdf = input_filename.replace(".fits", ".cdf")
model_image = input_filename.replace(".fits", "_model.fits")
residual_image = input_filename.replace(".fits", "_res.fits")

# import pacakges
iraf.stsdas()
iraf.analysis()
iraf.isophote()

for f in [
        output_bin, output_cdf, output_table, model_image,
        model_image.replace("model", "model_new_"),
        model_image.replace("model", "res")
]:
    if os.path.exists(f):
        os.remove(f)

# define parameters for ellipse run
iraf.ellipse.unlearn()

# geompar guess ...
iraf.ellipse.geompar.x0 = 112
iraf.ellipse.geompar.y0 = 115
Ejemplo n.º 6
0
                repeatflag=0
                print 'i think repeatflag = 0', repeatflag
                return
            else:
                s='mv *'+imprefix+'* Finished/'
                os.system(s)
                repeatflag=0
                print 'i think repeatflag = 0 ', repeatflag

            print 'repeatflag = ',repeatflag
            

raw_input('Make sure ds9 is open.  Hit return when ready.')
iraf.stsdas()
iraf.analysis()
iraf.isophote()
iraf.tables()
iraf.ttools()

#t=os.getcwd()
#s=t.split('cutouts')
#t=s[1].split('/')
#prefix=t[1]
#s=prefix+'*cutout-24.fits'
#mipsfiles=glob.glob(s)
#s=prefix+'*cutout-sdss.fits'
#print s
fileprefix=sys.argv[1]
print fileprefix
sdssrfiles=glob.glob(fileprefix)
print sdssrfiles
Ejemplo n.º 7
0
def ellipse(image, outname, verbose=False, **kwargs):
    """run ellipse task

    image : input image name
    outname : output filename
    
    Keywords:
    *geompar*
        x0, y0 -- required
        ellip0 : initial ellipticity (default=0.2)
        pa0 : initial PA in degrees ccw from +y (default=20)
        sma0 : initial semi-major axis (default=10)
        minsma : minimum sma (default=1)
        maxsma : maximum sma (default='INDEF')
        step : sma step size (default=0.1)
        linear : linear sampling of sma? (default='no')
    *controlpar*
        conver : 
    """
    # verify input
    if 'x0' not in kwargs.keys() or 'y0' not in kwargs.keys():
        raise KeyError('x0 or y0 is not found')
    # load packages
    iraf.stsdas(_doprint=0, motd=False)
    iraf.analysis(_doprint=0)
    iraf.isophote(_doprint=0)

    # reset all parameters
    iraf.unlearn('ellipse', 'geompar', 'controlpar', 'samplepar')
    iraf.ellipse.interactive = False
    iraf.ellipse.xylearn = False  # if True, it prompts input upon faling to find center

    # geompar
    iraf.ellipse.x0 = kwargs.pop('x0')
    iraf.ellipse.y0 = kwargs.pop('y0')
    iraf.ellipse.ellip0 = kwargs.pop('ellip0', 0.2)
    iraf.ellipse.pa0 = kwargs.pop('pa0', 20.0)
    iraf.ellipse.sma0 = kwargs.pop('sma0', 10.0)
    iraf.ellipse.minsma = kwargs.pop('minsma', 1.)
    iraf.ellipse.maxsma = kwargs.pop('maxsma', 'INDEF')
    iraf.ellipse.step = kwargs.pop('step', 0.1)
    iraf.ellipse.linear = kwargs.pop('linear', 0)
    iraf.ellipse.verbose = verbose

    # controlpar
    iraf.ellipse.conver = kwargs.pop('conver', 0.05)
    iraf.ellipse.minit = kwargs.pop('minit', 10)
    iraf.ellipse.maxit = kwargs.pop('maxit', 50)
    iraf.ellipse.hcenter = kwargs.pop('hcenter', 'no')

    # samplepar
    iraf.ellipse.tsample = kwargs.pop('tsample', 'none')
    iraf.ellipse.harmonics = kwargs.pop('harmonics', 'none')

    if verbose:
        iraf.lparam('ellipse')
        iraf.lparam('geompar')
        iraf.lparam('controlpar')
        iraf.lparam('samplepar')

    # run ellipse
    tempname = shorten_iauname(image) + str(uuid.uuid4()) + '.tab'
    try:
        iraf.ellipse(image, tempname)
        # print ascii table
        iraf.tprint(tempname, pwidth='INDEF', Stdout=outname)
        os.remove(tempname)
    except:
        print 'ellipse failed'