Пример #1
0
def simulate():

    direction = "J2000,0deg,%fdeg" % DEC
    v.MS = II(
        "${MSDIR}/KAT-7_${SYNTHESIS}h60s_${DEC}_${DFREQ}_${NCHAN}chans.ms")

    ms.create_empty_ms(msname=MS,
                       freq0=FREQ0,
                       dfreq=DFREQ,
                       nchan=NCHAN,
                       synthesis=SYNTHESIS,
                       dtime=60,
                       direction=direction,
                       pos=ANTENNAS,
                       tel="kat-7")

    tfile = tempfile.NamedTemporaryFile(suffix=".lsm.html")
    tfile.flush()

    tname = tfile.name
    x.sh("tigger-convert --recenter=$direction $LSMREF $tname -f")

    v.LSM = tname

    mqt.msrun(II("${mqt.CATTERY}/Siamese/turbo-sim.py"),
              job='_tdl_job_1_simulate_MS',
              section="sim",
              args=["${lsm.LSM_TDL}"])

    tfile.close()
Пример #2
0
def stackem(start=1, stop=100):
    
    v.MS = MS or II("${LSM:BASE}.MS")
    
    DO_STEP = lambda step: step>=float(start) and step<=float(stop)

    if not exists(MS) or MS_REDO:
        ms.create_empty_ms(tel=OBSERVATORY, pos=ANTENNAS, direction=DIRECTION, synthesis=SYNTHESIS, dtime=DTIME, 
                           freq0=FREQ0, dfreq=DFREQ)
        reload(ms)
        start = 1

    if DO_STEP(1):
        simsky()
        im.make_image()
     
    if DO_STEP(2):
        model = Tigger.load(LSM)
        radec = []
        flux = 0
        for src in model.sources:
            ra = src.pos.ra
            dec = src.pos.dec
            radec.append( map(numpy.rad2deg, [ra,dec]))
            flux += src.flux.I

        flux /=len(model.sources)
        
        sflux = stacker.stackem(im.DIRTY_IMAGE, radec, width=WIDTH)
        _add("%.4g %.4g"%(flux, sflux), STACKFILE, delimeter="\n")
def simulate():

    direction = "J2000,0deg,%fdeg"%DEC
    v.MS = II("${MSDIR}/KAT-7_${SYNTHESIS}h60s_${DEC}_${DFREQ}_${NCHAN}chans.ms")

    ms.create_empty_ms(msname=MS, freq0=FREQ0, dfreq=DFREQ, nchan=NCHAN, synthesis=SYNTHESIS,
                       dtime=60, direction=direction, pos=ANTENNAS, tel="kat-7")


    tfile = tempfile.NamedTemporaryFile(suffix=".lsm.html")
    tfile.flush()

    tname = tfile.name
    x.sh("tigger-convert --recenter=$direction $LSMREF $tname -f")

    v.LSM = tname

    mqt.msrun(II("${mqt.CATTERY}/Siamese/turbo-sim.py"),
             job = '_tdl_job_1_simulate_MS',
             section = "sim",
             args = ["${lsm.LSM_TDL}"]) 
    
    tfile.close()
