###################################################################### # # # Use Case Script for Jupiter 6cm VLA # # Demonstration of Calibration # # # # Last Updated STM 2007-10-16 (Beta) # # # ###################################################################### import time import os # #===================================================================== # # This script has some interactive commands: scriptmode = True # if you are running it and want it to stop during interactive parts. scriptmode = True #===================================================================== # # Set up some useful variables - these will be set during the script # also, but if you want to restart the script in the middle here # they are in one place: pathname=os.environ.get('AIPSPATH').split()[0] prefix='jupiter6cm.usecase' msfile = prefix + '.ms' print "NOTE - Assume flagged MS is on disk as "+msfile # The listobs output was: # # Observer: FLUX99 Project: # Observation: VLA # # Data records: 2021424 Total integration time = 85133.2 seconds # Observed from 23:15:27 to 22:54:20 # # ObservationID = 0 ArrayID = 0 # Date Timerange Scan FldId FieldName SpwIds # 15-Apr-1999/23:15:26.7 - 23:16:10.0 1 0 0137+331 [0, 1] # 23:38:40.0 - 23:48:00.0 2 1 0813+482 [0, 1] # 23:53:40.0 - 23:55:20.0 3 2 0542+498 [0, 1] # 16-Apr-1999/00:22:10.1 - 00:23:49.9 4 3 0437+296 [0, 1] # 00:28:23.3 - 00:30:00.1 5 4 VENUS [0, 1] # 00:48:40.0 - 00:50:20.0 6 1 0813+482 [0, 1] # 00:56:13.4 - 00:57:49.9 7 2 0542+498 [0, 1] # 01:10:20.1 - 01:11:59.9 8 5 0521+166 [0, 1] # 01:23:29.9 - 01:25:00.1 9 3 0437+296 [0, 1] # 01:29:33.3 - 01:31:10.0 10 4 VENUS [0, 1] # 01:49:50.0 - 01:51:30.0 11 6 1411+522 [0, 1] # 02:03:00.0 - 02:04:30.0 12 7 1331+305 [0, 1] # 02:17:30.0 - 02:19:10.0 13 1 0813+482 [0, 1] # 02:24:20.0 - 02:26:00.0 14 2 0542+498 [0, 1] # 02:37:49.9 - 02:39:30.0 15 5 0521+166 [0, 1] # 02:50:50.1 - 02:52:20.1 16 3 0437+296 [0, 1] # 02:59:20.0 - 03:01:00.0 17 6 1411+522 [0, 1] # 03:12:30.0 - 03:14:10.0 18 7 1331+305 [0, 1] # 03:27:53.3 - 03:29:39.9 19 1 0813+482 [0, 1] # 03:35:00.0 - 03:36:40.0 20 2 0542+498 [0, 1] # 03:49:50.0 - 03:51:30.1 21 6 1411+522 [0, 1] # 04:03:10.0 - 04:04:50.0 22 7 1331+305 [0, 1] # 04:18:49.9 - 04:20:40.0 23 1 0813+482 [0, 1] # 04:25:56.6 - 04:27:39.9 24 2 0542+498 [0, 1] # 04:42:49.9 - 04:44:40.0 25 8 MARS [0, 1] # 04:56:50.0 - 04:58:30.1 26 6 1411+522 [0, 1] # 05:24:03.3 - 05:33:39.9 27 7 1331+305 [0, 1] # 05:48:00.0 - 05:49:49.9 28 1 0813+482 [0, 1] # 05:58:36.6 - 06:00:30.0 29 8 MARS [0, 1] # 06:13:20.1 - 06:14:59.9 30 6 1411+522 [0, 1] # 06:27:40.0 - 06:29:20.0 31 7 1331+305 [0, 1] # 06:44:13.4 - 06:46:00.0 32 1 0813+482 [0, 1] # 06:55:06.6 - 06:57:00.0 33 8 MARS [0, 1] # 07:10:40.0 - 07:12:20.0 34 6 1411+522 [0, 1] # 07:28:20.0 - 07:30:10.1 35 7 1331+305 [0, 1] # 07:42:49.9 - 07:44:30.0 36 8 MARS [0, 1] # 07:58:43.3 - 08:00:39.9 37 6 1411+522 [0, 1] # 08:13:30.0 - 08:15:19.9 38 7 1331+305 [0, 1] # 08:27:53.4 - 08:29:30.0 39 8 MARS [0, 1] # 08:42:59.9 - 08:44:50.0 40 6 1411+522 [0, 1] # 08:57:09.9 - 08:58:50.0 41 7 1331+305 [0, 1] # 09:13:03.3 - 09:14:50.1 42 9 NGC7027 [0, 1] # 09:26:59.9 - 09:28:40.0 43 6 1411+522 [0, 1] # 09:40:33.4 - 09:42:09.9 44 7 1331+305 [0, 1] # 09:56:19.9 - 09:58:10.0 45 9 NGC7027 [0, 1] # 10:12:59.9 - 10:14:50.0 46 8 MARS [0, 1] # 10:27:09.9 - 10:28:50.0 47 6 1411+522 [0, 1] # 10:40:30.0 - 10:42:00.0 48 7 1331+305 [0, 1] # 10:56:10.0 - 10:57:50.0 49 9 NGC7027 [0, 1] # 11:28:30.0 - 11:35:30.0 50 10 NEPTUNE [0, 1] # 11:48:20.0 - 11:50:10.0 51 6 1411+522 [0, 1] # 12:01:36.7 - 12:03:10.0 52 7 1331+305 [0, 1] # 12:35:33.3 - 12:37:40.0 53 11 URANUS [0, 1] # 12:46:30.0 - 12:48:10.0 54 10 NEPTUNE [0, 1] # 13:00:29.9 - 13:02:10.0 55 6 1411+522 [0, 1] # 13:15:23.3 - 13:17:10.1 56 9 NGC7027 [0, 1] # 13:33:43.3 - 13:35:40.0 57 11 URANUS [0, 1] # 13:44:30.0 - 13:46:10.0 58 10 NEPTUNE [0, 1] # 14:00:46.7 - 14:01:39.9 59 0 0137+331 [0, 1] # 14:10:40.0 - 14:12:09.9 60 12 JUPITER [0, 1] # 14:24:06.6 - 14:25:40.1 61 11 URANUS [0, 1] # 14:34:30.0 - 14:36:10.1 62 10 NEPTUNE [0, 1] # 14:59:13.4 - 15:00:00.0 63 0 0137+331 [0, 1] # 15:09:03.3 - 15:10:40.1 64 12 JUPITER [0, 1] # 15:24:30.0 - 15:26:20.1 65 9 NGC7027 [0, 1] # 15:40:10.0 - 15:45:00.0 66 11 URANUS [0, 1] # 15:53:50.0 - 15:55:20.0 67 10 NEPTUNE [0, 1] # 16:18:53.4 - 16:19:49.9 68 0 0137+331 [0, 1] # 16:29:10.1 - 16:30:49.9 69 12 JUPITER [0, 1] # 16:42:53.4 - 16:44:30.0 70 11 URANUS [0, 1] # 16:54:53.4 - 16:56:40.0 71 9 NGC7027 [0, 1] # 17:23:06.6 - 17:30:40.0 72 2 0542+498 [0, 1] # 17:41:50.0 - 17:43:20.0 73 3 0437+296 [0, 1] # 17:55:36.7 - 17:57:39.9 74 4 VENUS [0, 1] # 18:19:23.3 - 18:20:09.9 75 0 0137+331 [0, 1] # 18:30:23.3 - 18:32:00.0 76 12 JUPITER [0, 1] # 18:44:49.9 - 18:46:30.0 77 9 NGC7027 [0, 1] # 18:59:13.3 - 19:00:59.9 78 2 0542+498 [0, 1] # 19:19:10.0 - 19:21:20.1 79 5 0521+166 [0, 1] # 19:32:50.1 - 19:34:29.9 80 3 0437+296 [0, 1] # 19:39:03.3 - 19:40:40.1 81 4 VENUS [0, 1] # 20:08:06.7 - 20:08:59.9 82 0 0137+331 [0, 1] # 20:18:10.0 - 20:19:50.0 83 12 JUPITER [0, 1] # 20:33:53.3 - 20:35:40.1 84 1 0813+482 [0, 1] # 20:40:59.9 - 20:42:40.0 85 2 0542+498 [0, 1] # 21:00:16.6 - 21:02:20.1 86 5 0521+166 [0, 1] # 21:13:53.4 - 21:15:29.9 87 3 0437+296 [0, 1] # 21:20:43.4 - 21:22:30.0 88 4 VENUS [0, 1] # 21:47:26.7 - 21:48:20.1 89 0 0137+331 [0, 1] # 21:57:30.0 - 21:59:10.0 90 12 JUPITER [0, 1] # 22:12:13.3 - 22:14:00.1 91 2 0542+498 [0, 1] # 22:28:33.3 - 22:30:19.9 92 4 VENUS [0, 1] # 22:53:33.3 - 22:54:19.9 93 0 0137+331 [0, 1] # # Fields: 13 # ID Name Right Ascension Declination Epoch # 0 0137+331 01:37:41.30 +33.09.35.13 J2000 # 1 0813+482 08:13:36.05 +48.13.02.26 J2000 # 2 0542+498 05:42:36.14 +49.51.07.23 J2000 # 3 0437+296 04:37:04.17 +29.40.15.14 J2000 # 4 VENUS 04:06:54.11 +22.30.35.91 J2000 # 5 0521+166 05:21:09.89 +16.38.22.05 J2000 # 6 1411+522 14:11:20.65 +52.12.09.14 J2000 # 7 1331+305 13:31:08.29 +30.30.32.96 J2000 # 8 MARS 14:21:41.37 -12.21.49.45 J2000 # 9 NGC7027 21:07:01.59 +42.14.10.19 J2000 # 10 NEPTUNE 20:26:01.14 -18.54.54.21 J2000 # 11 URANUS 21:15:42.83 -16.35.05.59 J2000 # 12 JUPITER 00:55:34.04 +04.45.44.71 J2000 # # Spectral Windows: (2 unique spectral windows and 1 unique polarization setups) # SpwID #Chans Frame Ch1(MHz) Resoln(kHz) TotBW(kHz) Ref(MHz) Corrs # 0 1 TOPO 4885.1 50000 50000 4885.1 RR RL LR LL # 1 1 TOPO 4835.1 50000 50000 4835.1 RR RL LR LL # # Feeds: 28: printing first row only # Antenna Spectral Window # Receptors Polarizations # 1 -1 2 [ R, L] # # Antennas: 27: # ID Name Station Diam. Long. Lat. # 0 1 VLA:W9 25.0 m -107.37.25.1 +33.53.51.0 # 1 2 VLA:N9 25.0 m -107.37.07.8 +33.54.19.0 # 2 3 VLA:N3 25.0 m -107.37.06.3 +33.54.04.8 # 3 4 VLA:N5 25.0 m -107.37.06.7 +33.54.08.0 # 4 5 VLA:N2 25.0 m -107.37.06.2 +33.54.03.5 # 5 6 VLA:E1 25.0 m -107.37.05.7 +33.53.59.2 # 6 7 VLA:E2 25.0 m -107.37.04.4 +33.54.01.1 # 7 8 VLA:N8 25.0 m -107.37.07.5 +33.54.15.8 # 8 9 VLA:E8 25.0 m -107.36.48.9 +33.53.55.1 # 9 10 VLA:W3 25.0 m -107.37.08.9 +33.54.00.1 # 10 11 VLA:N1 25.0 m -107.37.06.0 +33.54.01.8 # 11 12 VLA:E6 25.0 m -107.36.55.6 +33.53.57.7 # 12 13 VLA:W7 25.0 m -107.37.18.4 +33.53.54.8 # 13 14 VLA:E4 25.0 m -107.37.00.8 +33.53.59.7 # 14 15 VLA:N7 25.0 m -107.37.07.2 +33.54.12.9 # 15 16 VLA:W4 25.0 m -107.37.10.8 +33.53.59.1 # 16 17 VLA:W5 25.0 m -107.37.13.0 +33.53.57.8 # 17 18 VLA:N6 25.0 m -107.37.06.9 +33.54.10.3 # 18 19 VLA:E7 25.0 m -107.36.52.4 +33.53.56.5 # 19 20 VLA:E9 25.0 m -107.36.45.1 +33.53.53.6 # 21 22 VLA:W8 25.0 m -107.37.21.6 +33.53.53.0 # 22 23 VLA:W6 25.0 m -107.37.15.6 +33.53.56.4 # 23 24 VLA:W1 25.0 m -107.37.05.9 +33.54.00.5 # 24 25 VLA:W2 25.0 m -107.37.07.4 +33.54.00.9 # 25 26 VLA:E5 25.0 m -107.36.58.4 +33.53.58.8 # 26 27 VLA:N4 25.0 m -107.37.06.5 +33.54.06.1 # 27 28 VLA:E3 25.0 m -107.37.02.8 +33.54.00.5 # # Tables: # MAIN 2021424 rows # ANTENNA 28 rows # DATA_DESCRIPTION 2 rows # DOPPLER # FEED 28 rows # FIELD 13 rows # FLAG_CMD # FREQ_OFFSET # HISTORY 7058 rows # OBSERVATION 1 row # POINTING 2604 rows # POLARIZATION 1 row # PROCESSOR # SOURCE (see FIELD) # SPECTRAL_WINDOW 2 rows # STATE # SYSCAL # WEATHER # #===================================================================== # Calibration #===================================================================== # # Set the fluxes of the primary calibrator(s) # print '--Setjy--' default('setjy') print "Use setjy to set flux of 1331+305 (3C286)" vis = msfile # # 1331+305 = 3C286 is our primary calibrator field = '1331+305' # Setjy knows about this source so we dont need anything more setjy() # # You should see something like this in the logger and casapy.log file: # # 1331+305 spwid= 0 [I=7.462, Q=0, U=0, V=0] Jy, (Perley-Taylor 99) # 1331+305 spwid= 1 [I=7.51, Q=0, U=0, V=0] Jy, (Perley-Taylor 99) # print "Look in logger for the fluxes (should be 7.462 and 7.510 Jy)" # #===================================================================== # # Initial gain calibration # print '--Gaincal--' default('gaincal') print "Solve for antenna gains on 1331+305 and 0137+331" print "We have 2 single-channel continuum spw" print "Do not want bandpass calibration" vis = msfile # set the name for the output gain caltable gtable = prefix + '.gcal' caltable = gtable print "Output gain cal table will be "+gtable # Gain calibrators are 1331+305 and 0137+331 (FIELD_ID 7 and 0) # We have 2 IFs (SPW 0,1) with one channel each # selection is via the field and spw strings field = '1331+305,0137+331' spw = '' # a-priori calibration application # atmospheric optical depth (turn off) gaincurve = True opacity = 0.0 # scan-based G solutions for both amplitude and phase gaintype = 'G' solint = 0. calmode = 'ap' # reference antenna 11 (11=VLA:N1) refant = '11' # minimum SNR 3 minsnr = 3 gaincal() # #===================================================================== # # Bootstrap flux scale # print '--Fluxscale--' default('fluxscale') print "Use fluxscale to rescale gain table to make new one" vis = msfile # set the name for the output rescaled caltable ftable = prefix + '.fluxscale' fluxtable = ftable print "Output scaled gain cal table is "+ftable # point to our first gain cal table caltable = gtable # we will be using 1331+305 (the source we did setjy on) as # our flux standard reference reference = '1331+305' # we want to transfer the flux to our other gain cal source 0137+331 # to bring its gain amplitues in line with the absolute scale transfer = '0137+331' fluxscale() # You should see in the logger something like: #Flux density for 0137+331 in SpW=0 is: # 5.42575 +/- 0.00285011 (SNR = 1903.7, nAnt= 27) #Flux density for 0137+331 in SpW=1 is: # 5.46569 +/- 0.00301326 (SNR = 1813.88, nAnt= 27) #===================================================================== # # Interpolate the gains onto Jupiter (and others) # print '--Accum--' default('accum') print "This will interpolate the gains onto Jupiter" vis = msfile tablein = '' incrtable = ftable calfield = '1331+305, 0137+331' # set the name for the output interpolated caltable atable = prefix + '.accum' caltable = atable print "Output cumulative gain table will be "+atable # linear interpolation interp = 'linear' # make 10s entries accumtime = 10.0 accum() #===================================================================== # # Correct the data # (This will put calibrated data into the CORRECTED_DATA column) # print '--ApplyCal--' default('applycal') print "This will apply the calibration to the DATA" print "Fills CORRECTED_DATA" vis = msfile # Start with the interpolated fluxscale/gain table gaintable = atable # Since we did gaincurve=True in gaincal, we need it here also gaincurve = True opacity=0.0 # select the fields field = '1331+305,0137+331,JUPITER' spw = '' selectdata = False # do not need to select subset since we did accum # (note that correct only does 'nearest' interp) gainselect = '' applycal() # #===================================================================== # # Now split the Jupiter target data # print '--Split Jupiter--' default('split') vis = msfile # Now we write out the corrected data to a new MS # Make an output vis file srcsplitms = prefix + '.split.ms' outputvis = srcsplitms print "Split Jupiter data into new ms "+srcsplitms # Select the Jupiter field field = 'JUPITER' spw = '' # pick off the CORRECTED_DATA column datacolumn = 'corrected' split() #===================================================================== # # Export the Jupiter data as UVFITS # Start with the split file. # print '--Export UVFITS--' default('exportuvfits') srcuvfits = prefix + '.split.uvfits' print "Writing split Jupiter data to UVFITS file "+srcuvfits vis = srcsplitms fitsfile = srcuvfits # Since this is a split dataset, the calibrated data is # in the DATA column already. datacolumn = 'data' # Write as a multisource UVFITS (with SU table) # even though it will have only one field in it multisource = True # Run asynchronously so as not to interfere with other tasks # (BETA: also avoids crash on next importuvfits) async = True exportuvfits() # #===================================================================== # MS Statistics #===================================================================== # # Treat this like a regression script # WARNING: currently requires toolkit # print "Using MS to get stats of UV data" print "" print ' Jupiter split MS' print ' ================' print '' # Pull the max src amp value out of the MS ms.open(srcsplitms) thistest_src = max(ms.range(["amplitude"]).get('amplitude')) oldtest_src = 4.92000198364 print ' MS max amplitude should be ',oldtest_src print ' Found : Max in MS = ',thistest_src diff_src = abs((oldtest_src-thistest_src)/oldtest_src) print ' Difference (fractional) = ',diff_src ms.close() print "" print "Done with calibration" print "You can now go on to imaging" print "Use the final split MS "+srcsplitms print '' print '--- Done ---' # #=====================================================================