source: trunk/doc/cookbook.tex @ 538

Last change on this file since 538 was 538, checked in by phi196, 19 years ago

Updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.0 KB
Line 
1%% TODO
2%% Intro
3%% Fit saving
4
5\documentclass[11pt]{article}
6\usepackage{a4}
7\usepackage[dvips]{graphicx}
8
9% Adjust the page size
10\addtolength{\oddsidemargin}{-0.4in}
11\addtolength{\evensidemargin}{+0.4in}
12\addtolength{\textwidth}{+0.8in}
13
14\setlength{\parindent}{0mm}
15\setlength{\parskip}{1ex}
16
17
18\title{ATNF Spectral Analysis Package\\Cookbook }
19\author{Chris Phillips}
20
21
22\newcommand{\cmd}[1]{{\tt #1}}
23
24\begin{document}
25
26\maketitle
27
28\section{Introduction}
29
30%\section{Documentation Standards}
31
32%In most of the examples in this document, it has been assumed that the
33
34\section{Installation and running}
35
36Currently there are installations running on Linux machines at
37
38\begin{itemize}
39\item Epping - use hosts {\tt draco} or {\tt hydra}
40\item Narrabri - use host {\tt kaputar}
41\item Parkes - use host {\tt bourbon}
42\item Mopra - use host {\tt minos}
43\end{itemize}
44
45To start asap log onto one of these Linux hosts and  enter
46
47\begin{verbatim}
48  > cd /my/data/directory
49  > source /nfs/aips++/daily/aipsinit.csh  # Temporary measure
50  > asap
51\end{verbatim}
52
53This starts the asap. To quit, you need to type \verb+^+-d (control-d).
54
55\section{Interface}
56
57ASAP is written in C++ and python. The user interface uses the
58``ipython'' interactive shell, which is a simple interactive interface
59to python. The user does not need to understand python to use this,
60but certain aspects python affect what the user can do.  The current
61interface is object oriented.  In the future, we will build a
62functional (non object oriented) shell on top of this to ease
63interactive use.
64
65\subsection {Integer Indices are 0-relative}
66
67Please note, all integer indices in ASAP and iPython are {\bf 0-relative}.
68
69\subsection{Objects}
70
71The ASAP interface is based around a number of ``objects'' which the
72user deals with. Objects range from the data which have been read from
73disk, to tools used for fitting functions to the data. The following
74main objects are used :
75
76\begin{itemize}
77  \item[scantable] The data container (actual spectra and header information)
78  \item[fitter] A tool used to fit functions to the spectral data
79  \item[plotter] A tool used to plot the spectral line data
80  \item[reader] A tool which can be used to read data from disks
81    into a scantable object.
82\end{itemize}
83
84These are all described below.
85
86There can be many objects of the same type. Each object is referred to
87by a variable name made by the user. The name of this variable is not
88important and can be set to whatever the user prefers (ie ``s'' and
89``ParkesHOH-20052002'' are equivalent).  However, having a simple and
90consistent naming convention will help you a lot.
91
92\subsection{Member functions(functions)}
93
94Following the object oriented approach, objects have associated
95``member functions'' which can either be used to modify the data in
96some way or change global properties of the object. In this document
97member functions will be referred to simply as functions. From the
98command line, the user can execute these functions using the syntax:
99\begin{verbatim}
100  ASAP> out = object.function(arguments)
101\end{verbatim}
102
103Where \cmd{out} is the name of the returned variable (could be a new
104scantable object, or a vector of data, or a status return),  \cmd{object} is the
105object variable name (set by the user), \cmd{function} is the name of
106the member function and \cmd{arguments} is a list of arguments to the
107function. The arguments can be provided either though position or names.
108A mix of the two can be used.  E.g.
109
110\begin{verbatim}
111  ASAP> av = scans(msk,weight='tsys')
112  ASAP> av = scans(mask=msk,weight='tsys')
113  ASAP> av = scans(msk,True)
114  ASAP> scans.polybaseline(mask=msk, order=0, insitue=True)
115  ASAP> scans.polybaseline(msk,0,True)
116  ASAP> scans.polybaseline(mask, insitu=True)
117\end{verbatim}
118
119\subsection{Global Functions}
120
121Some functions do not make sense to be implemented as member
122functions, typically functions which operate on more than one scantable
123(e.g. time averaging of many scans). These functions will always be
124referred to as global functions.
125
126\subsection{Interactive environment}
127
128ipython has a number of useful interactive features and a few things to be aware
129of for the new user.
130
131\subsubsection{String completion}
132
133Tab completion is enabled for all function names. If you type the
134first few letters of a function name, then type <TAB> the function
135name will be auto completed if it is un-ambiguous, or a list of
136possibilities will be given. Auto-completion works for the user
137object names as well as function names. It does not work for filenames,
138nor for function arguments.
139
140Example
141\begin{verbatim}
142  ASAP> scans = scantable('MyData.rpf')
143  ASAP> scans.se<TAB>
144scans.set_cursor      scans.set_freqframe   scans.set_unit        scans.setpol
145scans.set_doppler     scans.set_instrument  scans.setbeam         
146scans.set_fluxunit    scans.set_restfreqs   scans.setif     
147  ASAP> scans.set_in<TAB>
148  ASAP> scans.set_instrument
149\end{verbatim}
150
151\subsubsection{Unix Interaction}
152
153Basic unix shell commands (pwd, ls, cd etc) can be issued from within
154ASAP. This allows the user to do things list look at files in the
155current directory. The shell command ``cd'' does work within ASAP
156allowing the user to change between data directories. Unix programs
157cannot be run this way, but the shell escape ``$!$'' can be used to run
158arbitrary programs. E.g.
159
160\begin{verbatim}
161  ASAP> pwd
162  ASAP> ls
163  ASAP> ! mozilla&
164\end{verbatim}
165
166\subsection{Help}
167
168ASAP has built in help for all functions. To get a list of functions type:
169
170\begin{verbatim}
171  ASAP> commands
172\end{verbatim}
173
174To get help on specific functions, the built in help needs to be given
175the object and function name. E.g.
176
177\begin{verbatim}
178  ASAP> help scantable.get_scan
179  ASAP> help scantable.stats
180  ASAP> help plotter.plot
181  ASAP> help fitter.plot
182
183  ASAP> scans = scantable('mydata.asap')
184  ASAP> help scans.get_scan # Same as above
185
186  ASAP> help average_time # Global functions just need their name
187
188\end{verbatim}
189
190Note that if you just type \cmd{help} the internal ipython help is
191invoked, which is probably {\em not} what you want. Type \verb+^+-d
192(control-d) to escape from this.
193
194\subsection{.asaprc}
195
196ASAP use a \cmd{.asaprc} file to control the users preferences of
197default values for various functions arguments. This includes the
198defaults for aguments such as \cmd{insitu}, scantable \cmd{freqframe}
199and the plotters \cmd{set\_mode} values. The help on individual
200functons says which agruments can be set default values from the
201\cmd{.asaprc} file. To get a sample contents for the \cmd{.asaprc}
202file use then command \cmd{list\_rcparameters}.
203
204Common values include:
205\begin{verbatim}
206  # apply operations on the input scantable or return new one
207  insitu                     : False
208
209  # default ouput format when saving scantable
210  scantable.save             : 'ASAP'
211
212
213  # default frequency frame to set when function
214  # scantable.set_freqframe is called
215  scantable.freqframe        : 'LSRK'
216
217  # auto averaging on read
218  scantable.autoaverage      : True
219\end{verbatim}
220
221\section{Scantables}
222
223\subsection {Description}
224
225\subsubsection {Basic Structure}
226
227ASAP data handling works on objects called scantables.  A scantable
228holds your data, and also provides functions to operate
229upon it.
230
231The building block of a scantable is an integration, which is a single
232row of a scantable. Each row contains spectra for each beam, IF and
233polarisation. For example Parkes multibeam data would contain many
234beams, one IF and 2-4 polarisations, while the new Mopra 8-GHz
235filterbank will eventually produce one beam, many IFs, and 2-4
236polarisations.
237
238A collection of sequential integrations (rows) for one source is termed
239a scan (and each scan has a unique numeric identifier, the ScanID). A
240scantable is then a collection  of one or more scans. If you have
241scan-averaged your data in time, then each scan would  hold just one
242(averaged) integration.
243
244Many of the functions which work on scantables can either return a
245new scantable with modified data or change the scantable insitu. Which
246method is used depends on the users preference. The default can be
247changed via the {\tt .asaprc} resource file.
248
249\subsubsection {Contents}
250
251A scantable has header information and data (a scantable is actually an AIPS++
252Table and it is stored in Memory when you are manipulating it with ASAP.
253You can store it to disk and then browse it with the AIPS++
254Table browser if you know how to do that !).
255
256The data are stored in columns (the length of a column is the number of
257rows/integrations of course). 
258
259Two important columns are those that describe the frequency setup.  We mention
260them explicitly here because you need to be able to understand the presentation
261of the frequency information and possibly how to manipulate it.
262
263These columns are called FreqID and RestFreqID.  They contain indices, for
264each IF, pointing into tables with all of the frequency information for that
265integration.   More on these below when we discuss the \cmd{summary} function
266in the next subsection.
267
268There are of course many other columns which contain the actual spectra,
269the flags, the Tsys, the source names and so on, but those are a little
270more transparently handled.
271
272\subsection{Management}
273
274During processing it is possible to create a large number of scan
275tables. These all consume memory, so it is best to periodically remove
276unneeded scan tables. Use \cmd{list\_scans} to print a list of all
277scantables and \cmd{del} to remove unneeded ones.
278
279Example:
280
281\begin{verbatim}
282  ASAP> list_scans
283  The user created scantables are:
284  ['s', 'scans', 'av', 's2', 'ss']
285
286  ASAP> del s2   
287  ASAP> del ss
288\end{verbatim}
289
290There is also a function \cmd{summary} to list a summary of the scantable.
291You will find this very useful.
292
293Example:
294
295\begin{verbatim}
296  ASAP> scans = scantable('MyData.rpf')
297  ASAP> scans.summary()                # Brief listing
298  ASAP> scans.summary(verbose=True)    # Include frequency information
299  ASAP> print scan                     # Equivalent to brief summary function call
300\end{verbatim}
301
302Most of what the \cmd{summary} function  prints out is obvious. However,
303it also prints out the FreqIDs and RestFreqIDs to which we alluded above.
304These are the last column of the listing.
305
306The summary function gives you a scan-based summary.  So it lists all of
307the FreqIDs and RestFreqIDs that it encountered for each scan.  If you'd
308like to see what each FreqID actually means, then set the verbose
309argument to True and the frequency table will be listed at the end.
310FreqID of 3 say, refers to the fourth row of the frequency table (ASAP
311is 0-relative). The list of rest frequencies, to which the RestFreqIDs
312refer, is always listed.
313
314You can copy one scantable to another with the \cmd{copy} function.
315
316Example:
317
318\begin{verbatim}
319  ASAP> scans = scantable('MyData.rpf')
320  ASAP> scan2 = scans.copy()
321\end{verbatim}
322
323\subsection{State}
324
325Each scantable contains "state"; these are properties  applying to all
326of the data in the scantable. 
327
328Examples are the selection of beam, IF and polarisation,  spectral unit
329(e.g. $km/s$) frequency reference frame (e.g. BARY) and velocity Doppler
330type (e.g. RADIO).
331
332\subsubsection{Units, Doppler and Frequency Reference Frame}
333
334The information describing the frequency setup for each integration
335is stored fundamentally in frequency in the reference frame
336of observation (E.g. TOPO).   
337
338When required, this is converted to the desired reference frame (e.g. LSRK),
339Doppler (e.g. OPTICAL) and unit (e.g. $km/s$) on-the-fly.  For example,
340this is important when you are displaying the data or fitting to it.
341
342For units, the user has the choice of frequency, velocity or channel.
343The \cmd{set\_unit} function is used to set the current unit for a
344scantable. All functions will (where relevant) work with the selected
345unit until this changes. This is mainly important for fitting (the fits
346can be computed in any of these units), plotting and mask creation.
347
348The velocity Doppler can be changed with the \cmd{set\_doppler}
349function, and the frequency reference frame can be changed with the
350\cmd{set\_freqframe} function.
351
352Example usage:
353
354\begin{verbatim}
355  ASAP> scans = scantable('2004-11-23_1841-P484.rpf') # Read in the data
356  ASAP> scans.set_freqframe('LSRK')  # Use the LSR velocity frame
357  ASAP> scans.set_unit('km/s')        # Use velocity for plots etc from now on
358  ASAP> scans.set_doppler('OPTICAL')  # Use the optical velocity convention
359  ASAP> scans.set_unit('MHz')         # Use frequency in MHz from now on
360\end{verbatim}
361
362
363\subsubsection{Rest Frequency}
364
365ASAP reads the line rest frequency from the RPFITS file when reading
366the data. The values stored in the RPFITS file are not always correct
367and so there is a function \cmd{set\_restfreq} to set the rest frequencies.
368
369For each integration, there is a rest-frequency per IF (the rest
370frequencies are just stored as a list with an index into them).
371There are a few ways to set the rest frequencies with this function.
372
373If you specify just one rest frequency, then it is selected for the
374specified source and IF and added to the list of rest frequencies.
375
376\begin{verbatim}
377  # Select for specified source/IF
378  ASAP> scans.set_restfreqs(freqs=1.667359e9, source='NGC253', theif=0)   
379
380  # Select for all sources and IFs
381  ASAP> scans.set_restfreqs(freqs=1.667359e9)                             
382\end{verbatim}
383
384
385If you specify a list of frequencies, then it must be of length the
386number of IFs.  Regardless of the source, the rest frequency will be set
387for each IF to the corresponding value in the provided list.  The
388internally stored list of rest frequencies will be replaced by this
389list.
390
391
392\begin{verbatim}
393  # Select for specified source/IF
394  ASAP> scans.set_restfreqs(freqs=1.667359e9, source='NGC253', theif=0)   
395
396  # Select for all sources and IFs
397  ASAP> scans.set_restfreqs(freqs=1.667359e9)                             
398\end{verbatim}
399
400
401In both of the above modes, you can also specify the rest frequencies via
402names in a known list rather than by their values.
403
404Examples:
405
406\begin{verbatim}
407  ASAP> scans.lines()                 # Print list of known lines
408  ASAP> scans.set_restfreqs(lines=['OH1665','OH1667'])
409\end{verbatim}
410
411 
412
413\subsection{Data Selection}
414
415Data selection is currently fairly limited. This will be improved in
416the future.
417
418
419\subsubsection{Cursor}
420
421Generally the user will want to run functions on all rows in a
422scantable. This allows very fast reduction of data. There are situations
423when functions should only operate on specific elements of the spectra. This
424is handled by the scantable cursor, which allows the user to select a
425single beam, IF and polarisation combination.
426
427Example :
428
429\begin{verbatim}
430  ASAP> scans.set_cursor(0,2,1)      # beam, IF, pol
431  ASAP> scans.smooth(allaxes=F)      # in situ by default or .aipsrc
432\end{verbatim}
433
434\subsubsection{Row number}
435
436Most functions work on all rows of a scan table. Exceptions are the
437fitter and plotter. If you wish to only operate on a selected set of
438scantable rows, use the \cmd{get\_scan} function to copy the rows into
439a new scantable.
440
441\subsubsection{Allaxes}
442
443Many functions have an \cmd{allaxes} option which controls whether the
444function will operate on all elements within a scantable row, or just
445those selected with the current cursor. The default is taken from the
446users {\tt .asaprc} file.
447
448\subsubsection{Masks}
449
450Many tasks (fitting, baseline subtraction, statistics etc) should only
451be run on range of channels. Depending on the current ``unit'' setting
452this range is set directly as channels, velocity or frequency
453ranges. Internally these are converted into a simple boolean mask for
454each channel of the abscissa. This means that if the unit setting is
455later changed, previously created mask are still valid. (This is not
456true for functions which change the shape or shift the frequency axis).
457You create masks with the function \cmd{create\_mask} and this specified
458the channels to be included in the selection.
459
460When setting the mask in velocity, the conversion from velocity
461to channels is based on the current cursor setting, selected row and
462selected frequency reference frame (**Currently first row only**)
463
464
465Example :
466\begin{verbatim}
467
468  # Select channel range for baselining
469  ASAP> scans.set_unit('channels')
470  ASAP> msk = q.create_mask([100,400],[600,800])
471 
472  # Select velocity range for fitting
473  ASAP> scans.set_unit('km/s')
474  ASAP> msk = q.create_mask([-30,-10])
475\end{verbatim}
476
477
478Sometimes it is more convenient to specify the channels to be
479excluded, rather included.  You can do this with the ``invert'' argument.
480
481Example :
482\begin{verbatim}
483  ASAP> scans.set_unit('channels')
484  ASAP> msk = q.create_mask([0,100],[900-1023], invert=True)   # Excludes specified channels
485\end{verbatim}
486
487Because the mask is stored in a simple python variable, the users is
488able to combine masks using simple arithmetic. To create a mask
489excluding the edge channels, a strong maser feature and a birdie in
490the middle of the band:
491
492\begin{verbatim}
493  ASAP> scans.set_unit('channels')
494  ASAP> msk1 = q.create_mask([0,100],[511,511],[900,1023],invert=True)
495  ASAP> scans.set_unit('km/s')
496  ASAP> msk2 = q.create_mask([-20,-10],invert=True)
497
498  ASAP> mask = msk1 and msk2
499\end{verbatim}
500
501
502\section{Data Input}
503
504Data can be loaded in one of two ways; using the reader object or via
505the scantable constructor. The scantable method is simpler but the
506reader allow the user more control on what is read.
507
508\subsection{Scantable constructor}
509
510This loads all of the data from filename into the scantable object scans
511and averages all the data within a scan (i.e.  the resulting scantable
512will have one row per scan).  The recognised input file formats are
513RPFITS, SDFITS (singledish fits), ASAP's scantable format and aips++
514MeasurementSet2 format.
515
516
517Example usage:
518
519\begin{verbatim}
520  ASAP> scan = scantable('2004-11-23_1841-P484.rpf')
521\end{verbatim}
522
523
524\subsection{Reader object}
525
526For more control when reading data into ASAP, the reader object should
527be used.  This has the option of only reading in a range of integrations
528and does not perform any scan averaging of the data, allowing analysis
529of the individual integrations.  Note that due to limitation of the
530RPFITS library, only one reader object can be open at one time reading
531RPFITS files.  To read multiple RPFITS files, the old reader must be
532destroyed before the new file is opened.  However, multiple readers can
533be created and attached to SDFITS files.
534
535
536Example usage:
537
538\begin{verbatim}
539  ASAP> r = reader('2003-03-16_082048_t0002.rpf')
540  ASAP> r.summary
541  ASAP> scan = r.read()
542  ASAP> s = r.read(range(100)) # To read in the first 100 integrations
543  ASAP> del r
544\end{verbatim}
545
546\section{Basic Processing}
547
548In the following section, a simple data reduction to form a quotient
549spectrum of a single source is followed. In the following it has been
550assume that the \cmd{.asaprc} file has been used to set \cmd{insitu}
551to a default value or \cmd{True}.
552
553%\subsection{Editing}
554
555%How and when?
556
557\subsection{Separate reference and source observations}
558
559Most data from ATNF observatories distinguishes on and off source data
560using the file name. This makes it easy to create two scantables with
561the source and reference data. As long as there was exactly one
562reference observation for each on source observation for following
563method will work.
564
565For Mopra and Parkes data:
566\begin{verbatim}
567  ASAP> r = scans.get_scan('*_R')
568  ASAP> s = scans.get_scan('*_S')
569\end{verbatim}
570
571For Tidbinbilla data
572\begin{verbatim}
573  ASAP> r = scans.get_scan('*_[ew]')
574  ASAP> s = scans.get_scan('*_[^ew]')
575\end{verbatim}
576
577\subsection{Make the quotient spectra}
578
579Use the quotient function
580
581\begin{verbatim}
582  ASAP> q = s.quotient(r)
583\end{verbatim}
584
585This uses the rows in scantable \cmd{r} as reference spectra for the
586rows in scantable \cmd{s}. Scantable \cmd{r} must have either 1 row
587(which is applied to all rows in \cmd{s}) or both scantables must have
588the same number of rows. By default the quotient spectra is calculated
589to preserve continuum emission. If you wish to remove continuum
590contribution, use the \cmd{preserve} argument:
591
592\begin{verbatim}
593  ASAP> q = s.quotient(r, preserve=True)
594\end{verbatim}
595
596\subsection{Time average separate scans}
597
598If you have observed the source with multiple source/reference cycles you
599will want to scan-average the quotient spectra together.
600
601\begin{verbatim}
602 ASAP> av = average_time(q)
603\end{verbatim}
604
605If for some you want to average multiple sets of scan tables together you can:
606
607\begin{verbatim}
608 ASAP> av = average_time(q1, q2, q3)
609\end{verbatim}
610
611The default is not to use any weighting, which probably is not what
612you want. The alternative is to use variance or Tsys weighting.
613
614To use variance based weighting, you need to supply a mask saying which
615channel range you want it to calculate the variance from.
616
617\begin{verbatim}
618 ASAP> av = average_time(q, weight='tsys')
619
620 ASAP> msk = q.create_mask([200,400],[600,800])
621 ASAP> av = average_time(q, mask=msk, weight='var')
622\end{verbatim}
623
624\subsection{Baseline fitting}
625
626To make a baseline fit, you must first create a mask of channels to
627use in the baseline fit.
628
629\begin{verbatim}
630 ASAP> msk = scans.create_mask([100,400],[600,900])
631 ASAP> scans.poly_baseline(msk, 1)
632\end{verbatim}
633
634This will fit a first order polynomial to the selected channels and subtract
635this polynomial from the full spectra.
636
637\subsubsection{Auto-baselining}
638
639The function \cmd{auto\_poly\_baseline} can be used to automatically
640baseline your data with out having to specify channel ranges for
641the line free data. It automatically figures out the line-free
642emission and fits a polynomial baseline to that data. The user can use
643masks to fix the range of channels or velocity range for the fit as
644well as mark the band edge as invalid.
645
646Simple example
647
648\begin{verbatim}
649  ASAP> scans.auto_poly_baseline(order=2,threshold=5)
650\end{verbatim}
651
652\cmd{order} is the polynomial order for the fit. \cmd{threshold} is
653the SNR threshold to use to deliminate line emission from
654signal. Making this too small or too large will result in a poor fit,
655but generally the value is not critical.
656
657Other examples:
658
659\begin{verbatim}
660  # Don't try and fit the edge of the bandpass which is noisier
661  ASAP> scans.auto_poly_baseline(edge=(500,450),order=3,threshold=3)
662
663  # Only fit a given region around the line
664  ASAP> scans.set_unit('km/s')
665  ASAP> msk = scans.create_mask((-60,-20))
666  ASAP> scans.auto_poly_baseline(mask=msk,order=3,threshold=3)
667
668\end{verbatim}
669
670\subsection{Average the polarisations}
671
672If you are just interested in the highest SNR for total intensity you
673will want to average the parallel polarisations together.
674
675\begin{verbatim}
676 ASAP> scans.average_pol()
677\end{verbatim}
678
679\subsection{Calibration}
680
681For most uses, calibration happens transparently as the input data
682contains the Tsys measurements taken during observations. The nominal
683``Tsys'' values may be in Kelvin or Jansky. The user may wish to
684supply a Tsys correction or apply gain-elevation and opacity
685corrections.
686
687\subsubsection{Brightness Units}
688
689RPFITS files to not contain any information as to whether the telescope
690calibration was in units of Kelvin or Janskys.  On reading the data a
691default value is set depending on the telescope and frequency of
692observation.  If this default is incorrect (you can see it in the
693listing from the \cmd{summary} function) the user can either override
694this value on reading the data or later.  E.g:
695
696\begin{verbatim}
697  ASAP> scans = scantable(('2004-11-23_1841-P484.rpf', unit='Jy')
698  # Or in two steps
699  ASAP> scans = scantable(('2004-11-23_1841-P484.rpf')
700  ASAP> scans.set_fluxunit('Jy)
701\end{verbatim}
702
703\subsubsection{Tsys scaling}
704
705Sometime the nominal Tsys measurement at the telescope is wrong due to
706an incorrect noise diode calibration. This can easily be corrected for
707with the scale function. By default, \cmd{scale} only scans the
708spectra and not the corresponding Tsys.
709
710\begin{verbatim}
711  ASAP> scans.scale(1.05, tsys=True)
712\end{verbatim}
713
714\subsubsection{Unit Conversion}
715
716To convert measurements in Kelvin to Jy (and vice versa) the global
717function \cmd{convert\_flux} is needed. This converts and scales the data
718from K to Jy or vice-versa depending on what the current brightness unit is
719set to. The function knows the basic parameters for some frequencies
720and telescopes, but the user may need to supply the aperture
721efficiency, telescope diameter or the Jy/K factor.
722
723\begin{verbatim}
724  ASAP> scans.convert_flux                 # If efficency known
725  ASAP> scans.convert_flux(eta=0.48)       # If telescope diameter known
726  ASAP> scans.convert_flux(eta=0.48,d=35)  # Unknown telescope
727  ASAP> scans.convert_flux(jypk=15)        # Alternative
728\end{verbatim}
729
730\subsubsection{Gain-Elevation and Opacity Corrections}
731
732As higher frequencies (particularly $>$20~GHz) it is important to make
733corrections for atmospheric opacity and gain-elevation effects.
734
735Gain-elevation curves for some telescopes and frequencies and known to
736ASAP (currently only for Tid at 20~GHz).  In these cases making
737gain-corrections is simple.  If the gain curve for your data is not
738known the user can supply either a gain polynomial or text file
739tabulating gain factors at a range of elevations (see \cmd{help
740gain\_el}).
741
742Examples:
743
744\begin{verbatim}
745  ASAP> scans.gain_el()   # If gain table known
746  ASAP> scans.gain_el(poly=[3.58788e-1,2.87243e-2,-3.219093e-4])
747\end{verbatim}
748
749Opacity corrections can be made with the global function
750\cmd{opacity}. This should work on all telescopes as long as a
751measurement of the opacity factor, was made during the
752observation.
753
754\begin{verbatim}
755  ASAP> scans.opacity(0.083)
756\end{verbatim}
757
758Note that at 3~mm Mopra uses a paddle wheel for Tsys calibration,
759which takes opacity effects into account (to first order). ASAP
760opacity corrections should not then be used for Mopra 3-mm data.
761
762\subsection{Frequency Frame Alignment}
763
764When time averaging a series of scans together, it is possible that the
765velocity scales are not exactly aligned.  This may be for many reasons
766such as not Doppler tracking the observations, errors in the Doppler
767tracking etc.  This mostly affects very long integrations or
768integrations averaged together from different days data.  Before
769averaging such data together, they should be frequency aligned using
770\cmd{freq\_align}.
771
772E.g.:
773
774\begin{verbatim}
775  ASAP> scans.freq_align()
776  ASAP> av = average_time(scans)
777\end{verbatim}
778
779\cmd{freq\_align} has two modes of operations controlled by the
780\cmd{perif} argument. By default it will align each source and freqid
781separately. This is needed for scan tables containing multiple
782sources. However if scan-based Doppler tracking has been made at the observatory,
783each row will have a different freqid. In these cases run with
784\cmd{perif=True} and all rows of a source will be aligned to the same
785frame. In general \cmd{perif=True} will be needed for most
786observations as Doppler tracking of some form is made at Parkes, Tid
787and Mopra.
788
789\begin{verbatim}
790  ASAP> scans.freq_align(perif=True)
791\end{verbatim}
792
793To average together data taken on different days, which are in
794different scantables, each scantable must aligned to a common
795reference time then the scantables averaged. The simplest way of
796doing this is to allow ASAP to choose the reference time for the first
797scantable then using this time for the subsequent scantables.
798
799\begin{verbatim}
800  ASAP> scans1.freq_align() # Copy the refeference Epoch from the output
801  ASAP> scans2.freq_align(reftime='2004/11/23/18:43:35')
802  ASAP> scans3.freq_align(reftime='2004/11/23/18:43:35')
803  ASAP> av = average_time(scans1, scans2, scans3)
804\end{verbatim}
805
806\section{Scantable manipulation}
807
808While it is very useful to have many independent sources within one
809scantable, it is often inconvenient for data processing. The
810\cmd{get\_scan} function can be used to create a new scantable with a
811selection of scans from a scantable. The selection can either be on
812the source name, with simple wildcard matching or set of scan ids.
813
814For example:
815
816\begin{verbatim}
817  ASAP> ss = scans.get_scan(10) # Get the 11th scan (zero based)
818  ASAP> ss = scans.get_scan(range(10)) # Get the first 10 scans
819  ASAP> ss = scans.get_scan(range(10,20)) # Get the next 10 scans
820  ASAP> ss = scans.get_scan([2,4,6,8,10]) # Get a selection of scans
821
822  ASAP> ss = scans.get_scan('345p407') # Get a specific source
823  ASAP> ss = scans.get_scan('345*')    # Get a few sources
824
825  ASAP> r = scans.get_scan('*_R') # Get all reference sources (Parkes/Mopra)
826  ASAP> s = scans.get_scan('*_S') # Get all program sources (Parkes/Mopra)
827  ASAP> r = scans.get_scan('*_[ew]')  # Get all reference sources (Tid)
828  ASAP> s = scans.get_scan('*_[^ew]') # Get all program sources (Tid)
829
830\end{verbatim}
831
832To copy a scantable the following does not work:
833
834\begin{verbatim}
835  ASAP> ss = scans
836\end{verbatim}
837
838as this just creates a reference to the original scantable. Any changes
839made to \cmd{ss} and also seen in \cmd{scans}. To duplicate a
840scantable, use the copy function.
841
842\begin{verbatim}
843  ASAP> ss = scans.copy
844\end{verbatim}
845
846\section{Data Output}
847
848ASAP can save scantables in a variety of formats, suitable for reading
849into other packages. The formats are:
850
851\begin{itemize}
852\item[ASAP] This is the internal format used for ASAP. It is the only
853format that allows the user to restore the data, fits etc. without
854loosing any information.   As mentioned before, the ASAP scantable
855is just an AIPS++ Table (a memory-based table).
856This function just converts it to a  disk-based
857Table.  You can the access that Table with the AIPS++ Table browser
858or any other AIPS++ tool.
859
860\item[SDFITS] The Single Dish FITS format. This format was
861designed to for interchange between packages, but few packages
862actually can read it.
863
864\item[FITS] This uses simple ``image'' fits to save the data, each row
865being written to a separate fits file. This format is suitable for
866importing the data into CLASS.
867
868\item[ASCII] A simple text based format suitable for the user to
869processing using Perl or, Python, gnuplot etc.
870
871\item[MS2] Saves the data in an aips++ MeasurementSet V2 format.
872You can also access this with the Table browser and other AIPS++
873tools.
874
875\end{itemize}
876
877The default output format can be set in the users {\tt .asaprc} file.
878Typical usages are:
879
880\begin{verbatim}
881  ASAP> scans.save('myscans') # Save in default format
882  ASAP> scans.save('myscans', 'FITS') # Save as FITS for exporting into CLASS
883
884  ASAP> scans.save('myscans', stokes=True) # Convert raw polarisations into Stokes
885  ASAP> scans.save('myscans', overwrite=True) # Overwrite an existing file
886\end{verbatim}
887
888
889\section{Plotter}
890
891Scantable spectra can be plotter at any time. An asapplotter object is
892used for plotting, meaning multiple plot windows can be active at the
893same time. On start up a default asapplotter object is created called
894``plotter''. This would normally be used for standard plotting.
895
896The plotter, optionally, will run in a multipanel mode and contain
897multiple plots per panel. The user must tell the plotter how they want
898the data distributed. This is done using the set\_mode function. The
899default can be set in the users {\tt .asaprc} file. The units (and frame
900etc) of the abscissa will be whatever has previously been set by
901\cmd{set\_unit}, \cmd{set\_freqframe} etc.
902
903Typical plotter usage would be:
904
905\begin{verbatim}
906  ASAP> scans.set_unit('km/s')
907  ASAP> plotter.set_mode(stacking='p',panelling='t')
908  ASAP> plotter.plot(scans)
909\end{verbatim}
910
911This will plot multiple polarisation within each plot panel and each
912scanrow in a separate panel.
913
914Other possibilities include:
915
916\begin{verbatim}
917  # Plot multiple IFs per panel
918  ASAP> plotter.set_mode(stacking='i',panelling='t')
919
920  # Plot multiple beams per panel
921  ASAP> plotter.set_mode(stacking='b',panelling='t')
922
923  # Plot one IF per panel, time stacked
924  ASAP> plotter.set_mode('t', 'i')
925
926  # Plot each scan in a seperate panel
927  ASAP> plotter.set_mode('t', 's')
928
929\end{verbatim}
930
931\subsection{Plot Selection}
932\label{sec:plotter_cursor}
933
934The plotter can plot up to 25 panels and stacked spectra per
935panel. If you have data larger than this (or for your own sanity) you
936need to select a subset of this data. This is particularly true for
937multibeam or multi IF data. The plotter \cmd{set\_cursor} function is
938used to select a subset of the data. The arguments \cmd{row},
939\cmd{beam} and \cmd{IF} all accept a vector if indices corresponding
940to tow, beam or IF selection. Only the selected data will be plotted.
941So select on polarisation, see section~\ref{sec:polplot}.
942
943Examples:
944
945\begin{verbatim}
946  # Select second IF
947  ASAP> plotter.set_cursor(IF=[1])
948
949  # Select first 4 beams
950  ASAP> plotter.set_cursor(beam=[0,1,2,3])
951
952  # Select a few rows
953  ASAP> plotter.set_cursor(row=[2,4,6,10])
954
955  # Multiple selection
956  ASAP> plotter.set_cursor(IF=[1], beam=[0,2], row=range(10))
957\end{verbatim}
958
959\subsection{Plot control}
960
961The plotter window has a row of buttons on the lower left. These can
962be used to control the plotter (mostly for zooming the individual
963plots). From left to right:
964
965\begin{itemize}
966
967\item[Home] This will unzoom the plots to the original zoom factor
968
969\item[Plot history] (left and right arrow). The plotter keeps a
970history of zoom settings. The left arrow sets the plot zoom to the
971previous value. The right arrow returns back again. This allows you,
972for example, to zoom in on one feature then return the plot to how it
973was previously.
974
975\item[Pan] (The Cross) This sets the cursor to pan, or scroll mode
976       allowing you to shift the plot within the window. Useful when
977       zoomed in on a feature.
978
979\item[Zoom] (the letter with the magnifying glass) lets you draw a
980       rectangle around a region of interest then zooms in on that
981       region. Use the plot history to unzoom again. 
982
983\item[Save] (floppy disk). Save the plot as a postscript or .png file
984
985\end{itemize}
986
987\subsection{Plot selection}
988
989\subsection{Other control}
990
991The plotter has a number of functions to describe the layout of the
992plot. These include \cmd{set\_legend}, \cmd{set\_layout} and \cmd{set\_title}.
993
994To set the exact velocity or channel range to be plotted use the
995\cmd{set\_range} function. To reset to the default value, call
996\cmd{set\_range} with no arguments. E.g.
997
998\begin{verbatim}
999  ASAP> scans.set_unit('km/s')
1000  ASAP> plotter.plot(scans)
1001  ASAP> plotter.set_range(-150,-50)
1002  ASAP> plotter.set_range()
1003\end{verbatim}
1004
1005To save a hardcopy of the current plot, use the save function, e.g.
1006
1007\begin{verbatim}
1008  ASAP> plotter.save('myplot.ps')
1009\end{verbatim}
1010
1011\section{Fitting}
1012
1013Currently multicomponent Gaussian function is available. This is done
1014by creating a fitting object, setting up the fit and actually fitting
1015the data. Fitting can either be done on a single scantable row/cursor
1016selection or on an entire scantable using the \cmd{auto\_fit} function.
1017
1018\begin{verbatim}
1019 ASAP> f = fitter()
1020 ASAP> f.set_function(gauss=2) # Fit two Gaussians
1021 ASAP> f.set_scan(scans)
1022 ASAP> scans.set_cursor(0,0,1) # Fit the second polarisation
1023 ASAP> scans.set_unit('km/s')  # Make fit in velocity units
1024 ASAP> f.fit(1)                # Run the fit on the second row in the table
1025 ASAP> f.plot()                # Show fit in a plot window
1026 ASAP> f.get_parameters()      # Return the fit paramaters
1027\end{verbatim}
1028
1029This auto-guesses the initial values of the fit and works well for data
1030without extra confusing features. Note that the fit is performed in
1031whatever unit the abscissa is set to.
1032
1033If you want to confine the fitting to a smaller range (e.g. to avoid
1034band edge effects or RFI you must set a mask.
1035
1036\begin{verbatim}
1037  ASAP> f = fitter()
1038  ASAP> f.set_function(gauss=2)
1039  ASAP> scans.set_unit('km/s')  # Set the mask in channel units
1040  ASAP> msk = s.create_mask([1800,2200])
1041  ASAP> scans.set_unit('km/s')  # Make fit in velocity units
1042  ASAP> f.set_scan(s,msk)
1043  ASAP> f.fit()
1044  ASAP> f.plot()
1045  ASAP> f.get_parameters()
1046\end{verbatim}
1047
1048If you wish, the initial parameter guesses can be specified specific
1049parameters can be fixed:
1050
1051\begin{verbatim}
1052  ASAP> f = fitter()
1053  ASAP> f.set_function(gauss=2)
1054  ASAP> f.set_scan(s,msk)
1055  ASAP> f.fit() # Fit using auto-estimates
1056  # Set Peak, centre and fwhm for the second gaussian.
1057  # Force the centre to be fixed
1058  ASAP> f.set_gauss_parameters(0.4,450,150,0,1,0,component=1)
1059  ASAP> f.fit() # Re-run the fit
1060\end{verbatim}
1061
1062The fitter \cmd{plot} function has a number of options to either view
1063the fit residuals or the individual components (by default it plots
1064the sum of the model components).
1065
1066Examples:
1067
1068\begin{verbatim}
1069  # Plot the residual
1070  ASAP> f.plot(residual=True)
1071
1072  # Plot the first 2 componentsa
1073  ASAP> f.plot(components=[0,1])
1074
1075  # Plot the first and third component plus the model sum
1076  ASAP> f.plot(components=[-1,0,2])  # -1 means the compoment sum
1077\end{verbatim}
1078
1079\section{Polarisation}
1080
1081Currently ASAP only supports polarmetric analysis on linearly
1082polarised feeds and the cross polarisation products measured. Other
1083cases will be added on an as needed basic.
1084
1085Conversions of linears to Stokes or Circular polarisations are done
1086``on-the-fly''. Leakage cannot be corrected for nor are there routines
1087able to calibrate position angle offsets.
1088
1089\subsection{Simple Calibration}
1090
1091{\em Currently the receiver position angle is not stored in the rpfits
1092file. This serverly hampers correct handling of polarimetry.}
1093
1094It is possible that there is a phase offset between polarisation which
1095will effect the phase of the cross polarisation
1096correlation. \cmd{rotate\_xyphase} can be used to correct for this
1097error. The user must know how to determine the size of the phase
1098offset.
1099
1100\begin{verbatim}
1101  ASAP> scans.rotate_xyphase(10.5)
1102\end{verbatim}
1103
1104Note that if this function is run twice, the sum of the two values is
1105applied.
1106
1107A correction for the receiver paralactic angle may need to be made,
1108either because of how it is mounted or if paralactifiying had to track
1109at 90 degrees rather than 0. Use \cmd{rotate\_linpolphase} to correct
1110the position angle. Running this function twice results in the sum of
1111the corrections being applied.
1112
1113\begin{verbatim}
1114  ASAP> scans.rotate_linpolphase(-20) # Correct for receiver mounting
1115
1116  # Receiver was tracking 90 degrees rather than 0
1117  ASAP> scans.rotate_linpolphase(90) 
1118\end{verbatim}
1119
1120\subsection{Plotting}
1121\label{sec:polplot}
1122
1123To plot stokes values, the plotter \cmd{set\_cursor} function should
1124be called first using the \cmd{pol} argument. The values which can be
1125plotted include a selection of [I,Q,U,V], [I, Plinear, Pangle, V] or
1126[XX, YY, Real(XY), Imaginary(XY)]. (Plinear and Pangle are the
1127percentage and position angle of linear polarisation). Conversion to
1128circular polarisations are currently not available.
1129
1130Example:
1131
1132\begin{verbatim}
1133  ASAP> plotter.set_cursor(pol=[``I'',''Q'']
1134  ASAP> plotter.set_cursor(pol=[``XX'',''YY'']
1135  ASAP> plotter.set_cursor(pol=[``I'',''Plinear'']
1136\end{verbatim}
1137
1138Row, beam and IF selection are also available in \cmd{set\_cursor} as
1139describe in section~\ref{sec:plotter_cursor}.
1140
1141\subsection{Saving}
1142
1143When saving data using the \cmd{save} function, the \cmd{stokes}
1144argument can be used to save the data as Stoke values when saving in
1145FITS format.
1146
1147Example:
1148
1149\begin{verbatim}
1150  ASAP> scans.save('myscan.sdfits', 'SDFITS', stokes=True)
1151\end{verbatim}
1152
1153\section{Function Summary}
1154
1155\begin{verbatim}
1156
1157    [The scan container]
1158        scantable           - a container for integrations/scans
1159                              (can open asap/rpfits/sdfits and ms files)
1160            copy            - returns a copy of a scan
1161            get_scan        - gets a specific scan out of a scantable
1162            summary         - print info about the scantable contents
1163            set_cursor      - set a specific Beam/IF/Pol 'cursor' for
1164                              further use
1165            get_cursor      - print out the current cursor position
1166            stats           - get specified statistic of the spectra in
1167                              the scantable
1168            stddev          - get the standard deviation of the spectra
1169                              in the scantable
1170            get_tsys        - get the TSys
1171            get_time        - get the timestamps of the integrations
1172            get_unit        - get the currnt unit
1173            set_unit        - set the abcissa unit to be used from this
1174                              point on
1175            get_abcissa     - get the abcissa values and name for a given
1176                              row (time)
1177            set_freqframe   - set the frame info for the Spectral Axis
1178                              (e.g. 'LSRK')
1179            set_doppler     - set the doppler to be used from this point on
1180            set_instrument  - set the instrument name
1181            get_fluxunit    - get the brightness flux unit
1182            set_fluxunit    - set the brightness flux unit
1183            create_mask     - return an mask in the current unit
1184                              for the given region. The specified regions
1185                              are NOT masked
1186            get_restfreqs   - get the current list of rest frequencies
1187            set_restfreqs   - set a list of rest frequencies
1188            lines           - print list of known spectral lines
1189            flag_spectrum   - flag a whole Beam/IF/Pol
1190            save            - save the scantable to disk as either 'ASAP'
1191                              or 'SDFITS'
1192            nbeam,nif,nchan,npol - the number of beams/IFs/Pols/Chans
1193            history         - print the history of the scantable
1194
1195            average_time    - return the (weighted) time average of a scan
1196                              or a list of scans
1197            average_pol     - average the polarisations together.
1198                              The dimension won't be reduced and
1199                              all polarisations will contain the
1200                              averaged spectrum.
1201            quotient        - return the on/off quotient
1202            scale           - return a scan scaled by a given factor
1203            add             - return a scan with given value added
1204            bin             - return a scan with binned channels
1205            resample        - return a scan with resampled channels
1206            smooth          - return the spectrally smoothed scan
1207            poly_baseline   - fit a polynomial baseline to all Beams/IFs/Pols
1208            gain_el         - apply gain-elevation correction
1209            opacity         - apply opacity correction
1210            convert_flux    - convert to and from Jy and Kelvin brightness
1211                              units
1212            freq_align      - align spectra in frequency frame
1213            rotate_xyphase  - rotate XY phase of cross correlation
1214            rotate_linpolphase - rotate the phase of the complex
1215                                 polarization O=Q+iU correlation
1216     [Math] Mainly functions which operate on more than one scantable
1217
1218            average_time    - return the (weighted) time average
1219                              of a list of scans
1220            quotient        - return the on/off quotient
1221            simple_math     - simple mathematical operations on two scantables,                              'add', 'sub', 'mul', 'div'
1222     [Fitting]
1223        fitter
1224            auto_fit        - return a scan where the function is
1225                              applied to all Beams/IFs/Pols.
1226            commit          - return a new scan where the fits have been
1227                              commited.
1228            fit             - execute the actual fitting process
1229            get_chi2        - get the Chi^2
1230            set_scan        - set the scantable to be fit
1231            set_function    - set the fitting function
1232            set_parameters  - set the parameters for the function(s), and
1233                              set if they should be held fixed during fitting
1234            set_gauss_parameters - same as above but specialised for individual                                   gaussian components
1235            get_parameters  - get the fitted parameters
1236            plot            - plot the resulting fit and/or components and
1237                              residual
1238    [Plotter]
1239        asapplotter         - a plotter for asap, default plotter is
1240                              called 'plotter'
1241            plot            - plot a (list of) scantable
1242            save            - save the plot to a file ('png' ,'ps' or 'eps')
1243            set_mode        - set the state of the plotter, i.e.
1244                              what is to be plotted 'colour stacked'
1245                              and what 'panelled'
1246            set_range       - set the abcissa 'zoom' range
1247            set_legend      - specify user labels for the legend indeces
1248            set_title       - specify user labels for the panel indeces
1249            set_ordinate    - specify a user label for the ordinate
1250            set_abcissa     - specify a user label for the abcissa
1251            set_layout      - specify the multi-panel layout (rows,cols)
1252
1253    [Reading files]
1254        reader              - access rpfits/sdfits files
1255            read            - read in integrations
1256            summary         - list info about all integrations
1257
1258    [General]
1259        commands            - this command
1260        print               - print details about a variable
1261        list_scans          - list all scantables created bt the user
1262        del                 - delete the given variable from memory
1263        range               - create a list of values, e.g.
1264                              range(3) = [0,1,2], range(2,5) = [2,3,4]
1265        help                - print help for one of the listed functions
1266        execfile            - execute an asap script, e.g. execfile('myscript')
1267        list_rcparameters   - print out a list of possible values to be
1268                              put into \$HOME/.asaprc
1269        mask_and,mask_or,
1270        mask_not            - boolean operations on masks created with
1271                              scantable.create_mask
1272
1273    Note:
1274        How to use this with help:
1275                                         # function 'summary'
1276        [xxx] is just a category
1277        Every 'sub-level' in this list should be replaces by a '.' Period when        using help
1278        Example:
1279            ASAP> help scantable # to get info on ths scantable
1280            ASAP> help scantable.summary # to get help on the scantable's
1281            ASAP> help average_time
1282\end{verbatim}
1283
1284%\section{Scripting}
1285
1286%Malte to add something
1287
1288\section{Appendix}
1289
1290\subsection{Installation}
1291
1292ASAP depends on a number of third-party libraries which you must
1293have installed before attempting to build ASAP. These are:
1294
1295\begin{itemize}
1296\item AIPS++
1297\item Boost
1298\item Matplotlib
1299\item ipython/python
1300\end{itemize}
1301
1302Debian Linux is currently supported and we intend also
1303to support other popular Linux flavours, Solaris and Mac.
1304
1305Of the dependencies, AIPS++ is the most complex to install.
1306
1307\subsection{ASCII output format}
1308
1309\subsection{.asaprc settings}
1310
1311\end{document}
1312
1313
Note: See TracBrowser for help on using the repository browser.