Пример #4
0
def azishe(config='$CFG'):

    # Get parameters from json file
    with open(II(config)) as jsn_std:
        jparams = json.load(jsn_std)

    # Remove empty strings and convert unicode characters to strings
    params = {}
    for key, val in jparams.iteritems():
        # Make sure all keys are strings
        _key = str(key)

        # ignore empty strings and comments
        if val == "" or _key == "#":
            pass
        # convert unicode values to strings
        elif isinstance(val, unicode):
            params[_key] = str(val).lower()
        else:
            params[_key] = val

    get_opts = lambda prefix: filter(lambda a: a[0].startswith(prefix),
                                     params.items())

    # Retrieve MS and imager options
    ms_dict = dict([(key.split('ms_')[-1], val)
                    for (key, val) in get_opts('ms_')])
    im_dict = dict([(key.split('im_')[-1], val)
                    for (key, val) in get_opts('im_')])

    # Seperate deconvolution settings
    _deconv = {}
    for dcv in 'lwimager wsclean moresane casa'.split():
        if params[dcv]:
            _deconv.update({
                dcv:
                dict([(key.split(dcv + '_')[-1], val)
                      for (key, val) in get_opts(dcv + '_')])
            })

    # Set imaging options
    im.IMAGER = imager.IMAGER = params['imager'].lower()
    for opt in 'npix weight robust mode stokes'.split():
        if opt in im_dict.keys():
            setattr(im, opt, im_dict.pop(opt))
    im.cellsize = '%farcsec' % (im_dict.pop('cellsize'))
    im.stokes = im.stokes.upper()

    weight_fov = im_dict.pop('weight_fov')
    if weight_fov:
        im.weight_fov = '%farcmin' % weight_fov

    # Create empty MS
    synthesis = ms_dict.pop('synthesis')
    scalenoise = 1
    if synthesis > 12:
        scalenoise = math.sqrt(12.0 / synthesis)

    msname = II('rodrigues%f.MS' % (time.time()))
    obs = params['observatory'].lower()
    antennas = _OBS[obs]

    freq0 = ms_dict.pop('freq0') * 1e6
    dfreq = ms_dict.pop('dfreq') * 1e3
    direction = "J2000,%s,%s" % (ms_dict.pop('ra'), ms_dict.pop('dec'))
    ms.create_empty_ms(msname=msname,
                       synthesis=synthesis,
                       freq0=freq0,
                       dfreq=dfreq,
                       tel=obs,
                       pos='%s/%s' % (OBSDIR, antennas),
                       direction=direction,
                       **ms_dict)
    if exists(msname):
        v.MS = msname
    else:
        abort(
            "Something went wrong while creating the empty MS. Please check logs for details"
        )

    makedir(DESTDIR)
    ms.plot_uvcov(ms=.1,
                  width=10,
                  height=10,
                  dpi=150,
                  save="$OUTFILE-uvcov.png")

    # Set noise for simulation
    spwtab = ms.ms(subtable="SPECTRAL_WINDOW")
    freq0 = spwtab.getcol("CHAN_FREQ")[ms.SPWID, 0]
    spwtab.close()
    if params['add_noise']:
        noise = compute_vis_noise(sefd=get_sefd(freq0)) * scalenoise
    else:
        noise = 0

    # Simulate Visibilities
    _katalog = params['katalog_id']
    if _katalog:
        katalog = '%s/%s' % (KATDIR, _KATALOG[params['katalog_id']])

        lsmname = II('${OUTDIR>/}${MS:BASE}.lsm.html')

        radius = float(params['radius'])
        fluxrange = params['fluxrange'].split('-')
        if len(fluxrange) > 1:
            fluxrange = map(float, fluxrange)
        elif len(fluxrange) == 1:
            fluxrange = [0, float(fluxrange[0])]

        select = ''
        fits = verify_sky(katalog) == 'FITS'
        if radius or fluxrange:
            if radius: select += '--select="r<%fdeg" ' % radius
            if fluxrange:
                select += '--select="I<%f" ' % fluxrange[1]
                select += '--select="I>%f" ' % fluxrange[0]
        if not fits:
            x.sh(
                'tigger-convert $select --recenter=$direction $katalog $lsmname -f'
            )
        else:
            from pyrap.measures import measures
            dm = measures()
            direction = dm.direction('J2000', ms_opts[ra], ms_opts[dec])
            ra = np.rad2deg(direction['m0']['value'])
            dec = np.rad2deg(direction['m1']['value'])
            hdu = pyfits.open(temp_file)
            hdu[0].hdr['CRVAL1'] = ra
            hdu[0].hdr['CRVAL2'] = dec
            hdu.writeto(tmp_file, clobber=True)

        simsky(lsmname=lsmname,
               tdlsec='turbo-sim:custom',
               noise=noise,
               column='CORRECTED_DATA')

    skymodel = params['sky_model']
    if skymodel:
        simsky(lsmname=skymodel,
               noise=0 if katalog else noise,
               addToCol='CORRECTED_DATA')

    ## Finally Lets image
    # make dirty map
    im.make_image(psf=True, **im_dict)

    # Deconvolve
    for deconv in _deconv:
        deconv = deconv.lower()
        if deconv in STAND_ALONE_DECONV:
            im.make_image(algorithm=deconv,
                          restore=_deconv[deconv],
                          restore_lsm=False,
                          **im_dict)
        else:
            im.IMAGER = deconv
            im.make_image(dirty=False,
                          restore=_deconv[deconv],
                          restore_lsm=False,
                          **im_dict)

    xo.sh('tar -czvf ${OUTDIR>/}${MS:BASE}.tar.gz $msname')
