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()
Esempio 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()
Esempio 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()
Esempio n. 4
0
    def __init__(self,
                 shortparlists,
                 parlists,
                 FitsDir,
                 logfile,
                 verbose=1,
                 clean_up=1,
                 skyKey='ALIGNSKY',
                 hdrGain=0,
                 crlower=None,
                 imNsci=1):
        self.modName = string.split(string.split(str(self))[0], '.')[0][1:]
        self.shortparlists = shortparlists
        self.parlists = parlists
        self.Fits = FitsDir
        self.verbose = verbose
        self.crmasks = {}  # cosmic ray masks names
        self.removeList = []
        self.clean_up = clean_up
        self.skyKey = skyKey
        self.hdrGain = hdrGain
        self.crlower = crlower
        if imNsci < 1:
            raise ValueError, 'Error: pyblot got imNsci = ' + imNsci
        self.imNsci = imNsci
        self.logfile = logfile
        print self.modName, 'version', __version__
        self.logfile.write('Instantiating ' + self.modName + ' version ' +
                           __version__)

        # make sure these packages are loaded
        iraf.stsdas()
        iraf.toolbox()
        iraf.imgtool()
        iraf.fourier()
        iraf.fitting()
        iraf.ttools()
        iraf.analysis()
        iraf.dither()
        # flush the cash! twice!
        iraf.flpr()
        iraf.flpr()
        iraf.reset(imtype='fits')  # seems to make deriv task a bit happier
        iraf.set(tmp='./')
Esempio n. 5
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
Esempio n. 6
0
from matplotlib import pyplot as plt
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
Esempio n. 7
0
#!/usr/bin/env python

print('This version of galTables works for *cutout-24-rot.tab files and *cutout-sdss.tab files. If you are not using rotated 24m files then use galTablesv2.py')

from pylab import *
import glob
from pyraf import iraf
import os

iraf.stsdas()
iraf.analysis()
iraf.toolbox()
iraf.ttools()

flag = str(raw_input('Which files? a=24  b=sdss '))
flag = str(flag)
if flag.find('a') > -1:
    tabfiles = glob.glob('*cutout-24-rot.tab')
if flag.find('b') > -1:
    tabfiles = glob.glob('*cutout-sdss.tab')

#tabfiles=glob.glob('*.tab')
#print tabfiles
for i in range(len(tabfiles)):
    tfile = tabfiles[i]

    nfile = tfile.split('.')
    dfile = nfile[0]+'.dat'
    print tfile,' -> ',dfile
    iraf.tprint(table=tfile,pwidth='INDEF',showhdr='no',showunits='no',Stdout=dfile)
Esempio n. 8
0
#########################################################################################
'''

import os
from pyraf import iraf
from astropy.io import fits
from shutil import copy2
import rsstools as rt
import numpy as np

iraf.noao(_doprint=0)
iraf.twodspec(_doprint=0)
iraf.longslit(_doprint=0)
iraf.apextract(dispaxis='1')
iraf.stsdas(_doprint=0)
iraf.analysis(_doprint=0)
iraf.fitting(_doprint=0)


class arc(object):
    def __init__(self, name):
        self.name = name 
        self.noext = os.path.splitext(self.name)[0]
        self.idname = rt.makesetups(self.name,"arc")
        self.idfits = self.idname+'.fits'
        self.linelist = self.idname.split('_')[0].lower()+'.dat'
        self.header = self.read_header()
    def read_header(self):
        return fits.getheader(self.name)  
    def __str__(self):
        return self.name+' :  idname --> '+self.idname
Esempio n. 9
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'