-
Notifications
You must be signed in to change notification settings - Fork 11
/
sun_master.tex
22628 lines (19409 loc) · 806 KB
/
sun_master.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[twoside,11pt]{starlink}
% ? Specify used packages
% ? End of specify used packages
% -----------------------------------------------------------------------------
% ? Document identification
% Fixed part
\stardoccategory {Starlink User Note}
\stardocinitials {SUN}
\stardocsource {sun\stardocnumber}
% Variable part - replace [xxx] as appropriate.
c+
\stardocnumber {211.30}
c-
f+
\stardocnumber {210.30}
f-
\stardocauthors {R.F. Warren-Smith \& D.S. Berry}
\stardocdate {25th Sep 2024}
\stardoctitle {AST\linebreak%
A Library for Handling\linebreak%
World Coordinate Systems\linebreak%
in Astronomy}
\stardoccopyright {Copyright (C) 2024 East Asian Observatory}
\stardocversion {V<VERSION_NUMBER>}
c+
\stardocmanual {Programmer's Guide\\(C Version)}
\startitlepic{
\includegraphics[width=0.25\textwidth]{sun211_figures/fronta}~~~~~\hfill
\includegraphics[width=0.25\textwidth]{sun211_figures/frontb}~~~~~\hfill
\includegraphics[width=0.25\textwidth]{sun211_figures/frontc}
}
c-
f+
\stardocmanual {Programmer's Guide\\(Fortran Version)}
\startitlepic{
\includegraphics[width=0.25\textwidth]{sun210_figures/fronta}~~~~~\hfill
\includegraphics[width=0.25\textwidth]{sun210_figures/frontb}~~~~~\hfill
\includegraphics[width=0.25\textwidth]{sun210_figures/frontc}
}
f-
\stardocabstract {
The AST library provides a comprehensive range of facilities for
attaching world coordinate systems to astronomical data, for
retrieving and interpreting that information in a variety of formats,
including FITS-WCS, and for generating graphical output based on it.
This programmer's manual should be of interest to anyone writing
astronomical applications which need to manipulate coordinate system
data, especially celestial or spectral coordinate systems. AST is portable and
environment-independent.
}
% ? End of document identification
% -----------------------------------------------------------------------------
% ? Document specific \providecommand or \newenvironment commands.
\providecommand{\appref}[1]{Appendix~\ref{#1}}
\providecommand{\secref}[1]{\S\ref{#1}}
\providecommand{\fitskey}[3]{{#1}&{#2}&{#3}\\}
% Use {\tt ... } as \texttt{...} does not work if there are new lines in #1
\providecommand{\sstsynopsis}[1]{\sstdiytopic{Synopsis}{\tt #1}}
% Format the constructor section.
\providecommand{\sstconstructor}[1]{\sstdiytopic{Constructor Function}{#1}}
% ? End of document specific commands
% -----------------------------------------------------------------------------
% Title Page.
% ===========
\begin{document}
\scfrontmatter
\begin{center}
c+
\emph{This is the C version of this document.\\
For the Fortran version, please see \xref{SUN/210}{sun210}{}.}
c-
f+
\emph{This is the Fortran version of this document.\\
For the C version, please see \xref{SUN/211}{sun211}{}.}
f-
\end{center}
% Main text of document.
\vspace{7mm}
\section{Introduction}
Welcome to the AST library. If you are writing software for astronomy
and need to use celestial coordinates (\emph{e.g.}\ RA and Dec), spectral
coordinates (\emph{e.g.}\ wavelength, frequency, \emph{etc.}), or
other coordinate system information, then this library should be of
interest. It provides solutions for most of the problems you will meet
and allows you to write robust and flexible software. It is able to read
and write WCS information in a variety of formats, including
\htmladdnormallink{FITS-WCS}{http://fits.gsfc.nasa.gov/fits_wcs.html}.
%\subsection{TBW---What is a World Coordinate System?}
\subsection{What Problems Does AST Tackle?}
Here are some of the main problems you may face when handling world
coordinate system (WCS) information and the solutions that AST
provides:
\begin{description}
\item[1. The Variety of Coordinate Systems]\mbox{}\\
Astronomers use a wide range of differing coordinate systems to describe
positions within a variety of physical domains. For instance, there are a
large number of celestial coordinate systems in use within astronomy to
describe positions on the sky. Understanding these, and knowing how to
convert coordinates between them, can require considerable expertise. It
can also be difficult to decide which of them your software should support.
The same applies to coordinate systems describing other domains, such as
position within an electro-magnetic spectrum.
\textbf{Solution.} AST has built-in knowledge of many coordinate systems
and allows you to convert freely between them without specialist
knowledge. This avoids the need to embed details of specific
coordinate systems in your software. You also benefit automatically
when new coordinate systems are added to AST.
\item[2. Storing and Retrieving WCS Information]\mbox{}\\
Storing coordinate system information in astronomical datasets and
retrieving it later can present a considerable challenge. Typically,
it requires knowledge of rather complex conventions
(\emph{e.g.}\ FITS) which are low-level, often mis-interpreted and may
be subject to change. Exchanging information with other software
systems is further complicated by the number of different conventions
in use.
\textbf{Solution.} AST combines a unifying high-level description of WCS
information with the ability to save and restore this using a variety
of formats. Details of the formats, which include FITS, are handled
internally by AST. This frees you from the need to understand them or
embed the details in your software. Again, you benefit automatically
when new formats are added to AST.
\item[3. Generating Graphical Output]\mbox{}\\
Producing graphical displays involving curvilinear coordinate systems,
such as celestial coordinate grids, can be complicated. Particular
difficulties arise when handling large areas of sky, the polar regions
and discontinuous (\emph{e.g.}\ segmented) sky projections. Even just
numbering and labelling curvilinear axes is rarely straightforward.
\textbf{Solution.} AST provides plotting facilities especially designed
for use with curvilinear coordinate systems. These include the
plotting of axes and complete labelled coordinate grids. A large
number of options are provided for tailoring the output to your
specific needs. Three dimensional coordinate grids can also be produced.
\item[4. Aligning Data from Different Sources]\mbox{}\\
One of the main uses of coordinate systems is to facilitate the
inter-comparison of data from different sources. A typical use might
be to plot (say) radio contours over an optical image. In practice,
however, different celestial coordinate systems may have been used,
making accurate alignment far from simple.
\textbf{Solution} AST provides a one-step method of aligning datasets,
searching for all possible intermediate coordinate systems. This
makes it simple to directly inter-relate the pixel coordinates of
different datasets.
\item[5. Handling Different Types of Coordinate System]\mbox{}\\
Not all coordinate systems used in astronomy are celestial ones, so if
you are writing general-purpose software such as (say) a display tool,
you may also need to handle axes representing wavelength, distance,
time or whatever else comes along. Obviously, you would prefer not to
handle each one as a special case.
\textbf{Solution} AST uses the same flexible high-level model to
describe all types of coordinate system. This allows you to write
software that handles different kinds of coordinate axis without
introducing special cases.
\end{description}
\subsection{Other Design Objectives}
As well as its scientific objectives, the AST library's design
includes a number of technical criteria intended to make it applicable
to as wide a range of projects as possible. The main considerations
are described here:
\begin{enumerate}
\item {\bf{Minimum Software Dependencies.}}
The AST library depends on no other other software\footnote{It comes with
bundled copies of the ERFA and
\xref{Starlink PAL libraries}{sun268}{} which are built
at the same time as the other AST internal libraries. Alternatively, external
PAL and ERFA libraries may be used by specifying the ``\texttt{--with-external\_pal}'' option when configuring AST}.
\item {\bf{Environment Independence.}}
AST is designed so that it can operate in a variety of ``programming
environments'' and is not tied to any particular one. To allow this,
it uses simple, flexible interfaces to obtain the following services:
\begin{itemize}
\item {\bf{Data Storage.}} Data I/O operations are based on text
and/or FITS headers. This makes it easy to interface to a wide variety
of astronomical data formats in a machine-independent way.
\item {\bf{Graphics.}} Graphical output is produced \emph{via} a
simple generic graphics interface, which may easily be re-implemented
over different graphics systems. AST provides a default implementation
based on the widely-used PGPLOT graphics system
(\xref{SUN/15}{sun15}{}).
\item {\bf{Error Handling.}} Error messages are written to standard
error by default, but go through a simple generic interface similar to
that used for graphics (above). This permits error message delivery
\emph{via} other routes when necessary (\emph{e.g.} in a graphical
interface).
\end{itemize}
\item {\bf{Multiple Language Support.}}
AST has been designed to be called from more than one language.
c+
Both C and Fortran interfaces are available (see
\xref{SUN/210}{sun210}{} for the Fortran version)
c-
f+
Both Fortran and C interfaces are available (see
\xref{SUN/211}{sun211}{} for the C version)
f-
and use from C$++$ is also straightforward if the C interface is
included using:
\begin{small}
\begin{terminalv}
extern "C" {
#include "star/ast.h"
}
\end{terminalv}
\end{small}
A JNI interface (known as ``JNIAST'' - see
\url{http://www.starlink.ac.uk/jniast/}) has also been developed by Starlink
which allows AST to be used from Java.
\item {\bf{Object Oriented Design.}}
AST uses ``object oriented'' techniques internally in order to provide
a flexible and easily-extended programming model. A fairly
traditional calling interface is provided, however, so that the
library's facilities are easily accessible to programmers using
c+
C and Fortran.
c-
f+
Fortran and C.
f-
\item {\bf{Portability.}}
AST is implemented entirely in ANSI standard C and, when called
\emph{via} its C interface, makes no explicit use of any
machine-dependent facilities.
The Fortran interface is, unavoidably, machine dependent. However, the
potential for problems has been minimised by encapsulating the
interface layer in a compact set of C macros which facilitate its
transfer to other platforms. No Fortran compiler is needed to build
the library.
Currently, AST is supported by Starlink on PC~Linux, Sun~Solaris and
Tru64~Unix (formerly DEC~UNIX) platforms.
\end{enumerate}
\subsection{What Does ``AST'' Stand For?}
The library name ``AST'' stands for ``ASTrometry Library''. The name
arose when it was thought that knowledge of ``astrometry''
(\emph{i.e.}\ celestial coordinate systems) would form the bulk of the
library. In fact, it turns out that astrometry forms only a minor
component, but the name AST has stuck.
\cleardoublepage
\section{Overview of AST Concepts}
This section presents a brief overview of AST concepts. It is intended
as a basic orientation course before you move on to the more technical
considerations in subsequent sections.
\subsection{\label{ss:mappingoverview}Relationships Between Coordinate Systems}
The relationships between coordinate systems are represented in AST by
Objects called Mappings. A Mapping does not represent a coordinate
system itself, but merely the process by which you move from one
coordinate system to another related one.
A convenient picture of a Mapping is as a ``black box''
(Figure~\ref{fig:mapping}) into which you can feed sets of
coordinates.
\begin{figure}[bhtp]
\begin{center}
c+
\includegraphics[width=0.7\textwidth]{sun211_figures/mapping}
c-
f+
\includegraphics[width=0.7\textwidth]{sun210_figures/mapping}
f-
\caption{A Mapping viewed as a ``black box'' for transforming coordinates.}
\label{fig:mapping}
\end{center}
\end{figure}
For each set you feed in, the Mapping returns a corresponding set of
transformed coordinates. Since each set of coordinates represents a
point in a coordinate space, the Mapping acts to inter-relate
corresponding positions in the two spaces, although what these spaces
represent is unspecified. Notice that a Mapping need not have the
same number of input and output coordinates. That is, the two
coordinate spaces which it inter-relates need not have the same number
of dimensions.
In many cases, the transformation can, in principle, be performed in
either direction: either from the \emph{input} coordinate space to the
\emph{output}, or \emph{vice versa}. The first of these is termed the
\emph{forward} transformation and the other the \emph{inverse}
transformation.
\textbf{Further reading:} For a more complete discussion of Mappings,
see~\secref{ss:mappings}.
\subsection{\label{ss:mappingselection}Mappings Available}
The basic concept of a Mapping (\secref{ss:mappingoverview}) is rather
generic and obviously it is necessary to have specific Mappings that
implement specific relationships between coordinate systems. AST
provides a range of these, to perform transformations such as the
following and, where appropriate, their inverses:
\begin{itemize}
\item Conversions between various celestial coordinate systems (the
SlaMap).
\item Conversions between various spectral coordinate systems (the
SpecMap and GrismMap).
\item Conversions between various time systems (the TimeMap).
\item Conversion between 2-dimensional spherical celestial coordinates
(longitude and latitude) and a 3-dimensional vectorial positions (the SphMap).
\item Various projections of the celestial sphere on to 2-dimensional
coordinate spaces---\emph{i.e.}\ map projections (the DssMap and WcsMap).
\item Permutation, introduction and elimination of coordinates (the
PermMap).
\item Various linear coordinate transformations (the MatrixMap, WinMap,
ShiftMap and ZoomMap).
\item General N-dimensional polynomial transformations (the PolyMap and
ChebyMap).
\item Lookup tables (the LutMap).
c+
\item General-purpose transformations expressed using arithmetic
operations and functions similar to those available in C (the
MathMap).
c-
f+
\item General-purpose transformations expressed using arithmetic
operations and functions similar to those available in Fortran (the
MathMap).
f-
c+
\item Transformations for internal use within a program, based on
private transformation functions which you write yourself in C (the
IntraMap).
c-
f+
\item Transformations for internal use within a program, based on
private transformation routines which you write yourself in Fortran
(the IntraMap).
f-
\end{itemize}
\textbf{Further reading:} For a more complete description of each of the
Mappings mentioned above, see its entry in
\appref{ss:classdescriptions}. In addition, see the discussion of the
PermMap in \secref{ss:permmapexample}, the UnitMap in
\secref{ss:unitmapexample} and the IntraMap in
\secref{ss:intramaps}. The ZoomMap is used as an example throughout
\secref{ss:primer}.
\subsection{\label{ss:cmpmapoverview}Compound Mappings}
The Mappings described in \secref{ss:mappingselection} provide a set
of basic building blocks from which more complex Mappings may be
constructed. The key to doing this is a type of Mapping called a
CmpMap, or compound Mapping. A CmpMap's role is, in principle, very
simple: it allows any other pair of Mappings to be joined together
into a single entity which behaves as if it were a single Mapping. A
CmpMap is therefore a container for another pair of Mappings.
A pair of Mappings may be combined using a CmpMap in either of two
ways. The first of these, \emph{in series}, is illustrated in
Figure~\ref{fig:seriescmpmap}.
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.7\textwidth]{sun211_figures/series}
c-
f+
\includegraphics[width=0.7\textwidth]{sun210_figures/series}
f-
\caption[A CmpMap composed of two component Mappings joined in series]{A CmpMap (compound Mapping) composed of two component
Mappings joined in series. The output coordinates of the first Mapping
feed into the input coordinates of the second one, so that the whole
entity behaves like a single Mapping.}
\label{fig:seriescmpmap}
\end{center}
\end{figure}
Here, the transformations implemented by each component Mapping are
performed one after the other, with the output from the first Mapping
feeding into the second. The second way, \emph{in parallel}, is shown in
Figure~\ref{fig:parallelcmpmap}.
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.5\textwidth]{sun211_figures/parallel}
c-
f+
\includegraphics[width=0.5\textwidth]{sun210_figures/parallel}
f-
\caption[A CmpMap composed of two Mappings joined in parallel.]{A CmpMap composed of two Mappings joined in parallel. Each
component Mapping acts on a complementary subset of the input and
output coordinates.}
\label{fig:parallelcmpmap}
\end{center}
\end{figure}
In this case, each Mapping acts on a complementary subset of the
input and output coordinates.\footnote{A pair of Mappings can be combined
in a third way using a TranMap. A TranMap allows the forward
transformation of one Mapping to be combined with the inverse
transformation of another to produce a single Mapping.}
The CmpMap forms the key to building arbitrarily complex Mappings
because it is itself a form of Mapping. This means that a CmpMap may
contain other CmpMaps as components
(\emph{e.g.}\ Figure~\ref{fig:complexcmpmap}). This nesting of CmpMaps
can be repeated indefinitely, so that complex Mappings may be built in
a hierarchical manner out of simper ones.
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.65\textwidth]{sun211_figures/complex}
c-
f+
\includegraphics[width=0.65\textwidth]{sun210_figures/complex}
f-
\caption[CmpMaps may be nested in order to
construct complex Mappings out of simpler building blocks.]{CmpMaps
(compound Mappings) may be nested in order to
construct complex Mappings out of simpler building blocks.}
\label{fig:complexcmpmap}
\end{center}
\end{figure}
This gives AST great flexibility in the coordinate transformations it
can describe.
\textbf{Further reading:} For a more complete description of CmpMaps,
see \secref{ss:cmpmaps}. Also see the CmpMap entry in
\appref{ss:classdescriptions}.
\subsection{Representing Coordinate Systems}
While Mappings (\secref{ss:mappingoverview}) represent the
relationships between coordinate systems in AST, the coordinate
systems themselves are represented by Objects called Frames
(Figure~\ref{fig:frames}).
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.55\textwidth]{sun211_figures/frames}
c-
f+
\includegraphics[width=0.55\textwidth]{sun210_figures/frames}
f-
\caption[Representing coordinate systems as Frames.]{(a) A basic Frame is used to represent a Cartesian coordinate
system, here 2-dimensional. (b) A SkyFrame represents a (spherical)
celestial coordinate system. (c) The axis order of any Frame may be
permuted to match the coordinate space it describes.}
\label{fig:frames}
\end{center}
\end{figure}
A Frame is similar in concept to the frame you might draw around a
graph. It contains information about the labels which appear on the
axes, the axis units, a title, knowledge of how to format the
coordinate values on each axis, \emph{etc.} An AST Frame is not,
however, restricted to two dimensions and may have any number of axes.
c+
A basic Frame may be used to represent a Cartesian coordinate system
by setting values for its \emph{attributes} (all AST Objects have
values associated with them called attributes, which may be set and
enquired). Usually, this would involve setting appropriate axis
labels and units, for example. Functions are provided for use with
Frames to perform operations such as formatting coordinate values as
text, calculating distances between points, interchanging axes,
\emph{etc.}
c-
f+
A basic Frame may be used to represent a Cartesian coordinate system
by setting values for its \emph{attributes} (all AST Objects have
values associated with them called attributes, which may be set and
enquired). Usually, this would involve setting appropriate axis
labels and units, for example. Routines are provided for use with
Frames to perform operations such as formatting coordinate values as
text, calculating distances between points, interchanging axes,
\emph{etc.}
f-
There are several more specialised forms of Frame, which provide the
additional functionality required when handling coordinates within some
specific physical domain. This ranges from tasks such as formatting axis
values, to complex tasks such as determining the transformation between
any pair of related coordinate systems. For instance, the SkyFrame
(Figure~\ref{fig:frames}b,c), represents celestial coordinate systems,
the SpecFrame represents spectral coordinate systems, and the TimeFrame
represents time coordinate systems. All these provide a wide range of
different systems for describing positions within their associated physical
domain, and these may be selected by setting appropriate attributes.
As with compound Mappings (\secref{ss:cmpmapoverview}), it is possible
to merge two Frames together to form a compound Frame, or CmpFrame, in
which both sets of axes are combined. One could, for example, have
celestial coordinates on two axes and an unrelated coordinate
(wavelength, perhaps) on a third (Figure~\ref{fig:cmpframe}).
Knowledge of the relationships between the axes is preserved
internally by the process of constructing the CmpFrame which
represents them.
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.4\textwidth]{sun211_figures/cmpframe}
c-
f+
\includegraphics[width=0.4\textwidth]{sun210_figures/cmpframe}
f-
\caption[A CmpFrame (compound Frame) formed by combining two simpler
Frames.]{A CmpFrame (compound Frame) formed by combining two simpler
Frames. Note how the special relationship which exists between the RA
and Dec axes is preserved within this data structure. As with compound
Mappings (Figure~\ref{fig:complexcmpmap}), CmpFrames may be nested in
order to build more complex Frames.}
\label{fig:cmpframe}
\end{center}
\end{figure}
\textbf{Further reading:} For a more complete description of Frames see
\secref{ss:frames}, for SkyFrames see \secref{ss:skyframes} and for
SpecFrames see \secref{ss:specframes}. Also see the Frame, SkyFrame,
SpecFrame, TimeFrame and CmpFrame entries in \appref{ss:classdescriptions}.
\subsection{Networks of Coordinate Systems}
Mappings and Frames may be connected together to form networks called
FrameSets, which are used to represent sets of inter-related
coordinate systems (Figure~\ref{fig:frameset}).
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.65\textwidth]{sun211_figures/frameset}
c-
f+
\includegraphics[width=0.65\textwidth]{sun210_figures/frameset}
f-
\caption[A FrameSet is a network of Frames.]{A FrameSet is a network of Frames inter-connected by Mappings
such that there is exactly one conversion path, \emph{via} Mappings,
between any pair of Frames.}
\label{fig:frameset}
\end{center}
\end{figure}
A FrameSet may be extended by adding a new Frame to it, together with
an associated Mapping which relates the new coordinate system to one
which is already present. This process ensures that there is always
exactly one path, \emph{via} Mappings, between any pair of Frames. A
function is provided for identifying this path and returning the
complete Mapping.
One of the Frames in a FrameSet is termed its \emph{base} Frame. This
underlies the FrameSet's purpose, which is to calibrate datasets and
other entities by attaching coordinate systems to them. In this
context, the base Frame represents the ``native'' coordinate system
(for example, the pixel coordinates of an image). Similarly, one
Frame is termed the \emph{current} Frame and represents the
``currently-selected'' coordinates. It might, typically, be a
celestial or spectral coordinate system and would be used during
interactions with
a user, as when plotting axes on a graph or producing a table of
results. Other Frames within the FrameSet represent a library of
alternative coordinate systems which a software user can select by
making them current.
\textbf{Further reading:} For a more complete description of
FrameSets, see \secref{ss:framesets} and \secref{ss:fshigher}. Also
see the FrameSet entry in \appref{ss:classdescriptions}.
\subsection{Input/Output Facilities}
AST allows you to convert any kind of Object into a stream of text
which contains a full description of that Object. This text may be
written out by one program and read back in by another, thus allowing
the original Object to be reconstructed.
The filter which converts Objects into text and back again is itself a
kind of Object, called a Channel. A Channel provides a number of
options for controlling the information content of the text, such as
the addition of comments for human interpretation. It is also
possible to intercept the text being processed by a Channel so that it
may be redirected to/from any chosen external data store, such as a
text file, an astronomical dataset, or a network connection.
The text format used by the basic Channel class is peculiar to the AST
library - no other software will understand it. However, more specialised
forms of Channel are provided which use text formats more widely
understood.
To further facilitate the storage of coordinate system information in
astronomical datasets, a more specialised form of Channel called a
FitsChan is provided. Instead of using free-format text, a FitsChan
converts AST Objects to and from FITS header cards. It also allows the
information to be encoded in the FITS cards in a number of ways
(called \emph{encodings}), so that WCS information from a variety of
sources can be handled.
Another sub-class of Channel, called XmlChan, is a specialised form of
Channel that stores the text in the form of XML markup. Currently, two
markup formats are provided by the XmlChan class, one is closely related
to the text format produced by the basic Channel class (currently, no
schema or DTD is available describing this format). The other is a subset
of an early draft of the IVOA Space-Time-Coordinates XML (STC-X) schema
(V1.20) described at
\url{http://www.ivoa.net/Documents/WD/STC/STC-20050225.html
}\footnote{XML documents which use only the subset of the STC schema
supported by AST can be read by the XmlChan class to produce
corresponding AST objects (subclasses of the Stc class). However, the
reverse is not possible. That is, AST objects can not currently be
written out in the form of STC documents.}. The version of STC-X that has
been adopted by the IVOA differs in several significant respects from
V1.20, and therefore this XmlChan format is of historical interest only.
The YamlChan class provides facilities for reading and writing WCS
information stored in YAML format using a subset of the the ASDF model
developed at StSci (see \url{http://asdf-standard.readthedocs.io}).
Finally, the StcsChan class provides facilities for reading and writing
IVOA STC-S region descriptions. STC-S (see
\url{http://www.ivoa.net/Documents/latest/STC-S.html}) is a linear string
syntax that allows simple specification of STC metadata. AST supports a
subset of the STC-S specification, allowing an STC-S description of a
region within an AST-supported astronomical coordinate system to be converted
into an equivalent AST Region object, and vice-versa.
\textbf{Further reading:} For a more complete description of Channels
see \secref{ss:channels} and for FitsChans see \secref{ss:nativefits}
and \secref{ss:foreignfits}. Also see the Channel and FitsChan entries
in \appref{ss:classdescriptions} and the Encoding entry in
\appref{ss:attributedescriptions}.
\subsection{Producing Graphical Output}
Two dimensional graphical output is supported by a specialised form of
FrameSet called
a Plot, whose base Frame corresponds with the native coordinates of
the underlying graphics system. Plotting operations are specified in
\emph{physical coordinates} which correspond with the Plot's current
Frame. Typically, this might be a celestial coordinate system.
Three dimensional plotting is also supported, via the Plot3D class -
sub-class of Plot.
Operations, such as drawing lines, are automatically transformed from
physical to graphical coordinates before plotting, using an adaptive
algorithm which ensures smooth curves (because the transformation is
usually non-linear). ``Missing'' coordinates (\emph{e.g.}\ graphical
coordinates which do not project on to the celestial sphere),
discontinuities and generalised clipping are all consistently handled.
It is possible, for example, to plot in equatorial coordinates and
clip in galactic coordinates. The usual plotting operations are
provided (text, markers), but a geodesic curve replaces the primitive
straight line element. There is also a separate function for drawing
axis lines, since these are normally not geodesics.
In addition to drawing coordinate grids over an area of the sky, another
common use of the Plot class is to produce line plots such as flux
against wavelength, displacement again time, \emph{etc}. For these
situations the current Frame of the Plot would be a compound Frame
(CmpFrame) containing a pair of 1-dimensional Frames - the first
representing the X axis quantity (wavelength, time, etc), and the second
representing the Y axis quantity (flux, displacement, etc). The Plot
class includes an option for axes to be plotted logarithmically.
Perhaps the most useful graphics function available is for drawing
fully annotated coordinate grids (\emph{e.g.}\ Figure~\ref{fig:gridplot}).
\begin{figure}
\begin{center}
c+
\includegraphics[width=0.6\textwidth]{sun211_figures/gridplot_bw}
c-
f+
\includegraphics[width=0.6\textwidth]{sun210_figures/gridplot_bw}
f-
\caption[A labelled coordinate grid for an all-sky zenithal equal area
projection in ecliptic coordinates.]{A labelled coordinate grid for an all-sky zenithal equal area
projection in ecliptic coordinates. This was composed and drawn
\emph{via} a Plot using a
c+
single function call.}
c-
f+
single subroutine call.}
f-
\label{fig:gridplot}
\end{center}
\end{figure}
This uses a general algorithm which does not depend on knowledge of
the coordinates being represented, so can also handle
programmer-defined coordinate systems. Grids for all-sky projections,
including polar regions, can be drawn and most aspects of the output
(colour, line style, \emph{etc.}) can be adjusted by setting
appropriate Plot attributes.
\textbf{Further reading:} For a more complete description of
Plots and how to produce graphical output, see \secref{ss:plots}. Also
see the Plot entry in \appref{ss:classdescriptions}.
\cleardoublepage
\section{\label{ss:howto}How To\ldots}
For those of you with a plane to catch, this section provides some
instant templates and recipes for performing the most
commonly-required operations using AST, but without going into
detail. The examples given (sort of) follow on from each other, so you
should be able to construct a variety of programs by piecing them
together. Note that some of them appear longer than they actually
are, because we have included plenty of comments and a few options
that you probably won't need.
If any of this material has you completely baffled, then you may want
to read the introduction to AST programming concepts in
\secref{ss:primer} first. Otherwise, references to more detailed
reading are given after each example, just in case they don't quite do
what you want.
\subsection{\ldots Obtain and Install AST}
The AST library is available both as a stand-alone package and also as
part of the Starlink Software Collection\footnote{The Starlink Software
Collection can be downloaded from
\url{http://www.starlink.ac.uk/Download/}.}. If your site has the Starlink
Software Collection installed then AST should already be available.
If not, you can download the AST library by itself from
\url{http://www.starlink.ac.uk/ast/}.
\subsection{\ldots Structure an AST Program}
An AST program normally has the following structure:
c+
\begin{small}
\begin{terminalv}
/* Include the interface to the AST library. */
#include "star/ast.h"
/* Main program (or could be any function). */
main () {
<normal C declarations and statements>
/* Enclose the parts which use AST between the astBegin and astEnd macros. */
astBegin;
<C statements which use AST>
astEnd;
<maybe more C statements>
}
\end{terminalv}
\end{small}
c-
f+
\small
\begin{terminalv}
* Include the interface to the AST library.
INCLUDE 'AST_PAR'
* Declare an integer status variable.
INTEGER STATUS
<maybe other declarations>
* Initialise the status to zero.
STATUS = 0
<maybe some Fortran statements>
* Enclose the parts which use AST between AST_BEGIN and AST_END calls.
CALL AST_BEGIN( STATUS )
<Fortran statements which use AST>
CALL AST_END( STATUS )
<maybe more Fortran statements>
END
\end{terminalv}
\normalsize
f-
c+
The use of astBegin and astEnd is optional, but has the effect of
tidying up after you have finished using AST, so is normally
recommended. For more details of this, see \secref{ss:contexts}. For
details of how to access the ``ast.h'' header file, see
\secref{ss:accessingheaderfile}.
c-
f+
The use of AST\_BEGIN and AST\_END is optional, but has the effect of
tidying up after you have finished using AST, so is normally
recommended. For more details of this, see \secref{ss:contexts}. For
details of how to access the AST\_PAR include file, see
\secref{ss:accessingheaderfile}.
f-
\subsection{\label{ss:howtobuild}\ldots Build an AST Program}
To build a simple AST program that doesn't use graphics, use:
c+
\begin{small}
\begin{terminalv}
cc program.c -L/star/lib -I/star/include `ast_link` -o program
\end{terminalv}
\end{small}
c-
f+
\begin{small}
\begin{terminalv}
f77 program.f -L/star/lib -I/star/include `ast_link` -o program
\end{terminalv}
\end{small}
On Linux systems you should usually use \verb+g77 -fno-second-underscore+ in
place of \verb+f77+ - see \xref{``Software development on Linux''}{sun212}
{software_development_on_linux} in \xref{SUN/212}{sun212}{}.
f-
To build a program which uses PGPLOT for graphics, use:
c+
\begin{small}
\begin{terminalv}
cc program.c -L/star/lib `ast_link -pgplot` -o program
\end{terminalv}
\end{small}
c-
f+
\begin{small}
\begin{terminalv}
f77 program.f -L/star/lib `ast_link -pgplot` -o program
\end{terminalv}
\end{small}
again using \verb+g77 -fno-second-underscore+ in place of \verb+f77+
on Linux systems.
f-
c+
For more details about accessing the ``ast.h'' header file, see
\secref{ss:accessingheaderfile}. For more
details about linking programs, see \secref{ss:linking} and the
description of the ``ast\_link'' command in
\appref{ss:commanddescriptions}.
c-
f+
For more details about accessing AST include files, see
\secref{ss:accessingheaderfile}. For more
details about linking programs, see \secref{ss:linking} and the
description of the ``ast\_link'' command in
\appref{ss:commanddescriptions}.
f-
\subsection{\label{ss:howtoreadwcs}\ldots Read a WCS Calibration from a Dataset}
c+
Precisely how you extract world coordinate system (WCS) information
from a dataset obviously depends on what type of dataset it
is. Usually, however, you should be able to obtain a set of FITS
header cards which contain the WCS information (and probably much more
besides). Suppose that ``cards'' is a pointer to a string
containing a complete set of concatenated FITS header cards (such as
produced by the CFITSIO function fits\_hdr2str). Then proceed as follows:
\begin{small}
\begin{terminalv}
fitsfile *fptr;
AstFitsChan *fitschan;
AstFrameSet *wcsinfo;
char *header;
int nkeys, status;
...
/* Obtain all the cards in the header concatenated into a single dynamically
allocated null-terminated character string. Note, we do not exclude
any cards since we may later modify the WCS information within the
header and consequently want to write the entire header out again. */
if( fits_hdr2str( fptr, 0, NULL, 0, &header, &nkeys, &status ) )
printf(" Error getting header\n");
...
/* Header obtained succesfully... */
} else {
/* Create a FitsChan and fill it with FITS header cards. */
fitschan = astFitsChan( NULL, NULL, "" );
astPutCards( fitschan, header );
/* Free the memory holding the concatenated header cards. */
header = free( header );
/* Read WCS information from the FitsChan. */
wcsinfo = astRead( fitschan );
...
\end{terminalv}
\end{small}
c-
f+
Precisely how you extract world coordinate system (WCS) information
from a dataset obviously depends on what type of dataset it
is. Usually, however, you should be able to obtain a set of FITS
header cards which contain the WCS information (and probably much more
besides). Suppose that CARDS is an array of character strings
containing a complete set of FITS header cards and NCARD is the number
of cards. Then proceed as follows:
\small
\begin{terminalv}
INTEGER FITSCHAN, ICARD, NCARD, WCSINFO
CHARACTER * ( 80 ) CARDS( NCARD )
...
* Create a FitsChan and fill it with FITS header cards.
FITSCHAN = AST_FITSCHAN( AST_NULL, AST_NULL, ' ', STATUS )
DO 1 ICARD = 1, NCARD
CALL AST_PUTFITS( FITSCHAN, CARDS( ICARD ), .FALSE., STATUS )
1 CONTINUE
* Rewind the FitsChan and read WCS information from it.
CALL AST_CLEAR( FITSCHAN, 'Card', STATUS )
WCSINFO = AST_READ( FITSCHAN, STATUS )
\end{terminalv}
\normalsize
f-
c+
The result should be a pointer, ``wcsinfo'', to a FrameSet which
contains the WCS information. This pointer can now be used to perform
many useful tasks, some of which are illustrated in the following
recipes.
c-
f+
The result should be a pointer, WCSINFO, to a FrameSet which contains
the WCS information. This pointer can now be used to perform many
useful tasks, some of which are illustrated in the following recipes.
f-
c+
Some datasets which do not easily yield FITS header cards may require
a different approach, possibly involving use of a Channel or XmlChan
(\secref{ss:channels}) rather than a FitsChan. In the case of the
Starlink NDF data format, for example, all the above may be replaced
by a single call to the function
\xref{ndfGtwcs}{sun33}{ndfGtwcs}---see \xref{SUN/33}{sun33}{}. The
whole process can probably be encapsulated in a similar way for
most data systems, whether they use FITS header cards or not.
c-
f+
Some datasets which do not easily yield FITS header cards may require
a different approach, possibly involving use of a Channel or XmlChan
(\secref{ss:channels}) rather than a FitsChan. In the case of the
Starlink NDF data format, for example, all the above may be replaced
by a single call to the routine
\xref{NDF\_GTWCS}{sun33}{NDF_GTWCS}---see \xref{SUN/33}{sun33}{}. The
whole process can probably be encapsulated in a similar way for most
other data systems, whether they use FITS header cards or not.
f-