コード例 #1
0
ファイル: Source_Spectra.py プロジェクト: teuben/admit
def _run(argv):

    # Verify arguments are good
    if ( not admit.recipeutils._processargs(argv,REQARGS,OPTARGS,KEYS,KEYDESC,__doc__)): return

    bdpname = argv[1]
    cubefile = argv[2]
    projdir = os.path.splitext(argv[2])[0] + '.admit'
    pbcorfile = None
    if len(argv) == 4:
        pbcorfile = argv[3]

    #========================================================================
    # Master project.  Beginning for ADMIT Commands
    # 
    p = admit.Project(projdir,commit=False)
    #
    # Set-up all ADMIT Flow tasks for execution including their aliases and connections
    # The aliases allow you to refer to a task's input by the alias name of the (previous) 
    # task providing that input.
    #
    Task0 = p.addtask(admit.BDPIngest_AT( alias='bdptable', file=bdpname
))
    if pbcorfile == None:
        Task1  = p.addtask(admit.Ingest_AT(alias='incube', file=cubefile ))
    else:
        Task1  = p.addtask(admit.Ingest_AT(alias='incube', file=cubefile, pb=pbcorfile))
    Task2  = p.addtask(admit.CubeSpectrum_AT(alias='cubespec',xaxis=KEYS["xaxis"]), ['incube', 'bdptable'])
    #
    #  Execute ADMIT flow
    #
    p.run()
コード例 #2
0
    def runTest(self):
        try:
            # instantiate the Admit class
            a = admit.Project(self.admitdir)

            # set up to write out figure files
            a.plotparams(admit.PlotControl.BATCH, admit.PlotControl.PNG)

            fitsin = admit.Ingest_AT(file=self.inputFile)
            task0id = a.addtask(fitsin)

            # instantiate a moment AT and set some moment parameters
            m = admit.Smooth_AT()
            m.setkey('bmaj', {'value': 10.0, 'unit': 'arcsec'})
            m.setkey('bmin', {'value': 10.0, 'unit': 'arcsec'})
            m.setkey('velres', {'value': 205, 'unit': 'km/s'})
            m.setkey('bpa', 0.0)
            task1id = a.addtask(m, [(task0id, 0)])

            # check the fm
            a.fm.verify()

            # run admit
            a.run()
            # save it out to disk.
            a.write()

            a2 = admit.Project(
                self.admitdir)  # read in the admit.xml and bdp files
            self.assertEqual(len(a.fm), len(a2.fm))
            for atask in a.fm:
                self.assertEqual(len(a.fm[atask]._bdp_out),
                                 len(a2.fm[atask]._bdp_out))
                # Note: we don't check bdp_in because they are connected
                # "just in time" so will be set None up read-in.

            self.assertEqual(a.fm._connmap, a2.fm._connmap)

            for at in a.fm:
                for i in range(len(a.fm[at]._bdp_out)):
                    self.assertEqual(a.fm[at]._bdp_out[i]._taskid,
                                     a2.fm[at]._bdp_out[i]._taskid)
                    self.assertEqual(a.fm[at]._bdp_out[i].xmlFile,
                                     a2.fm[at]._bdp_out[i].xmlFile)
            self.success = "OK"
        except Exception, e:
            m = "exception=%s, file=%s, lineno=%s" % (
                sys.exc_info()[0].__name__,
                os.path.basename(
                    sys.exc_info()[2].tb_frame.f_code.co_filename),
                sys.exc_info()[2].tb_lineno)
            self.success = "FAILED"
            traceback.print_exc()
            self.fail("%s failed with: %s" % (self.__class__.__name__, m))
コード例 #3
0
    def runTest(self):
        try:
            # instantiate the class
            a = admit.Project(self.admitDir)
            a.plotparams(admit.PlotControl.BATCH,admit.PlotControl.PNG)

            fitsin = admit.Ingest_AT(file=self.inputFile)
            task0id = a.addtask(fitsin)

            l = admit.LineID_AT()
            task2id = a.addtask(l)
            l._needToSave = True
            ll = admit.LineList_BDP()

