Manually Scaling Flux Density

From CASA Guides
Jump to navigationJump to search

+++ UNDER CONSTRUCTION +++

The ALMA flux calibration procedure and accuracy is described in a few places:

However, some users may desire to manually scale the flux density of their UV data after it has been pipeline calibrated, based on scientific information outside of the ALMA Calibrator Catalog. The following script provides an example of how to do so.

# In CASA
import numpy as np

# Copy these parameters from pipeline setjy/gaincal calls
myMS = 'myData.ms'
fluxcal = 'J2000-0001'
phasecal = 'J2000-0002'
myspws = [0, 1, 2, 3]
spix = -0.7
refant = 'DV21,DA54,DV20...'
reffreq = 'TOPO 346.650GHz'
intent = 'CALIBRATE_BANDPASS#ON_SOURCE'

# Stokes I flux density for each spw as determined by pipeline
pipeline_flux = [1.1, 1.0, 0.9, 0.8]

# User set parameter
scale_factor = 1.2
scaled_flux = np.array(pipeline_flux) * scale_factor

###################################

# Create amp cal table of unity
for i in [fluxcal, phasecal]:
    gaincal(
        vis=myMS,
        caltable='baseamplitude.cal',
        field=i,
        spw=myspws,
        selectdata=True,
        antenna='',
        solint='inf',
        preavg=-1,
        combine='scan',
        refant=refant,
        refantmode='flex',
        minblperant=4,
        minsnr=2.0,
        solnorm=False,
        gaintype='T',
        calmode='a',
        append=True,
        parang=False,
    )

# Set model column of MS with new desired flux values
for i, spw in enumerate(myspws):
    setjy(
        vis=myMS,
        field=fluxcal,
        spw=spw,
        selectdata=True,
        intent=intent,
        scalebychan=True,
        standard='manual',
        fluxdensity=[scaled_flux[i], 0.0, 0.0, 0.0],
        spix=spix,
        reffreq=reffreq,
        usescratch=True,
    )

# Create scaled cal table
fluxscale(
    vis=myMS,
    caltable='baseamplitude.cal',
    fluxtable='rescaledflux.cal',
    reference=fluxcal,
    transfer=phasecal,
)

# Apply scaled cal table
applycal(
    vis=myMS,
    field='',
    spw=myspws,
    antenna='*&*',
    docallib=False,
    gaintable='rescaledflux.cal',
    gainfield=[fluxcal, phasecal],  # Unsure about this
    applymode='calflagstrict',
    flagbackup=True,
)