<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://ovsa.njit.edu//wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sshaik</id>
	<title>EOVSA Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://ovsa.njit.edu//wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sshaik"/>
	<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php/Special:Contributions/Sshaik"/>
	<updated>2026-04-07T10:25:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.38.1</generator>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6574</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6574"/>
		<updated>2022-07-07T22:18:58Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.1=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====4.3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
=====4.5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6573</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6573"/>
		<updated>2022-07-07T22:18:35Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 4.1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*=====4.1=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====4.3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
=====4.5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6572</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6572"/>
		<updated>2022-07-07T22:17:48Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.1=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====4.3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
=====4.5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6571</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6571"/>
		<updated>2022-07-07T22:13:06Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 5 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====4.3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
=====4.5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6570</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6570"/>
		<updated>2022-07-07T22:12:56Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====4.3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====4.4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6569</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6569"/>
		<updated>2022-07-07T22:12:44Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====4.3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6568</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6568"/>
		<updated>2022-07-07T22:12:28Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====4.2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6567</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6567"/>
		<updated>2022-07-07T21:56:24Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 3. Software requirements and installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control of all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=11. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6566</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6566"/>
		<updated>2022-07-07T21:56:02Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Other useful links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control of all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=11. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6565</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6565"/>
		<updated>2022-07-07T21:39:23Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]   # Not used?&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6564</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6564"/>
		<updated>2022-07-07T21:33:42Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                plt.pause(0.5)                           # Allows viewing of each image as it is plotted.&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6563</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6563"/>
		<updated>2022-07-07T21:32:16Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 5 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))                             # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)                                   # gs = gridspec.GridSpec(5, 10)       # For post-2020 data (50 spws)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6562</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6562"/>
		<updated>2022-07-07T21:31:39Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:                              # if sp &amp;lt; 0:                           # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_i = 1                              #     sp_i = 0                         # For post-2020 data (50 spws)&lt;br /&gt;
                if sp_e &amp;gt; 30:                             # if sp_e &amp;gt; 49:                        # For post-2020 data (50 spws)&lt;br /&gt;
                    sp_e = 30                             #     sp_e = 49                        # For post-2020 data (50 spws)&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6561</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6561"/>
		<updated>2022-07-07T21:29:45Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
            plt.pause(0.5)                               # Allows viewing of the plot&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6560</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6560"/>
		<updated>2022-07-07T21:27:23Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]                                              ###spws=[str(s+1) for s in range(49)]   # For post-2020 data&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))                                 # fig = plt.figure(figsize=(14, 7))   # For post-2020 data (50 spws)&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)                                       # gs = gridspec.GridSpec(5, 10)        # For post-2020 data (50 spws)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)                                      # spbg=max(int(sp)-2,0)               # For post-2020 data (50 spws)&lt;br /&gt;
                sped=min(int(sp)+2,30)                                     # sped=min(int(sp)+2,49)              # For post-2020 data (50 spws) &lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6559</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6559"/>
		<updated>2022-07-07T21:19:54Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 2: Concatenate all the 10 mins data, if there are any */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|right|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6558</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6558"/>
		<updated>2022-07-07T21:18:23Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 12. Installation of SunCASA (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control of all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=11. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6557</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6557"/>
		<updated>2022-07-07T21:18:15Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 11. Spectral Fitting with GSFIT (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control of all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6556</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6556"/>
		<updated>2022-07-07T21:17:59Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 10. Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control of all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6555</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6555"/>
		<updated>2022-07-07T21:17:32Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 9. Downloading fits files to your local system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control of all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6554</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6554"/>
		<updated>2022-07-07T21:15:37Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|center|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Step 4=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
=====Step 5=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6553</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6553"/>
		<updated>2022-07-07T21:12:02Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|center|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step 2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
=====Step 3=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6552</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6552"/>
		<updated>2022-07-07T21:11:21Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|center|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
=====Step2=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6551</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6551"/>
		<updated>2022-07-07T21:10:40Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|center|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
=====Step2=====&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6550</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6550"/>
		<updated>2022-07-07T21:06:52Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|center|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna=antennas,&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas=antennas&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna=antennas,&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6549</id>
		<title>Tohban EOVSA Imaging Tutorial A-Z</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=Tohban_EOVSA_Imaging_Tutorial_A-Z&amp;diff=6549"/>
		<updated>2022-07-07T21:03:18Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Step 4: Self-calibration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This tutorial describes the step-by-step procedure to download EOVSA IDB data, obtain and calibrate the measurement sets (.ms), and, transfer them to the inti server for self-calibration and further analysis. &lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites:''' Accounts on Pipeline and Inti or Baozi servers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Connection details to pipeline server ===&lt;br /&gt;
One can use the Mobaxterm platform to connect to the Pipeline server through a Windows machine or use SSH through a Mac machine.&lt;br /&gt;
&lt;br /&gt;
==== Step 1: Downloading raw data (IDB) on Pipeline machine====&lt;br /&gt;
On CASA of the Pipeline machine, which has the complete EOVSA SQL database.&lt;br /&gt;
&lt;br /&gt;
If you are not using mobaxterm, directly SSH to Pipeline through your Linux or Mac computer and start tcsh to run CASA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from astropy.time import Time&lt;br /&gt;
import os&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:25:00'])                               ###Change accordingly###&lt;br /&gt;
#### (Optional) change output path, default current directory &amp;quot;./&amp;quot; #####&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
######################################################&lt;br /&gt;
msfiles = importeovsa(idbfiles=trange, ncpu=1, visprefix=outpath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The above step currently gives an error with importeovsa. This is because the data location was changed and the code doesn't know where to look for the IDB files. Sijie is looking into the problem. We will update the page when it is fixed. For now, please use the method below for all time ranges. &lt;br /&gt;
&lt;br /&gt;
OR (for a time range longer than 10 minutes)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.tasks import task_calibeovsa as calibeovsa&lt;br /&gt;
from suncasa.tasks import task_importeovsa as timporteovsa&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import dump_tsys as dt&lt;br /&gt;
from util import Time&lt;br /&gt;
import numpy as np&lt;br /&gt;
import os&lt;br /&gt;
from glob import glob&lt;br /&gt;
from eovsapy import util&lt;br /&gt;
&lt;br /&gt;
trange = Time(['2017-08-21 20:15:00', '2017-08-21 20:35:00'])                               ###Change accordingly###&lt;br /&gt;
idbdir = util.get_idbdir(trange[0])&lt;br /&gt;
&lt;br /&gt;
info = dt.rd_fdb(trange[0])&lt;br /&gt;
for k, v in info.iteritems():&lt;br /&gt;
    info[k] = info[k][~(info[k] == '')]&lt;br /&gt;
&lt;br /&gt;
sidx = np.where(&lt;br /&gt;
    np.logical_and(info['SOURCEID'] == 'Sun', info['PROJECTID'] == 'NormalObserving') &amp;amp; np.logical_and(&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;gt;= trange[0].lv,&lt;br /&gt;
        info['ST_TS'].astype(np.float) &amp;lt;= trange[&lt;br /&gt;
            1].lv))&lt;br /&gt;
filelist = info['FILE'][sidx]&lt;br /&gt;
&lt;br /&gt;
outpath = './msdata/'                                                                       ###Change accordingly###&lt;br /&gt;
if not os.path.exists(outpath):&lt;br /&gt;
    os.makedirs(outpath)&lt;br /&gt;
inpath = idbdir + '{}/'.format(trange[0].datetime.strftime(&amp;quot;%Y%m%d&amp;quot;))&lt;br /&gt;
ncpu = 1&lt;br /&gt;
&lt;br /&gt;
msfiles = timporteovsa.importeovsa(idbfiles=[inpath + ll for ll in filelist], ncpu=ncpu, timebin=&amp;quot;0s&amp;quot;, width=1,&lt;br /&gt;
                                   visprefix=outpath,&lt;br /&gt;
                                   nocreatms=False, doconcat=False,&lt;br /&gt;
                                   modelms=&amp;quot;&amp;quot;, doscaling=False, keep_nsclms=False, udb_corr=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you come across errors with calibeovsa, add following lines to your ~/.casa/init.py file.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/common/python')&lt;br /&gt;
sys.path.append('/common/python/packages/pipeline_casa')&lt;br /&gt;
execfile('/common/python/suncasa/tasks/mytasks.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Step 2: Concatenate all the 10 mins data, if there are any====&lt;br /&gt;
Follow this step if there are more than one .ms files, if not run step 3 directly. If doimage=True, a quicklook image will be produced (by integrating over the entire time) as shown below.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
# This is to set the path/name for the concatenated files&lt;br /&gt;
concatvis = os.path.basename(msfiles[0])[:11] + '_concat_cal.ms'&lt;br /&gt;
vis = calibeovsa.calibeovsa(msfiles, doconcat=True, concatvis=concatvis, caltype=['refpha','phacal'], doimage=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[file:Figure1_imagingtutorial.png|frame|center|800px|'''Figure 1:''' Quick-look full-Sun image after the initial calibration.]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3: Calibration ====&lt;br /&gt;
This will calibrate the input visibility, write out calibration tables under /data1/eovsa/caltable/, and apply the calibration. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
vis = calibeovsa.calibeovsa('IDB20170821202020.ms', caltype=['refpha','phacal'], doimage=True)            ###Change the vis filename accordingly###&lt;br /&gt;
# Append '_cal' to the ms filename and split the corrected column to the new caled ms&lt;br /&gt;
vis_str = str(' '.join(vis))&lt;br /&gt;
caled_vis=vis_str.replace('.ms','_cal.ms')&lt;br /&gt;
split(vis=' '.join(vis),outputvis=caled_vis,datacolumn='corrected',timerange='',correlation='XX')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One needs to transfer the created caled ms data files (xxx_concat_cal.ms or xxx_cal.ms) from pipeline to inti server, which has all the casatasks installed, in order to run the rest of the imaging steps.&lt;br /&gt;
&lt;br /&gt;
=== Connection details to Inti server ===&lt;br /&gt;
For Windows, on Mobaxterm,&lt;br /&gt;
&lt;br /&gt;
#With your NJIT VPN connected, connect to one of the afsconnect servers (for example, afsaccess3.njit.edu) using your UCID and password.&lt;br /&gt;
#ssh -X UCID@inti.hpcnet.campus.njit.edu &lt;br /&gt;
&lt;br /&gt;
To avoid typing the full inti address each time you attempt for ssh, you may wish to add the following lines with your username to C:\Program Files\Git\etc\ssh\ssh_config on Windows and /.ssh/config on Mac and Linux machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host inti&lt;br /&gt;
Hostname inti.hpcnet.campus.njit.edu&lt;br /&gt;
User USERNAME                                                                                              ###Insert UCID/inti username here###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have sufficient disk space with EOVSA data analysis over Inti, use your dedicated directory YOURDIRECTORY at the location given below. If you do not have a directory, Please take help from Sijie in creating one. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
cd /inti/data/users/YOURDIRECTORY     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Linux or Mac machine,&lt;br /&gt;
ssh -X UCID@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
=== Transferring data files between servers ===&lt;br /&gt;
For directly transferring your calibrated .ms data between the Pipeline and Inti servers, follow the below given steps. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
1. Log into Inti using your username.&lt;br /&gt;
ssh -X USERNAME@inti.hpcnet.campus.njit.edu&lt;br /&gt;
&lt;br /&gt;
Then create a tunnel into Pipeline from Inti.&lt;br /&gt;
ssh -L 8888:pipeline.solar.pvt:22 guest@ovsa.njit.edu&lt;br /&gt;
&lt;br /&gt;
2. Log into Inti again from a new terminal.&lt;br /&gt;
&lt;br /&gt;
Change to your working directory and give this command to copy your data on Pipeline.&lt;br /&gt;
scp -v -C -r -P 8888 USERNAMEofPipeline@localhost:PATHofMSDATA/MSfilename ./&lt;br /&gt;
Eg: scp -v -C -r -P 8888 shaheda@localhost:/data1/shaheda/IDB20220118173922_cal.ms ./&lt;br /&gt;
where, MSfilename, PATHofMSDATA are your .ms data and its path on Pipeline machine.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can follow the below procedure to do the transfer.&lt;br /&gt;
&lt;br /&gt;
For Windows, on mobaxterm, drag and drop the ms file to your local machine or use scp command as given below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C userid@pipeline:/your/folder/msfile /localmachine/destination/folder/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On mobaxterm and on your local terminal, use the following command to finally copy the ms file to Inti.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
scp -r -C /localmachine/destination/folder/msfile UCID@inti.hpcnet.campus.njit.edu:/inti/data/users/YOURDIRECTORY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Mac and Linux, SCP can be used in the same way. Add the following lines to your SSH config file, to bypass ovsa.njit.edu from copying.&lt;br /&gt;
vi ~/.ssh/config&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
Host ovsa&lt;br /&gt;
        HostName ovsa.njit.edu&lt;br /&gt;
        User guest&lt;br /&gt;
Host pipeline&lt;br /&gt;
        Hostname pipeline.solar.pvt&lt;br /&gt;
        User userid&lt;br /&gt;
        ProxyCommand ssh -W %h:%p guest@ovsa.njit.edu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Software details on the servers ===&lt;br /&gt;
On Inti,&lt;br /&gt;
when logging in for the first time, please add the following lines to your accounts ~/.bashrc file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;vi ~/.bashrc  &lt;br /&gt;
Insert the text given below and save it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
#### setting start ####&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;baozi.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /srg/.setenv_baozi&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;inti.hpcnet.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /inti/.setenv_inti&lt;br /&gt;
fi&lt;br /&gt;
if [ $HOSTNAME == &amp;quot;guko.resource.campus.njit.edu&amp;quot; ]; then&lt;br /&gt;
    source /data/data/.setenv_guko&lt;br /&gt;
fi&lt;br /&gt;
#### setting end ####&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both CASA 5 and 6 are available on Inti. &lt;br /&gt;
&lt;br /&gt;
Enter the bash environment on inti, and load the desired casa environment.&lt;br /&gt;
To load CASA 5, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa5&lt;br /&gt;
&amp;gt;&amp;gt; suncasa              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to load CASA 6, enter bash environment by giving &amp;gt;&amp;gt;bash &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; loadcasa6&lt;br /&gt;
&amp;gt;&amp;gt; ipython              #This should load the software making you ready for the analysis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, for example, to use clean, first start ipython as given above, then type in &amp;gt;&amp;gt;from casatasks import tclean&lt;br /&gt;
&lt;br /&gt;
====Step 4: Self-calibration====&lt;br /&gt;
[[file:Figure3_imagingtutorial.png|thumb|center|500px|Figure 2: Cotton-Schwab clean major and minor cycles. [Source: http://www.aoc.nrao.edu/~rurvashi/ImagingAlgorithmsInCasa/node2.html].]]&lt;br /&gt;
Follow the below given steps to run the self-calibration of the imaging data and produce the calibrated images in .fits format. https://github.com/binchensun/casa-eovsa/blob/master/slfcal_example.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import helioimage2fits as hf&lt;br /&gt;
import os&lt;br /&gt;
import numpy as np&lt;br /&gt;
import pickle&lt;br /&gt;
from matplotlib import gridspec as gridspec&lt;br /&gt;
from sunpy import map as smap&lt;br /&gt;
from matplotlib import pyplot as plt&lt;br /&gt;
from split_cli import split_cli as split&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# =========== task handlers =============&lt;br /&gt;
dofullsun = 1 # initial full-sun imaging                                         ###Change accordingly###&lt;br /&gt;
domasks=1 # get masks                                                            ###Change accordingly###&lt;br /&gt;
doslfcal=1 # main cycle of doing selfcalibration                                 ###Change accordingly###&lt;br /&gt;
doapply=1 # apply the results                                                    ###Change accordingly###&lt;br /&gt;
doclean_slfcaled=1 # perform clean for self-calibrated data                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# ============ declaring the working directories ============&lt;br /&gt;
workdir = os.getcwd()+'/' #main working directory. Using current directory in this example&lt;br /&gt;
slfcaldir = workdir+'slfcal/' #place to put all selfcalibration products&lt;br /&gt;
imagedir = slfcaldir+'images/' #place to put all selfcalibration images&lt;br /&gt;
maskdir = slfcaldir+'masks/' #place to put clean masks&lt;br /&gt;
imagedir_slfcaled = slfcaldir+'images_slfcaled/' #place to put final self-calibrated images&lt;br /&gt;
caltbdir = slfcaldir+'caltbs/' # place to put calibration tables&lt;br /&gt;
# make these directories if they do not already exist&lt;br /&gt;
dirs = [workdir, slfcaldir, imagedir, maskdir, imagedir_slfcaled, caltbdir]&lt;br /&gt;
for d in dirs:&lt;br /&gt;
    if not os.path.exists(d):&lt;br /&gt;
        os.makedirs(d)&lt;br /&gt;
&lt;br /&gt;
# ============ Split a short time for self-calibration ===========&lt;br /&gt;
# input visibility&lt;br /&gt;
ms_in = workdir + 'IDB20170821202020_cal.ms'                                    ###Change the initial calibrated (through calibeovsa) vis accordingly###&lt;br /&gt;
# output, selfcaled, visibility&lt;br /&gt;
ms_slfcaled = workdir + os.path.basename(ms_in).replace('cal','slfcaled') &lt;br /&gt;
# intermediate small visibility for selfcalbration &lt;br /&gt;
# selected time range for generating self-calibration solutions&lt;br /&gt;
trange='2017/08/21/20:21:10~2017/08/21/20:21:30'                                ###Change accordingly###&lt;br /&gt;
slfcalms = slfcaldir+'slfcalms.XX.slfcal'&lt;br /&gt;
slfcaledms = slfcaldir+'slfcalms.XX.slfcaled'&lt;br /&gt;
if not os.path.exists(slfcalms):&lt;br /&gt;
    split(vis=ms_in,outputvis=slfcalms,datacolumn='data',timerange=trange,correlation='XX')&lt;br /&gt;
&lt;br /&gt;
# ============ Prior definitions for spectral windows, antennas, pixel numbers =========&lt;br /&gt;
spws=[str(s+1) for s in range(30)]&lt;br /&gt;
antennas='0~12&amp;amp;0~12' &lt;br /&gt;
npix=512&lt;br /&gt;
nround=3 #number of slfcal cycles&lt;br /&gt;
&lt;br /&gt;
# =========== Step 1, doing a full-Sun image to find out phasecenter and appropriate field of view =========&lt;br /&gt;
if dofullsun:&lt;br /&gt;
    #initial mfs clean to find out the image phase center&lt;br /&gt;
    im_init='fullsun_init'&lt;br /&gt;
    os.system('rm -rf '+im_init+'*')&lt;br /&gt;
    tclean(vis=slfcalms,&lt;br /&gt;
            antenna='0~12',&lt;br /&gt;
            imagename=im_init,&lt;br /&gt;
            spw='1~15',&lt;br /&gt;
            specmode='mfs',&lt;br /&gt;
            timerange=trange,&lt;br /&gt;
            imsize=[npix],&lt;br /&gt;
            cell=['5arcsec'],&lt;br /&gt;
            niter=1000,&lt;br /&gt;
            gain=0.05,&lt;br /&gt;
            stokes='I',&lt;br /&gt;
            restoringbeam=['30arcsec'],&lt;br /&gt;
            interactive=False,&lt;br /&gt;
            pbcor=True)&lt;br /&gt;
&lt;br /&gt;
    hf.imreg(vis=slfcalms,imagefile=im_init+'.image.pbcor',fitsfile=im_init+'.fits',&lt;br /&gt;
             timerange=trange,usephacenter=False,verbose=True)&lt;br /&gt;
    clnjunks = ['.flux', '.mask', '.model', '.psf', '.residual','.sumwt','.pb','.image']     #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
    for clnjunk in clnjunks:&lt;br /&gt;
        if os.path.exists(im_init + clnjunk):&lt;br /&gt;
            os.system('rm -rf '+im_init + clnjunk)&lt;br /&gt;
&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fig = plt.figure(figsize=(6,6))&lt;br /&gt;
    ax = fig.add_subplot(111)&lt;br /&gt;
    eomap=smap.Map(im_init+'.fits')&lt;br /&gt;
    #eomap.data=eomap.data.reshape((npix,npix))&lt;br /&gt;
    eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
    eomap.plot(axes = ax)&lt;br /&gt;
    eomap.draw_limb()&lt;br /&gt;
    plt.show()&lt;br /&gt;
    viewer(im_init+'.image.pbcor')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure2_imagingtutorial.png|thumb|center|500px|Figure 3: Full-Sun image after initial clean to find the flare location.]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# parameters specific to the event (found from step 1)&lt;br /&gt;
phasecenter='J2000 10h02m59 11d58m07'                                               ###Change accordingly###&lt;br /&gt;
xran=[280,480]                                                                      ###Change accordingly###&lt;br /&gt;
yran=[-50,150]                                                                      ###Change accordingly###&lt;br /&gt;
&lt;br /&gt;
# =========== Step 2 (optional), generate masks =========&lt;br /&gt;
# if skipped, will not use any masks&lt;br /&gt;
if domasks:&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    delmod(slfcalms)&lt;br /&gt;
    antennas='0~12' &lt;br /&gt;
    pol='XX'&lt;br /&gt;
    imgprefix=maskdir+'slf_t0'&lt;br /&gt;
&lt;br /&gt;
    # step 1: set up the clean masks&lt;br /&gt;
    img_init=imgprefix+'_init_ar_'&lt;br /&gt;
    os.system('rm -rf '+img_init+'*')&lt;br /&gt;
    #spwrans_mask=['1~5','6~12','13~20','21~30']&lt;br /&gt;
    spwrans_mask=['1~12']&lt;br /&gt;
    #convert to a list of spws&lt;br /&gt;
    spwrans_mask_list = [[str(i) for i in (np.arange(int(m.split('~')[0]),int(m.split('~')[1])))] for m in spwrans_mask]&lt;br /&gt;
    masks=[]&lt;br /&gt;
    imnames=[]&lt;br /&gt;
    for spwran in spwrans_mask:&lt;br /&gt;
        imname=img_init+spwran.replace('~','-')&lt;br /&gt;
        try:&lt;br /&gt;
            tclean(vis=slfcalms,&lt;br /&gt;
                    antenna='0~12',&lt;br /&gt;
                    imagename=imname,&lt;br /&gt;
                    spw=spwran,&lt;br /&gt;
                    specmode='mfs',&lt;br /&gt;
                    timerange=trange,&lt;br /&gt;
                    imsize=[npix],&lt;br /&gt;
                    cell=['2arcsec'],&lt;br /&gt;
                    niter=1000,&lt;br /&gt;
                    gain=0.05,&lt;br /&gt;
                    stokes='XX',&lt;br /&gt;
                    restoringbeam=['20arcsec'],&lt;br /&gt;
                    phasecenter=phasecenter,&lt;br /&gt;
                    weighting='briggs',&lt;br /&gt;
                    robust=1.0,&lt;br /&gt;
                    interactive=True,&lt;br /&gt;
		    datacolumn='data',&lt;br /&gt;
                    pbcor=True,&lt;br /&gt;
                    savemodel='modelcolumn')&lt;br /&gt;
            imnames.append(imname+'.image')&lt;br /&gt;
            masks.append(imname+'.mask')&lt;br /&gt;
            clnjunks = ['.flux', '.model', '.psf', '.residual']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for clnjunk in clnjunks:&lt;br /&gt;
                if os.path.exists(imname + clnjunk):&lt;br /&gt;
                    os.system('rm -rf '+ imname + clnjunk)&lt;br /&gt;
        except:&lt;br /&gt;
            print('error in cleaning spw: '+spwran)&lt;br /&gt;
&lt;br /&gt;
    pickle.dump(masks,open(slfcaldir+'masks.p','wb'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Figure4_imagingtutorial.PNG|thumb|center|800px|Figure 4: Interactive clean window to create masks over the source. The white outline surrounding the source is the mask selected by the polygon drawing option.]]&lt;br /&gt;
&lt;br /&gt;
The outlines drawn for masks can be created by any of the icons with the letter 'R' in the Viewer window. The instructions for doing this can be found by hovering over those icons.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 3, main step of selfcalibration =========&lt;br /&gt;
if doslfcal:&lt;br /&gt;
    if os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        masks=pickle.load(open(slfcaldir+'masks.p','rb'))&lt;br /&gt;
    if not os.path.exists(slfcaldir+'masks.p'):&lt;br /&gt;
        print 'masks do not exist. Use default mask'&lt;br /&gt;
        masks=[]&lt;br /&gt;
    os.system('rm -rf '+imagedir+'*')&lt;br /&gt;
    os.system('rm -rf '+caltbdir+'*')&lt;br /&gt;
    #first step: make a mock caltable for the entire database&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    slftbs=[]&lt;br /&gt;
    calprefix=caltbdir+'slf'&lt;br /&gt;
    imgprefix=imagedir+'slf'&lt;br /&gt;
    tb.open(slfcalms+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    # starting beam size at 3.4 GHz in arcsec        #Change accordingly&lt;br /&gt;
    sbeam=40.&lt;br /&gt;
    strtmp=[m.replace(':','') for m in trange.split('~')]&lt;br /&gt;
    timestr='t'+strtmp[0]+'-'+strtmp[1]&lt;br /&gt;
    refantenna='0'&lt;br /&gt;
    # number of iterations for each round&lt;br /&gt;
    niters=[100, 300, 500]&lt;br /&gt;
    # roburst value for weighting the baselines&lt;br /&gt;
    robusts=[1.0, 0.5, 0.0]&lt;br /&gt;
    # apply calibration tables? Set to true for most cases&lt;br /&gt;
    doapplycal=[1,1,1]&lt;br /&gt;
    # modes for calibration, 'p' for phase-only, 'a' for amplitude only, 'ap' for both&lt;br /&gt;
    calmodes=['p','p','a']&lt;br /&gt;
    # setting uvranges for model image (optional, not used here)&lt;br /&gt;
    uvranges=['','',''] &lt;br /&gt;
    for n in range(nround):&lt;br /&gt;
        slfcal_tb_g= calprefix+'.G'+str(n)&lt;br /&gt;
        fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
        gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
        for s,sp in enumerate(spws):&lt;br /&gt;
            print 'processing spw: '+sp&lt;br /&gt;
            cfreq=cfreqs[int(sp)]&lt;br /&gt;
            # setting restoring beam size (not very useful for selfcal anyway, but just to see the results)&lt;br /&gt;
            bm=max(sbeam*cfreqs[1]/cfreq, 6.)&lt;br /&gt;
            slfcal_img = imgprefix+'.spw'+sp.zfill(2)+'.slfcal'+str(n)&lt;br /&gt;
            # only the first round uses nearby spws for getting initial model&lt;br /&gt;
            if n == 0:&lt;br /&gt;
                spbg=max(int(sp)-2,1)&lt;br /&gt;
                sped=min(int(sp)+2,30)&lt;br /&gt;
                spwran=str(spbg)+'~'+str(sped)&lt;br /&gt;
                print('using spw {0:s} as model'.format(spwran))&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print('using mask {0:s}'.format(mask))&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            else:&lt;br /&gt;
                spwran = sp&lt;br /&gt;
                if 'spwrans_mask' in vars():&lt;br /&gt;
                    for m, spwran_mask in enumerate(spwrans_mask):&lt;br /&gt;
                        if sp in spwran_mask:&lt;br /&gt;
                            mask = masks[m]&lt;br /&gt;
                            print 'using mask {0:s}'.format(mask)&lt;br /&gt;
                            findmask = True&lt;br /&gt;
                    if not findmask:&lt;br /&gt;
                        print('mask not found. Do use any masks')&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=slfcalms,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=slfcal_img,&lt;br /&gt;
                        uvrange=uvranges[n],&lt;br /&gt;
                        spw=spwran,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['2arcsec'],&lt;br /&gt;
                        niter=niters[n],&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes='XX', #use pol XX image as the model&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=robusts[n],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask=mask,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        pbcor=False,&lt;br /&gt;
                        interactive=False,&lt;br /&gt;
                        savemodel='modelcolumn')&lt;br /&gt;
                if os.path.exists(slfcal_img+'.image'):&lt;br /&gt;
                    fitsfile=slfcal_img+'.fits'&lt;br /&gt;
                    hf.imreg(vis=slfcalms,imagefile=slfcal_img+'.image',fitsfile=fitsfile,&lt;br /&gt;
                             timerange=trange,usephacenter=False,toTb=True,verbose=False,overwrite=True)&lt;br /&gt;
                clnjunks = ['.mask','.flux', '.model', '.psf', '.residual', '.image','.pb','.image.pbcor','.sumwt']   #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
                for clnjunk in clnjunks:&lt;br /&gt;
                    if os.path.exists(slfcal_img + clnjunk):&lt;br /&gt;
                        os.system('rm -rf '+ slfcal_img + clnjunk)&lt;br /&gt;
                ax = fig.add_subplot(gs[s])&lt;br /&gt;
                eomap=smap.Map(fitsfile)&lt;br /&gt;
                eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
                eomap.plot(axes = ax)&lt;br /&gt;
                eomap.draw_limb()&lt;br /&gt;
                #eomap.draw_grid()&lt;br /&gt;
                ax.set_title(' ')&lt;br /&gt;
		ax.get_xaxis().set_visible(False)&lt;br /&gt;
		ax.get_yaxis().set_visible(False)&lt;br /&gt;
                ax.set_xlim(xran)&lt;br /&gt;
                ax.set_ylim(yran)&lt;br /&gt;
                os.system('rm -f '+ fitsfile)&lt;br /&gt;
&lt;br /&gt;
            except:&lt;br /&gt;
                print 'error in cleaning spw: '+sp&lt;br /&gt;
                print 'using nearby spws for initial model'&lt;br /&gt;
                sp_e=int(sp)+2&lt;br /&gt;
                sp_i=int(sp)-2&lt;br /&gt;
                if sp_i &amp;lt; 1:&lt;br /&gt;
                    sp_i = 1&lt;br /&gt;
                if sp_e &amp;gt; 30:&lt;br /&gt;
                    sp_e = 30&lt;br /&gt;
                sp_=str(sp_i)+'~'+str(sp_e)&lt;br /&gt;
                try:&lt;br /&gt;
                    tget(tclean)&lt;br /&gt;
                    spw=sp_&lt;br /&gt;
                    print('using spw {0:s} as model'.format(sp_))&lt;br /&gt;
                    tclean()&lt;br /&gt;
                except:&lt;br /&gt;
                    print 'still not successful. abort...'&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
            gaincal(vis=slfcalms, refant=refantenna,antenna=antennas,caltable=slfcal_tb_g,spw=sp, uvrange='',\&lt;br /&gt;
                    gaintable=[],selectdata=True,timerange=trange,solint='inf',gaintype='G',calmode=calmodes[n],\&lt;br /&gt;
                    combine='',minblperant=4,minsnr=2,append=True)&lt;br /&gt;
            if not os.path.exists(slfcal_tb_g):&lt;br /&gt;
                print 'No solution found in spw: '+sp&lt;br /&gt;
        figname=imagedir+'slf_t0_n{:d}.png'.format(n)&lt;br /&gt;
	plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
        plt.savefig(figname)&lt;br /&gt;
        time.sleep(10)&lt;br /&gt;
        plt.close()&lt;br /&gt;
&lt;br /&gt;
        if os.path.exists(slfcal_tb_g):&lt;br /&gt;
            slftbs.append(slfcal_tb_g)&lt;br /&gt;
            slftb=[slfcal_tb_g]&lt;br /&gt;
            os.chdir(slfcaldir)&lt;br /&gt;
            if calmodes[n] == 'p': &lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='phase',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,-180,180],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            if calmodes[n] == 'a':&lt;br /&gt;
                plotcal(caltable=slfcal_tb_g,antenna='1~12',xaxis='freq',yaxis='amp',\&lt;br /&gt;
                        subplot=431,plotrange=[-1,-1,0,2.],iteration='antenna',figfile=slfcal_tb_g+'.png',showgui=False)&lt;br /&gt;
            os.chdir(workdir)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        if doapplycal[n]:&lt;br /&gt;
            clearcal(slfcalms)&lt;br /&gt;
            delmod(slfcalms)&lt;br /&gt;
            applycal(vis=slfcalms,gaintable=slftb,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
                     antenna=antennas,interp='nearest',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
&lt;br /&gt;
        if n &amp;lt; nround-1: &lt;br /&gt;
            prompt=raw_input('Continuing to selfcal?')&lt;br /&gt;
            #prompt='y'&lt;br /&gt;
            if prompt.lower() == 'n':&lt;br /&gt;
                if os.path.exists(slfcaledms):&lt;br /&gt;
                    os.system('rm -rf '+slfcaledms)&lt;br /&gt;
                split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
                print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
                break&lt;br /&gt;
            if prompt.lower() == 'y':&lt;br /&gt;
                slfcalms_=slfcalms+str(n)&lt;br /&gt;
                if os.path.exists(slfcalms_):&lt;br /&gt;
                    os.system('rm -rf '+slfcalms_)&lt;br /&gt;
                split(slfcalms,slfcalms_,datacolumn='corrected')&lt;br /&gt;
                slfcalms=slfcalms_&lt;br /&gt;
        else:&lt;br /&gt;
            if os.path.exists(slfcaledms):&lt;br /&gt;
                os.system('rm -rf '+slfcaledms)&lt;br /&gt;
            split(slfcalms,slfcaledms,datacolumn='corrected')&lt;br /&gt;
            print 'Final calibrated ms is {0:s}'.format(slfcaledms)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 4: Apply self-calibration tables =========&lt;br /&gt;
if doapply:&lt;br /&gt;
    import glob&lt;br /&gt;
    os.chdir(workdir)&lt;br /&gt;
    clearcal(ms_in)&lt;br /&gt;
    clearcal(slfcalms)&lt;br /&gt;
    applycal(vis=slfcalms,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    applycal(vis=ms_in,gaintable=slftbs,spw=','.join(spws),selectdata=True,\&lt;br /&gt;
             antenna=antennas,interp='linear',flagbackup=False,applymode='calonly',calwt=False)&lt;br /&gt;
    if os.path.exists(ms_slfcaled):&lt;br /&gt;
        os.system('rm -rf '+ms_slfcaled)&lt;br /&gt;
    split(ms_in, ms_slfcaled,datacolumn='corrected')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Slf.G0.png|thumb|center|500px|Figure 1: Phase before self-calibration]]&lt;br /&gt;
[[file:Slf.G1.png|thumb|center|500px|Figure 2: Phase after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
# =========== Step 5: Generate final self-calibrated images (optional) =========&lt;br /&gt;
if doclean_slfcaled:&lt;br /&gt;
    import glob&lt;br /&gt;
    pol='XX'&lt;br /&gt;
    print('Processing ' + trange)&lt;br /&gt;
    img_final=imagedir_slfcaled+'/slf_final_{0}_t0'.format(pol)&lt;br /&gt;
    vis = ms_slfcaled&lt;br /&gt;
    spws=[str(s+1) for s in range(30)]&lt;br /&gt;
    tb.open(vis+'/SPECTRAL_WINDOW')&lt;br /&gt;
    reffreqs=tb.getcol('REF_FREQUENCY')&lt;br /&gt;
    bdwds=tb.getcol('TOTAL_BANDWIDTH')&lt;br /&gt;
    cfreqs=reffreqs+bdwds/2.&lt;br /&gt;
    tb.close()&lt;br /&gt;
    sbeam=30.&lt;br /&gt;
    from matplotlib import gridspec as gridspec&lt;br /&gt;
    from sunpy import map as smap&lt;br /&gt;
    from matplotlib import pyplot as plt&lt;br /&gt;
    fitsfiles=[]&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        bm=max(sbeam*cfreqs[1]/cfreq,4.)&lt;br /&gt;
        imname=img_final+'_s'+sp.zfill(2)&lt;br /&gt;
        fitsfile=imname+'.fits'&lt;br /&gt;
        if not os.path.exists(fitsfile):&lt;br /&gt;
            print 'cleaning spw {0:s} with beam size {1:.1f}&amp;quot;'.format(sp,bm)&lt;br /&gt;
            try:&lt;br /&gt;
                tclean(vis=vis,&lt;br /&gt;
                        antenna=antennas,&lt;br /&gt;
                        imagename=imname,&lt;br /&gt;
                        spw=sp,&lt;br /&gt;
                        specmode='mfs',&lt;br /&gt;
                        timerange=trange,&lt;br /&gt;
                        imsize=[npix],&lt;br /&gt;
                        cell=['1arcsec'],&lt;br /&gt;
                        niter=1000,&lt;br /&gt;
                        gain=0.05,&lt;br /&gt;
                        stokes=pol,&lt;br /&gt;
                        weighting='briggs',&lt;br /&gt;
                        robust=2.0,&lt;br /&gt;
                        restoringbeam=[str(bm)+'arcsec'],&lt;br /&gt;
                        phasecenter=phasecenter,&lt;br /&gt;
                        mask='',&lt;br /&gt;
                        pbcor=True,&lt;br /&gt;
                        interactive=False)&lt;br /&gt;
            except:&lt;br /&gt;
                print 'cleaning spw '+sp+' unsuccessful. Proceed to next spw'&lt;br /&gt;
                continue&lt;br /&gt;
            if os.path.exists(imname+'.image.pbcor'):&lt;br /&gt;
                imn = imname+'.image.pbcor'&lt;br /&gt;
                hf.imreg(vis=vis,imagefile=imn,fitsfile=fitsfile,&lt;br /&gt;
                         timerange=trange,usephacenter=False,toTb=True,verbose=False)&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
            junks=['.flux','.model','.psf','.residual','.mask','.image','.pb','.image.pbcor','.sumwt']  #Do not run the next 4 lines if needed to view and assess the subset of clean process images&lt;br /&gt;
            for junk in junks:&lt;br /&gt;
                if os.path.exists(imname+junk):&lt;br /&gt;
                    os.system('rm -rf '+imname+junk)&lt;br /&gt;
        else:&lt;br /&gt;
            print('fits file '+fitsfile+' already exists, skip clean...')&lt;br /&gt;
            fitsfiles.append(fitsfile)&lt;br /&gt;
&lt;br /&gt;
    fig = plt.figure(figsize=(8.4,7.))&lt;br /&gt;
    gs = gridspec.GridSpec(5, 6)&lt;br /&gt;
    for s,sp in enumerate(spws):&lt;br /&gt;
        cfreq=cfreqs[int(sp)]&lt;br /&gt;
        ax = fig.add_subplot(gs[s])&lt;br /&gt;
        eomap=smap.Map(fitsfiles[s])&lt;br /&gt;
        eomap.plot_settings['cmap'] = plt.get_cmap('jet')&lt;br /&gt;
        eomap.plot(axes = ax)&lt;br /&gt;
        eomap.draw_limb()&lt;br /&gt;
        ax.set_title(' ')&lt;br /&gt;
        ax.get_xaxis().set_visible(False)&lt;br /&gt;
        ax.get_yaxis().set_visible(False)&lt;br /&gt;
        ax.set_xlim(xran)&lt;br /&gt;
        ax.set_ylim(yran)&lt;br /&gt;
        plt.text(0.98,0.85,'{0:.1f} GHz'.format(cfreq/1e9),transform=ax.transAxes,ha='right',color='w',fontweight='bold')&lt;br /&gt;
    plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)&lt;br /&gt;
    plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The .fits files of the self calibrated images at each frequency for the given time are saved at /slfcal/images_slfcaled in your working directory.&lt;br /&gt;
&lt;br /&gt;
[[file:Slf_t0_n0.png|thumb|center|500px|Figure 3: Multi-frequency images before self-calibration]]&lt;br /&gt;
[[file:Slf_t0_n1.png|thumb|center|500px|Figure 4: Multi-frequency images after self-calibration]]&lt;br /&gt;
&lt;br /&gt;
====Step 5: Quick-look imaging ==== &amp;lt;!-- ====Step 6: Making the full set of images====  --&amp;gt;&lt;br /&gt;
For spectral imaging analysis of the event, follow [http://www.ovsa.njit.edu/wiki/index.php/EOVSA_Data_Analysis_Tutorial#Spectral_Imaging_with_SunCASA this tutorial] using the self-calibrated data obtained from the previous step or use [https://colab.research.google.com/drive/1lSLLxgOG6b8kgu9Sk6kSKvrViyubnXG6?usp=sharing#scrollTo=xbXyyLmCFCGL this link].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
from suncasa.utils import qlookplot as ql    ## (Optional) Supply the npz file of the dynamic spectrum from previous step.&lt;br /&gt;
				            ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
                                            ## set the time interval&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
visibility_data = 'IDB20170821202020_slfcaled.ms'&lt;br /&gt;
specfile = visibility_data + '.dspec.npz'&lt;br /&gt;
d = ds.Dspec(visibility_data, bl='4&amp;amp;9', specfile=specfile)&lt;br /&gt;
&lt;br /&gt;
timerange = '19:02:00~19:02:10'             ## select frequency range from 2.5 GHz to 3.5 GHz&lt;br /&gt;
spw = '2~5'                                 ## select stokes XX&lt;br /&gt;
stokes = 'XX'                               ## turn off AIA image plotting, default is True&lt;br /&gt;
plotaia = False&lt;br /&gt;
xycen = [375, 45]  ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec'] ## pixel size&lt;br /&gt;
imsize=[128]   ## x and y image size in pixels. &lt;br /&gt;
fov = [100,100]  ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
spw = ['{}'.format(s) for s in range(1,31)]&lt;br /&gt;
clevels = [0.5, 1.0]  ## contour levels to fill in between.&lt;br /&gt;
calpha=0.35  ## now tune down the alpha&lt;br /&gt;
restoringbeam=['6arcsec']&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, stokes=stokes, \&lt;br /&gt;
            restoringbeam=restoringbeam,imsize=imsize,cell=cell, \&lt;br /&gt;
            xycen=xycen,fov=fov,clevels=clevels,calpha=calpha)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6548</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6548"/>
		<updated>2022-07-07T20:10:10Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 1. Introduction to EOVSA and Datasets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at 451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
===Level 0 (raw visibility) Data===&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.  However, to be useful for imaging, these files must be first calibrated and then converted to a CASA measurement set.  At present, this can only be done with software at the OVRO site although we are working on software to allow this processing to be done elsewhere.  For now, please request this processing to be done for you by emailing Dale Gary, Bin Chen, Sijie Yu, or others you may know in the solar radio group.&lt;br /&gt;
&lt;br /&gt;
===Level 1 (calibrated visibility) Data===&lt;br /&gt;
The images you see in the browser are generated by an automated pipeline that also produces calibrated CASA ms datasets, but at 1-min integration.  If a 1-min cadence is sufficient for your purposes, you may wish to download the calibrated data and perform your own imaging.  The 1-min cadence calibrated data are at [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ this link].  You should be aware that a model disk has been subtracted from the visibilities in these files, which is what you want if you are interested in imaging active regions or flares.  It is possible to add the model back, but this is not available (yet) in standard software, so please contact someone in the NJIT solar radio group for help with that.&lt;br /&gt;
&lt;br /&gt;
===Other useful links===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files. Please&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6540</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6540"/>
		<updated>2022-07-07T08:34:35Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 11. Spectral Fitting with GSFIT (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files. Please&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer [http://ovsa.njit.edu/wiki/index.php/GSFIT_Help this page] for a detailed description of further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6539</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6539"/>
		<updated>2022-07-07T08:33:42Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 9. Downloading fits files to your local system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files. Please&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer this page for the detailed description on further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6538</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6538"/>
		<updated>2022-07-07T08:32:03Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 11. Spectral Fitting with GSFIT (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] can be read as an input to the GSFIT package. The screenshot of that is shown in Figure 9. Refer this page for the detailed description on further GSFIT analysis. &lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6537</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6537"/>
		<updated>2022-07-07T08:28:01Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 11. Spectral Fitting with GSFIT (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the can be taken as input to the GSFIT package. The screenshot of that is shown in Figure 9.&lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.PNG|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=File:GSFIT_20220507.PNG&amp;diff=6536</id>
		<title>File:GSFIT 20220507.PNG</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=File:GSFIT_20220507.PNG&amp;diff=6536"/>
		<updated>2022-07-07T08:27:37Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6535</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6535"/>
		<updated>2022-07-07T08:27:12Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 11. Spectral Fitting with GSFIT (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the can be taken as input to the GSFIT package. The screenshot of that is shown in Figure 9.&lt;br /&gt;
&lt;br /&gt;
[[file:GSFIT_20220507.png|thumb|right|400px|Figure 9: Image and the corresponding spectrum on GSFIT GUI.]]&lt;br /&gt;
&lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6534</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6534"/>
		<updated>2022-07-07T08:23:42Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 10. Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Figure 8: Multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the can be taken as input to the GSFIT package. The screenshot of that is shown in Figure &lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6533</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6533"/>
		<updated>2022-07-07T08:22:56Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 8. Quick-Look Imaging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5: EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the can be taken as input to the GSFIT package. The screenshot of that is shown in Figure &lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6532</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6532"/>
		<updated>2022-07-07T08:22:44Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 8. Quick-Look Imaging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|Figure 5:EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|Figure 6: EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|Figure 7: EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the can be taken as input to the GSFIT package. The screenshot of that is shown in Figure &lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6530</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6530"/>
		<updated>2022-07-07T08:21:46Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 11. Installation of SunCASA (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Spectral Fitting with GSFIT (optional)=&lt;br /&gt;
The .fits images obtained in the can be taken as input to the GSFIT package. The screenshot of that is shown in Figure &lt;br /&gt;
=12. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6529</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6529"/>
		<updated>2022-07-07T08:16:02Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Installation of SunCASA (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=11. Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6528</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6528"/>
		<updated>2022-07-07T08:15:50Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=10. Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6527</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6527"/>
		<updated>2022-07-07T08:15:36Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
=Plotting Images in SSWIDL=&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6526</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6526"/>
		<updated>2022-07-07T08:15:24Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 9. Downloading fits files to your local system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] for an example on downloading image fits files.&lt;br /&gt;
&lt;br /&gt;
===Plotting Images in SSWIDL===&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6525</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6525"/>
		<updated>2022-07-07T08:14:01Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 9. Downloading fits files to your local system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. Please follow the &lt;br /&gt;
&lt;br /&gt;
===Plotting Images in SSWIDL===&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6524</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6524"/>
		<updated>2022-07-07T07:50:27Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* 9. Downloading fits files to your local system with Batch-Mode Imaging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
&lt;br /&gt;
===Plotting Images in SSWIDL===&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6523</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6523"/>
		<updated>2022-07-07T07:49:34Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system with Batch-Mode Imaging=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
====Producing a 30-band map cube for a given time====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_example.py. First, download or copy the script to your own working directory and cd to your directory. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg.png|thumb|right|300px|Example multi-frequency images at a single time integration]]&lt;br /&gt;
&lt;br /&gt;
Second (optional), change inputs in the following block in your copy of the &amp;quot;imaging_example.py&amp;quot; script and save the changes. This block has definitions for time range, image center and FOV, antennas used, cell size, number of pixels, etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
trange = '2017/08/21/20:21:00~2017/08/21/20:21:30' # time range for imaging&lt;br /&gt;
xycen = [380., 50.] # center of the output map (in solar X and Y, Unit: arcsec)&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = '' # Use all 13 EOVSA 2-m antennas by default&lt;br /&gt;
npix = 256 # number of pixels in the image&lt;br /&gt;
cell = '1arcsec' # pixel scale in arcsec&lt;br /&gt;
pol = 'XX' # polarization to image, use XX for now&lt;br /&gt;
pbcor = True # correct for primary beam response?&lt;br /&gt;
outdir = './images' # Specify where to save the output fits files&lt;br /&gt;
outimgpre = 'EO' # Something to add to the output image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA via&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is a combined 30-band FITS file saved under &amp;quot;outdir&amp;quot;. The naming conversion is outimgpre + YYYYMMDDTHHMMSS_ALLBD.fits. In this example, it is &amp;quot;./images/EO20170821T202115.000_ALLBD.fits&amp;quot;. Here is the detailed information of the axes of the output FITS file.&lt;br /&gt;
&amp;lt;pre&amp;gt;                         &lt;br /&gt;
NAXIS   =                    4 / number of array dimensions                     &lt;br /&gt;
NAXIS1  =                  128                                                  &lt;br /&gt;
NAXIS2  =                  128                                                  &lt;br /&gt;
NAXIS3  =                   30                                                  &lt;br /&gt;
NAXIS4  =                    2  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From this point, you can use your favorite language to read the fits files and plot them. The last block of the example script uses SunPy.map to generate the plot shown on the right. For SSWIDL users, please refer to [[#Plotting Images in SSWIDL|Section 3.3.3.3]].&lt;br /&gt;
&lt;br /&gt;
====Producing a time series of 30-band maps (a 4-d cube)====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_timeseries_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_timeseries_example.py. The script enables parallel-processing (based on a customized task &amp;quot;ptclean3&amp;quot; -- do not ask me why we have &amp;quot;3&amp;quot; in the task name). To invoke more CPU processes for parallel-processing, change &amp;quot;nthreads&amp;quot; in the preambles from 1 to the number of threads you wish to use.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_timeseries_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Similar as the previous script, change inputs in the following block of your copy of the &amp;quot;imaging_timeseries_example.py&amp;quot; script and save the changes. &lt;br /&gt;
&lt;br /&gt;
[[file:fig-specmovie.png|thumb|right|300px|Example multi-frequency images at one time frame in the [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html output javascript movie]]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ####################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
specfile = vis + '.dspec.npz'  ## input dynamic spectrum&lt;br /&gt;
nthreads = 1  # Number of processing threads to use&lt;br /&gt;
overwrite = True  # whether to overwrite the existed fits files.&lt;br /&gt;
trange = ''  # time range for imaging, default to all times in the data&lt;br /&gt;
twidth = 1  # make one image out of every 2 time integrations&lt;br /&gt;
xycen = [380., 50.]  # center of the output map in solar X and Y. Unit: arcsec&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = ''  # default is to use all 13 EOVSA 2-m antennas. &lt;br /&gt;
npix = 128  # number of pixels in the image&lt;br /&gt;
cell = '2arcsec'  # pixel scale in arcsec&lt;br /&gt;
pol = 'XX'  # polarization to image, use XX for now&lt;br /&gt;
pbcor = True  # correct for primary beam response?&lt;br /&gt;
grid_spacing = 5. * u.deg  # grid spacing in degrees&lt;br /&gt;
outdir = './image_series/'  # Specify where to save the output fits files&lt;br /&gt;
imresfile = 'imres.npz'  # File to write summary of the imaging results&lt;br /&gt;
outimgpre = 'EO'  # Something to add to the image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA by&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_timeseries_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output fits images and a summary file imresfile are saved under &amp;quot;outdir&amp;quot; (in this example &amp;quot;./image_timeseries&amp;quot;). The naming convention of output fits images is the same as [[#Producing a 30-band map at a given time|the previous section]]. The summary yields the time, frequency, and path to every image.&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres = np.load(outdir + imresfile)['imres'].item()&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres.keys()&lt;br /&gt;
['FreqGHz', 'ImageName', 'Succeeded', 'BeginTime', 'EndTime']&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: ls image_series/*.fits | head -5&lt;br /&gt;
image_series/EO20170821T201800.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201804.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201808.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201812.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201816.500_ALLBD.fits&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last block of the example script uses SunPy.map to generate a series of plots and wraps them as a [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html javascript movie].&lt;br /&gt;
&lt;br /&gt;
===Plotting Images in SSWIDL===&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|400px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6522</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6522"/>
		<updated>2022-07-07T07:48:42Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system with Batch-Mode Imaging=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
====Producing a 30-band map cube for a given time====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_example.py. First, download or copy the script to your own working directory and cd to your directory. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg.png|thumb|right|300px|Example multi-frequency images at a single time integration]]&lt;br /&gt;
&lt;br /&gt;
Second (optional), change inputs in the following block in your copy of the &amp;quot;imaging_example.py&amp;quot; script and save the changes. This block has definitions for time range, image center and FOV, antennas used, cell size, number of pixels, etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
trange = '2017/08/21/20:21:00~2017/08/21/20:21:30' # time range for imaging&lt;br /&gt;
xycen = [380., 50.] # center of the output map (in solar X and Y, Unit: arcsec)&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = '' # Use all 13 EOVSA 2-m antennas by default&lt;br /&gt;
npix = 256 # number of pixels in the image&lt;br /&gt;
cell = '1arcsec' # pixel scale in arcsec&lt;br /&gt;
pol = 'XX' # polarization to image, use XX for now&lt;br /&gt;
pbcor = True # correct for primary beam response?&lt;br /&gt;
outdir = './images' # Specify where to save the output fits files&lt;br /&gt;
outimgpre = 'EO' # Something to add to the output image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA via&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is a combined 30-band FITS file saved under &amp;quot;outdir&amp;quot;. The naming conversion is outimgpre + YYYYMMDDTHHMMSS_ALLBD.fits. In this example, it is &amp;quot;./images/EO20170821T202115.000_ALLBD.fits&amp;quot;. Here is the detailed information of the axes of the output FITS file.&lt;br /&gt;
&amp;lt;pre&amp;gt;                         &lt;br /&gt;
NAXIS   =                    4 / number of array dimensions                     &lt;br /&gt;
NAXIS1  =                  128                                                  &lt;br /&gt;
NAXIS2  =                  128                                                  &lt;br /&gt;
NAXIS3  =                   30                                                  &lt;br /&gt;
NAXIS4  =                    2  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From this point, you can use your favorite language to read the fits files and plot them. The last block of the example script uses SunPy.map to generate the plot shown on the right. For SSWIDL users, please refer to [[#Plotting Images in SSWIDL|Section 3.3.3.3]].&lt;br /&gt;
&lt;br /&gt;
====Producing a time series of 30-band maps (a 4-d cube)====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_timeseries_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_timeseries_example.py. The script enables parallel-processing (based on a customized task &amp;quot;ptclean3&amp;quot; -- do not ask me why we have &amp;quot;3&amp;quot; in the task name). To invoke more CPU processes for parallel-processing, change &amp;quot;nthreads&amp;quot; in the preambles from 1 to the number of threads you wish to use.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_timeseries_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Similar as the previous script, change inputs in the following block of your copy of the &amp;quot;imaging_timeseries_example.py&amp;quot; script and save the changes. &lt;br /&gt;
&lt;br /&gt;
[[file:fig-specmovie.png|thumb|right|300px|Example multi-frequency images at one time frame in the [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html output javascript movie]]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ####################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
specfile = vis + '.dspec.npz'  ## input dynamic spectrum&lt;br /&gt;
nthreads = 1  # Number of processing threads to use&lt;br /&gt;
overwrite = True  # whether to overwrite the existed fits files.&lt;br /&gt;
trange = ''  # time range for imaging, default to all times in the data&lt;br /&gt;
twidth = 1  # make one image out of every 2 time integrations&lt;br /&gt;
xycen = [380., 50.]  # center of the output map in solar X and Y. Unit: arcsec&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = ''  # default is to use all 13 EOVSA 2-m antennas. &lt;br /&gt;
npix = 128  # number of pixels in the image&lt;br /&gt;
cell = '2arcsec'  # pixel scale in arcsec&lt;br /&gt;
pol = 'XX'  # polarization to image, use XX for now&lt;br /&gt;
pbcor = True  # correct for primary beam response?&lt;br /&gt;
grid_spacing = 5. * u.deg  # grid spacing in degrees&lt;br /&gt;
outdir = './image_series/'  # Specify where to save the output fits files&lt;br /&gt;
imresfile = 'imres.npz'  # File to write summary of the imaging results&lt;br /&gt;
outimgpre = 'EO'  # Something to add to the image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA by&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_timeseries_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output fits images and a summary file imresfile are saved under &amp;quot;outdir&amp;quot; (in this example &amp;quot;./image_timeseries&amp;quot;). The naming convention of output fits images is the same as [[#Producing a 30-band map at a given time|the previous section]]. The summary yields the time, frequency, and path to every image.&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres = np.load(outdir + imresfile)['imres'].item()&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres.keys()&lt;br /&gt;
['FreqGHz', 'ImageName', 'Succeeded', 'BeginTime', 'EndTime']&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: ls image_series/*.fits | head -5&lt;br /&gt;
image_series/EO20170821T201800.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201804.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201808.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201812.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201816.500_ALLBD.fits&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last block of the example script uses SunPy.map to generate a series of plots and wraps them as a [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html javascript movie].&lt;br /&gt;
&lt;br /&gt;
====Plotting Images in SSWIDL====&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.PNG|thumb|right|300px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=File:Batch_mode_images.PNG&amp;diff=6521</id>
		<title>File:Batch mode images.PNG</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=File:Batch_mode_images.PNG&amp;diff=6521"/>
		<updated>2022-07-07T07:46:41Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6520</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6520"/>
		<updated>2022-07-07T07:46:18Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system with Batch-Mode Imaging=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
====Producing a 30-band map cube for a given time====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_example.py. First, download or copy the script to your own working directory and cd to your directory. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg.png|thumb|right|300px|Example multi-frequency images at a single time integration]]&lt;br /&gt;
&lt;br /&gt;
Second (optional), change inputs in the following block in your copy of the &amp;quot;imaging_example.py&amp;quot; script and save the changes. This block has definitions for time range, image center and FOV, antennas used, cell size, number of pixels, etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
trange = '2017/08/21/20:21:00~2017/08/21/20:21:30' # time range for imaging&lt;br /&gt;
xycen = [380., 50.] # center of the output map (in solar X and Y, Unit: arcsec)&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = '' # Use all 13 EOVSA 2-m antennas by default&lt;br /&gt;
npix = 256 # number of pixels in the image&lt;br /&gt;
cell = '1arcsec' # pixel scale in arcsec&lt;br /&gt;
pol = 'XX' # polarization to image, use XX for now&lt;br /&gt;
pbcor = True # correct for primary beam response?&lt;br /&gt;
outdir = './images' # Specify where to save the output fits files&lt;br /&gt;
outimgpre = 'EO' # Something to add to the output image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA via&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is a combined 30-band FITS file saved under &amp;quot;outdir&amp;quot;. The naming conversion is outimgpre + YYYYMMDDTHHMMSS_ALLBD.fits. In this example, it is &amp;quot;./images/EO20170821T202115.000_ALLBD.fits&amp;quot;. Here is the detailed information of the axes of the output FITS file.&lt;br /&gt;
&amp;lt;pre&amp;gt;                         &lt;br /&gt;
NAXIS   =                    4 / number of array dimensions                     &lt;br /&gt;
NAXIS1  =                  128                                                  &lt;br /&gt;
NAXIS2  =                  128                                                  &lt;br /&gt;
NAXIS3  =                   30                                                  &lt;br /&gt;
NAXIS4  =                    2  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From this point, you can use your favorite language to read the fits files and plot them. The last block of the example script uses SunPy.map to generate the plot shown on the right. For SSWIDL users, please refer to [[#Plotting Images in SSWIDL|Section 3.3.3.3]].&lt;br /&gt;
&lt;br /&gt;
====Producing a time series of 30-band maps (a 4-d cube)====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_timeseries_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_timeseries_example.py. The script enables parallel-processing (based on a customized task &amp;quot;ptclean3&amp;quot; -- do not ask me why we have &amp;quot;3&amp;quot; in the task name). To invoke more CPU processes for parallel-processing, change &amp;quot;nthreads&amp;quot; in the preambles from 1 to the number of threads you wish to use.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_timeseries_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Similar as the previous script, change inputs in the following block of your copy of the &amp;quot;imaging_timeseries_example.py&amp;quot; script and save the changes. &lt;br /&gt;
&lt;br /&gt;
[[file:fig-specmovie.png|thumb|right|300px|Example multi-frequency images at one time frame in the [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html output javascript movie]]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ####################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
specfile = vis + '.dspec.npz'  ## input dynamic spectrum&lt;br /&gt;
nthreads = 1  # Number of processing threads to use&lt;br /&gt;
overwrite = True  # whether to overwrite the existed fits files.&lt;br /&gt;
trange = ''  # time range for imaging, default to all times in the data&lt;br /&gt;
twidth = 1  # make one image out of every 2 time integrations&lt;br /&gt;
xycen = [380., 50.]  # center of the output map in solar X and Y. Unit: arcsec&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = ''  # default is to use all 13 EOVSA 2-m antennas. &lt;br /&gt;
npix = 128  # number of pixels in the image&lt;br /&gt;
cell = '2arcsec'  # pixel scale in arcsec&lt;br /&gt;
pol = 'XX'  # polarization to image, use XX for now&lt;br /&gt;
pbcor = True  # correct for primary beam response?&lt;br /&gt;
grid_spacing = 5. * u.deg  # grid spacing in degrees&lt;br /&gt;
outdir = './image_series/'  # Specify where to save the output fits files&lt;br /&gt;
imresfile = 'imres.npz'  # File to write summary of the imaging results&lt;br /&gt;
outimgpre = 'EO'  # Something to add to the image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA by&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_timeseries_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output fits images and a summary file imresfile are saved under &amp;quot;outdir&amp;quot; (in this example &amp;quot;./image_timeseries&amp;quot;). The naming convention of output fits images is the same as [[#Producing a 30-band map at a given time|the previous section]]. The summary yields the time, frequency, and path to every image.&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres = np.load(outdir + imresfile)['imres'].item()&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres.keys()&lt;br /&gt;
['FreqGHz', 'ImageName', 'Succeeded', 'BeginTime', 'EndTime']&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: ls image_series/*.fits | head -5&lt;br /&gt;
image_series/EO20170821T201800.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201804.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201808.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201812.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201816.500_ALLBD.fits&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last block of the example script uses SunPy.map to generate a series of plots and wraps them as a [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html javascript movie].&lt;br /&gt;
&lt;br /&gt;
====Plotting Images in SSWIDL====&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:Batch_mode_images.png|thumb|right|300px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6519</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6519"/>
		<updated>2022-07-07T07:44:18Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system with Batch-Mode Imaging=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
====Producing a 30-band map cube for a given time====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_example.py. First, download or copy the script to your own working directory and cd to your directory. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg.png|thumb|right|300px|Example multi-frequency images at a single time integration]]&lt;br /&gt;
&lt;br /&gt;
Second (optional), change inputs in the following block in your copy of the &amp;quot;imaging_example.py&amp;quot; script and save the changes. This block has definitions for time range, image center and FOV, antennas used, cell size, number of pixels, etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
trange = '2017/08/21/20:21:00~2017/08/21/20:21:30' # time range for imaging&lt;br /&gt;
xycen = [380., 50.] # center of the output map (in solar X and Y, Unit: arcsec)&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = '' # Use all 13 EOVSA 2-m antennas by default&lt;br /&gt;
npix = 256 # number of pixels in the image&lt;br /&gt;
cell = '1arcsec' # pixel scale in arcsec&lt;br /&gt;
pol = 'XX' # polarization to image, use XX for now&lt;br /&gt;
pbcor = True # correct for primary beam response?&lt;br /&gt;
outdir = './images' # Specify where to save the output fits files&lt;br /&gt;
outimgpre = 'EO' # Something to add to the output image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA via&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is a combined 30-band FITS file saved under &amp;quot;outdir&amp;quot;. The naming conversion is outimgpre + YYYYMMDDTHHMMSS_ALLBD.fits. In this example, it is &amp;quot;./images/EO20170821T202115.000_ALLBD.fits&amp;quot;. Here is the detailed information of the axes of the output FITS file.&lt;br /&gt;
&amp;lt;pre&amp;gt;                         &lt;br /&gt;
NAXIS   =                    4 / number of array dimensions                     &lt;br /&gt;
NAXIS1  =                  128                                                  &lt;br /&gt;
NAXIS2  =                  128                                                  &lt;br /&gt;
NAXIS3  =                   30                                                  &lt;br /&gt;
NAXIS4  =                    2  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From this point, you can use your favorite language to read the fits files and plot them. The last block of the example script uses SunPy.map to generate the plot shown on the right. For SSWIDL users, please refer to [[#Plotting Images in SSWIDL|Section 3.3.3.3]].&lt;br /&gt;
&lt;br /&gt;
====Producing a time series of 30-band maps (a 4-d cube)====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_timeseries_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_timeseries_example.py. The script enables parallel-processing (based on a customized task &amp;quot;ptclean3&amp;quot; -- do not ask me why we have &amp;quot;3&amp;quot; in the task name). To invoke more CPU processes for parallel-processing, change &amp;quot;nthreads&amp;quot; in the preambles from 1 to the number of threads you wish to use.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_timeseries_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Similar as the previous script, change inputs in the following block of your copy of the &amp;quot;imaging_timeseries_example.py&amp;quot; script and save the changes. &lt;br /&gt;
&lt;br /&gt;
[[file:fig-specmovie.png|thumb|right|300px|Example multi-frequency images at one time frame in the [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html output javascript movie]]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ####################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
specfile = vis + '.dspec.npz'  ## input dynamic spectrum&lt;br /&gt;
nthreads = 1  # Number of processing threads to use&lt;br /&gt;
overwrite = True  # whether to overwrite the existed fits files.&lt;br /&gt;
trange = ''  # time range for imaging, default to all times in the data&lt;br /&gt;
twidth = 1  # make one image out of every 2 time integrations&lt;br /&gt;
xycen = [380., 50.]  # center of the output map in solar X and Y. Unit: arcsec&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = ''  # default is to use all 13 EOVSA 2-m antennas. &lt;br /&gt;
npix = 128  # number of pixels in the image&lt;br /&gt;
cell = '2arcsec'  # pixel scale in arcsec&lt;br /&gt;
pol = 'XX'  # polarization to image, use XX for now&lt;br /&gt;
pbcor = True  # correct for primary beam response?&lt;br /&gt;
grid_spacing = 5. * u.deg  # grid spacing in degrees&lt;br /&gt;
outdir = './image_series/'  # Specify where to save the output fits files&lt;br /&gt;
imresfile = 'imres.npz'  # File to write summary of the imaging results&lt;br /&gt;
outimgpre = 'EO'  # Something to add to the image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA by&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_timeseries_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output fits images and a summary file imresfile are saved under &amp;quot;outdir&amp;quot; (in this example &amp;quot;./image_timeseries&amp;quot;). The naming convention of output fits images is the same as [[#Producing a 30-band map at a given time|the previous section]]. The summary yields the time, frequency, and path to every image.&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres = np.load(outdir + imresfile)['imres'].item()&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres.keys()&lt;br /&gt;
['FreqGHz', 'ImageName', 'Succeeded', 'BeginTime', 'EndTime']&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: ls image_series/*.fits | head -5&lt;br /&gt;
image_series/EO20170821T201800.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201804.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201808.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201812.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201816.500_ALLBD.fits&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last block of the example script uses SunPy.map to generate a series of plots and wraps them as a [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html javascript movie].&lt;br /&gt;
&lt;br /&gt;
====Plotting Images in SSWIDL====&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg_idl.png|thumb|right|300px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-05-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6518</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6518"/>
		<updated>2022-07-07T07:39:53Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system with Batch-Mode Imaging=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
====Producing a 30-band map cube for a given time====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_example.py. First, download or copy the script to your own working directory and cd to your directory. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg.png|thumb|right|300px|Example multi-frequency images at a single time integration]]&lt;br /&gt;
&lt;br /&gt;
Second (optional), change inputs in the following block in your copy of the &amp;quot;imaging_example.py&amp;quot; script and save the changes. This block has definitions for time range, image center and FOV, antennas used, cell size, number of pixels, etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
trange = '2017/08/21/20:21:00~2017/08/21/20:21:30' # time range for imaging&lt;br /&gt;
xycen = [380., 50.] # center of the output map (in solar X and Y, Unit: arcsec)&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = '' # Use all 13 EOVSA 2-m antennas by default&lt;br /&gt;
npix = 256 # number of pixels in the image&lt;br /&gt;
cell = '1arcsec' # pixel scale in arcsec&lt;br /&gt;
pol = 'XX' # polarization to image, use XX for now&lt;br /&gt;
pbcor = True # correct for primary beam response?&lt;br /&gt;
outdir = './images' # Specify where to save the output fits files&lt;br /&gt;
outimgpre = 'EO' # Something to add to the output image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA via&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is a combined 30-band FITS file saved under &amp;quot;outdir&amp;quot;. The naming conversion is outimgpre + YYYYMMDDTHHMMSS_ALLBD.fits. In this example, it is &amp;quot;./images/EO20170821T202115.000_ALLBD.fits&amp;quot;. Here is the detailed information of the axes of the output FITS file.&lt;br /&gt;
&amp;lt;pre&amp;gt;                         &lt;br /&gt;
NAXIS   =                    4 / number of array dimensions                     &lt;br /&gt;
NAXIS1  =                  128                                                  &lt;br /&gt;
NAXIS2  =                  128                                                  &lt;br /&gt;
NAXIS3  =                   30                                                  &lt;br /&gt;
NAXIS4  =                    2  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From this point, you can use your favorite language to read the fits files and plot them. The last block of the example script uses SunPy.map to generate the plot shown on the right. For SSWIDL users, please refer to [[#Plotting Images in SSWIDL|Section 3.3.3.3]].&lt;br /&gt;
&lt;br /&gt;
====Producing a time series of 30-band maps (a 4-d cube)====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_timeseries_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_timeseries_example.py. The script enables parallel-processing (based on a customized task &amp;quot;ptclean3&amp;quot; -- do not ask me why we have &amp;quot;3&amp;quot; in the task name). To invoke more CPU processes for parallel-processing, change &amp;quot;nthreads&amp;quot; in the preambles from 1 to the number of threads you wish to use.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_timeseries_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Similar as the previous script, change inputs in the following block of your copy of the &amp;quot;imaging_timeseries_example.py&amp;quot; script and save the changes. &lt;br /&gt;
&lt;br /&gt;
[[file:fig-specmovie.png|thumb|right|300px|Example multi-frequency images at one time frame in the [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html output javascript movie]]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ####################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
specfile = vis + '.dspec.npz'  ## input dynamic spectrum&lt;br /&gt;
nthreads = 1  # Number of processing threads to use&lt;br /&gt;
overwrite = True  # whether to overwrite the existed fits files.&lt;br /&gt;
trange = ''  # time range for imaging, default to all times in the data&lt;br /&gt;
twidth = 1  # make one image out of every 2 time integrations&lt;br /&gt;
xycen = [380., 50.]  # center of the output map in solar X and Y. Unit: arcsec&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = ''  # default is to use all 13 EOVSA 2-m antennas. &lt;br /&gt;
npix = 128  # number of pixels in the image&lt;br /&gt;
cell = '2arcsec'  # pixel scale in arcsec&lt;br /&gt;
pol = 'XX'  # polarization to image, use XX for now&lt;br /&gt;
pbcor = True  # correct for primary beam response?&lt;br /&gt;
grid_spacing = 5. * u.deg  # grid spacing in degrees&lt;br /&gt;
outdir = './image_series/'  # Specify where to save the output fits files&lt;br /&gt;
imresfile = 'imres.npz'  # File to write summary of the imaging results&lt;br /&gt;
outimgpre = 'EO'  # Something to add to the image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA by&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_timeseries_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output fits images and a summary file imresfile are saved under &amp;quot;outdir&amp;quot; (in this example &amp;quot;./image_timeseries&amp;quot;). The naming convention of output fits images is the same as [[#Producing a 30-band map at a given time|the previous section]]. The summary yields the time, frequency, and path to every image.&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres = np.load(outdir + imresfile)['imres'].item()&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres.keys()&lt;br /&gt;
['FreqGHz', 'ImageName', 'Succeeded', 'BeginTime', 'EndTime']&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: ls image_series/*.fits | head -5&lt;br /&gt;
image_series/EO20170821T201800.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201804.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201808.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201812.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201816.500_ALLBD.fits&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last block of the example script uses SunPy.map to generate a series of plots and wraps them as a [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html javascript movie].&lt;br /&gt;
&lt;br /&gt;
====Plotting Images in SSWIDL====&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. &lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles, eomaps [calcrms];, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg_idl.png|thumb|right|300px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-0-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
	<entry>
		<id>http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6517</id>
		<title>EOVSA Data Analysis Tutorial 2022</title>
		<link rel="alternate" type="text/html" href="http://ovsa.njit.edu//wiki/index.php?title=EOVSA_Data_Analysis_Tutorial_2022&amp;diff=6517"/>
		<updated>2022-07-07T07:38:10Z</updated>

		<summary type="html">&lt;p&gt;Sshaik: /* Plotting Images in SSWIDL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=1. Introduction to EOVSA and Datasets=&lt;br /&gt;
[[file:Eovsa1.png|center|500px|EOVSA]]&lt;br /&gt;
EOVSA (Expanded Owens Valley Solar Array) is a solar-dedicated radio interferometer operated by the New Jersey Institute of Technology. EOVSA observes the full disk of the Sun at all times when the Sun is &amp;gt;10 degrees above the local horizon, which is season dependent and ranges from 7-12 hours duration centered on 20 UT. Like any radio interferometer, the fundamental measurement for imaging is the correlated amplitude and phase between each pair of antennas, which is called a “complex visibility.” EOVSA’s 13 antennas form 78 such visibilities at any frequency and instant of time, i.e. 78 measurements of the spatial Fourier transform of the solar brightness distribution. EOVSA records these visibilities at *451 science frequency channels each second, in four polarization products (XX, YY, XY, YX), as well as additional total flux measurements from each individual antenna. These data are then processed through a pipeline processing system whose data flow is shown in the block diagram (Figure 1). One of the outputs of the pipeline is a visibility database in a widely used open-standard format called a CASA measurement set (or “ms”; CASA is the Common Astronomy Software Applications package used by many modern interferometer arrays).&lt;br /&gt;
&lt;br /&gt;
EOVSA delivers the radio interferometry data on the following three levels:&lt;br /&gt;
[[file:EOVSA_data_levels.PNG|thumb|right|500px|Figure 1: Pipeline block diagram]]&lt;br /&gt;
* '''Level 0''' - Raw visibility data - This includes observations of cosmic sources for phase calibration, and gain and pointing observations required for total power calibration.&lt;br /&gt;
* '''Level 1''' - Calibrated visibility data - After applying calibration and other preliminary processing to level 0 data, we create the calibrated visibility data in CASA ms format (second column in Figure 1). These visibility data have all of the required content to produce Level 2 images and spectrogram data in standard FITS format. The following tutorial will guide you through how to make EOVSA images and spectrogram from visibility data. We provide a set of standard ms’s for each day (pink solid boxes in Figure 1) for users who wish to start with visibility data. You can retrieve EOVSA 1-min averaged visibility data in CASA ms format from this [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ page]. Full-resolution EOVSA visibility data in CASA ms format will be provided per request. Please contact the *EOVSA team if you wish to have Level 1 visibility data for a specific event.&lt;br /&gt;
* '''Level 2''' - Images and spectrogram data in standard FITS format - Most users, however, will prefer to work with spectrogram (frequency-time) and image data, which are also outputs of the pipeline system shown in Figure 1 (orange boxes). Spectrograms are provided as standard FITS tables containing the frequency list, list of times, and data in both total power and a sum of amplitudes over intermediate-length baselines (cross power). Likewise, image data products are in FITS format with standard keywords and are converted into the Helioprojective Cartesian coordinate system compatible with the World Coordinate System (WCS) convention, along with correct registration for the spatial, spectral, and temporal coordinates. Both the spectrogram and image data products are calibrated and have physical radio intensity units (sfu for spectrograms and brightness temperature for radio images).&lt;br /&gt;
&lt;br /&gt;
=2. Browsing and Obtaining EOVSA data=&lt;br /&gt;
[[file:EOVSA_Browser.PNG|thumb|right|500px|Figure 2: EOVSA Browser]]&lt;br /&gt;
[[file:RHESSI_browser.png|thumb|right|500px|Figure 3: RHESSI Browser]]&lt;br /&gt;
&lt;br /&gt;
====EOVSA Browser====&lt;br /&gt;
The most convenient way for browsing '''Level 2''' EOVSA data is through the [http://ovsa.njit.edu/browser EOVSA Browser]. The overview EOVSA dynamic spectra on the top-left panel are from the median of the uncalibrated cross-power visibilities at a few short baselines, which are not (but a good proxy of) the total-power dynamic spectra. The effects of spatial information blended in the cross-power visibilities can be clearly seen as the &amp;quot;U&amp;quot;-shaped features throughout the day, which are due to the movement of the Sun across the sky that effectively changes the length and orientation of the baselines. Flare emission can be seen in the dynamic spectra, which usually appears as vertical bright features across many frequency bands. The pipeline quicklook full-disk images are also displayed for the given frequencies along with multi-wavelength full-disk maps such as SDO AIA, HMI, BBSO H-alpha by hovering on the buttons on the bottom of each map..  More information can be found on this [http://ovsa.njit.edu/data-browsing.html page]. The figure on the right shows an example of the overview EOVSA dynamic spectrum for 2021 May 07.&lt;br /&gt;
&lt;br /&gt;
====RHESSI Browser====&lt;br /&gt;
EOVSA data can also be browsed through [http://sprg.ssl.berkeley.edu/~tohban/browser/ RHESSI Browser]. Check the &amp;quot;EOVSA Radio Data&amp;quot; box on the data selection area (top-left corner). Then select year/month/date to view the overall EOVSA dynamic spectrum. Note if a time is selected at early UTC hours (e.g., 0-3 UT), it will show the EOVSA dynamic spectrum from the previous day. Also, note that EOVSA data were not commissioned for spectroscopic imaging prior to April 2017. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you identify the flare time, you can find the full-resolution (1-s cadence) uncalibrated visibility files (in Miriad format) at [http://www.ovsa.njit.edu/fits/IDB/ this link]. Each data file is usually 10 minutes in duration. The name convention is YYYYMMDD (folder name) /IDBYYYYMMDDHHMMSS (file name), where the time in the file name indicates the start time of the visibility data.&lt;br /&gt;
&lt;br /&gt;
====Other useful links====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [https://join.slack.com/t/eovsatutorial-2021/shared_invite/zt-sob838f4-zvs_qH3M4yTbWGlPIiw6og EOVSA User Forum]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Recent_Flare_List_(2021) EOVSA Flare list]&lt;br /&gt;
* [http://ovsa.njit.edu/browser EOVSA browser]&lt;br /&gt;
* [http://www.ovsa.njit.edu/wiki/index.php/Expanded_Owens_Valley_Solar_Array EOVSA wiki]&lt;br /&gt;
* [http://www.ovsa.njit.edu/fits/UDBms_slfcaled/ EOVSA 1-min averaged CASA ms database]&lt;br /&gt;
* [https://github.com/suncasa/suncasa-src SunCASA on Github] and [https://pypi.org/project/suncasa/ PyPI]&lt;br /&gt;
* Flare pipeline?&lt;br /&gt;
&lt;br /&gt;
=3. Software requirements and installation= &lt;br /&gt;
EOVSA data processing and analysis are developed over two packages:&lt;br /&gt;
* '''[https://github.com/suncasa/suncasa SunCASA]''' A Python wrapper around [https://casa.nrao.edu/ CASA (the Common Astronomy Software Applications package)] for synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for &amp;quot;supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA&amp;quot;, an international effort led by the [https://public.nrao.edu/ National Radio Astronomy Observatory]. The current version of CASA uses Python (3.6, 3.10*) interface. More information about CASA can be found on [https://casa.nrao.edu/ NRAO's CASA website ]. Note, CASA is available ONLY on UNIX-BASED PLATFORMS (and therefore, so is SunCASA). &lt;br /&gt;
&lt;br /&gt;
* '''[https://github.com/Gelu-Nita/GSFIT GSFIT]''' A IDL-widget (GUI)-based spectral fitting package called GSFIT, which provides a user-friendly display of EOVSA image cubes and an interface to fast-fitting codes (via platform-dependent shared-object libraries). &lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will demonstrate using SunCASA to create EOVSA image and spectrogram from the visibility data observed for an M class flare on 2021 May 07. There are two approaches to accessing the SunCASA package:&lt;br /&gt;
&lt;br /&gt;
# Through [https://colab.research.google.com/ Google Colaboratory (colab)] which hosts a free virtual environment that requires no setup and runs entirely in the cloud. For example, the [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA workspace] of this tutorial explains the analysis setup.&lt;br /&gt;
# Install on your own machine, and run the notebook as a regular Jupyter Notebook. See [http://ovsa.njit.edu//wiki/index.php/EOVSA_Data_Analysis_Tutorial_2022#Installation_of_SunCASA_(optional) SunCASA Installation] section below, also [http://www.ovsa.njit.edu/wiki/index.php/SunCASA_Installation this page] and [http://www.ovsa.njit.edu/wiki/index.php/GSFIT_Installation GSFIT Installation] for instructions.&lt;br /&gt;
&lt;br /&gt;
=4. Download Sample EOVSA Data for the Tutorial=&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use an M4 class flare on 07 May 2021, around 19:00 UT occurred near the solar east limb as viewed from Earth, and was well observed by Solar Orbiter (including the STIX instrument). For other recent EOVSA events, check here.&lt;br /&gt;
Here, we provide a calibrated and self-calibrated EOVSA visibility dataset in CASA ms format (IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms) which is ready for science analyses purposes,&lt;br /&gt;
&lt;br /&gt;
=5. Information on the EOVSA Visibility Data (CASA Measurement Set)=&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
With the pip installation, the CASA modules may be used in a standard Python manner. For example, CASA tasks can be invoked using import, while CASA tools are Python classes that first need to be instantiated to create usable objects. A useful first task to run is [https://casa.nrao.edu/docs/taskref/listobs-task.html listobs], which provides a summary of the measurement set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from casatasks import listobs&lt;br /&gt;
import os&lt;br /&gt;
msfile = 'IDB20210507_1840-1920XXYY.cal.10s.slfcaled.ms'&lt;br /&gt;
rc = listobs(vis=msfile, listfile = msfile + '.listobs', overwrite=True)&lt;br /&gt;
&lt;br /&gt;
print(os.popen(&amp;quot;cat &amp;quot; + msfile + &amp;quot;.listobs&amp;quot;).read())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[file:Listobs_20210507.png|thumb|center|1400px|Figure 4: Output of listobs task]]&lt;br /&gt;
&lt;br /&gt;
=6. Self-calibration (optional)=&lt;br /&gt;
Self-calibration is often needed in bringing out details of the flare at multiple frequencies. An example script, run in SunCASA, for doing self-calibration of the 2017 Aug 21 flare at ~20:20 UT can be found at [http://www.ovsa.njit.edu/wiki/index.php/Tohban_EOVSA_Imaging_Tutorial_A-Z here]. The EOVSA workspace discussed along with this tutorial anyway uses the self-calibrated dataset for analysis.&lt;br /&gt;
&lt;br /&gt;
=7. Cross-Power Dynamic Spectrum=&lt;br /&gt;
The first module we introduce is [https://github.com/suncasa/suncasa/blob/main/suncasa/utils/dspec.py''dspec'']. This module allows you to generate a cross-power dynamic spectrum from an MS file, and visualize it. You can select a subset of data by specifying a [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu112.html time range], [https://casaguides.nrao.edu/index.php/Selecting_Spectral_Windows_and_Channels spectral windows/channels],  [https://casaguides.nrao.edu/index.php/Antenna/Baseline_Selection_Syntax_with_or_without_Autocorrelations antenna baseline], or [https://casa.nrao.edu/Release3.3.0/docs/UserMan/UserMansu113.html uvrange]. The selection syntax follows the ''CASA'' convention. More information of CASA selection syntax may be found in the above links or the [https://casa.nrao.edu/casadocs/casa-5.4.0/data-selection/data-selection-in-a-measurementset Measurement Selection Syntax].&lt;br /&gt;
&lt;br /&gt;
[[file:Dynspec_20210507.png|thumb|right|300px|Figure 4: EOVSA cross power dynamic spectrum at stokes XX polarization]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa import dspec as ds&lt;br /&gt;
import time&lt;br /&gt;
           ## define the output filename of the dynamic spectrum &lt;br /&gt;
specfile = msfile + '.dspec.npz'&lt;br /&gt;
           ## The example below shows the cross-power spectrogram from a baseline selected using the parameter &amp;quot;bl&amp;quot;.&lt;br /&gt;
           ## bl = '4&amp;amp;9' means selecting a baseline from Antenna ID 4 (Antenna Name &amp;quot;eo05&amp;quot;) correlating with Antenna ID 9 &lt;br /&gt;
           ## (Antenna Name &amp;quot;eo10&amp;quot;) - refer listobs output.&lt;br /&gt;
           ## you can also use the &amp;quot;bl&amp;quot; parameter to select multiple baseline(s), i.e., bl='0&amp;amp;2;4&amp;amp;9;8&amp;amp;11'.&lt;br /&gt;
           &lt;br /&gt;
           ## Hover over &amp;quot;Dspec&amp;quot; in the next line to see additional arguments such as frequency range (&amp;quot;spw&amp;quot;), and time range (&amp;quot;timeran&amp;quot;) &lt;br /&gt;
           ## or use help(ds.Dspec)&lt;br /&gt;
           ## this step generates a dynamic spectrum and saves it to specfile as a numpy .npz file&lt;br /&gt;
d = ds.Dspec(msfile, bl='4&amp;amp;9', specfile=specfile) &lt;br /&gt;
d.plot(vmin=None, vmax=None, pol='XX')&lt;br /&gt;
print(d.data.shape) # The shape gives the dimensions of polarization, baselines, frequencies, time         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative methods of using the &amp;quot;dspec&amp;quot; task are discussed in the EOVSA workspace.&lt;br /&gt;
&lt;br /&gt;
NOTE: If you are using your own machine, the plotting should be in interactive mode. In that mode, hovering your mouse over the dynamic spectrum allows you to read the time, frequency, and flux information under the cursor at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
=8. Quick-Look Imaging=&lt;br /&gt;
We use CASA's CLEAN algorithm for EOVSA imaging. As the default coordinate system is equatorial, solar coordinate transformation and image registration need to be done to place the image into the usual Helioprojective Cartesian Coordinates (X- and Y-axes are Solar X and Solar Y in arcsecond unit, respectively). We have bundled a number of these steps into a module named  [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], allowing users to generate an observing summary plot showing the cross power dynamic spectrum, GOES light curves and EOVSA quick-look images. &lt;br /&gt;
&lt;br /&gt;
Now, let us start with making a summary plot of the EOVSA image at the spectral windows 2 to 5 (2.4–3.7 GHz).&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSAimg_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils import qlookplot as ql&lt;br /&gt;
           ## (Optional) Supply the npz file of the dynamic spectrum from previous step. &lt;br /&gt;
           ## If not provided, the program will generate a new one from the visibility.&lt;br /&gt;
           &lt;br /&gt;
timerange = '19:02:00~19:02:10' ## set the time interval           &lt;br /&gt;
spw = '2~5'                     ## select frequency range          &lt;br /&gt;
stokes = 'XX'                   ## select stokes XX           &lt;br /&gt;
plotaia = False                 ## Initially, turn off AIA image plotting, default is True&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=plotaia, restoringbeam=['60arcsec'], robust=0.5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty panels are there as only one polarization is selected for imaging/spectroscopy. &lt;br /&gt;
&lt;br /&gt;
Feel free while working in [https://colab.research.google.com/drive/19NQb6Emb9HvKX4QHq9ZYCP3RM6nT7sDL#scrollTo=cLdDVptBGG-X EOVSA Workspace] to explore by adjusting the above parameters, e.g. use a different time range (&amp;quot;timerange&amp;quot; parameter) and/or frequency range (&amp;quot;spw&amp;quot; parameter). &lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data====&lt;br /&gt;
&lt;br /&gt;
With [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''], it is easy to engage solar data from SDO/AIA in the summary plot. Setting ''plotaia=True'' in the [https://github.com/suncasa/suncasa/blob/master/utils/qlookplot.py ''qlookplot''] command will download SDO/AIA data at the given time to current directory and add it to the summary plot.&lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_20210507.png|thumb|right|400px|EOVSA full-Sun single-band quicklook image with SDO/AIA as background]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
outfits = 'EOVSA_20210507T190205.000000.outim.image.fits'&lt;br /&gt;
ql.qlookplot(vis=msfile, specfile=specfile, timerange=timerange, spw=spw, \&lt;br /&gt;
    stokes=stokes, plotaia=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting radio image is a 4-D datacube (in solar X-pos, Y-pos, frequency, and polarization), which is, by default, saved as a fits file Instrument_yymmddTHHMMS.ffffff.outim.image.fits under your working directory. An alternate name for the output fits file can be specified using the outfits parameter. In this example, we combine all selected frequencies (specified in keyword spw) into one image (i.e., multi-frequency synthesis). Therefore the third axis only has one plane. The fourth axis contains polarization. In this example, the fourth axis only has one plane as well (XX). Here is the relevant information (first few lines) in the header of the resulting FITS file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from astropy.io import fits&lt;br /&gt;
In [2]: hdu = fits.open('EOVSA_20210507T190230.000000.outim.image.fits')[0]&lt;br /&gt;
In [3]: hdu.header&lt;br /&gt;
Out[3]:&lt;br /&gt;
SIMPLE  =                    T / conforms to FITS standard&lt;br /&gt;
BITPIX  =                  -64 / array data type&lt;br /&gt;
NAXIS   =                    4 / number of array dimensions&lt;br /&gt;
NAXIS1  =                  512 / Nx&lt;br /&gt;
NAXIS2  =                  512 / Ny&lt;br /&gt;
NAXIS3  =                    1 / number of frequencies&lt;br /&gt;
NAXIS4  =                    1 / number of polarizations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, qlookplot produces a full sun radio image (512x512 with a pixel size of 5&amp;quot;). If you know where the radio source is (e.g., from the previous full-Sun imaging), you can make a partial solar image around the source by specifying the image center (xycen), pixel scale (cell), and image field of view (fov). Here we show an example that images for each spectral window in this data set (from spw 0 to 49) at the same time interval around 19:02 UT. At high frequencies, the microwave source concentrates near the flare site, corresponding pretty well with the flare kernel in SDO/AIA. At low frequencies, the microwave source extends to higher altitudes in the corona. Again, feel free to change some of these parameters to explore what they do.&lt;br /&gt;
&lt;br /&gt;
====Quick-look Imaging with AIA data and all spw====&lt;br /&gt;
Next, we will make images for every single spectral window in this data set (from spw 0 to 47). &lt;br /&gt;
&lt;br /&gt;
[[file:EOVSA_AIA_allspw_20210507.png|thumb|right|400px|EOVSA multi-band quicklook image]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9&amp;quot;&amp;gt;&lt;br /&gt;
## in SunCASA&lt;br /&gt;
from suncasa.utils.mstools import time2filename&lt;br /&gt;
timerange = '19:02:00~19:02:10'   ## set the time interval&lt;br /&gt;
spw = ['{}'.format(l) for l in range(48)].     ## select (almost) all spectral windows from spw id #0 to #47&lt;br /&gt;
outfits = time2filename(visibility_data,timerange=timerange)+'.outim.image.allbd.fits'&lt;br /&gt;
&lt;br /&gt;
stokes = 'XX'.            ## select stokes XX&lt;br /&gt;
xycen = [-900, 280]       ## image center for clean in solar X-Y in arcsec&lt;br /&gt;
cell=['2.0arcsec']        ## pixel scale&lt;br /&gt;
imsize=[128]              ## number of pixels in X and Y. If only one value is provided, NX = NY&lt;br /&gt;
fov = [300,300]           ## field of view of the zoomed-in panels in unit of arcsec&lt;br /&gt;
&lt;br /&gt;
plotaia = True            ## turn off AIA image plotting, default is True&lt;br /&gt;
aiawave = 1600            ## AIA passband in Å. The options are [171,131,304,335,211,193,94,1600,1700]&lt;br /&gt;
acmap = 'gray_r'          ## Choose the coloar map for AIA images. If not provided, the program will use default AIA colormap.&lt;br /&gt;
&lt;br /&gt;
ql.qlookplot(vis=visibility_data, specfile=specfile, timerange=timerange, &lt;br /&gt;
             spw=spw, stokes=stokes, plotaia=plotaia, aiawave=aiawave, &lt;br /&gt;
             restoringbeam=['60arcsec'], robust = 0.5, acmap=acmap,&lt;br /&gt;
             imsize=imsize,cell=cell,xycen=xycen,fov=fov, &lt;br /&gt;
             outfits=outfits,overwrite=False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=9. Downloading fits files to your local system with Batch-Mode Imaging=&lt;br /&gt;
This section is for interested users who wish to generate FITS files with full control on all parameters being used for synthesis imaging. We provide one example SunCASA script for generating 30-band spectral imaging maps, and another for iterating over time to produce a time series of these maps.&lt;br /&gt;
====Producing a 30-band map cube for a given time====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_example.py. First, download or copy the script to your own working directory and cd to your directory. &lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg.png|thumb|right|300px|Example multi-frequency images at a single time integration]]&lt;br /&gt;
&lt;br /&gt;
Second (optional), change inputs in the following block in your copy of the &amp;quot;imaging_example.py&amp;quot; script and save the changes. This block has definitions for time range, image center and FOV, antennas used, cell size, number of pixels, etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
trange = '2017/08/21/20:21:00~2017/08/21/20:21:30' # time range for imaging&lt;br /&gt;
xycen = [380., 50.] # center of the output map (in solar X and Y, Unit: arcsec)&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = '' # Use all 13 EOVSA 2-m antennas by default&lt;br /&gt;
npix = 256 # number of pixels in the image&lt;br /&gt;
cell = '1arcsec' # pixel scale in arcsec&lt;br /&gt;
pol = 'XX' # polarization to image, use XX for now&lt;br /&gt;
pbcor = True # correct for primary beam response?&lt;br /&gt;
outdir = './images' # Specify where to save the output fits files&lt;br /&gt;
outimgpre = 'EO' # Something to add to the output image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA via&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is a combined 30-band FITS file saved under &amp;quot;outdir&amp;quot;. The naming conversion is outimgpre + YYYYMMDDTHHMMSS_ALLBD.fits. In this example, it is &amp;quot;./images/EO20170821T202115.000_ALLBD.fits&amp;quot;. Here is the detailed information of the axes of the output FITS file.&lt;br /&gt;
&amp;lt;pre&amp;gt;                         &lt;br /&gt;
NAXIS   =                    4 / number of array dimensions                     &lt;br /&gt;
NAXIS1  =                  128                                                  &lt;br /&gt;
NAXIS2  =                  128                                                  &lt;br /&gt;
NAXIS3  =                   30                                                  &lt;br /&gt;
NAXIS4  =                    2  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From this point, you can use your favorite language to read the fits files and plot them. The last block of the example script uses SunPy.map to generate the plot shown on the right. For SSWIDL users, please refer to [[#Plotting Images in SSWIDL|Section 3.3.3.3]].&lt;br /&gt;
&lt;br /&gt;
====Producing a time series of 30-band maps (a 4-d cube)====&lt;br /&gt;
An example script can be found at [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/imaging_timeseries_example.py this Github link]. If you are on the AWS server Virgo, it is under /common/data/eovsa_tutorial/imaging_timeseries_example.py. The script enables parallel-processing (based on a customized task &amp;quot;ptclean3&amp;quot; -- do not ask me why we have &amp;quot;3&amp;quot; in the task name). To invoke more CPU processes for parallel-processing, change &amp;quot;nthreads&amp;quot; in the preambles from 1 to the number of threads you wish to use.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
# in SunCASA&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: cd your_working_directory&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: !cp /common/data/eovsa_tutorial/imaging_timeseries_example.py ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Similar as the previous script, change inputs in the following block of your copy of the &amp;quot;imaging_timeseries_example.py&amp;quot; script and save the changes. &lt;br /&gt;
&lt;br /&gt;
[[file:fig-specmovie.png|thumb|right|300px|Example multi-frequency images at one time frame in the [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html output javascript movie]]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
################### USER INPUT GOES IN THIS BLOK ####################&lt;br /&gt;
vis = 'IDB20170821201800-202300.4s.slfcaled.ms'  # input visibility data&lt;br /&gt;
specfile = vis + '.dspec.npz'  ## input dynamic spectrum&lt;br /&gt;
nthreads = 1  # Number of processing threads to use&lt;br /&gt;
overwrite = True  # whether to overwrite the existed fits files.&lt;br /&gt;
trange = ''  # time range for imaging, default to all times in the data&lt;br /&gt;
twidth = 1  # make one image out of every 2 time integrations&lt;br /&gt;
xycen = [380., 50.]  # center of the output map in solar X and Y. Unit: arcsec&lt;br /&gt;
xran = [340., 420.]  # plot range in solar X. Unit: arcsec&lt;br /&gt;
yran = [10., 90.]  # plot range in solar Y. Unit: arcsec&lt;br /&gt;
antennas = ''  # default is to use all 13 EOVSA 2-m antennas. &lt;br /&gt;
npix = 128  # number of pixels in the image&lt;br /&gt;
cell = '2arcsec'  # pixel scale in arcsec&lt;br /&gt;
pol = 'XX'  # polarization to image, use XX for now&lt;br /&gt;
pbcor = True  # correct for primary beam response?&lt;br /&gt;
grid_spacing = 5. * u.deg  # grid spacing in degrees&lt;br /&gt;
outdir = './image_series/'  # Specify where to save the output fits files&lt;br /&gt;
imresfile = 'imres.npz'  # File to write summary of the imaging results&lt;br /&gt;
outimgpre = 'EO'  # Something to add to the image name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, run the script in SunCASA by&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: execfile('imaging_timeseries_example.py')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output fits images and a summary file imresfile are saved under &amp;quot;outdir&amp;quot; (in this example &amp;quot;./image_timeseries&amp;quot;). The naming convention of output fits images is the same as [[#Producing a 30-band map at a given time|the previous section]]. The summary yields the time, frequency, and path to every image.&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres = np.load(outdir + imresfile)['imres'].item()&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: imres.keys()&lt;br /&gt;
['FreqGHz', 'ImageName', 'Succeeded', 'BeginTime', 'EndTime']&lt;br /&gt;
CASA &amp;lt;##&amp;gt;: ls image_series/*.fits | head -5&lt;br /&gt;
image_series/EO20170821T201800.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201804.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201808.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201812.500_ALLBD.fits&lt;br /&gt;
image_series/EO20170821T201816.500_ALLBD.fits&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last block of the example script uses SunPy.map to generate a series of plots and wraps them as a [https://web.njit.edu/~sjyu/download/eovsa-tutorial/movie.html javascript movie].&lt;br /&gt;
&lt;br /&gt;
====Plotting Images in SSWIDL====&lt;br /&gt;
All the output files are in standard FITS format in the Helioprojective Cartesian coordinate system (that most spacecraft solar image data adopt; FITS header CTYPE is HPLN-TAN and HPLT-TAN). They are fully compatible with [https://hesperia.gsfc.nasa.gov/rhessidatacenter/complementary_data/maps/ the SSWIDL map suite] which deals with FITS files. We have prepared SSWIDL routines to convert the single time or time-series FITS files to an array of SSWIDL map structure. The scripts are available in the [https://github.com/binchensun/eovsa-tutorial/tree/master/rhessi18 Github repository of our tutorial]. For those working on Virgo, local copies are placed under /common/data/eovsa_tutorial/. Two scripts are relevant to this tutorial:&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_readfits.pro casa_readfits.pro]: read an array of multi-frequency FITS files into FITS header (index) and data.&lt;br /&gt;
* [https://github.com/binchensun/eovsa-tutorial/blob/master/rhessi18/casa_fits2map.pro casa_fits2map.pro]: convert an array of multi-frequency FITS files into an array of SSWIDL map structure (adapted from P. T. Gallagher's hsi_fits2map.pro)&lt;br /&gt;
&lt;br /&gt;
First, start SSWIDL from command line:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
sswidl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
file = 'EOVSA_20210507T190205.000000.outim.image.allbd.fits'&lt;br /&gt;
fits2map,file,eomaps&lt;br /&gt;
window,0,xs=1000,ys=800&lt;br /&gt;
loadct,3&lt;br /&gt;
!p.multi=[0,6,5]&lt;br /&gt;
for i=0, 29 do plot_map,eomaps[i],grid=5.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find and convert the fits files:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; cd to your path that contains casa_readfits.pro and casa_fits2map.pro. If on Virgo, just add the path&lt;br /&gt;
IDL&amp;gt; add_path, '/common/data/eovsa_tutorial/'&lt;br /&gt;
IDL&amp;gt; fitsdir = '/common/data/eovsa_tutorial/image_series/'&lt;br /&gt;
IDL&amp;gt; fitsfiles = file_search(fitsdir+'*_ALLBD.fits')&lt;br /&gt;
; The resulting fitfiles contains all multi-frequency FITS files under &amp;quot;fitsdir&amp;quot; &lt;br /&gt;
; The following command converts the fits files to an array of map structures. &lt;br /&gt;
; &amp;quot;casa_fits2map.pro&amp;quot; also work well on a single FITS file. &lt;br /&gt;
; (Optional) keyword &amp;quot;calcrms&amp;quot; is to calculate rms and dynamic range (SNR) of the maps in a user-defined &amp;quot;empty&amp;quot; region &lt;br /&gt;
;        of the map specified by &amp;quot;rmsxran&amp;quot; and &amp;quot;rmsyran&amp;quot;&lt;br /&gt;
;;; Here we load 10 time frames as a demonstration&lt;br /&gt;
IDL&amp;gt; casa_fits2map, fitsfiles[45:54], eomaps [, /calcrms, rmsxran=[260., 320.], rmsyran=[-70., 0.]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting maps have a shape of [# of frequencies, # of polarizations, # of times]&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
IDL&amp;gt; help,eomaps&lt;br /&gt;
EOMAPS          STRUCT    = -&amp;gt; &amp;lt;Anonymous&amp;gt; Array[30, 1, 10]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They have compatible keywords recognized by, e.g., plot_map.pro. Example of the output map keywords:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IDL&amp;gt; help,omaps,/str&lt;br /&gt;
** Structure &amp;lt;cd28140&amp;gt;, 24 tags, length=132272, data length=132272, refs=2:&lt;br /&gt;
   DATA            DOUBLE    Array[128, 128]&lt;br /&gt;
   XC              DOUBLE          -901.02022&lt;br /&gt;
   YC              DOUBLE           278.99427&lt;br /&gt;
   DX              DOUBLE           2.0000000&lt;br /&gt;
   DY              DOUBLE           2.0000000&lt;br /&gt;
   TIME            STRING    ' 7-May-2021 19:02:00.000'&lt;br /&gt;
   ID              STRING    'EOVSA XX 1.256 GHz'&lt;br /&gt;
   DUR             DOUBLE           9.9999998&lt;br /&gt;
   XUNITS          STRING    'arcsec'&lt;br /&gt;
   YUNITS          STRING    'arcsec'&lt;br /&gt;
   ROLL_ANGLE      DOUBLE          0.00000000&lt;br /&gt;
   ROLL_CENTER     DOUBLE    Array[2]&lt;br /&gt;
   FREQ            DOUBLE           1.2557989&lt;br /&gt;
   FREQUNIT        STRING    'GHz'&lt;br /&gt;
   STOKES          STRING    'XX'&lt;br /&gt;
   DATAUNIT        STRING    'K'&lt;br /&gt;
   DATATYPE        STRING    'Brightness Temperature'&lt;br /&gt;
   BMAJ            DOUBLE         0.021222222&lt;br /&gt;
   BMIN            DOUBLE         0.021222222&lt;br /&gt;
   BPA             DOUBLE          -337.28110&lt;br /&gt;
   RSUN            DOUBLE    Array[48]&lt;br /&gt;
   L0              FLOAT     Array[48]&lt;br /&gt;
   B0              DOUBLE    Array[48]&lt;br /&gt;
   COMMENT         STRING    'Converted by CASA_FITS2MAP.PRO'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[file:fig-specimg_idl.png|thumb|right|300px|Example multi-frequency EOVSA images at one time plotted in SSWIDL]]&lt;br /&gt;
An example for plotting all images at a selected time:&lt;br /&gt;
&amp;lt;pre  style=&amp;quot;background-color:#FCEBD9;&amp;quot;&amp;gt;&lt;br /&gt;
; choose a time pixel&lt;br /&gt;
IDL&amp;gt; plttime = anytim('2021-0-07T19:02:00')&lt;br /&gt;
IDL&amp;gt; dt = min(abs(anytim(eomaps[0,0,*].time)-plttime),tidx)&lt;br /&gt;
; use maps at this time, first polarization, and all bands&lt;br /&gt;
IDL&amp;gt; eomap = reform(eomaps[*,0,tidx])&lt;br /&gt;
IDL&amp;gt; window,0,xs=1000,ys=800&lt;br /&gt;
IDL&amp;gt; !p.multi=[0,6,5]&lt;br /&gt;
IDL&amp;gt; loadct, 3&lt;br /&gt;
IDL&amp;gt; for i=0, 29 do plot_map,eomap[i],grid=5.,$&lt;br /&gt;
         tit=string(eomap[i].freq,format='(f5.2)')+' GHz', $&lt;br /&gt;
         chars=2.0,xran=[340.,420.],yran=[10.,90.]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Installation of SunCASA (optional)=&lt;br /&gt;
If you want to install SunCASA on your local machine follow this section. If not, run SunCASA directly on the Colab Workspace.&lt;br /&gt;
&lt;br /&gt;
PIP wheels for SunCASA and its CASA dependencies are available as a Python 3 module from [https://pypi.org/ PyPI]. This allows simple installation across most of the UNIX-BASED PLATFORMS (Linux &amp;amp; macOS) and import into standard *Python 3.6* environments. The RHEL 6/7  are the officially supported platforms for the casa modules. We have also tested the SunCASA/CASA packages under other Linux-based platforms such as Ubuntu 18, Scientific Linux 6/7, CentOS 7, as well as macOS Big Sur to some extent. YMMV for other versions of Linux or macOS. We do not recommend the use of Conda until CASA's compatibility with Conda is better understood. &lt;br /&gt;
&lt;br /&gt;
====Requirements====&lt;br /&gt;
The following prerequisites must be present on the host machine before installing SunCASA:&lt;br /&gt;
&lt;br /&gt;
* '''Python 3.6''' (3.7 may also work, its compatibility with CASA is not fully understood yet)&lt;br /&gt;
* '''For Linux:''' libgfortran3 ([https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-yum yum] or [https://help.ubuntu.com/community/AptGet/Howto) apt-get] install)&lt;br /&gt;
* '''For MacOS:''' gcc ([https://brew.sh/) brew install], [https://www.xquartz.org/ XQuartz] and [https://apps.apple.com/us/app/xcode/id497799835?mt=12 Xcode])&lt;br /&gt;
&lt;br /&gt;
====Installating SunCASA====&lt;br /&gt;
Installation instructions are as follows (from a UNIX terminal window). First create a Python virtual environment named suncasaenv under the $HOME directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd $HOME&lt;br /&gt;
$ python3.6 -m venv suncasaenv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.&lt;br /&gt;
&lt;br /&gt;
Then use [https://pypi.org/project/suncasa/ pip] to install SunCASA within the newly-created virtual environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
$ source suncasaenv/bin/activate&lt;br /&gt;
(suncasaenv) $ pip install --upgrade pip&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''  If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install casatasks&lt;br /&gt;
(suncasaenv) $ pip install casatools&lt;br /&gt;
(suncasaenv) $ pip install casadata&lt;br /&gt;
(suncasaenv) $ pip install PyQt5&lt;br /&gt;
(suncasaenv) $ pip install sunpy[all]&lt;br /&gt;
(suncasaenv) $ pip install suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit the python venv, type &amp;quot;deactivate&amp;quot; from the terminal.  However, the rest of this tutorial '''assumes the venv is active''' (to reactivate, type source $HOME/suncasaenv/bin/activate)&lt;br /&gt;
&lt;br /&gt;
====Updating a previous installation of SunCASA====&lt;br /&gt;
You can update suncasa to its latest version by running:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ pip install --upgrade suncasa&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sanity check====&lt;br /&gt;
With the pip installation, SunCASA, as well as CASA, may be used in a standard Pythonic manner. For example, SunCASA modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #FCEBD9;overflow: auto;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
(suncasaenv) $ ipython&lt;br /&gt;
Python 3.6.9 (default, Jun 16 2021, 22:21:26)&lt;br /&gt;
Type 'copyright', 'credits' or 'license' for more information&lt;br /&gt;
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.&lt;br /&gt;
In [1]: import suncasa&lt;br /&gt;
In [2]: help(suncasa)&lt;br /&gt;
In [3]: import casatasks&lt;br /&gt;
In [4]: help(casatasks)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of SunCASA can be kept on a single machine in different environments. In addition, SunCASA is built and tested using standard (python 3.6) libraries which can be replicated with a fresh venv, keeping the libraries needed for SunCASA isolated from other libraries which may already be installed on your machine.&lt;/div&gt;</summary>
		<author><name>Sshaik</name></author>
	</entry>
</feed>