source: trunk/doc/userguide.tex @ 971

Last change on this file since 971 was 971, checked in by mar637, 18 years ago

proof read chris' lat version. added some info.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 62.0 KB
RevLine 
[534]1\documentclass[11pt]{article}
2\usepackage{a4}
[770]3\usepackage{calc}
[534]4\usepackage[dvips]{graphicx}
[794]5\usepackage{makeidx}
[534]6
7% Adjust the page size
8\addtolength{\oddsidemargin}{-0.4in}
9\addtolength{\evensidemargin}{+0.4in}
10\addtolength{\textwidth}{+0.8in}
11
12\setlength{\parindent}{0mm}
13\setlength{\parskip}{1ex}
14
[770]15\title{ATNF Spectral Analysis Package\\User Guide }
[534]16\author{Chris Phillips}
17
18\newcommand{\cmd}[1]{{\tt #1}}
19
[770]20\newcommand{\asaprc}[3]{
21  \begin{minipage}[t]{45mm}#1\end{minipage}
22  \begin{minipage}[t]{30mm}\raggedright #2\end{minipage}\hspace{3mm}
23  \begin{minipage}[t]{\textwidth-75mm}#3\end{minipage}
24}
25
[794]26\makeindex
27
28
[534]29\begin{document}
30
31\maketitle
32
33\section{Introduction}
34
[544]35ASAP is a single dish spectral line processing package currently being
36developed by the ATNF. It is intended to process data from all ATNF
[770]37antennas, and can probably be used for other antennas if they can
[544]38produce ``Single Dish FITS'' format. It is based on the AIPS++
39package.
40
[953]41This useeguide is currently being updated for the ASAP 2.0 release
42which has a number of significant changes which affect the user
43interface. Please report any mistakes you find in this userguide.
[534]44
[544]45\section{Installation and Running}
[534]46
[738]47Currently there are installations running on Linux machines at
[534]48
49\begin{itemize}
50\item Epping - use hosts {\tt draco} or {\tt hydra}
51\item Narrabri - use host {\tt kaputar}
[537]52\item Parkes - use host {\tt bourbon}
[534]53\item Mopra - use host {\tt minos}
54\end{itemize}
55
[794]56\index{Running}To start asap log onto one of these Linux hosts and enter
[534]57
58\begin{verbatim}
59  > cd /my/data/directory
[966]60  > asap
[534]61\end{verbatim}
62
[544]63This starts the ASAP. To quit, you need to type \verb+^+-d
[971]64(control-d) or type \cmd{\%Exit}.
[534]65
66\section{Interface}
67
[794]68\index{Interface}ASAP is written in C++ and python. The user interface uses the
[534]69``ipython'' interactive shell, which is a simple interactive interface
70to python. The user does not need to understand python to use this,
71but certain aspects python affect what the user can do.  The current
72interface is object oriented.  In the future, we will build a
73functional (non object oriented) shell on top of this to ease
74interactive use.
75
76\subsection {Integer Indices are 0-relative}
77
78Please note, all integer indices in ASAP and iPython are {\bf 0-relative}.
79
80\subsection{Objects}
[794]81\index{objects}
[534]82The ASAP interface is based around a number of ``objects'' which the
83user deals with. Objects range from the data which have been read from
84disk, to tools used for fitting functions to the data. The following
85main objects are used :
86
87\begin{itemize}
[544]88  \item[\cmd{scantable}] The data container (actual spectra and header
89    information)
[953]90  \item[\cmd{selector}] Allows the user to select a subsection of the
91    data, such as a specified or ramge of beam numbers, IFs, etc.
92  \item[\cmd{plotter}] A tool used to plot the spectral line data
[544]93  \item[\cmd{fitter}] A tool used to fit functions to the spectral data
94  \item[\cmd{reader}] A tool which can be used to read data from disks
[971]95    into a scantable object (advanced use).
[534]96\end{itemize}
97
[738]98There can be many objects of the same type. Each object is referred to
[534]99by a variable name made by the user. The name of this variable is not
[770]100important and can be set to whatever the user prefers (i.e. ``s'' and
[534]101``ParkesHOH-20052002'' are equivalent).  However, having a simple and
102consistent naming convention will help you a lot.
103
[544]104\subsection{Member Functions (functions)}
[534]105
[794]106\index{Functions!member}Following the object oriented approach,
107objects have associated ``member functions'' which can either be used
108to modify the data in some way or change global properties of the
109object. In this document member functions will be referred to simply
110as functions. From the command line, the user can execute these
111functions using the syntax:
[534]112\begin{verbatim}
113  ASAP> out = object.function(arguments)
114\end{verbatim}
115
116Where \cmd{out} is the name of the returned variable (could be a new
[544]117scantable object, or a vector of data, or a status return),
118\cmd{object} is the object variable name (set by the user),
119\cmd{function} is the name of the member function and \cmd{arguments}
120is a list of arguments to the function. The arguments can be provided
121either though position or \cmd{name=}.  A mix of the two can be used.
122E.g.
[534]123
124\begin{verbatim}
[953]125  ASAP> av = scans.average_time(msk,weight='tsys')
126  ASAP> av = scans.average_time(mask=msk,weight='tsys')
127  ASAP> av = scans.average_time(msk,tsys)
[971]128  ASAP> scans.poly_baseline(mask=msk, order=0, insitu=True)
129  ASAP> scans.poly_baseline(msk,0,True)
130  ASAP> scans.poly_baseline(mask, insitu=True)
[534]131\end{verbatim}
132
133\subsection{Global Functions}
134
[794]135\index{Functions!global}It does not make sense to implement some functions as member
[544]136functions, typically functions which operate on more than one
137scantable (e.g. time averaging of many scans). These functions will
138always be referred to as global functions.
[534]139
[538]140\subsection{Interactive environment}
[534]141
[794]142\index{ipython!environment}ipython has a number of useful interactive
143features and a few things to be aware of for the new user.
[534]144
145\subsubsection{String completion}
146
[794]147\index{ipython!string completion}Tab completion is enabled for all
148function names. If you type the first few letters of a function name,
149then type {\tt <TAB>} the function name will be auto completed if it
150is un-ambiguous, or a list of possibilities will be
151given. Auto-completion works for the user object names as well as
152function names. It does not work for filenames, nor for function
153arguments.
[534]154
155Example
156\begin{verbatim}
157  ASAP> scans = scantable('MyData.rpf')
158  ASAP> scans.se<TAB>
159  ASAP> scans.set_in<TAB>
[971]160scans.set_cursor      scans.set_freqframe   scans.set_selection
161scans.set_doppler     scans.set_instrument  scans.set_unit
162scans.set_fluxunit    scans.set_restfreqs
163
[794]164  ASAP> scans.set_instrument()
[534]165\end{verbatim}
166
[544]167\subsubsection{Leading Spaces}
168
[794]169\index{ipython!leading space}Python uses leading space to mark blocks
170of code. This means that it you start a command line with a space, the
171command generally will fail with an syntax error.
[544]172
[770]173\subsubsection{Variable Names}
174
[794]175\index{ipython!variable names}During normal data processing, the user
176will have to create named variables to hold spectra etc. These must
177conform to the normal python syntax, specifically they cannot contain
178``special'' characters such as \@ \$ etc and cannot start with a
179number (but can contain numbers).  Variable (and function) names are
180case sensitive.
[770]181
[534]182\subsubsection{Unix Interaction}
183
[794]184\index{ipython!unix interaction}Basic unix shell commands (\cmd{pwd},
185\cmd{ls}, \cmd{cd} etc) can be issued from within ASAP. This allows
186the user to do things like look at files in the current directory. The
187shell command ``\cmd{cd}'' works within ASAP, allowing the user to
188change between data directories. Unix programs cannot be run this way,
189but the shell escape ``$!$'' can be used to run arbitrary
190programs. E.g.
[534]191
192\begin{verbatim}
193  ASAP> pwd
194  ASAP> ls
[953]195  ASAP> cd /my/data/directory
[534]196  ASAP> ! mozilla&
197\end{verbatim}
198
199\subsection{Help}
200
[794]201\index{Help}ASAP has built in help for all functions. To get a list of
202functions type:
[534]203
[538]204\begin{verbatim}
[794]205  ASAP> commands()
[538]206\end{verbatim}
207
208To get help on specific functions, the built in help needs to be given
209the object and function name. E.g.
210
211\begin{verbatim}
[971]212  ASAP> help scantable.get_scan # or help(scantable.get_scan)
[538]213  ASAP> help scantable.stats
214  ASAP> help plotter.plot
215  ASAP> help fitter.plot
216
217  ASAP> scans = scantable('mydata.asap')
218  ASAP> help scans.get_scan # Same as above
[544]219\end{verbatim}
[538]220
[544]221Global functions just need their name
[538]222
[544]223\begin{verbatim}
[738]224  ASAP> help average_time
[538]225\end{verbatim}
226
227Note that if you just type \cmd{help} the internal ipython help is
228invoked, which is probably {\em not} what you want. Type \verb+^+-d
229(control-d) to escape from this.
230
[738]231\subsection{Customisation - .asaprc}
[534]232
[794]233\index{.asaprc}ASAP use an \cmd{.asaprc} file to control the user's
234preference of default values for various functions arguments. This
235includes the defaults for arguments such as \cmd{insitu}, scantable
236\cmd{freqframe} and the plotters \cmd{set\_mode} values. The help on
237individual functions says which arguments can be set default values
238from the \cmd{.asaprc} file. To get a sample contents for the
239\cmd{.asaprc} file use then command \cmd{list\_rcparameters}.
[534]240
[538]241Common values include:
242\begin{verbatim}
243  # apply operations on the input scantable or return new one
244  insitu                     : False
245
[738]246  # default output format when saving scantable
[953]247  scantable.save             : ASAP
[538]248
249  # default frequency frame to set when function
250  # scantable.set_freqframe is called
[953]251  scantable.freqframe        : LSRK
[538]252
253  # auto averaging on read
254  scantable.autoaverage      : True
255\end{verbatim}
256
[953]257For a complete list of \cmd{.asaprc} values, see the Appendix.
[770]258
[534]259\section{Scantables}
[794]260\index{Scantables}
[534]261\subsection {Description}
262
263\subsubsection {Basic Structure}
264
[794]265\index{Scantable!structure}ASAP data handling works on objects called
266scantables.  A scantable holds your data, and also provides functions
267to operate upon it.
[534]268
[953]269{\bf [MALTE: Could you please reword this??]}
270
[534]271The building block of a scantable is an integration, which is a single
[971]272row of a scantable. Each row contains just one spectrum for each beam, IF and
[534]273polarisation. For example Parkes multibeam data would contain many
274beams, one IF and 2-4 polarisations, while the new Mopra 8-GHz
275filterbank will eventually produce one beam, many IFs, and 2-4
[971]276polarisations. All of the combinations of Beams/IFs an Polarisations are
277contained in seperate rows. These rows are grouped in cycles - same time stamp.
[534]278
[971]279A collection of cyclesfor one source is termed
280a scan (and each scan has a unique numeric identifier, the ScanNo). A
[534]281scantable is then a collection  of one or more scans. If you have
[971]282scan-averaged your data in time, i.e. you have averegaed all cycles within
283a scan, then each scan would hold just one (averaged) integration.
[534]284
285Many of the functions which work on scantables can either return a
286new scantable with modified data or change the scantable insitu. Which
287method is used depends on the users preference. The default can be
288changed via the {\tt .asaprc} resource file.
289
290\subsubsection {Contents}
291
[794]292\index{Scantable!contents}A scantable has header information and data
[953]293(a scantable is actually an AIPS++ Table and it is generally stored in
294memory when you are manipulating it with ASAP.  You can save it to
295disk and then browse it with the AIPS++ Table browser if you know how
296to do that !).
[534]297
298The data are stored in columns (the length of a column is the number of
[738]299rows/integrations of course).
[534]300
[953]301{\bf [MALTE: Is this outdated??]}
302
[534]303Two important columns are those that describe the frequency setup.  We mention
[538]304them explicitly here because you need to be able to understand the presentation
[534]305of the frequency information and possibly how to manipulate it.
306
[971]307These columns are called FreqID and MoleculeID.  They contain indices, for
308each IF, pointing into tables with all of the frequency and rest-frequency
309information for that integration. More on these below when we discuss
310the \cmd{summary} function in the next subsection.
[534]311
312There are of course many other columns which contain the actual spectra,
[971]313the flags, the Tsys, the source names and so on.
[534]314
315There is also a function \cmd{summary} to list a summary of the scantable.
316You will find this very useful.
317
318Example:
319
320\begin{verbatim}
321  ASAP> scans = scantable('MyData.rpf')
322  ASAP> scans.summary()                # Brief listing
[544]323
324  # Equivalent to brief summary function call
[738]325  ASAP> print scan
[534]326\end{verbatim}
327
[971]328The summary function gives you a scan-based summary, presenting the
329scantable as a cascading view od Beams and IFs.
[534]330
[953]331\subsection{Data Selection}
332\label{sec:selection}
333
[966]334ASAP contains flexible data selection. Data can be selected based on
335IF, beam, polarisation, scan number as well as values such as
336Tsys. Advanced users can also make use of the AIPS++ TAQL language to
[971]337create selections based on almost any of the values recorded.
[953]338
[966]339Selection is based on a \cmd{selector} object. This object is created
340and various selection functions applied to it (\cmd{set\_ifs},
341\cmd{set\_beams} etc). The selection object then must be applied to a
342scantable using the \cmd{set\_selection} function. A single selection
343object can be created and setup then applied to multiple scantables.
[534]344
[966]345Once a selection has been applied, all following functions will only
346``see'' the selected spectra (including functions such as
347\cmd{summary}). The selection can then be reset and all spectra are
348visible. Note that if functions such as \cmd{copy} are run on a
349scantable with active selection, only the selected spectra are copied.
[534]350
[966]351The common selection functions are:
[534]352
[966]353\begin{itemize}
354
355\item[\cmd{set\_beams}] Select beams by index number
356\item[\cmd{set\_ifs}] Select ifs by index number
357\item[\cmd{set\_name}] Select by source name. Can contain ``*'' as a
358wildcard, e.g. ``Orion*\_R''.
359\item[\cmd{set\_ifs}] Select ifs by index number
360\item[\cmd{set\_polarisation}] Select but polarisation index or
361name. If polarisation names are given, the data will be on-the-fly
[971]362converted (for example from linears to Stokes).
[966]363\item[\cmd{set\_query}] Set query directly. For power users only!
364\item[\cmd{set\_tsys}] Select data based on Tsys. Also example of user
365definable query.
366\item[\cmd{reset}] Reset the selection to include all spectra.
367
368
369Note that all indices are zero based.
370
371Examples:
372
373\begin{verbatim}
374  ASAP> selection = selector()         # Create selection object
375  ASAP> selection.set_ifs(0)           # Just select the first IF
376  ASAP> scans.set_selection(selection) # Apply the selection
377  ASAP> print scans                    # Will just show the first IF
378
379  ASAP> selection.set_ifs([0,1])       # Select the first two IFs
380  ASAP> selection.set_beams([1,3,5])   # Also select three of the beams
381  ASAP> scans.set_selection(selection) # Apply the selection
382
383  ASAP> selection.set_name('G308*')     # Select by source name
384
385  ASAP> selection.reset()              # Turn off selection
386  ASAP> scans.set_selection(selection) # Apply the reset selection
387
[970]388\end{verbatim}
389
[966]390\end{itemize}
391
[534]392\subsection{State}
393
[794]394\index{Scantable!state}Each scantable contains "state"; these are
395properties applying to all of the data in the scantable.
[534]396
397Examples are the selection of beam, IF and polarisation,  spectral unit
[770]398(e.g. km/s), frequency reference frame (e.g. BARY) and velocity Doppler
[534]399type (e.g. RADIO).
400
401\subsubsection{Units, Doppler and Frequency Reference Frame}
402
403The information describing the frequency setup for each integration
404is stored fundamentally in frequency in the reference frame
[738]405of observation (E.g. TOPO).
[534]406
[544]407When required, this is converted to the desired reference frame
408(e.g. LSRK), Doppler (e.g. OPTICAL) and unit (e.g. km/s) on-the-fly.
409This is important, for example, when you are displaying the data or
[971]410fitting to it. The reference frame is set on file read to the value
411set in the user \cmd{.asaprc} file.
[534]412
413For units, the user has the choice of frequency, velocity or channel.
414The \cmd{set\_unit} function is used to set the current unit for a
415scantable. All functions will (where relevant) work with the selected
416unit until this changes. This is mainly important for fitting (the fits
[738]417can be computed in any of these units), plotting and mask creation.
[534]418
[544]419The velocity definition can be changed with the \cmd{set\_doppler}
420function, and the frequency reference frame can be changed with the
[534]421\cmd{set\_freqframe} function.
422
423Example usage:
424
425\begin{verbatim}
426  ASAP> scans = scantable('2004-11-23_1841-P484.rpf') # Read in the data
427  ASAP> scans.set_freqframe('LSRK')  # Use the LSR velocity frame
428  ASAP> scans.set_unit('km/s')        # Use velocity for plots etc from now on
429  ASAP> scans.set_doppler('OPTICAL')  # Use the optical velocity convention
430  ASAP> scans.set_unit('MHz')         # Use frequency in MHz from now on
431\end{verbatim}
432
433
434\subsubsection{Rest Frequency}
435
[794]436\index{Scantable!rest frequency}ASAP reads the line rest frequency
437from the RPFITS file when reading the data. The values stored in the
438RPFITS file are not always correct and so there is a function
[953]439\cmd{set\_restfreq} to set the rest frequencies for the currently
440selected data.
[534]441
442For each integration, there is a rest-frequency per IF (the rest
443frequencies are just stored as a list with an index into them).
444There are a few ways to set the rest frequencies with this function.
445
[953]446If you specify just one rest frequency, then it is set for all IF.
[534]447
448\begin{verbatim}
[953]449  # Set all IFs
[738]450  ASAP> scans.set_restfreqs(freqs=1.667359e9)
[534]451\end{verbatim}
452
[953]453If set a rest frequency for each IF, specify a list of frequencies (of
454length the number of IFs).  Regardless of the source, the rest
455frequency will be set for each IF to the corresponding value in the
[970]456provided list.
[534]457
458\begin{verbatim}
[770]459  # Set rest frequency for all IFs
460  ASAP> scans.set_restfreqs(freqs=[1.6654018e9,1.667359e9,])
[538]461
[534]462\end{verbatim}
463
[953]464{\em Currently this is not implemented}
465
[534]466In both of the above modes, you can also specify the rest frequencies via
467names in a known list rather than by their values.
468
469Examples:
470
471\begin{verbatim}
[953]472  ASAP> scans.set_restfreqs(freqs=['OH1665','OH1667'])
[534]473\end{verbatim}
474
475
476\subsubsection{Masks}
477
[970]478\index{Masks}\index{Scantable!masks}
[534]479
[966]480Many tasks (fitting, baseline subtraction, statistics etc) should only
481be run on range of channels. Depending on the current ``unit'' setting
482this range is set directly as channels, velocity or frequency
483ranges. Internally these are converted into a simple boolean mask for
484each channel of the abscissa. This means that if the unit setting is
485later changed, previously created mask are still valid. (This is not
486true for functions which change the shape or shift the frequency
487axis).  You create masks with the function \cmd{create\_mask} and this
488specified the channels to be included in the selection. When setting
489the mask in velocity, the conversion from velocity to channels is
490based on the current cursor setting, selected row and selected
491frequency reference frame.
[534]492
[966]493
494Note that for multi IF data with different number of channels per IF a
495single mask cannot be applied to different IFs. To use a mask on such
496data the selector should be applied to select all IFs with the same
497number of channels.
498
[534]499Example :
500\begin{verbatim}
501
502  # Select channel range for baselining
503  ASAP> scans.set_unit('channels')
[544]504  ASAP> msk = scans.create_mask([100,400],[600,800])
[738]505
[534]506  # Select velocity range for fitting
507  ASAP> scans.set_unit('km/s')
[544]508  ASAP> msk = scans.create_mask([-30,-10])
[534]509\end{verbatim}
510
[544]511Sometimes it is more convenient to specify the channels to be
512excluded, rather included.  You can do this with the ``invert''
513argument.
[534]514
515Example :
516\begin{verbatim}
517  ASAP> scans.set_unit('channels')
[738]518  ASAP> msk = scans.create_mask([0,100],[900-1023], invert=True)
[534]519\end{verbatim}
520
[544]521By default \cmd{create\_mask} uses the frequency setup of the first row
522to convert velocities into a channel mask. If the rows in the data
523cover different velocity ranges, the scantable row to use should be
524specified:
525
526\begin{verbatim}
527  ASAP> scans.set_unit('km/s')
528  ASAP> msk = q.create_mask([-30,-10], row=5)
529\end{verbatim}
530
[534]531Because the mask is stored in a simple python variable, the users is
532able to combine masks using simple arithmetic. To create a mask
533excluding the edge channels, a strong maser feature and a birdie in
534the middle of the band:
535
536\begin{verbatim}
537  ASAP> scans.set_unit('channels')
538  ASAP> msk1 = q.create_mask([0,100],[511,511],[900,1023],invert=True)
539  ASAP> scans.set_unit('km/s')
540  ASAP> msk2 = q.create_mask([-20,-10],invert=True)
541
542  ASAP> mask = msk1 and msk2
543\end{verbatim}
544
545
[953]546\subsection{Management}
547
548\index{Scantable!management}During processing it is possible to create
549a large number of scan tables. These all consume memory, so it is best
550to periodically remove unneeded scan tables. Use \cmd{list\_scans} to
551print a list of all scantables and \cmd{del} to remove unneeded ones.
552
553Example:
554
555\begin{verbatim}
556  ASAP> list_scans()
557  The user created scantables are:
558  ['s', 'scans', 'av', 's2', 'ss']
559
560  ASAP> del s2
561  ASAP> del ss
562\end{verbatim}
563
[534]564\section{Data Input}
565
[971]566\index{Reading data}Data can be loaded in one of two ways; using the
567reader object or via the scantable constructor. The scantable method
568is simpler but the reader allows the user more control on what is read.
[534]569
570\subsection{Scantable constructor}
571
[794]572\index{Scantable constructor}\index{Scantable!constructor}This loads
573all of the data from filename into the scantable object scans and
574averages all the data within a scan (i.e.  the resulting scantable
[534]575will have one row per scan).  The recognised input file formats are
576RPFITS, SDFITS (singledish fits), ASAP's scantable format and aips++
[738]577MeasurementSet2 format.
[534]578
579Example usage:
580
581\begin{verbatim}
582  ASAP> scan = scantable('2004-11-23_1841-P484.rpf')
[544]583
584  # Don't scan average the data
585  ASAP> scan = scantable('2004-11-23_1841-P484.rpf', average=False)
[534]586\end{verbatim}
587
588
589\subsection{Reader object}
590
[794]591\index{Reader object}\index{Scantable!reader object}For more control
592when reading data into ASAP, the reader object should be used.  This
[953]593has the option of only reading in a range of integrations, only a
594specified beam or IF and does not perform any scan averaging of the
595data, allowing analysis of the individual integrations.  Note that due
596to limitation of the RPFITS library, only one reader object can be
597open at one time reading RPFITS files.  To read multiple RPFITS files,
598the old reader must be destroyed before the new file is opened.
599However, multiple readers can be created and attached to SDFITS files.
[534]600
601
602Example usage:
603
604\begin{verbatim}
605  ASAP> r = reader('2003-03-16_082048_t0002.rpf')
[794]606  ASAP> r.summary()
[534]607  ASAP> scan = r.read()
608  ASAP> del r
609\end{verbatim}
610
611\section{Basic Processing}
612
613In the following section, a simple data reduction to form a quotient
[544]614spectrum of a single source is followed.  It has been assume that the
615\cmd{.asaprc} file has {\em not} been used to change the \cmd{insitu}
616default value from \cmd{True}.
[534]617
[738]618\subsection{Auto quotient}
[794]619\index{Auto quotient}Quotients can be computed ``automatically''. This
620requires the data to have matching source/reference pairs or one
621reference for multiple sources. Auto quotient assumes reference scans
622have a trailing ``\_R'' in the source name for data from Parkes and
623Mopra, and a trailing ``e'' or ``w'' for data fro, Tidbinbilla.
[534]624
[738]625\begin{verbatim}
626  ASAP> q = s.auto_quotient()
627\end{verbatim}
628
[971]629By default the quotient spectra is calculated
630to preserve continuum emission. If you wish to remove the continuum
631contribution, use the \cmd{preserve} argument:
632
633\begin{verbatim}
634 ASAP> q = s.auto_quotient(preserve=True)
635\end{verbatim}
636
[953]637%If this is not sufficient the following alternative method can be used.
638%
639%\subsection{Separate reference and source observations}
640%
641%\index{Quotient spectra}Most data from ATNF observatories
642%distinguishes on and off source data using the file name. This makes
643%it easy to create two scantables with the source and reference
644%data. As long as there was exactly one reference observation for each
645%on source observation for following method will work.
646%
647%For Mopra and Parkes data:
648%\begin{verbatim}
649%  ASAP> r = scans.get_scan('*_R')
650%  ASAP> s = scans.get_scan('*_S')
651%\end{verbatim}
652%
653%For Tidbinbilla data
654%\begin{verbatim}
655%  ASAP> r = scans.get_scan('*_[ew]')
656%  ASAP> s = scans.get_scan('*_[^ew]')
657%\end{verbatim}
658%
659%\subsection{Make the quotient spectra}
660%
661%Use the quotient function
662%
663%\begin{verbatim}
664%  ASAP> q = s.quotient(r)
665%\end{verbatim}
666%
667%This uses the rows in scantable \cmd{r} as reference spectra for the
668%rows in scantable \cmd{s}. Scantable \cmd{r} must have either 1 row
669%(which is applied to all rows in \cmd{s}) or both scantables must have
[971]670%the same number of rows.
[738]671
[534]672\subsection{Time average separate scans}
673
[794]674\index{Time average}If you have observed the source with multiple
675source/reference cycles you will want to scan-average the quotient
676spectra together.
[534]677
678\begin{verbatim}
[953]679 ASAP> av = q.average_time()
[534]680\end{verbatim}
681
[544]682If for some you want to average multiple sets of scantables together
683you can:
[534]684
685\begin{verbatim}
686 ASAP> av = average_time(q1, q2, q3)
687\end{verbatim}
688
[544]689The default is to use integration time weighting. The alternative is
[770]690to use none, variance, Tsys weighting or Tsys \& integration time.
[534]691
[544]692\begin{verbatim}
693 ASAP> av = average_time(q, weight='tintsys')
694\end{verbatim}
695
[534]696To use variance based weighting, you need to supply a mask saying which
697channel range you want it to calculate the variance from.
698
699\begin{verbatim}
[544]700 ASAP> msk = scans.create_mask([200,400],[600,800])
701 ASAP> av = average_time(scans, mask=msk, weight='var')
[534]702\end{verbatim}
703
[953]704If you have not observed your data with Doppler tracking (or run
705\cmd{freq\_align} explicitally) you should align the data in frequency
706before averaging.
[794]707
[953]708\begin{verbatim}
709 ASAP> av = scans.average_time(align=True)
710\end{verbatim}
711
712Note that, if needed, you should run \cmd{gain\_el} and \cmd{opacity}
713before you average the data in time (\S \ref{sec:gainel} \&
714\ref{sec:freqalign}).
715
[534]716\subsection{Baseline fitting}
717
[794]718\index{Baseline fitting}To make a baseline fit, you must first create
719a mask of channels to use in the baseline fit.
[534]720
721\begin{verbatim}
722 ASAP> msk = scans.create_mask([100,400],[600,900])
[971]723 ASAP> scans.poly_baseline(msk, order=1)
[534]724\end{verbatim}
725
726This will fit a first order polynomial to the selected channels and subtract
727this polynomial from the full spectra.
728
729\subsubsection{Auto-baselining}
730
[794]731\index{Auto-baseline}The function \cmd{auto\_poly\_baseline} can be used to automatically
[770]732baseline your data without having to specify channel ranges for the
733line free data. It automatically figures out the line-free emission
734and fits a polynomial baseline to that data. The user can use masks to
735fix the range of channels or velocity range for the fit as well as
736mark the band edge as invalid.
[534]737
738Simple example
739
740\begin{verbatim}
741  ASAP> scans.auto_poly_baseline(order=2,threshold=5)
742\end{verbatim}
743
744\cmd{order} is the polynomial order for the fit. \cmd{threshold} is
745the SNR threshold to use to deliminate line emission from
[548]746signal. Generally the value of threshold is not too critical, however
747making this too large will compromise the fit (as it will include
748strong line features) and making it too small will mean it cannot find
749enough line free channels.
[534]750
[548]751
[534]752Other examples:
753
754\begin{verbatim}
755  # Don't try and fit the edge of the bandpass which is noisier
756  ASAP> scans.auto_poly_baseline(edge=(500,450),order=3,threshold=3)
757
758  # Only fit a given region around the line
759  ASAP> scans.set_unit('km/s')
[971]760  ASAP> msk = scans.create_mask([-60,-20])
[534]761  ASAP> scans.auto_poly_baseline(mask=msk,order=3,threshold=3)
762
763\end{verbatim}
764
765\subsection{Average the polarisations}
766
[794]767\index{average\_pol}If you are just interested in the highest SNR for total intensity you
[534]768will want to average the parallel polarisations together.
769
770\begin{verbatim}
771 ASAP> scans.average_pol()
772\end{verbatim}
773
774\subsection{Calibration}
775
[794]776\index{Calibration}For most uses, calibration happens transparently as the input data
[534]777contains the Tsys measurements taken during observations. The nominal
778``Tsys'' values may be in Kelvin or Jansky. The user may wish to
779supply a Tsys correction or apply gain-elevation and opacity
780corrections.
781
782\subsubsection{Brightness Units}
783
[794]784\index{Brightness Units}RPFITS files do not contain any information as
785to whether the telescope calibration was in units of Kelvin or
786Janskys.  On reading the data a default value is set depending on the
787telescope and frequency of observation.  If this default is incorrect
788(you can see it in the listing from the \cmd{summary} function) the
789user can either override this value on reading the data or later.
790E.g:
[534]791
792\begin{verbatim}
[971]793  ASAP> scans = scantable('2004-11-23_1841-P484.rpf', unit='Jy')
[534]794  # Or in two steps
[971]795  ASAP> scans = scantable('2004-11-23_1841-P484.rpf')
[534]796  ASAP> scans.set_fluxunit('Jy)
797\end{verbatim}
798
799\subsubsection{Tsys scaling}
800
[794]801\index{Tsys scaling}Sometime the nominal Tsys measurement at the
802telescope is wrong due to an incorrect noise diode calibration. This
803can easily be corrected for with the scale function. By default,
804\cmd{scale} only scans the spectra and not the corresponding Tsys.
[534]805
806\begin{verbatim}
[738]807  ASAP> scans.scale(1.05, tsys=True)
[534]808\end{verbatim}
809
810\subsubsection{Unit Conversion}
811
[794]812\index{Unit conversion}To convert measurements in Kelvin to Jy (and
813vice versa) the global function \cmd{convert\_flux} is needed. This
814converts and scales the data from K to Jy or vice-versa depending on
815what the current brightness unit is set to. The function knows the
816basic parameters for some frequencies and telescopes, but the user may
817need to supply the aperture efficiency, telescope diameter or the Jy/K
818factor.
[534]819
820\begin{verbatim}
[794]821  ASAP> scans.convert_flux()               # If efficency known
[534]822  ASAP> scans.convert_flux(eta=0.48)       # If telescope diameter known
823  ASAP> scans.convert_flux(eta=0.48,d=35)  # Unknown telescope
824  ASAP> scans.convert_flux(jypk=15)        # Alternative
825\end{verbatim}
826
827\subsubsection{Gain-Elevation and Opacity Corrections}
[794]828\label{sec:gainel}
[534]829
[794]830\index{Gain-elevation}As higher frequencies (particularly $>$20~GHz)
831it is important to make corrections for atmospheric opacity and
832gain-elevation effects.
[534]833
[794]834Note that currently the elevation is not written correctly into
[770]835Tidbinbilla rpfits files. This means that gain-elevation and opacity
[794]836corrections will not work unless these get recalculated.
[770]837
[794]838\begin{verbatim}
839  ASAP> scans.recalc_azel()                # recalculate az/el based on pointing
840\end{verbatim}
841
[544]842Gain-elevation curves for some telescopes and frequencies are known to
[794]843ASAP (currently only for Tidbinbilla at 20~GHz).  In these cases
844making gain-corrections is simple.  If the gain curve for your data is
845not known, the user can supply either a gain polynomial or text file
[534]846tabulating gain factors at a range of elevations (see \cmd{help
[544]847scantable.gain\_el}).
[534]848
849Examples:
850
851\begin{verbatim}
852  ASAP> scans.gain_el()   # If gain table known
853  ASAP> scans.gain_el(poly=[3.58788e-1,2.87243e-2,-3.219093e-4])
854\end{verbatim}
855
[794]856\index{Opacity}Opacity corrections can be made with the global
857function \cmd{opacity}. This should work on all telescopes as long as
858a measurement of the opacity factor was made during the observation.
[534]859
860\begin{verbatim}
861  ASAP> scans.opacity(0.083)
862\end{verbatim}
863
864Note that at 3~mm Mopra uses a paddle wheel for Tsys calibration,
865which takes opacity effects into account (to first order). ASAP
[544]866opacity corrections should not be used for Mopra 3-mm data.
[534]867
868\subsection{Frequency Frame Alignment}
[794]869\label{sec:freqalign}
[534]870
[794]871\index{Frequency alignment}\index{Velicity alignment}When time
872averaging a series of scans together, it is possible that the velocity
873scales are not exactly aligned.  This may be for many reasons such as
874not Doppler tracking the observations, errors in the Doppler tracking
875etc.  This mostly affects very long integrations or integrations
876averaged together from different days.  Before averaging such data
877together, they should be frequency aligned using \cmd{freq\_align}.
[534]878
879E.g.:
880
881\begin{verbatim}
882  ASAP> scans.freq_align()
883  ASAP> av = average_time(scans)
884\end{verbatim}
885
[953]886{\em A Global freq\_align command will be made eventually}
[534]887
888To average together data taken on different days, which are in
889different scantables, each scantable must aligned to a common
890reference time then the scantables averaged. The simplest way of
891doing this is to allow ASAP to choose the reference time for the first
[738]892scantable then using this time for the subsequent scantables.
[534]893
894\begin{verbatim}
895  ASAP> scans1.freq_align() # Copy the refeference Epoch from the output
896  ASAP> scans2.freq_align(reftime='2004/11/23/18:43:35')
897  ASAP> scans3.freq_align(reftime='2004/11/23/18:43:35')
898  ASAP> av = average_time(scans1, scans2, scans3)
899\end{verbatim}
900
901\section{Scantable manipulation}
902
[794]903\index{Scantable!manipulation}While it is very useful to have many
904independent sources within one scantable, it is often inconvenient for
905data processing. The \cmd{get\_scan} function can be used to create a
906new scantable with a selection of scans from a scantable. The
907selection can either be on the source name, with simple wildcard
[953]908matching or set of scan ids. Internally this uses the selector object,
909so for more complicated selection the selector should be used directly
910instead.
[534]911
912For example:
913
914\begin{verbatim}
915  ASAP> ss = scans.get_scan(10) # Get the 11th scan (zero based)
916  ASAP> ss = scans.get_scan(range(10)) # Get the first 10 scans
[538]917  ASAP> ss = scans.get_scan(range(10,20)) # Get the next 10 scans
[534]918  ASAP> ss = scans.get_scan([2,4,6,8,10]) # Get a selection of scans
919
920  ASAP> ss = scans.get_scan('345p407') # Get a specific source
921  ASAP> ss = scans.get_scan('345*')    # Get a few sources
922
923  ASAP> r = scans.get_scan('*_R') # Get all reference sources (Parkes/Mopra)
924  ASAP> s = scans.get_scan('*_S') # Get all program sources (Parkes/Mopra)
[953]925  ASAP> r = scans.get_scan('*[ew]')  # Get all reference sources (Tid)
926  ASAP> s = scans.get_scan('*[^ew]') # Get all program sources (Tid)
[534]927
928\end{verbatim}
929
930To copy a scantable the following does not work:
931
932\begin{verbatim}
933  ASAP> ss = scans
934\end{verbatim}
935
[544]936as this just creates a reference to the original scantable. Any
937changes made to \cmd{ss} are also seen in \cmd{scans}. To duplicate a
[534]938scantable, use the copy function.
939
940\begin{verbatim}
[794]941  ASAP> ss = scans.copy()
[534]942\end{verbatim}
943
944\section{Data Output}
945
[794]946\index{Scantable!save}\index{Saving data}ASAP can save scantables in a
947variety of formats, suitable for reading into other packages. The
948formats are:
[534]949
[953]950{\em Currently only raw ASAP output is available. Other formats will be added soon}
951
[534]952\begin{itemize}
953\item[ASAP] This is the internal format used for ASAP. It is the only
[544]954  format that allows the user to restore the data, fits etc. without
955  loosing any information.  As mentioned before, the ASAP scantable is
956  an AIPS++ Table (a memory-based table).  This function just converts
957  it to a disk-based Table.  You can the access that Table with the
958  AIPS++ Table browser or any other AIPS++ tool.
[534]959
[544]960\item[SDFITS] The Single Dish FITS format. This format was designed to
961  for interchange between packages, but few packages actually can read
962  it.
[534]963
964\item[FITS] This uses simple ``image'' fits to save the data, each row
[544]965  being written to a separate fits file. This format is suitable for
966  importing the data into CLASS.
[534]967
968\item[ASCII] A simple text based format suitable for the user to
969processing using Perl or, Python, gnuplot etc.
970
971\item[MS2] Saves the data in an aips++ MeasurementSet V2 format.
972You can also access this with the Table browser and other AIPS++
973tools.
974
975\end{itemize}
976
[738]977The default output format can be set in the users {\tt .asaprc} file.
[534]978Typical usages are:
979
980\begin{verbatim}
981  ASAP> scans.save('myscans') # Save in default format
982  ASAP> scans.save('myscans', 'FITS') # Save as FITS for exporting into CLASS
983  ASAP> scans.save('myscans', overwrite=True) # Overwrite an existing file
984\end{verbatim}
985
986
987\section{Plotter}
988
[794]989\index{Plotter}Scantable spectra can be plotted at any time. An asapplotter object is
[534]990used for plotting, meaning multiple plot windows can be active at the
991same time. On start up a default asapplotter object is created called
992``plotter''. This would normally be used for standard plotting.
993
[538]994The plotter, optionally, will run in a multipanel mode and contain
[534]995multiple plots per panel. The user must tell the plotter how they want
996the data distributed. This is done using the set\_mode function. The
997default can be set in the users {\tt .asaprc} file. The units (and frame
[538]998etc) of the abscissa will be whatever has previously been set by
999\cmd{set\_unit}, \cmd{set\_freqframe} etc.
[534]1000
1001Typical plotter usage would be:
1002
1003\begin{verbatim}
1004  ASAP> scans.set_unit('km/s')
1005  ASAP> plotter.set_mode(stacking='p',panelling='t')
1006  ASAP> plotter.plot(scans)
1007\end{verbatim}
1008
1009This will plot multiple polarisation within each plot panel and each
[544]1010scan row in a separate panel.
[534]1011
[538]1012Other possibilities include:
[534]1013
1014\begin{verbatim}
1015  # Plot multiple IFs per panel
1016  ASAP> plotter.set_mode(stacking='i',panelling='t')
[538]1017
1018  # Plot multiple beams per panel
1019  ASAP> plotter.set_mode(stacking='b',panelling='t')
1020
1021  # Plot one IF per panel, time stacked
1022  ASAP> plotter.set_mode('t', 'i')
1023
1024  # Plot each scan in a seperate panel
1025  ASAP> plotter.set_mode('t', 's')
1026
[534]1027\end{verbatim}
1028
[538]1029\subsection{Plot Selection}
1030\label{sec:plotter_cursor}
1031
[794]1032\index{Plotter!selection}The plotter can plot up to 25 panels and
1033stacked spectra per panel. If you have data larger than this (or for
1034your own sanity) you need to select a subset of this data. This is
[953]1035particularly true for multibeam or multi IF data. The selector object
[971]1036should be used for this purpose. Selection can either be applied to
[953]1037the scantable or directly to the plotter, the end result is the same.
[971]1038You don't have to reset the scantable slection though, if you set
1039the selection on the plotter.
[538]1040
1041Examples:
1042
1043\begin{verbatim}
[953]1044  ASAP> selection = selector()
[538]1045  # Select second IF
[966]1046  ASAP> selection.set_ifs(1)
[953]1047  ASAP> plotter.set_selection(selection)
[538]1048
1049  # Select first 4 beams
[966]1050  ASAP> selection.set_beams([0,1,2,3])
[953]1051  ASAP> plotter.set_selection(selection)
[538]1052
[953]1053  # Select a few scans
1054  ASAP> selection.set_scans([2,4,6,10])
1055  ASAP> plotter.set_selection(selection)
[538]1056
1057  # Multiple selection
[966]1058  ASAP> selection.set_ifs(1)
[953]1059  ASAP> selection.set_scans([2,4,6,10])
1060  ASAP> plotter.set_selection(selection)
1061
[538]1062\end{verbatim}
1063
[544]1064\subsection{Plot Control}
1065
[794]1066\index{Plotter!control}The plotter window has a row of buttons on the
1067lower left. These can be used to control the plotter (mostly for
1068zooming the individual plots). From left to right:
[534]1069
1070\begin{itemize}
1071
1072\item[Home] This will unzoom the plots to the original zoom factor
1073
1074\item[Plot history] (left and right arrow). The plotter keeps a
1075history of zoom settings. The left arrow sets the plot zoom to the
1076previous value. The right arrow returns back again. This allows you,
1077for example, to zoom in on one feature then return the plot to how it
1078was previously.
1079
1080\item[Pan] (The Cross) This sets the cursor to pan, or scroll mode
[953]1081  allowing you to shift the plot within the window. Useful when
1082  zoomed in on a feature.
[534]1083
1084\item[Zoom] (the letter with the magnifying glass) lets you draw a
[953]1085  rectangle around a region of interest then zooms in on that
1086  region. Use the plot history to unzoom again.
[534]1087
[953]1088\item[Adjust] (rectangle with 4 arrows) adjust subplot paramaters
1089  (space at edge of plots)
1090
[534]1091\item[Save] (floppy disk). Save the plot as a postscript or .png file
1092
[794]1093You can also type ``g'' in the plot window to toggle on and off grid
1094lines. Typing 'l' turns on and off logarithmic Y-axis.
1095
[534]1096\end{itemize}
1097
1098\subsection{Other control}
1099
1100The plotter has a number of functions to describe the layout of the
1101plot. These include \cmd{set\_legend}, \cmd{set\_layout} and \cmd{set\_title}.
1102
1103To set the exact velocity or channel range to be plotted use the
1104\cmd{set\_range} function. To reset to the default value, call
1105\cmd{set\_range} with no arguments. E.g.
1106
1107\begin{verbatim}
1108  ASAP> scans.set_unit('km/s')
1109  ASAP> plotter.plot(scans)
1110  ASAP> plotter.set_range(-150,-50)
[544]1111  ASAP> plotter.set_range() # To reset
[534]1112\end{verbatim}
1113
[544]1114Both the range of the ``x'' and ``y'' axis can be set at once, if desired:
1115
1116\begin{verbatim}
1117  ASAP> plotter.set_range(-10,30,-1,6.6)
1118\end{verbatim}
1119
[738]1120To save a hardcopy of the current plot, use the save function, e.g.
[534]1121
1122\begin{verbatim}
1123  ASAP> plotter.save('myplot.ps')
[971]1124  ASAP> plotter.save('myplot.png', dpi=80)
[534]1125\end{verbatim}
1126
1127\section{Fitting}
1128
[794]1129\index{Fitting}Currently multicomponent Gaussian function is
1130available. This is done by creating a fitting object, setting up the
1131fit and actually fitting the data. Fitting can either be done on a
[966]1132single scantable selection or on an entire scantable using the
1133\cmd{auto\_fit} function. If single value fitting is used, and the
1134current selection includes multiple spectra (beams, IFs, scans etc)
[971]1135then the first spectrum in the scantable will be used for fitting.
[534]1136
1137\begin{verbatim}
1138 ASAP> f = fitter()
1139 ASAP> f.set_function(gauss=2) # Fit two Gaussians
1140 ASAP> f.set_scan(scans)
[966]1141 ASAP> selection = selector()
[971]1142 ASAP> selection.set_polarisations(1) # Fit the second polarisation
[966]1143 ASAP> scans.set_selection(selection)
[534]1144 ASAP> scans.set_unit('km/s')  # Make fit in velocity units
1145 ASAP> f.fit(1)                # Run the fit on the second row in the table
1146 ASAP> f.plot()                # Show fit in a plot window
1147 ASAP> f.get_parameters()      # Return the fit paramaters
1148\end{verbatim}
1149
1150This auto-guesses the initial values of the fit and works well for data
1151without extra confusing features. Note that the fit is performed in
1152whatever unit the abscissa is set to.
1153
1154If you want to confine the fitting to a smaller range (e.g. to avoid
1155band edge effects or RFI you must set a mask.
1156
1157\begin{verbatim}
1158  ASAP> f = fitter()
1159  ASAP> f.set_function(gauss=2)
1160  ASAP> scans.set_unit('km/s')  # Set the mask in channel units
1161  ASAP> msk = s.create_mask([1800,2200])
1162  ASAP> scans.set_unit('km/s')  # Make fit in velocity units
1163  ASAP> f.set_scan(s,msk)
1164  ASAP> f.fit()
1165  ASAP> f.plot()
1166  ASAP> f.get_parameters()
1167\end{verbatim}
1168
[544]1169If you wish, the initial parameter guesses can be specified and
1170specific parameters can be fixed:
[534]1171
1172\begin{verbatim}
1173  ASAP> f = fitter()
1174  ASAP> f.set_function(gauss=2)
1175  ASAP> f.set_scan(s,msk)
1176  ASAP> f.fit() # Fit using auto-estimates
[738]1177  # Set Peak, centre and fwhm for the second gaussian.
[534]1178  # Force the centre to be fixed
1179  ASAP> f.set_gauss_parameters(0.4,450,150,0,1,0,component=1)
1180  ASAP> f.fit() # Re-run the fit
1181\end{verbatim}
1182
1183The fitter \cmd{plot} function has a number of options to either view
1184the fit residuals or the individual components (by default it plots
1185the sum of the model components).
1186
1187Examples:
1188
1189\begin{verbatim}
1190  # Plot the residual
[738]1191  ASAP> f.plot(residual=True)
[534]1192
1193  # Plot the first 2 componentsa
[738]1194  ASAP> f.plot(components=[0,1])
[534]1195
1196  # Plot the first and third component plus the model sum
1197  ASAP> f.plot(components=[-1,0,2])  # -1 means the compoment sum
1198\end{verbatim}
1199
[544]1200\subsection{Fit saving}
1201
[794]1202\index{Fitter!Fit saving}One you are happy with your fit, it is
1203possible to store it as part of the scantable.
[544]1204
1205\begin{verbatim}
1206  ASAP> f.storefit()
1207\end{verbatim}
1208
1209This will be saved to disk with the data, if the ``ASAP'' file format
1210is selected. Multiple fits to the same data can be stored in the
[738]1211scantable.
[544]1212
1213The scantable function \cmd{get\_fit} can be used to retrieve the
1214stored fits. Currently the fit parameters are just printed to the
1215screen.
1216
1217\begin{verbatim}
1218  ASAP> scans.get_fit(4) # Print fits for row 4
1219\end{verbatim}
1220
[534]1221\section{Polarisation}
1222
[794]1223\index{Polarisation}Currently ASAP only supports polarmetric analysis
1224on linearly polarised feeds and the cross polarisation products
[971]1225measured. Other cases will be added on an as needed basis.
[534]1226
[538]1227Conversions of linears to Stokes or Circular polarisations are done
[966]1228``on-the-fly''. Leakage cannot be corrected for nor are there routines
1229to calibrate position angle offsets.
[534]1230
[538]1231\subsection{Simple Calibration}
1232
[794]1233\index{Polarisation!calibration}It is possible that there is a phase
1234offset between polarisation which will effect the phase of the cross
1235polarisation correlation, and so give rise to spurious
1236polarisation. \cmd{rotate\_xyphase} can be used to correct for this
1237error. At this point, the user must know how to determine the size of
1238the phase offset themselves.
[538]1239
1240\begin{verbatim}
[546]1241  ASAP> scans.rotate_xyphase(10.5)            # Degrees
[538]1242\end{verbatim}
1243
1244Note that if this function is run twice, the sum of the two values is
[546]1245applied because it is done in-situ.
[538]1246
[546]1247A correction for the receiver parallactic angle may need to be made,
[953]1248generally because of how it is mounted. Use \cmd{rotate\_linpolphase}
1249to correct the position angle. Running this function twice results in
1250the sum of the corrections being applied because it is applied
1251in-situ.
[538]1252
1253\begin{verbatim}
[953]1254  ASAP> scans.rotate_linpolphase(-45) # Degrees; correct for receiver mounting
1255\end{verbatim}
[538]1256
[953]1257If the sign of the complex correlation is wrong (this can happen
1258depending on the correlator configuration), use \cmd{invert\_phase} to
1259change take the complex conjugate of the complex correlation
1260term. This is always performed in-situ.
1261
1262\begin{verbatim}
1263  ASAP> scans.invert_phase()
[538]1264\end{verbatim}
1265
[953]1266Depending on how the correlator is configured, ``BA'' may be
1267correlated insead of ``AB''. Use \cmd{swap\_linears} to correct for
1268this problem:
1269
1270\begin{verbatim}
[970]1271  ASAP> scans.swap_linears()
[953]1272\end{verbatim}
1273
[538]1274\subsection{Plotting}
1275\label{sec:polplot}
1276
[953]1277\index{Polarisation!plotting}To plot Stokes values, a selector object
1278must be created and the set\_polarisation function used to select the
1279desired polarisation products.
1280
1281The values which can be plotted include a selection of [I,Q,U,V], [I,
1282Plinear, Pangle, V], [RR, LL] or [XX, YY, Real(XY),
[794]1283Imaginary(XY)]. (Plinear and Pangle are the percentage and position
1284angle of linear polarisation). Conversion to circular polarisations
1285are currently not available.
[538]1286
1287Example:
1288
1289\begin{verbatim}
[953]1290  ASAP> selection = selector()
[970]1291
[971]1292  ASAP> selection.set_polarisations(``I Q U V'')
[953]1293  ASAP  plotter.set_selection(selection);              # Select I, Q, U \& V
1294
[971]1295  ASAP> selection.set_polarisations(``I Q'')
[953]1296  ASAP  plotter.set_selection(selection);              # Select just I \& Q
1297
[971]1298  ASAP> selection.set_polarisations(``RR LL'')
[953]1299  ASAP  plotter.set_selection(selection);              # Select just RR \& LL
1300
[971]1301  ASAP> selection.set_polarisations(``XX YY'')
[953]1302  ASAP  plotter.set_selection(selection);              # Select linears
1303
[971]1304  ASAP> selection.set_polarisations(``I Plinear'')
[966]1305  ASAP  plotter.set_selection(selection);              # Fractional linear
[953]1306
[966]1307[[MALTE: This does not work]]
1308
[971]1309  ASAP> selection.set_polarisations(``Pangle'')
[966]1310  ASAP  plotter.set_selection(selection);              # Position angle
1311
[538]1312\end{verbatim}
1313
[970]1314Scan, beam and IF selection are also available in the selector object as
[953]1315describe in section~\ref{sec:selection}.
[538]1316
1317\subsection{Saving}
1318
[794]1319\index{Polarisation!saving}When saving data using the \cmd{save}
1320function, the \cmd{stokes} argument can be used to save the data as
1321Stoke values when saving in FITS format.
[538]1322
1323Example:
1324
1325\begin{verbatim}
1326  ASAP> scans.save('myscan.sdfits', 'SDFITS', stokes=True)
1327\end{verbatim}
1328
[770]1329\section{Scantable Mathematics}
1330
[794]1331\index{Scantable!maths}It is possible to to simple mathematics
1332directly on scantables from the command line using the \cmd{+, -, *,
1333/} operators as well as their cousins \cmd{+=, -= *=, /=}. This works
[971]1334between a scantable and a float. (Note that it does
[794]1335not work for integers).
[770]1336
[971]1337{\em Currently mathematics between two scantables is not available }
[966]1338
[971]1339%  ASAP> sum = scan1+scan2
[534]1340\begin{verbatim}
[770]1341  ASAP> scan2 = scan1+2.0
1342  ASAP> scan *= 1.05
1343\end{verbatim}
1344
1345\section{Scripting}
1346
[794]1347\index{Scripting}Because asap is based on python, it easy for the user
1348write their own scripts and functions to process data. This is highly
1349recommended as most processing of user data could then be done in a
1350couple of steps using a few simple user defined functions. A Python
1351primer is beyond the scope of this userguide. See the asap home pages
1352for a scripting tutorial or the main python website for comprehensive
1353documentation.
[770]1354
1355\hspace{1cm} http://www.atnf.csiro.au/computing/software/asap/tutorials
[953]1356
[770]1357\hspace{1cm} http://www.python.org/doc/Introduction.html
1358
1359\subsection{Running scripts}
1360
1361The asap global function \cmd{execfile} reads the named text file and
1362executes the contained python code. This file can either contain
1363function definitions which will be used in subsequent processing or
1364just a set of commands to process a specific dataset.
1365
1366\subsection{asapuserfuncs.py}
1367
1368The file $\sim$/.asap/asapuserfuncs.py is automatically read in when
1369asap is started. The user can use this to define a set of user
1370functions which are automatically available each time asap is
1371used. The \cmd{execfile} function can be called from within this file.
1372
1373\section{Worked examples}
1374
1375In the following section a few examples of end-to-end processing of
[794]1376some data in asap are given.
[770]1377
1378\subsection{Mopra}
[794]1379\index{Mopra}
[770]1380
[794]1381The following example is of some dual polarisation, position switched
1382data from Mopra. The source has been observed mulitple times split
1383into a number of seperate rpfits files. To make the processing easier,
1384the first step is to \cmd{cat} the seeprate rpfits files together and
1385load as a whole (future versions of asap will make this unnecessary).
1386
1387
1388\begin{verbatim}
1389# Concatenate the individual rpfits files together before loading
1390!cat 2005-06*.rpf > data.rpf
1391
1392# Load the data into a scantable
1393data = scantable('data.rpf')
1394print data
1395
1396# Form the quotient spectra
1397q = data.auto_quotient()
1398print q
1399
1400# Look at the spectra
1401plotter.plot(q)
1402
[966]1403# Set reference frame
[794]1404q.set_unit('km/s')
1405q.set_freqframe('LSRK')
1406
[966]1407# Average all scans in time, aligning in velocity
1408av = q.average_time(align=True)
[794]1409plotter.plot(av)
1410
1411# Remove the baseline
1412msk = av.create_mask([100,130],[160,200])
1413av.poly_baseline(msk,2)
1414
1415# Average the two polarisations together
1416iav = av.average_pol()
1417print iav
1418plotter.plot(iav)
1419
1420# Set a sensible velocity range on the plot
1421plotter.set_range(85,200)
1422
1423# Smooth the data a little
1424av.smooth('gauss',4)
1425plotter.plot()
1426
1427# Fit a guassian to the emission
1428f = fitter()
1429f.set_function(gauss=1)
1430f.set_scan(av)
1431f.fit()
1432
1433# View the fit
1434f.plot()
1435
1436# Get the fit parameters
1437f.get_parameters()
1438
1439\end{verbatim}
1440
1441
[770]1442\subsection{Parkes Polarimetry}
1443
[794]1444\index{Parkes}\index{Polarisation}The following example is processing
1445of some Parkes polarmetric observations of OH masers at
14461.6~GHz. Because digital filters where used in the backend, the
1447baselines are stable enough not to require a quotient spectra. The
14484~MHz bandwidth is wide enough to observe both the 1665 and 1667~MHz
1449OH maser transitions. Each source was observed once for about 10
1450minutes. Tsys information was not written to the rpfits file (a
1451nominal 25K values was used), so the amplitudes need to be adjusted
1452based on a separate log file. A simple user function is used to
1453simplify this, contained in a file called mypol.py:
[770]1454
1455\begin{verbatim}
1456def xyscale(data,xtsys=1.0,ytsys=1.0,nomtsys=25.0) :
1457
[966]1458 selection = selector()
[971]1459 selection.set_polarisations(0)
[966]1460 data.set_selection(selection)
1461 data.scale(xtsys/nomtsys)
[770]1462
[971]1463 selection.set_polarisations(1)
[966]1464 data.set_selection(selection)
1465 data.scale(ytsys/nomtsys)
[770]1466
[971]1467 selection.set_polarisations(0)
[966]1468 data.set_selection(selection)
1469 data.scale((xtsys+ytsys)/(2*nomtsys))
[770]1470
[971]1471 selection.set_polarisations(0)
[966]1472 data.set_selection(selection)
1473 data.scale((xtsys+ytsys)/(2*nomtsys))
[770]1474\end{verbatim}
1475
1476The typical asap session would be
1477
1478\begin{verbatim}
[794]1479
[770]1480# Remind ourself the name of the rpfits files
[794]1481ls
[770]1482
1483# Load data from an rpfits file
1484d1665 = scantable('2005-10-27_0154-P484.rpf')
1485
1486# Check what we have just loaded
1487d1665.summary
1488
1489# View the data in velocity
1490d1665.set_unit('km/s')
1491d1665.set_freqframe('LSRK')
1492
1493# Correct for the known phase offset in the crosspol data
1494d1665.rotate_xyphase(-4)
1495
[794]1496# Create a copy of the data and set the rest frequency to the 1667 MHz
[770]1497# transition
1498d1667 = d1665.copy()
[966]1499d1667.set_restfreqs([1667.3590], 'MHz')
1500d1667.summary()
[770]1501
1502# Copy out the scan we wish to process
1503g351_5 = d1665.get_scan('351p160')
1504g351_7 = d1667.get_scan('351p160')
1505
[966]1506# Baseline both
1507msk = g351_5.create_mask([-30,-25],[-5,0])
1508g351_5.poly_baseline(msk,order=1)
1509msk = g351_7.create_mask([-30,-25],[-5,0])
1510g351_7.poly_baseline(msk,order=1)
[770]1511
[966]1512
1513# Plot the data. The plotter can only plot a single scantable
1514# So we must merge the two tables first
1515
1516plotscans = merge(g351_5, g351_7)
1517
1518plotter.plot(plotscans) # Only shows one panel
1519
[770]1520# Tell the plotter to stack polarisation and panel scans
1521plotter.set_mode('p','s')
1522
1523# Correct for the Tsys using our predefined function
[971]1524execfile('mypol.py') # Read in the function xyscale
[770]1525xyscale(g351_5,23.2,22.7) # Execute it on the data
1526xyscale(g351_7,23.2,22.7)
1527
1528# Only plot the velocity range of interest
1529plotter.set_range(-30,10)
1530
1531# Update the plot with the baselined data
1532plotter.plot()
1533
1534# Look at the various polarisation products
[966]1535selection = selector()
1536selection.set_polarisations(``RR LL'')
1537plotter.set_selection(selection)
1538selection.set_polarisations(``I Plinear'')
1539plotter.set_selection(selection)
1540selection.set_polarisations(``I Q U V'')
1541plotter.set_selection(selection)
[770]1542
1543# Save the plot as postscript
[966]1544plotter.save('g351_stokes.ps')
[770]1545
1546# Save the process spectra
[966]1547plotscans.save('g351.asap')
[770]1548
1549\end{verbatim}
1550
1551\subsection{Tidbinbilla}
1552
[794]1553\index{Tidbinbilla}The following example is processing of some
1554Tidbinbilla observations of NH$_3$ at 12~mm. Tidbinbilla has (at the
1555time of observations) a single polarisation, but can process two IFs
1556simultaneously. In the example, the first half of the observation was
1557observing the (1,1) and (2,2) transitions simultaneously). The second
1558half observed only the (4,4) transition due to bandwidth
1559limitations. The data is position switched, observing first an
1560reference to the west, then the source twice and finally reference to
1561the east.
[770]1562
1563\begin{verbatim}
1564
1565# Load the rpfits file and inspect
1566d = scantable('2003-03-16_082048_t0002.rpf')
1567print d
1568
1569# Make the quotient spectra
1570q = d.auto_quotient()
1571print q
1572
[966]1573del d
1574
[770]1575# Plot/select in velocity
1576q.set_freqframe('LSRK')
1577q.set_unit('km/s')
1578
[966]1579# Correct for gain/el effects
1580
1581q.recalc_azel()  # Tid does not write the elevation
1582q.gain_el()
1583q.opacity(0.05)
1584
[770]1585# Seperate data from the (1,1)&(2,2) and (4,4) transitions
[971]1586g1 = q.get_scan(range(6))     # scans 0..5
1587g2 = q.get_scan(range(6,12))  # scans 6..11
[770]1588
[794]1589# Align data in velocity
[966]1590g1.freq_align()
1591g2.freq_align()
[770]1592
1593# Average individual scans
1594a1 = g1.average_time()
1595a2 = g2.average_time()
1596
1597# Rpfits file only contrains a single rest frequency. Set both
[966]1598a1.set_restfreqs([23694.4700e6,23722.6336e6])
[770]1599
[966]1600plotter.plot(a1)
[770]1601plotter.set_mode('i','s')
1602
1603a1.auto_poly_baseline()
1604
1605plotter.plot()
1606
1607a1.smooth('gauss',5)
1608plotter.plot()
1609
[966]1610
[770]1611\end{verbatim}
1612
1613\newpage
1614
1615\section{Appendix}
1616
1617\subsection{Function Summary}
1618
[794]1619\index{Functions!summary}%
[770]1620\begin{verbatim}
[738]1621    [The scan container]
[534]1622        scantable           - a container for integrations/scans
1623                              (can open asap/rpfits/sdfits and ms files)
1624            copy            - returns a copy of a scan
1625            get_scan        - gets a specific scan out of a scantable
1626            summary         - print info about the scantable contents
1627            set_cursor      - set a specific Beam/IF/Pol 'cursor' for
1628                              further use
1629            get_cursor      - print out the current cursor position
1630            stats           - get specified statistic of the spectra in
1631                              the scantable
1632            stddev          - get the standard deviation of the spectra
1633                              in the scantable
1634            get_tsys        - get the TSys
1635            get_time        - get the timestamps of the integrations
[794]1636            get_azimuth     - get the azimuth of the scans
1637            get_elevation   - get the elevation of the scans
1638            get_parangle    - get the parallactic angle of the scans
[534]1639            get_unit        - get the currnt unit
1640            set_unit        - set the abcissa unit to be used from this
1641                              point on
1642            get_abcissa     - get the abcissa values and name for a given
1643                              row (time)
1644            set_freqframe   - set the frame info for the Spectral Axis
1645                              (e.g. 'LSRK')
1646            set_doppler     - set the doppler to be used from this point on
1647            set_instrument  - set the instrument name
1648            get_fluxunit    - get the brightness flux unit
1649            set_fluxunit    - set the brightness flux unit
1650            create_mask     - return an mask in the current unit
1651                              for the given region. The specified regions
1652                              are NOT masked
1653            get_restfreqs   - get the current list of rest frequencies
1654            set_restfreqs   - set a list of rest frequencies
1655            lines           - print list of known spectral lines
1656            flag_spectrum   - flag a whole Beam/IF/Pol
1657            save            - save the scantable to disk as either 'ASAP'
1658                              or 'SDFITS'
1659            nbeam,nif,nchan,npol - the number of beams/IFs/Pols/Chans
1660            history         - print the history of the scantable
[544]1661            get_fit         - get a fit which has been stored witnh the data
[738]1662            average_time    - return the (weighted) time average of a scan
[534]1663                              or a list of scans
1664            average_pol     - average the polarisations together.
1665                              The dimension won't be reduced and
1666                              all polarisations will contain the
1667                              averaged spectrum.
[738]1668            auto_quotient   - return the on/off quotient with
1669                              automatic detection of the on/off scans
[534]1670            quotient        - return the on/off quotient
1671            scale           - return a scan scaled by a given factor
[738]1672            add             - return a scan with given value added
[534]1673            bin             - return a scan with binned channels
1674            resample        - return a scan with resampled channels
1675            smooth          - return the spectrally smoothed scan
1676            poly_baseline   - fit a polynomial baseline to all Beams/IFs/Pols
[738]1677            auto_poly_baseline - automatically fit a polynomial baseline
[794]1678            recalc_azel     - recalculate azimuth and elevation based on
1679                              the pointing
[534]1680            gain_el         - apply gain-elevation correction
1681            opacity         - apply opacity correction
1682            convert_flux    - convert to and from Jy and Kelvin brightness
1683                              units
1684            freq_align      - align spectra in frequency frame
1685            rotate_xyphase  - rotate XY phase of cross correlation
1686            rotate_linpolphase - rotate the phase of the complex
1687                                 polarization O=Q+iU correlation
1688     [Math] Mainly functions which operate on more than one scantable
1689
[738]1690            average_time    - return the (weighted) time average
[534]1691                              of a list of scans
1692            quotient        - return the on/off quotient
[544]1693            simple_math     - simple mathematical operations on two scantables,
1694                              'add', 'sub', 'mul', 'div'
[534]1695     [Fitting]
1696        fitter
1697            auto_fit        - return a scan where the function is
1698                              applied to all Beams/IFs/Pols.
1699            commit          - return a new scan where the fits have been
1700                              commited.
1701            fit             - execute the actual fitting process
[544]1702            store_fit       - store the fit paramaters in the data (scantable)
[534]1703            get_chi2        - get the Chi^2
1704            set_scan        - set the scantable to be fit
1705            set_function    - set the fitting function
1706            set_parameters  - set the parameters for the function(s), and
1707                              set if they should be held fixed during fitting
[544]1708            set_gauss_parameters - same as above but specialised for individual
1709                                   gaussian components
[534]1710            get_parameters  - get the fitted parameters
1711            plot            - plot the resulting fit and/or components and
1712                              residual
1713    [Plotter]
1714        asapplotter         - a plotter for asap, default plotter is
1715                              called 'plotter'
1716            plot            - plot a (list of) scantable
1717            save            - save the plot to a file ('png' ,'ps' or 'eps')
1718            set_mode        - set the state of the plotter, i.e.
1719                              what is to be plotted 'colour stacked'
1720                              and what 'panelled'
[544]1721            set_cursor      - only plot a selected part of the data
1722            set_range       - set a 'zoom' window
[534]1723            set_legend      - specify user labels for the legend indeces
1724            set_title       - specify user labels for the panel indeces
1725            set_ordinate    - specify a user label for the ordinate
1726            set_abcissa     - specify a user label for the abcissa
1727            set_layout      - specify the multi-panel layout (rows,cols)
[738]1728
[534]1729    [Reading files]
1730        reader              - access rpfits/sdfits files
1731            read            - read in integrations
1732            summary         - list info about all integrations
1733
1734    [General]
1735        commands            - this command
1736        print               - print details about a variable
1737        list_scans          - list all scantables created bt the user
1738        del                 - delete the given variable from memory
1739        range               - create a list of values, e.g.
1740                              range(3) = [0,1,2], range(2,5) = [2,3,4]
1741        help                - print help for one of the listed functions
[538]1742        execfile            - execute an asap script, e.g. execfile('myscript')
[544]1743        list_rcparameters   - print out a list of possible values to be
[770]1744                              put into \$HOME/.asaprc
[534]1745        mask_and,mask_or,
1746        mask_not            - boolean operations on masks created with
1747                              scantable.create_mask
[738]1748
[534]1749    Note:
1750        How to use this with help:
1751                                         # function 'summary'
1752        [xxx] is just a category
[544]1753        Every 'sub-level' in this list should be replaces by a '.' Period when
[738]1754        using help
[534]1755        Example:
1756            ASAP> help scantable # to get info on ths scantable
1757            ASAP> help scantable.summary # to get help on the scantable's
1758            ASAP> help average_time
[544]1759
[534]1760\end{verbatim}
1761
1762\subsection{ASCII output format}
1763
1764\subsection{.asaprc settings}
[794]1765\index{.asaprc}
[971]1766\asaprc{verbose}{{\bf True}/False}{Print verbose output, good to disable in scripts}
[770]1767
1768\asaprc{insitu}{{\bf True}/False}{Apply operations on the input
1769scantable or return new one}
1770
1771% plotting
1772
1773\asaprc{useplotter}{{\bf True}/False}{Preload a default plotter}
1774
1775\asaprc{plotter.gui}{{\bf True}/False}{Do we want a GUI or plot to a
1776file}
1777
1778\asaprc{plotter.stacking}{{\bf Pol} Beam IF Scan Time}{Default mode for
1779colour stacking}
1780
1781\asaprc{plotter.panelling}{Pol Beam IF {\bf Scan} Time}{Default mode
1782for panelling}
1783
1784\asaprc{plotter.ganged}{{\bf True}/False}{Push panels together, to
1785share axislabels}
1786
1787\asaprc{plotter.decimate}{True/{\bf False}}{Decimate the number of
1788points plotted by a factor of nchan/1024}
1789
1790% default colours/linestyles
1791%\asaprc{plotter.colours}{.}{.}
1792%\asaprc{plotter.linestyles{.}{.}
1793
1794% scantable
1795\asaprc{scantable.save}{{\bf ASAP} SDFITS FITS ASCII MS2}{Default output
[794]1796format when saving}
[770]1797
1798\asaprc{scantable.autoaverage}{{\bf True}/False}{Auto averaging on
1799read}
1800
1801\asaprc{scantable.freqframe}{{\bf LSRK} TOPO BARY etc}{default
1802frequency frame to set when function scantable.set\_freqframe is
[971]1803called or the data is imported}
[770]1804
[953]1805\subsection{Installation}
1806
1807\index{Installation}ASAP depends on a number of third-party libraries which you must
1808have installed before attempting to build ASAP. These are:
1809
1810\begin{itemize}
1811\item AIPS++
1812\item Boost
1813\item Matplotlib
1814\item python/ipython
1815\end{itemize}
1816
1817Debian Linux is currently supported and we intend also
1818to support other popular Linux flavours, Solaris and Mac.
1819
1820Of the dependencies, AIPS++ is the most complex to install.
1821
[794]1822\printindex
1823
[534]1824\end{document}
[770]1825
Note: See TracBrowser for help on using the repository browser.