#             ll.addRow([115.271,"CO","CO-115.271","Carbon Monoxide","1-0",0.0,0.0,3.2,0.01,1.3,0.0,5.0,15,20,5.2])
#             ll.addRow([115.832,"U", "U-115.832", "", "",0.0,0.0,0.0,0.0,0.0,0.0,0.0,25,35,2.4])

            # keys (column names of LineList_BDP)
            # "frequency", "uid", "formula", "name", "transition", "velocity", 
            # "El", "Eu", "linestrength", "peakintensity", "peakoffset", "fwhm", 
            # "startchan", "endchan", "peakrms", "blend"
            keys = {"frequency":115.271, "uid":"CO","formula":"CO-115.271",
                    "name":"Carbon Monoxide", "transition":"1-0",
                    "velocity":0.0,
                    "linestrength":0.01, "peakintensity":1.3,
                    "peakoffset":0.0, "fwhm":5.0,
                    "peakrms":5.2, "blend":0}

            data = admit.LineData()
            data.setkey(name=keys)
            ll.addRow(data)

            keys = {"frequency":115.832, "uid":"U","formula":"U-115.832",
                    "name":"", "transition":"",
                    "velocity":0.0,
                    "linestrength":0.0, "peakintensity":0.0,
                    "peakoffset":0.0, "fwhm":0.0,
                    "peakrms":2.4, "blend":0}

            data.setkey(name=keys)
            ll.addRow(data)

            l.addoutput(ll)
            l.markUpToDate()

            # instantiate a linecube_AT
            lcube = admit.LineCube_AT()
            task1id = a.addtask(lcube,[(task0id,0),(task2id,0)])

            # check the fm 
            a.fm.verify()

            # run admit 
            a.run()
            a.write()
            # read in the admit.xml and bdp files
            a2 = admit.Project(self.admitDir)

            self.assertEqual(len(a.fm),len(a2.fm))
            for atask in a.fm:
                self.assertEqual(len(a.fm[atask]._bdp_out),
                                 len(a2.fm[atask]._bdp_out))
            self.assertEqual(a.fm._connmap,a2.fm._connmap)
            for at in a.fm:
                for i in range(len(a.fm[at]._bdp_out)) :
                    self.assertEqual( a.fm[at]._bdp_out[i]._taskid,
                                     a2.fm[at]._bdp_out[i]._taskid)
                    self.assertEqual( a.fm[at]._bdp_out[i].xmlFile,
                                     a2.fm[at]._bdp_out[i].xmlFile)
            self.success = "OK"
        except Exception, e:
            m = "exception=%s, file=%s, lineno=%s" % ( sys.exc_info()[0].__name__, os.path.basename(sys.exc_info()[2].tb_frame.f_code.co_filename), sys.exc_info()[2].tb_lineno)
            self.success = "FAILED"
            traceback.print_exc()
            self.fail("%s failed with: %s" % (self.__class__.__name__ , m))
コード例 #4
0
ファイル: admit-example0.py プロジェクト: astroumd/admit
#
# =============================================================================

# Used Python and ADMIT functionality.
import os
import admit

# Retrieve FITS file name, respecting CASA options.
ifile = admit.utils.casa_argv(sys.argv)[1]

# Create (or re-open) the ADMIT project.
# Our project directory is the input path with extension set to admit.
proj = admit.Project(os.path.splitext(ifile)[0] + '.admit', commit=False)

# Ingest the FITS cube.
proj.addtask(admit.Ingest_AT(file=ifile, alias='cube'))

# Cube manipulation template.
tmpl = proj.addtask(admit.Template_AT(imgslice=550, specpos=(183, 151)),
                    ['cube'])

# Calculate some statistics on the FITS cube (including peak point plot).
cstats = proj.addtask(admit.CubeStats_AT(ppp=True), ['cube'])

# Calculate the moment-0 (integrated intensity) map for the entire cube.
csum = proj.addtask(admit.CubeSum_AT(numsigma=4., sigma=99.), ['cube', cstats])

# Calculate the source spectrum at (by default) the peak position in the cube.
cspect = proj.addtask(admit.CubeSpectrum_AT(), ['cube', csum])

# Identify lines in the cube.
コード例 #5
0
#!/usr/bin/env casarun
import admit

NUM_SIGMA = 2
MIN_CHAN = 2
MAX_CHAN = 10
FITS_CUBE = "/media/haotian/documents-local/ASTR4998/data/products/SerpS_TC_spw5.pbcor_cutout_180_180_100_line.fits"
VLSR = 8.0

