Changeset 966


Ignore:
Timestamp:
03/31/06 17:40:57 (18 years ago)
Author:
Chris Phillips
Message:

Added selection section, updated worked examples and minor tweaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/cookbook.tex

    r953 r966  
    5858\begin{verbatim}
    5959  > cd /my/data/directory
    60   > asap2
     60  > asap
    6161\end{verbatim}
    6262
     
    341341\label{sec:selection}
    342342
    343 CHRIS TOFILL IN
    344 
    345 %You can copy one scantable to another with the \cmd{copy} function.
    346 
    347 %Example:
    348 
    349 %\begin{verbatim}
    350 %  ASAP> scans = scantable('MyData.rpf')
    351 %  ASAP> scan2 = scans.copy()
    352 %\end{verbatim}
     343ASAP contains flexible data selection. Data can be selected based on
     344IF, beam, polarisation, scan number as well as values such as
     345Tsys. Advanced users can also make use of the AIPS++ TAQL language to
     346create selections based on almost any of the standard header values.
     347
     348Selection is based on a \cmd{selector} object. This object is created
     349and various selection functions applied to it (\cmd{set\_ifs},
     350\cmd{set\_beams} etc). The selection object then must be applied to a
     351scantable using the \cmd{set\_selection} function. A single selection
     352object can be created and setup then applied to multiple scantables.
     353
     354Once a selection has been applied, all following functions will only
     355``see'' the selected spectra (including functions such as
     356\cmd{summary}). The selection can then be reset and all spectra are
     357visible. Note that if functions such as \cmd{copy} are run on a
     358scantable with active selection, only the selected spectra are copied.
     359
     360The common selection functions are:
     361
     362\begin{itemize}
     363
     364\item[\cmd{set\_beams}] Select beams by index number
     365\item[\cmd{set\_ifs}] Select ifs by index number
     366\item[\cmd{set\_name}] Select by source name. Can contain ``*'' as a
     367wildcard, e.g. ``Orion*\_R''.
     368\item[\cmd{set\_ifs}] Select ifs by index number
     369\item[\cmd{set\_polarisation}] Select but polarisation index or
     370name. If polarisation names are given, the data will be on-the-fly
     371converted (for example from linears to Stokes). Not all conversions
     372are currently supported.
     373\item[\cmd{set\_query}] Set query directly. For power users only!
     374\item[\cmd{set\_tsys}] Select data based on Tsys. Also example of user
     375definable query.
     376\item[\cmd{reset}] Reset the selection to include all spectra.
     377
     378
     379Note that all indices are zero based.
     380
     381Examples:
     382
     383\begin{verbatim}
     384
     385\end{verbatim}
     386  ASAP> selection = selector()         # Create selection object
     387  ASAP> selection.set_ifs(0)           # Just select the first IF
     388  ASAP> scans.set_selection(selection) # Apply the selection
     389  ASAP> print scans                    # Will just show the first IF
     390
     391  ASAP> selection.set_ifs([0,1])       # Select the first two IFs
     392  ASAP> selection.set_beams([1,3,5])   # Also select three of the beams
     393  ASAP> scans.set_selection(selection) # Apply the selection
     394
     395  ASAP> selection.set_name('G308*')     # Select by source name
     396
     397  ASAP> selection.reset()              # Turn off selection
     398  ASAP> scans.set_selection(selection) # Apply the reset selection
     399
     400\end{itemize}
    353401
    354402\subsection{State}
     
    437485\subsubsection{Masks}
    438486
    439 \index{Masks}\index{Scantable!masks}Many tasks (fitting, baseline
    440 subtraction, statistics etc) should only be run on range of
    441 channels. Depending on the current ``unit'' setting this range is set
    442 directly as channels, velocity or frequency ranges. Internally these
    443 are converted into a simple boolean mask for each channel of the
    444 abscissa. This means that if the unit setting is later changed,
    445 previously created mask are still valid. (This is not true for
    446 functions which change the shape or shift the frequency axis).  You
    447 create masks with the function \cmd{create\_mask} and this specified
    448 the channels to be included in the selection.
    449 
    450 When setting the mask in velocity, the conversion from velocity
    451 to channels is based on the current cursor setting, selected row and
    452 selected frequency reference frame.
     487\index{Masks}\index{Scantable!masks}
     488
     489Many tasks (fitting, baseline subtraction, statistics etc) should only
     490be run on range of channels. Depending on the current ``unit'' setting
     491this range is set directly as channels, velocity or frequency
     492ranges. Internally these are converted into a simple boolean mask for
     493each channel of the abscissa. This means that if the unit setting is
     494later changed, previously created mask are still valid. (This is not
     495true for functions which change the shape or shift the frequency
     496axis).  You create masks with the function \cmd{create\_mask} and this
     497specified the channels to be included in the selection. When setting
     498the mask in velocity, the conversion from velocity to channels is
     499based on the current cursor setting, selected row and selected
     500frequency reference frame.
     501
     502
     503Note that for multi IF data with different number of channels per IF a
     504single mask cannot be applied to different IFs. To use a mask on such
     505data the selector should be applied to select all IFs with the same
     506number of channels.
    453507
    454508Example :
     
    9981052  ASAP> selection = selector()
    9991053  # Select second IF
    1000   ASAP> selection.set_if(1)
     1054  ASAP> selection.set_ifs(1)
    10011055  ASAP> plotter.set_selection(selection)
    10021056
    10031057  # Select first 4 beams
    1004   ASAP> selection.set_beam([0,1,2,3])
     1058  ASAP> selection.set_beams([0,1,2,3])
    10051059  ASAP> plotter.set_selection(selection)
    10061060
     
    10101064
    10111065  # Multiple selection
    1012   ASAP> selection.set_if(1)
     1066  ASAP> selection.set_ifs(1)
    10131067  ASAP> selection.set_scans([2,4,6,10])
    10141068  ASAP> plotter.set_selection(selection)
     
    10831137available. This is done by creating a fitting object, setting up the
    10841138fit and actually fitting the data. Fitting can either be done on a
    1085 single scantable row/cursor selection or on an entire scantable using
    1086 the \cmd{auto\_fit} function.
     1139single scantable selection or on an entire scantable using the
     1140\cmd{auto\_fit} function. If single value fitting is used, and the
     1141current selection includes multiple spectra (beams, IFs, scans etc)
     1142then the first spectra in the scantable will be used for fitting.
    10871143
    10881144\begin{verbatim}
     
    10901146 ASAP> f.set_function(gauss=2) # Fit two Gaussians
    10911147 ASAP> f.set_scan(scans)
    1092  ASAP> scans.set_cursor(0,0,1) # Fit the second polarisation
     1148 ASAP> selection = selector()
     1149 ASAP> selection.set_polarisation(1) # Fit the second polarisation
     1150 ASAP> scans.set_selection(selection)
    10931151 ASAP> scans.set_unit('km/s')  # Make fit in velocity units
    10941152 ASAP> f.fit(1)                # Run the fit on the second row in the table
     
    11751233
    11761234Conversions of linears to Stokes or Circular polarisations are done
    1177 ``on-the-fly''. Leakage cannot be corrected for nor are these routines
    1178 able to calibrate position angle offsets.
     1235``on-the-fly''. Leakage cannot be corrected for nor are there routines
     1236to calibrate position angle offsets.
    11791237
    11801238\subsection{Simple Calibration}
     
    12391297  ASAP> selection = selector()
    12401298 
    1241   ASAP> selection.set_polarisations([``I'', ``Q'', ``U'', ``V''])
     1299  ASAP> selection.set_polarisations([``I Q U V''])
    12421300  ASAP  plotter.set_selection(selection);              # Select I, Q, U \& V
    12431301
    1244   ASAP> selection.set_polarisations([``I'', ``Q'')
     1302  ASAP> selection.set_polarisations([``I Q'')
    12451303  ASAP  plotter.set_selection(selection);              # Select just I \& Q
    12461304
    1247   ASAP> selection.set_polarisations([``RR'', ``LL'')
     1305  ASAP> selection.set_polarisations([``RR LL'')
    12481306  ASAP  plotter.set_selection(selection);              # Select just RR \& LL
    12491307
    1250   ASAP> selection.set_polarisations([``XX'', ``YY'')
     1308  ASAP> selection.set_polarisations([``XX YY'')
    12511309  ASAP  plotter.set_selection(selection);              # Select linears
    12521310
    1253   ASAP> selection.set_polarisations([``I'', ``Plinear'')
    1254   ASAP  plotter.set_selection(selection);              # Select linears
     1311  ASAP> selection.set_polarisations([``I Plinear'')
     1312  ASAP  plotter.set_selection(selection);              # Fractional linear
     1313
     1314[[MALTE: This does not work]]
     1315
     1316  ASAP> selection.set_polarisations([``Pangle'')
     1317  ASAP  plotter.set_selection(selection);              # Position angle
    12551318
    12561319\end{verbatim}
     
    12701333  ASAP> scans.save('myscan.sdfits', 'SDFITS', stokes=True)
    12711334\end{verbatim}
    1272 
    12731335
    12741336\section{Scantable Mathematics}
     
    12801342not work for integers).
    12811343
    1282 \begin{verbatim}
    1283   ASAP> sum = scan1+scan2
     1344{\em Currently mathematics between two scan tables is not available }
     1345
     1346\begin{verbatim}
     1347%  ASAP> sum = scan1+scan2
    12841348  ASAP> scan2 = scan1+2.0
    12851349  ASAP> scan *= 1.05
     
    13441408plotter.plot(q)
    13451409
    1346 # Velocity align the data before averaging
     1410# Set reference frame
    13471411q.set_unit('km/s')
    13481412q.set_freqframe('LSRK')
    1349 q.freq_align()
    1350 
    1351 # Average all scans in time
    1352 av = q.average_time()
     1413
     1414# Average all scans in time, aligning in velocity
     1415av = q.average_time(align=True)
    13531416plotter.plot(av)
    13541417
     
    14001463def xyscale(data,xtsys=1.0,ytsys=1.0,nomtsys=25.0) :
    14011464
    1402  data.set_cursor(pol=0)
    1403  data.scale(xtsys/nomtsys,allaxes=False)
    1404 
    1405  data.set_cursor(pol=1)
    1406  data.scale(ytsys/nomtsys,allaxes=False)
    1407 
    1408  data.set_cursor(pol=2)
    1409  data.scale((xtsys+ytsys)/(2*nomtsys),allaxes=False)
    1410 
    1411  data.set_cursor(pol=3)
    1412  data.scale((xtsys+ytsys)/(2*nomtsys),allaxes=False)
     1465 selection = selector()
     1466 selection.set_polarisation(0)
     1467 data.set_selection(selection)
     1468 data.scale(xtsys/nomtsys)
     1469
     1470 selection.set_polarisation(1)
     1471 data.set_selection(selection)
     1472 data.scale(ytsys/nomtsys)
     1473
     1474 selection.set_polarisation(0)
     1475 data.set_selection(selection)
     1476 data.scale((xtsys+ytsys)/(2*nomtsys))
     1477
     1478 selection.set_polarisation(0)
     1479 data.set_selection(selection)
     1480 data.scale((xtsys+ytsys)/(2*nomtsys))
    14131481\end{verbatim}
    14141482
     
    14361504# transition
    14371505d1667 = d1665.copy()
    1438 d1667.set_restfreqs(lines=['OH1667'])
    1439 d1667.summary
     1506d1667.set_restfreqs([1667.3590], 'MHz')
     1507d1667.summary()
    14401508
    14411509# Copy out the scan we wish to process
     
    14431511g351_7 = d1667.get_scan('351p160')
    14441512
    1445 # Plot the data
    1446 plotter.plot(g351_5,g351_7) # Only shows one panel
     1513# Baseline both
     1514msk = g351_5.create_mask([-30,-25],[-5,0])
     1515g351_5.poly_baseline(msk,order=1)
     1516msk = g351_7.create_mask([-30,-25],[-5,0])
     1517g351_7.poly_baseline(msk,order=1)
     1518
     1519
     1520# Plot the data. The plotter can only plot a single scantable
     1521# So we must merge the two tables first
     1522
     1523plotscans = merge(g351_5, g351_7)
     1524
     1525plotter.plot(plotscans) # Only shows one panel
    14471526
    14481527# Tell the plotter to stack polarisation and panel scans
     
    14571536plotter.set_range(-30,10)
    14581537
    1459 # Baseline the data
    1460 msk = g351_5.create_mask([-20,-15],[0,5])
    1461 g351_5.poly_baseline(msk,1)
    1462 msk = g351_7.create_mask([-20,-15],[0,5])
    1463 g351_7.poly_baseline(msk,1)
    1464 
    14651538# Update the plot with the baselined data
    14661539plotter.plot()
    14671540
    14681541# Look at the various polarisation products
    1469 plotter.set_cursor(pol='RR LL')
    1470 plotter.set_cursor(pol='I Plinear')
    1471 plotter.set_cursor(pol='I Q U V')
     1542selection = selector()
     1543selection.set_polarisations(``RR LL'')
     1544plotter.set_selection(selection)
     1545selection.set_polarisations(``I Plinear'')
     1546plotter.set_selection(selection)
     1547selection.set_polarisations(``I Q U V'')
     1548plotter.set_selection(selection)
    14721549
    14731550# Save the plot as postscript
    1474 plotter.save('g361_stokes.ps')
     1551plotter.save('g351_stokes.ps')
    14751552
    14761553# Save the process spectra
    1477 g351_5.save('junk5.asap')
    1478 g351_7.save('junk7.asap')
     1554plotscans.save('g351.asap')
    14791555
    14801556\end{verbatim}
     
    15021578print q
    15031579
     1580del d
     1581
    15041582# Plot/select in velocity
    15051583q.set_freqframe('LSRK')
    15061584q.set_unit('km/s')
    15071585
     1586# Correct for gain/el effects
     1587
     1588q.recalc_azel()  # Tid does not write the elevation
     1589q.gain_el()
     1590q.opacity(0.05)
     1591
    15081592# Seperate data from the (1,1)&(2,2) and (4,4) transitions
    15091593g1 = q.get_scan(range(6))     # Rows 0..5
     
    15111595
    15121596# Align data in velocity
    1513 g1.freq_align(perif=True)
    1514 g2.freq_align(perif=True)
     1597g1.freq_align()
     1598g2.freq_align()
    15151599
    15161600# Average individual scans
     
    15191603
    15201604# Rpfits file only contrains a single rest frequency. Set both
    1521 a1.set_restfreqs(freqs= [23694.4700e6,23722.6336e6])
    1522 
    1523 plotter.plot(a1,a2)
     1605a1.set_restfreqs([23694.4700e6,23722.6336e6])
     1606
     1607plotter.plot(a1)
    15241608plotter.set_mode('i','s')
    15251609
    15261610a1.auto_poly_baseline()
    1527 a2.auto_poly_baseline()
    15281611
    15291612plotter.plot()
    15301613
    15311614a1.smooth('gauss',5)
    1532 a2.smooth('gauss',5)
    15331615plotter.plot()
     1616
    15341617
    15351618\end{verbatim}
     
    17271810called}
    17281811
    1729 \asaprc{scantable.allaxes}{{\bf True}/False}{Apply action to all axes
    1730 not just the cursor location}
    1731 
    17321812\asaprc{scantable.plotter}{{\bf True}/False}{Use internal plotter}
    17331813
Note: See TracChangeset for help on using the changeset viewer.