Пример #5
0
def azishe(config='$CFG'):

    # Get parameters from json file    
    with open(II(config)) as jsn_std:
        jparams = json.load(jsn_std)

    # Remove empty strings and convert unicode characters to strings
    params = {}
    for key, val in jparams.iteritems():
        # Make sure all keys are strings
        _key = str(key)

        # ignore empty strings and comments
        if val=="" or _key=="#":
            pass
        # convert unicode values to strings
        elif isinstance(val,unicode):
            params[_key] = str(val).lower()
        else:
            params[_key] = val
 
    get_opts = lambda prefix: filter(lambda a: a[0].startswith(prefix), params.items())

    # Retrieve MS and imager options
    ms_dict = dict([(key.split('ms_')[-1],val) for (key,val) in get_opts('ms_') ] )
    im_dict = dict([(key.split('im_')[-1],val) for (key,val) in get_opts('im_') ] )

    # Seperate deconvolution settings
    _deconv = {}
    for dcv in 'lwimager wsclean moresane casa'.split():
        if params[dcv]:
            _deconv.update( {dcv:dict([(key.split(dcv+'_')[-1],val) for (key,val) in get_opts(dcv+'_') ] )} )
    
    # Set imaging options
    im.IMAGER = imager.IMAGER = params['imager'].lower()
    for opt in 'npix weight robust mode stokes'.split():
        if opt in im_dict.keys():
            setattr(im,opt,im_dict.pop(opt))
    im.cellsize = '%farcsec'%(im_dict.pop('cellsize'))
    im.stokes = im.stokes.upper()

    weight_fov = im_dict.pop('weight_fov')
    if weight_fov:
        im.weight_fov = '%farcmin'%weight_fov
    
    # Create empty MS
    synthesis = ms_dict.pop('synthesis')
    scalenoise = 1
    if synthesis > 12:
        scalenoise = math.sqrt(12.0/synthesis)
    
    msname = II('rodrigues%f.MS'%(time.time())) 
    obs = params['observatory'].lower()
    antennas = _OBS[obs]
    
    freq0 = ms_dict.pop('freq0')*1e6
    dfreq = ms_dict.pop('dfreq')*1e3
    direction = "J2000,%s,%s"%(ms_dict.pop('ra'),ms_dict.pop('dec'))
    ms.create_empty_ms(msname=msname,synthesis=synthesis,freq0=freq0,
                dfreq=dfreq,tel=obs,pos='%s/%s'%(OBSDIR,antennas),
                direction=direction,**ms_dict)
    if exists(msname):
        v.MS = msname
    else:
        abort("Something went wrong while creating the empty MS. Please check logs for details")

    makedir(DESTDIR)
    ms.plot_uvcov(ms=.1,width=10,height=10,dpi=150,save="$OUTFILE-uvcov.png")

    # Set noise for simulation
    spwtab = ms.ms(subtable="SPECTRAL_WINDOW")
    freq0 = spwtab.getcol("CHAN_FREQ")[ms.SPWID,0]
    spwtab.close()
    if params['add_noise']:
        noise =  compute_vis_noise(sefd=get_sefd(freq0)) * scalenoise
    else:
        noise = 0

    # Simulate Visibilities
    _katalog = params['katalog_id']
    if _katalog:
        katalog = '%s/%s'%(KATDIR,_KATALOG[params['katalog_id']])

        lsmname = II('${OUTDIR>/}${MS:BASE}.lsm.html')

        radius = float(params['radius'])
        fluxrange = params['fluxrange'].split('-')
        if len(fluxrange)>1:
            fluxrange = map(float,fluxrange)
        elif len(fluxrange)==1:
            fluxrange = [0,float(fluxrange[0])]

        
        select = ''
        fits = verify_sky(katalog) == 'FITS'
        if radius or fluxrange:
            if radius: select += '--select="r<%fdeg" '%radius
            if fluxrange: 
                select += '--select="I<%f" '%fluxrange[1]
                select += '--select="I>%f" '%fluxrange[0]
        if not fits:
            x.sh('tigger-convert $select --recenter=$direction $katalog $lsmname -f')
        else:
            from pyrap.measures import measures
            dm = measures()
            direction = dm.direction('J2000',ms_opts[ra],ms_opts[dec])
            ra = np.rad2deg(direction['m0']['value'])
            dec = np.rad2deg(direction['m1']['value'])
            hdu = pyfits.open(temp_file)
            hdu[0].hdr['CRVAL1'] = ra
            hdu[0].hdr['CRVAL2'] = dec
            hdu.writeto(tmp_file,clobber=True)

        simsky(lsmname=lsmname,tdlsec='turbo-sim:custom',noise=noise,column='CORRECTED_DATA')

    skymodel = params['sky_model']
    if skymodel:
        simsky(lsmname=skymodel,noise=0 if katalog else noise,addToCol='CORRECTED_DATA')

    ## Finally Lets image
    # make dirty map
    im.make_image(psf=True,**im_dict)

    # Deconvolve
    for deconv in _deconv:
        deconv = deconv.lower()
        if deconv in STAND_ALONE_DECONV:
            im.make_image(algorithm=deconv,restore=_deconv[deconv],restore_lsm=False,**im_dict)
        else:
            im.IMAGER = deconv
            im.make_image(dirty=False,restore=_deconv[deconv],restore_lsm=False,**im_dict)

    xo.sh('tar -czvf ${OUTDIR>/}${MS:BASE}.tar.gz $msname')