if __name__ == "__main__":
    p = admit.Project("{}.admit_BDP".format(FITS_CUBE), dataserver=True)
    t0 = p.addtask(admit.Ingest_AT(file=FITS_CUBE))
    t1 = p.addtask(admit.CubeStats_AT(ppp=True), [t0])
    t2 = p.addtask(admit.Moment_AT(mom0clip=2.0, numsigma=[NUM_SIGMA]),
                   [t0, t1])
    t3 = p.addtask(admit.CubeSpectrum_AT(), [t0, t2])
    t5 = p.addtask(
        admit.LineSegment_AT(maxgap=MAX_CHAN,
                             minchan=MIN_CHAN,
                             numsigma=NUM_SIGMA,
                             csub=[0, 0]), [t1, t3])
    t6 = p.addtask(admit.ContinuumSub_AT(), [t0, t5])
    t7 = p.addtask(admit.CubeStats_AT(ppp=True), [t6])
    t8 = p.addtask(admit.Moment_AT(mom0clip=2.0, numsigma=[NUM_SIGMA]),
                   [t6, t7])
    t9 = p.addtask(admit.CubeSpectrum_AT(), [t6, t8])
    t10 = p.addtask(
        admit.LineID_AT(allowexotics=True,
                        maxgap=MAX_CHAN,
                        minchan=MIN_CHAN,
                        numsigma=NUM_SIGMA,
コード例 #6
0
ファイル: admit1.py プロジェクト: astroumd/admit
else:
    print "All done, we just read an existing admit.xml and it should do nothing"
    print "Use admit0.py to re-run inside of your admit directory"
    #
    a.fm.diagram(a.dir() + 'admit.dot')
    a.show()
    a.showsetkey()
    sys.exit(
        0
    )  # doesn't work properly in IPython, leaves the user with a confusing mess

# Default ADMIT plotting environment
a.plotparams(plotmode, plottype)

# ingest
ingest1 = a.addtask(admit.Ingest_AT(file=file, basename=basename))
a[ingest1].setkey('mask', useMask)
a[ingest1].setkey('pb', pb)
a[ingest1].setkey('smooth', insmooth)
if vlsr != None:
    a[ingest1].setkey('vlsr', vlsr)
if restfreq != None:
    a[ingest1].setkey('restfreq', restfreq)
if len(inbox) > 0:
    a[ingest1].setkey('box', inbox)
if len(inedge) > 0:
    a[ingest1].setkey('edge', inedge)
bandcube1 = (ingest1, 0)

if False:
    # test File_AT:
コード例 #7
0
ファイル: admit5.py プロジェクト: teuben/admit
#! /usr/bin/env casarun
#
# Example multi-file admit flow, hardcoded for a specific 4-spw case
#
# REMOVE existing project directory before running script for the first time!
#
import admit

# Master project.
p = admit.Project('all-cubes.admit', commit=False)

# Flow tasks.
t0 = p.addtask(admit.Ingest_AT(file='concat.spw17.image.fits'))
t1 = p.addtask(admit.CubeStats_AT(), [t0])
t2 = p.addtask(admit.CubeSum_AT(numsigma=5.0, sigma=1.0), [t0, t1])
t3 = p.addtask(admit.CubeSpectrum_AT(alias='spec11'), [t0, t2])
t4 = p.addtask(admit.LineSegment_AT(minchan=4, maxgap=4, numsigma=6.0),
               [t1, t3])
t5 = p.addtask(admit.ContinuumSub_AT(fitorder=1, pad=40), [t0, t4])
t5a = p.addtask(admit.CubeStats_AT(), [t5])
t6 = p.addtask(admit.CubeSpectrum_AT(alias='spec12'), [t5, t2])
t7 = p.addtask(admit.Moment_AT(mom0clip=2.0, numsigma=[3.0]), [t5, t1])
t8 = p.addtask(admit.PVSlice_AT(clip=0.3, width=5), [t5, t2])
t9 = p.addtask(admit.PVCorr_AT(), [t8, t1])
t10 = p.addtask(
    admit.LineID_AT(csub=[1, 1], minchan=3, maxgap=4, numsigma=6.0), [t5a, t6])
t11 = p.addtask(admit.LineCube_AT(pad=40), [t5, t10])
t12 = p.addtask(admit.Moment_AT(mom0clip=2.0, moments=[0, 1, 2]), [t11, t1])
t13 = p.addtask(admit.CubeSpectrum_AT(), [t11, t12])

p.run()
コード例 #8
0
ファイル: Archive_SpecLine.py プロジェクト: teuben/admit
        KEYS["box"] = ast.literal_eval(str(KEYS["box"]))
    except Exception, e:
        print("Exception converting keyword value to number:", e)
        return
    #
    # Set-up all ADMIT Flow tasks for execution including their aliases and connections
    # The aliases allow you to refer to a task's input by the alias name of the (previous)
    # task providing that input.
    #

    # list object for Tasks so we don't have to individually name them
    Tasks = []
    if pbcorfile == None:
        Tasks.append(
            p.addtask(
                admit.Ingest_AT(alias='incube', file=cubefile,
                                box=KEYS["box"])))
    else:
        Tasks.append(
            p.addtask(
                admit.Ingest_AT(alias='incube',
                                file=cubefile,
                                pb=pbcorfile,
                                box=KEYS["box"])))

    Tasks.append(p.addtask(admit.CubeStats_AT(alias='instats'), ['incube']))
    Tasks.append(
        p.addtask(admit.CubeSum_AT(sigma=1, numsigma=3.0, alias='insum'),
                  ['incube', 'instats']))
    Tasks.append(
        p.addtask(admit.CubeSpectrum_AT(alias='spec1'), ['incube', 'insum']))
    Tasks.append(
コード例 #9
0
ファイル: admit-example1.py プロジェクト: astroumd/admit
if a.new:
    # copy the script into the admit directory
    print "Starting a new ADMIT using ", argv[0]
    os.system('cp -a %s %s' % (argv[0], adir))
else:
    print "All done, we just read an existing admit.xml and it should do nothing"
    a.fm.diagram(a.dir() + 'admit.dot')
    a.show()
    a.showsetkey()
    sys.exit(0)  # doesn't work properly in IPython!

# Default ADMIT plotting environment
a.plotparams(plotmode, plottype)

# Ingest
ingest1 = a.addtask(admit.Ingest_AT(file=file, alias=alias))
a[ingest1].setkey('mask', useMask)
bandcube1 = (ingest1, 0)

# CubeStats - will also do log(Noise),log(Peak) plot
cubestats1 = a.addtask(admit.CubeStats_AT(), [bandcube1])
a[cubestats1].setkey('robust', robust)
a[cubestats1].setkey('ppp', usePPP)
csttab1 = (cubestats1, 0)

# CubeSum
moment1 = a.addtask(admit.CubeSum_AT(), [bandcube1, csttab1])
a[moment1].setkey('numsigma', 4.0)  # Nsigma clip in cube
# >0 force single cuberms sigma from cubestats; <0 would use rms(freq) table
a[moment1].setkey('sigma', 99.0)
csmom0 = (moment1, 0)
コード例 #10
0
 # convert key values from string
 try:
     KEYS["minchan"] = int(KEYS["minchan"])
     KEYS["numsigma"] = float(KEYS["numsigma"])
     KEYS["pad"] = int(KEYS["pad"])
     KEYS["cutoff"] = ast.literal_eval(str(KEYS["cutoff"]))
 except Exception, e:
     print("Exception converting keyword value to number:", e)
     return
 #
 # Set-up all ADMIT Flow tasks for execution including their aliases and connections
 # The aliases allow you to refer to a task's input by the alias name of the (previous)
 # task providing that input.
 #
 if pbcorfile == None:
     Task0 = p.addtask(admit.Ingest_AT(file=cubefile, alias='incube'))
 else:
     Task0 = p.addtask(
         admit.Ingest_AT(file=cubefile, pb=pbcorfile, alias='incube'))
 Task1 = p.addtask(admit.CubeStats_AT(alias='instats'), ['incube'])
 Task2 = p.addtask(admit.CubeSum_AT(sigma=1, numsigma=3.0, alias='insum'),
                   ['incube', 'instats'])
 Task3 = p.addtask(admit.CubeSpectrum_AT(alias='spec1'),
                   ['incube', 'insum'])
 Task4 = p.addtask(
     admit.LineID_AT(csub=[1, 1],
                     minchan=KEYS["minchan"],
                     numsigma=KEYS["numsigma"],
                     alias='lines'), ['instats', 'spec1'])
 Task5 = p.addtask(admit.LineCube_AT(alias='cutcubes', pad=KEYS["pad"]),
                   ['incube', 'lines'])
コード例 #11
0
ファイル: Archive_Pipeline.py プロジェクト: teuben/admit
    #========================================================================
    # Master project.  Beginning for ADMIT Commands
    # 
    p = admit.Project(projdir,commit=False,loglevel=loglevel)
    
    # list object for Tasks so we don't have to individually name them
    Tasks = []
    #
    # Set-up all ADMIT Flow tasks for execution including their aliases and connections
    # The aliases allow you to refer to a task's input by the alias name of the (previous) 
    # task providing that input.
    #

    # Add spectral line processing to flow
    if KEYS["specpb"] == None:
        Tasks.append(p.addtask(admit.Ingest_AT(file=cubefile, alias='incube')))
    else:
        Tasks.append(p.addtask(admit.Ingest_AT(file=cubefile, alias='incube', pb=KEYS["specpb"])))

    Tasks.append(p.addtask(admit.CubeStats_AT      (alias='instats'),                                                                  ['incube']))
    Tasks.append(p.addtask(admit.CubeSum_AT        (alias='insum',    sigma=1, numsigma=3.0),                                          ['incube', 'instats']))
    Tasks.append(p.addtask(admit.CubeSpectrum_AT   (alias='spec1'),                                                                    ['incube', 'insum']))
    Tasks.append(p.addtask(admit.PVSlice_AT        (                  width=KEYS["width"]),                                            ['incube', 'insum']))
    Tasks.append(p.addtask(admit.LineID_AT         (alias='lines',    csub=[0,0], minchan=KEYS["minchan"], numsigma=KEYS["numsigma"]), ['instats','spec1']))
    Tasks.append(p.addtask(admit.LineCube_AT       (alias='cutcubes', pad=KEYS["pad"]),                                                ['incube', 'lines']))
    Tasks.append(p.addtask(admit.Moment_AT         (alias='linemom',  mom0clip=2.0, numsigma=KEYS["cutoff"], moments=[0, 1, 2]),       ['cutcubes', 'instats']))
    Tasks.append(p.addtask(admit.CubeSpectrum_AT   (alias='linespec'),                                                                 ['cutcubes', 'linemom']))
    # While 'linemom' produces 3 moment image BDPs, the default input is taken 
    # here, which is the first BDP which is the zeroth moment.  This relies on
    # Moment_AT's default behavior of putting the zeroth moment in the 
    # BDP index 0.
コード例 #12
0
    print "Starting a new ADMIT using ", argv[0]
    os.system('cp -a %s %s' % (argv[0], adir))
else:
    print "All done, we just read an existing admit.xml and it should do nothing"
    print "Use admit0.py to re-run inside of your admit directory"
    #
    a.fm.diagram(a.dir() + 'admit.dot')
    a.show()
    a.showsetkey()
    sys.exit(0)  # doesn't work properly in IPython!

# Default ADMIT plotting environment
a.plotparams(plotmode, plottype)

# Ingest
ingest1 = a.addtask(admit.Ingest_AT(file=file, alias=alias))
a[ingest1].setkey('mask', useMask)
a[ingest1].setkey('smooth', insmooth)
if len(inbox) > 0:
    a[ingest1].setkey('box', inbox)
if len(inedge) > 0:
    a[ingest1].setkey('edge', inedge)
bandcube1 = (ingest1, 0)

if len(smooth) > 0:
    smooth1 = a.addtask(admit.Smooth_AT(), [bandcube1])
    a[smooth1].setkey('bmaj', {'value': smooth[0], 'unit': 'pixel'})
    a[smooth1].setkey('bmin', {'value': smooth[1], 'unit': 'pixel'})
    a[smooth1].setkey('bpa', 0.0)
    if len(smooth) > 2:
        a[smooth1].setkey('velres', {'value': smooth[2], 'unit': 'pixel'})
コード例 #13
0
ファイル: admit2.py プロジェクト: teuben/admit
            for line in lines:
                exec(line.strip())
else:
    print "All done, we just read an existing admit.xml and it should do nothing"
    print "Use admit0.py to re-run inside of your admit directory"
    #
    a.fm.diagram(a.dir()+'admit.dot')
    a.show()
    a.showsetkey()
    sys.exit(0)      # doesn't work in IPython!

# Default ADMIT plotting environment
a.plotparams(plotmode,plottype)

# Ingest
ingest1 = a.addtask(admit.Ingest_AT(file=file,basename=basename))
a[ingest1].setkey('mask',useMask) 
a[ingest1].setkey('smooth',insmooth)
a[ingest1].setkey('pb',pb)
if len(inbox) > 0:
    a[ingest1].setkey('box',inbox)
bandcube1 = (ingest1,0)
pbmap1 = (ingest1,1)

if stop == 'ingest':  a.exit(1)

if len(smooth) > 0:
    smooth1 = a.addtask(admit.Smooth_AT(), [bandcube1])
    a[smooth1].setkey('bmaj',{'value':smooth[0], 'unit':'pixel'})  # yuck, i'd like the default not to have to mention it here
    a[smooth1].setkey('bmin',{'value':smooth[1], 'unit':'pixel'})
    a[smooth1].setkey('bpa',0.0)                       
コード例 #14
0
ファイル: Source_Find.py プロジェクト: teuben/admit
    p = admit.Project(projdir,commit=False)

    # convert key values from string
    try:
        KEYS["numsigma"] = float(KEYS["numsigma"])
        KEYS["snmax"]   = float(KEYS["snmax"])
    except Exception, e:
        print("Exception converting keyword value to number:",e)
        return
    #
    # Set-up all ADMIT Flow tasks for execution including their aliases and connections
    # The aliases allow you to refer to a task's input by the alias name of the (previous) 
    # task providing that input.
    #
    if pbcorfile == None:
        Task0  = p.addtask(admit.Ingest_AT(alias='inimage',file=imagefile))
    else:
        Task0  = p.addtask(admit.Ingest_AT( alias='inimage', file=imagefile, pb=pbcorfile ))
    Task1  = p.addtask(admit.CubeStats_AT(alias='instats'), ['inimage'])
    Task2  = p.addtask(admit.SFind2D_AT(alias='srcfind',numsigma=KEYS["numsigma"], snmax=KEYS["snmax"]), ['inimage', 'instats'])
    #
    #  Execute ADMIT flow
    #
    p.run()

if __name__ == "__main__":

    # Command line processing to pick-up file name and define
    #        ADMIT directory that you will be creating
    argv = admit.utils.casa_argv(sys.argv)
コード例 #15
0
ファイル: admit_script.py プロジェクト: xinglunju/reduction
# set up admit in the casa environment
import admit
import os

project = os.getenv('PROJECT')
if project is None:
    raise ValueError
else:
    print(f"Project -> {project}")

basefn = os.path.basename(project).replace(".image", "")
print(f"basefn = {basefn}")

p = admit.Project(f'{basefn}.admit', dataserver=True)
# Flow tasks.
t0 = p.addtask(admit.Ingest_AT(file=basefn + '.image'))
t1 = p.addtask(admit.CubeStats_AT(ppp=True), [t0])
t2 = p.addtask(admit.CubeSum_AT(numsigma=5.0, sigma=99.0), [t0, t1])
t3 = p.addtask(admit.CubeSpectrum_AT(), [t0, t2])
t4 = p.addtask(
    admit.LineSegment_AT(csub=[0, 0], minchan=4, maxgap=6, numsigma=5.0),
    [t1, t3])
t5 = p.addtask(admit.ContinuumSub_AT(fitorder=1, pad=60), [t0, t4])
t6 = p.addtask(admit.CubeStats_AT(ppp=True), [t5])
t7 = p.addtask(admit.CubeSpectrum_AT(), [t5, t6])
t8 = p.addtask(admit.Moment_AT(mom0clip=2.0, numsigma=[3.0]), [t5, t6])
t9 = p.addtask(admit.LineID_AT(csub=[0, 0], minchan=4, maxgap=6, numsigma=5.0),
               [t6, t7])
t10 = p.addtask(admit.LineCube_AT(pad=40), [t5, t9])
t11 = p.addtask(admit.Moment_AT(mom0clip=2.0, moments=[0, 1, 2]), [t10, t6])
t11 = p.addtask(admit.CubeSpectrum_AT(), [t10, t11])