quickstart.html
7.79 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Getting Started</title>
<link href="gammalib.css" media="screen,print" type="text/css" rel="stylesheet">
</head>
<body>
<p class="Header">Getting started</p>
<p style="padding-top: 0pt; text-align: left;" class="Body"><a href="#First%20steps%20with%20GammaLib">
First steps with GammaLib</a><br>
<a href="#Getting_Help">
Getting Help</a>
</p>
<br>
<p class="Title"><a name="First steps with GammaLib"></a>First
steps with GammaLib</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">GammaLib
comes with a Python interface, and as first step you should verify that
the
Python interfaces workes correctly. You do this by typing:
</p>
<p class="Code">> python<br>
>>> from gammalib import *<br>
>>>
</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">If
everything works fine you should just get a new Python prompt after
importing GammaLib. If you get an error message, make sure that you've
setup correctly the GammaLib environment. You basically need the <span style="font-family: Courier New,Courier,monospace;">PYTHONPATH</span>
variable set to GammaLib's Python site-package, and you also have to
make sure that GammaLib and any dependent library (cfitsio, readline,
ncurses) is in the library load path (eventually you may need to adjust
<span style="font-family: Courier New,Courier,monospace;">LD_LIBRARY_PATH</span>).
This is all done automatically if you set up the environment as
described <a href="installation.html#Setting_up_your_environment">here</a>.</p>
<br>
<p style="padding-top: 0pt; text-align: left;" class="Body">Now
try:
</p>
<p class="Code">>>> models=GModels()<br>
>>> print models<br>
=== GModels ===<br>
Number of models ..........: 0<br>
Number of parameters ......: 0<br>
>>>
</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">You
just alloacted
your first GammaLib object, which is an empty model container.</p>
<br>
<p style="padding-top: 0pt; text-align: left;" class="Body">Now
let's append a model to this container. For this, type:
</p>
<p class="Code">>>> pos = GSkyDir()<br>
>>> pos.radec_deg(83.6331, 22.0145)<br>
>>> spatial = GModelSpatialPtsrc(pos)<br>
>>> spectral = GModelSpectralPlaw(1.0, -2.0)<br>
>>> model = GModelPointSource(spatial, spectral)<br>
>>> models.append(model)<br>
>>> print models<br>
=== GModels ===<br>
Number of models ..........: 1<br>
Number of parameters ......: 6<br>
=== GModelPointSource ===<br>
Name ......................:<br>
Instruments ...............: all<br>
Model type ................: "SkyDirFunction" * "PowerLaw" * "Constant"<br>
Number of parameters ......: 6<br>
Number of spatial par's ...: 2<br>
RA .......................: 83.6331 deg (fixed,scale=1)<br>
DEC ......................: 22.0145 deg (fixed,scale=1)<br>
Number of spectral par's ..: 3<br>
Prefactor ................: 1 +/- 0 [0,infty[ ph/cm2/s/MeV
(free,scale=1,gradient)<br>
Index ....................: -2 +/- 0 [-10,10]
(free,scale=1,gradient)<br>
PivotEnergy ..............: 100 MeV (fixed,scale=1,gradient)<br>
Number of temporal par's ..: 1<br>
Constant .................: 1 (relative value)
(fixed,scale=1,gradient)<br>
>>>
</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">With
this
sequence of commands you first defined a sky direction in celestial
coordinates using <span style="font-family: Courier New,Courier,monospace;">GSkyDir</span>.
You may easily recognise that this is the position of the Crab. You
then used this position to define the spatial component of a sky model
using <span style="font-family: Courier New,Courier,monospace;">GModelSpatialPtsrc</span>.
As the name suggests, the spatial component is a point source. Next,
you defined the spectral component using <span style="font-family: Courier New,Courier,monospace;">GModelSpactralPlaw</span>:
a power law with normalisation of 1 and index of -2. Then, you combined
the spatial and spectral components in a point source model using <span style="font-family: Courier New,Courier,monospace;">GModelPointSource</span>.
And finally you appended the point source to the model container
allocated previously using the <span style="font-family: Courier New,Courier,monospace;">append</span>
method. When you then print the model container you see that is
contains now one model with 6 parameters. Among them, you find the
specified source position (parameters <span style="font-family: Courier New,Courier,monospace;">RA</span>
and <span style="font-family: Courier New,Courier,monospace;">DEC</span>),
the power law normalisation (parameter <span style="font-family: Courier New,Courier,monospace;">Prefactor</span>)
and the spectral index (parameter <span style="font-family: Courier New,Courier,monospace;">Index</span>).
In addition, the reference energy for the normalisation has been set
automatically to 100 MeV (parameter <span style="font-family: Courier New,Courier,monospace;">PivotEnergy</span>)
and the temporal component has been set by default to a constant
(parameter <span style="font-family: Courier New,Courier,monospace;">Constant</span>).</p>
<br>
<p style="padding-top: 0pt; text-align: left;" class="Body">Suppose
you want
to change one of these parameters, such as the <span style="font-family: Courier New,Courier,monospace;">PivotEnergy</span>
that you want
to set to 1 TeV. This can be done using:</p>
<p class="Code">>>>
models[0]['PivotEnergy'].value(1.0e6)<br>
>>> print models<br>
...<br>
PivotEnergy ..............: 1e+06 MeV (fixed,scale=1,gradient)<br>
...<br>
</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">As
the units are MeV, we had to specify a value of 1e6 to set the
reference energy to 1 TeV. We did this by accessing the first model in
the container using <span style="font-family: Courier New,Courier,monospace;">models[0]</span>
(counting in GammaLib always starts from 0). Then we addressed the <span style="font-family: Courier New,Courier,monospace;">PivotEnergy</span>
parameter by specifying <span style="font-family: Courier New,Courier,monospace;">['PivotEnergy']</span>.
And finally we called the <span style="font-family: Courier New,Courier,monospace;">value</span>
method that sets the value of a particular parameter.</p>
<br>
<p style="padding-top: 0pt; text-align: left;" class="Body">After
all this
hard work, you may save your model into a XML file by typing:</p>
<p class="Code">>>>
models.save('test.xml')<br>
>>><br>
</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">and
you
can load it from an XML file in memory using</p>
<p class="Code">>>>
newmodels=GModels('test.xml')<br>
>>> print newmodels<br>
</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">The
last
print command is to convince yourself that the models have been
loaded properly.</p>
<br>
<p style="padding-top: 0pt; text-align: left;" class="Body">Much
more is still to come. Please be a little bit patient, I'm working on
it. In the meantime you may check the <a href="doxygen.html">Doxygen
documentation</a> to see what classes and methods are available.</p>
<br>
<p class="Title"><a name="Getting_Help"></a>Getting
Help</p>
<p style="padding-top: 0pt; text-align: left;" class="Body">
Any questions, bug reports, or suggested enhancements related to
GammaLib should be submitted
via the Tracker on <a href="https://sourceforge.net/projects/gammalib/" target="_blank">https://sourceforge.net/projects/gammalib/</a>
or the
<a href="mailto:gammalib-users@lists.soureforge.net">gammalib-users@lists.sourceforge.net</a>
mailing list.
</p>
<br>
<hr size="1">
<p class="Body">Last updated by: Jürgen
Knödlseder 20 July
2011
</p>
</body></html>