Commit c0a3fbd10536ba8a487a0f03afad094213f76da0
1 parent
48e1ba13
Add "howto" tutorials to check-tutorials target
Showing
10 changed files
with
302 additions
and
111 deletions
doc/source/users/tutorials/howto/extended_model.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| 2 | +<source_library title="source library"> | ||
| 3 | + <source name="Src001" type="PointSource"> | ||
| 4 | + <spectrum type="ExponentialCutoffPowerLaw"> | ||
| 5 | + <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 6 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | ||
| 7 | + <parameter name="CutoffEnergy" scale="1e7" value="1.0" min="0.01" max="1000.0" free="1"/> | ||
| 8 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 9 | + </spectrum> | ||
| 10 | + <spatialModel type="PointSource"> | ||
| 11 | + <parameter name="RA" scale="1" value="266.424" free="1" /> | ||
| 12 | + <parameter name="DEC" scale="1" value="-29.005" free="1" /> | ||
| 13 | + </spatialModel> | ||
| 14 | + </source> | ||
| 15 | + <source name="Src002" type="PointSource"> | ||
| 16 | + <spectrum type="PowerLaw"> | ||
| 17 | + <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 18 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="5.0" free="1"/> | ||
| 19 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 20 | + </spectrum> | ||
| 21 | + <spatialModel type="PointSource"> | ||
| 22 | + <parameter name="RA" scale="1" value="266.832" free="1" /> | ||
| 23 | + <parameter name="DEC" scale="1" value="-28.146" free="1" /> | ||
| 24 | + </spatialModel> | ||
| 25 | + </source> | ||
| 26 | + <source name="Src003" type="ExtendedSource" tscalc="1"> | ||
| 27 | + <spectrum type="PowerLaw"> | ||
| 28 | + <parameter name="Prefactor" scale="5.7e-18" value="1.0" min="0" max="1000.0" free="1"/> | ||
| 29 | + <parameter name="Index" scale="-2.48" value="1.0" min="-4.0" max="4.0" free="1"/> | ||
| 30 | + <parameter name="PivotEnergy" scale="300000" value="1.0" free="0" /> | ||
| 31 | + </spectrum> | ||
| 32 | + <spatialModel type="RadialDisk"> | ||
| 33 | + <parameter name="RA" scale="1.0" value="266.3070" min="-360" max="360" free="1"/> | ||
| 34 | + <parameter name="DEC" scale="1.0" value="-30.1876" min="-90" max="90" free="1"/> | ||
| 35 | + <parameter name="Radius" scale="1.0" value="0.3" min="0.001" max="10" free="1"/> | ||
| 36 | + </spatialModel> | ||
| 37 | + </source> | ||
| 38 | + <source name="IEM" type="DiffuseSource"> | ||
| 39 | + <spectrum type="ConstantValue"> | ||
| 40 | + <parameter name="Value" scale="1" value="1" min="1e-05" max="100000" free="1"/> | ||
| 41 | + </spectrum> | ||
| 42 | + <spatialModel type="MapCubeFunction" file="$CTADATA/models/cube_iem.fits"> | ||
| 43 | + <parameter name="Normalization" scale="1" value="1" min="0.001" max="1000" free="0"/> | ||
| 44 | + </spatialModel> | ||
| 45 | + </source> | ||
| 46 | + <source name="Background" type="CTACubeBackground" instrument="CTA"> | ||
| 47 | + <spectrum type="PowerLaw"> | ||
| 48 | + <parameter name="Prefactor" scale="1" value="1" min="0.01" max="100" free="1"/> | ||
| 49 | + <parameter name="Index" scale="1" value="0" min="-5" max="5" free="1"/> | ||
| 50 | + <parameter name="PivotEnergy" scale="1000000" value="1" min="0.01" max="1000.0" free="0"/> | ||
| 51 | + </spectrum> | ||
| 52 | + </source> | ||
| 53 | +</source_library> |
doc/source/users/tutorials/howto/howto_connect_irfs.rst
| @@ -52,21 +52,11 @@ array: | @@ -52,21 +52,11 @@ array: | ||
| 52 | Output event data file or observation definition XML file [north.fits] south.fits | 52 | Output event data file or observation definition XML file [north.fits] south.fits |
| 53 | 53 | ||
| 54 | You now need to combine the information about these two observations in an | 54 | You now need to combine the information about these two observations in an |
| 55 | -observation definition XML file: | 55 | +observation definition XML file. Let's put the following content in in the |
| 56 | +``obs_irf.xml``: | ||
| 56 | 57 | ||
| 57 | -.. code-block:: xml | ||
| 58 | - | ||
| 59 | - <?xml version="1.0" standalone="no"?> | ||
| 60 | - <observation_list title="observation library"> | ||
| 61 | - <observation name="Crab" id="00001" instrument="CTA"> | ||
| 62 | - <parameter name="EventList" file="north.fits"/> | ||
| 63 | - <parameter name="Calibration" database="prod2" response="North_0.5h"/> | ||
| 64 | - </observation> | ||
| 65 | - <observation name="Crab" id="00002" instrument="CTA"> | ||
| 66 | - <parameter name="EventList" file="south.fits"/> | ||
| 67 | - <parameter name="Calibration" database="prod2" response="South_0.5h"/> | ||
| 68 | - </observation> | ||
| 69 | - </observation_list> | 58 | +.. literalinclude:: obs_irf.xml |
| 59 | + :language: xml | ||
| 70 | 60 | ||
| 71 | Each observation now has a ``Calibration`` parameter with the attributes | 61 | Each observation now has a ``Calibration`` parameter with the attributes |
| 72 | ``database`` and ``response``. | 62 | ``database`` and ``response``. |
doc/source/users/tutorials/howto/howto_extent.rst
| @@ -33,22 +33,12 @@ To do this, copy the 1DC :ref:`model definition <glossary_moddef>` file | @@ -33,22 +33,12 @@ To do this, copy the 1DC :ref:`model definition <glossary_moddef>` file | ||
| 33 | 33 | ||
| 34 | $ cp $CTOOLS/share/models/1dc_howto.xml extended_model.xml | 34 | $ cp $CTOOLS/share/models/1dc_howto.xml extended_model.xml |
| 35 | 35 | ||
| 36 | -and add the following source to it | ||
| 37 | - | ||
| 38 | -.. code-block:: xml | ||
| 39 | - | ||
| 40 | - <source name="Src003" type="ExtendedSource" tscalc="1"> | ||
| 41 | - <spectrum type="PowerLaw"> | ||
| 42 | - <parameter name="Prefactor" scale="5.7e-18" value="1.0" min="0" max="1000.0" free="1"/> | ||
| 43 | - <parameter name="Index" scale="-2.48" value="1.0" min="-4.0" max="4.0" free="1"/> | ||
| 44 | - <parameter name="PivotEnergy" scale="300000" value="1.0" free="0" /> | ||
| 45 | - </spectrum> | ||
| 46 | - <spatialModel type="RadialDisk"> | ||
| 47 | - <parameter name="RA" scale="1.0" value="266.3070" min="-360" max="360" free="1"/> | ||
| 48 | - <parameter name="DEC" scale="1.0" value="-30.1876" min="-90" max="90" free="1"/> | ||
| 49 | - <parameter name="Radius" scale="1.0" value="0.3" min="0.001" max="10" free="1"/> | ||
| 50 | - </spatialModel> | ||
| 51 | - </source> | 36 | +to :download:`extended_model.xml <extended_model.xml>` and add the following |
| 37 | +source to it: | ||
| 38 | + | ||
| 39 | +.. literalinclude:: extended_model.xml | ||
| 40 | + :language: xml | ||
| 41 | + :lines: 26-37 | ||
| 52 | 42 | ||
| 53 | Then run :ref:`ctlike` to fit the parameters of ``Src003`` together with the | 43 | Then run :ref:`ctlike` to fit the parameters of ``Src003`` together with the |
| 54 | other source parameters | 44 | other source parameters |
doc/source/users/tutorials/howto/howto_ts.rst
| @@ -19,28 +19,13 @@ Copy the 1DC :ref:`model definition <glossary_moddef>` file | @@ -19,28 +19,13 @@ Copy the 1DC :ref:`model definition <glossary_moddef>` file | ||
| 19 | $ cp $CTOOLS/share/models/1dc_howto.xml ts_model.xml | 19 | $ cp $CTOOLS/share/models/1dc_howto.xml ts_model.xml |
| 20 | 20 | ||
| 21 | and modify the file by adding ``tscalc="1"`` to the ``<source>`` tag for | 21 | and modify the file by adding ``tscalc="1"`` to the ``<source>`` tag for |
| 22 | -source ``Src1``. Your | 22 | +source ``Src1``. The first lines of the :download:`ts_model.xml <ts_model.xml>` |
| 23 | :ref:`model definition XML file <glossary_moddef>` | 23 | :ref:`model definition XML file <glossary_moddef>` |
| 24 | should then look like this: | 24 | should then look like this: |
| 25 | 25 | ||
| 26 | -.. code-block:: xml | ||
| 27 | - | ||
| 28 | - <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| 29 | - <source_library title="source library"> | ||
| 30 | - <source name="Src001" type="PointSource" tscalc="1"> | ||
| 31 | - <spectrum type="ExponentialCutoffPowerLaw"> | ||
| 32 | - <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 33 | - <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | ||
| 34 | - <parameter name="CutoffEnergy" scale="1e7" value="1.0" min="0.01" max="1000.0" free="1"/> | ||
| 35 | - <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 36 | - </spectrum> | ||
| 37 | - <spatialModel type="PointSource"> | ||
| 38 | - <parameter name="RA" scale="1" value="266.424" free="1" /> | ||
| 39 | - <parameter name="DEC" scale="1" value="-29.005" free="1" /> | ||
| 40 | - </spatialModel> | ||
| 41 | - </source> | ||
| 42 | - ... | ||
| 43 | - </source_library> | 26 | +.. literalinclude:: ts_model.xml |
| 27 | + :language: xml | ||
| 28 | + :lines: 1-14 | ||
| 44 | 29 | ||
| 45 | Then run :ref:`ctlike` to compute the so-called Test Statistic, which is twice | 30 | Then run :ref:`ctlike` to compute the so-called Test Statistic, which is twice |
| 46 | the difference between the log-likelihood value obtained for a fit that includes | 31 | the difference between the log-likelihood value obtained for a fit that includes |
doc/source/users/tutorials/howto/howto_tsmap.rst
| @@ -100,12 +100,13 @@ The figure below shows the resulting Test Statistic map. | @@ -100,12 +100,13 @@ The figure below shows the resulting Test Statistic map. | ||
| 100 | cttsmap inobs=cntcube.fits inmodel=$CTOOLS/share/models/test_cube.xml srcname=Test expcube=expcube.fits psfcube=psfcube.fits bkgcube=bkgcube.fits nxpix=10 nypix=10 binsz=0.05 coordsys=GAL proj=CAR xref=0.0 yref=0.0 logL0=-447785.5939102234 binmin=70 binmax=80 outmap=tsmap_split_7.fits logfile=tsmap_split_7.log & | 100 | cttsmap inobs=cntcube.fits inmodel=$CTOOLS/share/models/test_cube.xml srcname=Test expcube=expcube.fits psfcube=psfcube.fits bkgcube=bkgcube.fits nxpix=10 nypix=10 binsz=0.05 coordsys=GAL proj=CAR xref=0.0 yref=0.0 logL0=-447785.5939102234 binmin=70 binmax=80 outmap=tsmap_split_7.fits logfile=tsmap_split_7.log & |
| 101 | cttsmap inobs=cntcube.fits inmodel=$CTOOLS/share/models/test_cube.xml srcname=Test expcube=expcube.fits psfcube=psfcube.fits bkgcube=bkgcube.fits nxpix=10 nypix=10 binsz=0.05 coordsys=GAL proj=CAR xref=0.0 yref=0.0 logL0=-447785.5939102234 binmin=80 binmax=90 outmap=tsmap_split_8.fits logfile=tsmap_split_8.log & | 101 | cttsmap inobs=cntcube.fits inmodel=$CTOOLS/share/models/test_cube.xml srcname=Test expcube=expcube.fits psfcube=psfcube.fits bkgcube=bkgcube.fits nxpix=10 nypix=10 binsz=0.05 coordsys=GAL proj=CAR xref=0.0 yref=0.0 logL0=-447785.5939102234 binmin=80 binmax=90 outmap=tsmap_split_8.fits logfile=tsmap_split_8.log & |
| 102 | cttsmap inobs=cntcube.fits inmodel=$CTOOLS/share/models/test_cube.xml srcname=Test expcube=expcube.fits psfcube=psfcube.fits bkgcube=bkgcube.fits nxpix=10 nypix=10 binsz=0.05 coordsys=GAL proj=CAR xref=0.0 yref=0.0 logL0=-447785.5939102234 binmin=90 binmax=100 outmap=tsmap_split_9.fits logfile=tsmap_split_9.log & | 102 | cttsmap inobs=cntcube.fits inmodel=$CTOOLS/share/models/test_cube.xml srcname=Test expcube=expcube.fits psfcube=psfcube.fits bkgcube=bkgcube.fits nxpix=10 nypix=10 binsz=0.05 coordsys=GAL proj=CAR xref=0.0 yref=0.0 logL0=-447785.5939102234 binmin=90 binmax=100 outmap=tsmap_split_9.fits logfile=tsmap_split_9.log & |
| 103 | + wait | ||
| 103 | 104 | ||
| 104 | Now run the ASCII file by typing | 105 | Now run the ASCII file by typing |
| 105 | 106 | ||
| 106 | .. code-block:: bash | 107 | .. code-block:: bash |
| 107 | 108 | ||
| 108 | - ./tsmap_commands.dat | 109 | + $ ./tsmap_commands.dat |
| 109 | 110 | ||
| 110 | This will execute 10 :ref:`cttsmap` jobs in parallel. Each of the jobs will | 111 | This will execute 10 :ref:`cttsmap` jobs in parallel. Each of the jobs will |
| 111 | compute 10 pixels of the Test Statistic map. You combine the resulting 10 | 112 | compute 10 pixels of the Test Statistic map. You combine the resulting 10 |
doc/source/users/tutorials/howto/howto_ulimit.rst
| @@ -22,21 +22,12 @@ To do this, copy the 1DC :ref:`model definition <glossary_moddef>` file | @@ -22,21 +22,12 @@ To do this, copy the 1DC :ref:`model definition <glossary_moddef>` file | ||
| 22 | 22 | ||
| 23 | $ cp $CTOOLS/share/models/1dc_howto.xml ulimit_model.xml | 23 | $ cp $CTOOLS/share/models/1dc_howto.xml ulimit_model.xml |
| 24 | 24 | ||
| 25 | -and add the following source to it | ||
| 26 | - | ||
| 27 | -.. code-block:: xml | ||
| 28 | - | ||
| 29 | - <source name="Test" type="PointSource"> | ||
| 30 | - <spectrum type="PowerLaw"> | ||
| 31 | - <parameter name="Prefactor" value="1" scale="1.0e-20" min="0" free="1"/> | ||
| 32 | - <parameter name="Index" value="1" scale="-2.48" min="-5" max="5" free="0"/> | ||
| 33 | - <parameter name="PivotEnergy" value="1" scale="300000" free="0"/> | ||
| 34 | - </spectrum> | ||
| 35 | - <spatialModel type="PointSource"> | ||
| 36 | - <parameter name="GLON" value="0.1" scale="1" free="0"/> | ||
| 37 | - <parameter name="GLAT" value="0.4" scale="1" free="0"/> | ||
| 38 | - </spatialModel> | ||
| 39 | - </source> | 25 | +to :download:`ulimit_model.xml <ulimit_model.xml>` and add the following |
| 26 | +source to it: | ||
| 27 | + | ||
| 28 | +.. literalinclude:: ulimit_model.xml | ||
| 29 | + :language: xml | ||
| 30 | + :lines: 3-13 | ||
| 40 | 31 | ||
| 41 | Now run the :ref:`ctulimit` tool as follows: | 32 | Now run the :ref:`ctulimit` tool as follows: |
| 42 | 33 |
doc/source/users/tutorials/howto/obs_irf.xml
0 → 100644
| 1 | +<?xml version="1.0" standalone="no"?> | ||
| 2 | +<observation_list title="observation library"> | ||
| 3 | + <observation name="Crab" id="00001" instrument="CTA"> | ||
| 4 | + <parameter name="EventList" file="north.fits"/> | ||
| 5 | + <parameter name="Calibration" database="prod2" response="North_0.5h"/> | ||
| 6 | + </observation> | ||
| 7 | + <observation name="Crab" id="00002" instrument="CTA"> | ||
| 8 | + <parameter name="EventList" file="south.fits"/> | ||
| 9 | + <parameter name="Calibration" database="prod2" response="South_0.5h"/> | ||
| 10 | + </observation> | ||
| 11 | +</observation_list> | ||
| 12 | + |
doc/source/users/tutorials/howto/ts_model.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| 2 | +<source_library title="source library"> | ||
| 3 | + <source name="Src001" type="PointSource" tscalc="1"> | ||
| 4 | + <spectrum type="ExponentialCutoffPowerLaw"> | ||
| 5 | + <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 6 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | ||
| 7 | + <parameter name="CutoffEnergy" scale="1e7" value="1.0" min="0.01" max="1000.0" free="1"/> | ||
| 8 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 9 | + </spectrum> | ||
| 10 | + <spatialModel type="PointSource"> | ||
| 11 | + <parameter name="RA" scale="1" value="266.424" free="1" /> | ||
| 12 | + <parameter name="DEC" scale="1" value="-29.005" free="1" /> | ||
| 13 | + </spatialModel> | ||
| 14 | + </source> | ||
| 15 | + <source name="Src002" type="PointSource"> | ||
| 16 | + <spectrum type="PowerLaw"> | ||
| 17 | + <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 18 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="5.0" free="1"/> | ||
| 19 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 20 | + </spectrum> | ||
| 21 | + <spatialModel type="PointSource"> | ||
| 22 | + <parameter name="RA" scale="1" value="266.832" free="1" /> | ||
| 23 | + <parameter name="DEC" scale="1" value="-28.146" free="1" /> | ||
| 24 | + </spatialModel> | ||
| 25 | + </source> | ||
| 26 | + <source name="IEM" type="DiffuseSource"> | ||
| 27 | + <spectrum type="ConstantValue"> | ||
| 28 | + <parameter name="Value" scale="1" value="1" min="1e-05" max="100000" free="1"/> | ||
| 29 | + </spectrum> | ||
| 30 | + <spatialModel type="MapCubeFunction" file="$CTADATA/models/cube_iem.fits"> | ||
| 31 | + <parameter name="Normalization" scale="1" value="1" min="0.001" max="1000" free="0"/> | ||
| 32 | + </spatialModel> | ||
| 33 | + </source> | ||
| 34 | + <source name="Background" type="CTACubeBackground" instrument="CTA"> | ||
| 35 | + <spectrum type="PowerLaw"> | ||
| 36 | + <parameter name="Prefactor" scale="1" value="1" min="0.01" max="100" free="1"/> | ||
| 37 | + <parameter name="Index" scale="1" value="0" min="-5" max="5" free="1"/> | ||
| 38 | + <parameter name="PivotEnergy" scale="1000000" value="1" min="0.01" max="1000.0" free="0"/> | ||
| 39 | + </spectrum> | ||
| 40 | + </source> | ||
| 41 | +</source_library> |
doc/source/users/tutorials/howto/ulimit_model.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| 2 | +<source_library title="source library"> | ||
| 3 | + <source name="Test" type="PointSource"> | ||
| 4 | + <spectrum type="PowerLaw"> | ||
| 5 | + <parameter name="Prefactor" value="1" scale="1.0e-20" min="0" free="1"/> | ||
| 6 | + <parameter name="Index" value="1" scale="-2.48" min="-5" max="5" free="0"/> | ||
| 7 | + <parameter name="PivotEnergy" value="1" scale="300000" free="0"/> | ||
| 8 | + </spectrum> | ||
| 9 | + <spatialModel type="PointSource"> | ||
| 10 | + <parameter name="GLON" value="0.1" scale="1" free="0"/> | ||
| 11 | + <parameter name="GLAT" value="0.4" scale="1" free="0"/> | ||
| 12 | + </spatialModel> | ||
| 13 | + </source> | ||
| 14 | + <source name="Src001" type="PointSource"> | ||
| 15 | + <spectrum type="ExponentialCutoffPowerLaw"> | ||
| 16 | + <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 17 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | ||
| 18 | + <parameter name="CutoffEnergy" scale="1e7" value="1.0" min="0.01" max="1000.0" free="1"/> | ||
| 19 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 20 | + </spectrum> | ||
| 21 | + <spatialModel type="PointSource"> | ||
| 22 | + <parameter name="RA" scale="1" value="266.424" free="1" /> | ||
| 23 | + <parameter name="DEC" scale="1" value="-29.005" free="1" /> | ||
| 24 | + </spatialModel> | ||
| 25 | + </source> | ||
| 26 | + <source name="Src002" type="PointSource"> | ||
| 27 | + <spectrum type="PowerLaw"> | ||
| 28 | + <parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/> | ||
| 29 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="5.0" free="1"/> | ||
| 30 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | ||
| 31 | + </spectrum> | ||
| 32 | + <spatialModel type="PointSource"> | ||
| 33 | + <parameter name="RA" scale="1" value="266.832" free="1" /> | ||
| 34 | + <parameter name="DEC" scale="1" value="-28.146" free="1" /> | ||
| 35 | + </spatialModel> | ||
| 36 | + </source> | ||
| 37 | + <source name="IEM" type="DiffuseSource"> | ||
| 38 | + <spectrum type="ConstantValue"> | ||
| 39 | + <parameter name="Value" scale="1" value="1" min="1e-05" max="100000" free="1"/> | ||
| 40 | + </spectrum> | ||
| 41 | + <spatialModel type="MapCubeFunction" file="$CTADATA/models/cube_iem.fits"> | ||
| 42 | + <parameter name="Normalization" scale="1" value="1" min="0.001" max="1000" free="0"/> | ||
| 43 | + </spatialModel> | ||
| 44 | + </source> | ||
| 45 | + <source name="Background" type="CTACubeBackground" instrument="CTA"> | ||
| 46 | + <spectrum type="PowerLaw"> | ||
| 47 | + <parameter name="Prefactor" scale="1" value="1" min="0.01" max="100" free="1"/> | ||
| 48 | + <parameter name="Index" scale="1" value="0" min="-5" max="5" free="1"/> | ||
| 49 | + <parameter name="PivotEnergy" scale="1000000" value="1" min="0.01" max="1000.0" free="0"/> | ||
| 50 | + </spectrum> | ||
| 51 | + </source> | ||
| 52 | +</source_library> |
test/tutorials.py
| @@ -25,6 +25,7 @@ | @@ -25,6 +25,7 @@ | ||
| 25 | # ========================================================================== | 25 | # ========================================================================== |
| 26 | import os | 26 | import os |
| 27 | import sys | 27 | import sys |
| 28 | +import stat | ||
| 28 | import subprocess | 29 | import subprocess |
| 29 | import gammalib | 30 | import gammalib |
| 30 | import ctools | 31 | import ctools |
| @@ -49,6 +50,7 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -49,6 +50,7 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 49 | # Initialise private members | 50 | # Initialise private members |
| 50 | self._rst_step = 0 # Step counter | 51 | self._rst_step = 0 # Step counter |
| 51 | self._rst_path = '' # Path where the tested RST file resides | 52 | self._rst_path = '' # Path where the tested RST file resides |
| 53 | + self._cwd = '.' # Current working directory | ||
| 52 | 54 | ||
| 53 | # Return | 55 | # Return |
| 54 | return | 56 | return |
| @@ -74,6 +76,9 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -74,6 +76,9 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 74 | path : str | 76 | path : str |
| 75 | Result directory path | 77 | Result directory path |
| 76 | """ | 78 | """ |
| 79 | + # Set default working directory | ||
| 80 | + os.chdir(self._cwd) | ||
| 81 | + | ||
| 77 | # Create result directory | 82 | # Create result directory |
| 78 | try: | 83 | try: |
| 79 | os.makedirs(path) | 84 | os.makedirs(path) |
| @@ -111,7 +116,7 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -111,7 +116,7 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 111 | cmdline = cmd.split(' ') | 116 | cmdline = cmd.split(' ') |
| 112 | 117 | ||
| 113 | # Check command line | 118 | # Check command line |
| 114 | - self.test_assert((len(cmdline) > 0), 'Test command.', cmd) | 119 | + self.test_assert((len(cmdline) > 0), 'Test that command line is not empty.', cmd) |
| 115 | 120 | ||
| 116 | # Continue only if valid | 121 | # Continue only if valid |
| 117 | if len(cmdline) > 0: | 122 | if len(cmdline) > 0: |
| @@ -121,7 +126,7 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -121,7 +126,7 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 121 | 126 | ||
| 122 | # Handle "mkdir" command | 127 | # Handle "mkdir" command |
| 123 | if command == 'mkdir': | 128 | if command == 'mkdir': |
| 124 | - self.test_value(len(cmdline), 2, 'Test command "mkdir".') | 129 | + self.test_value(len(cmdline), 2, 'Test number of arguments for "mkdir".') |
| 125 | self.test_value(len(args), 0, 'Test that no lines follow "mkdir".') | 130 | self.test_value(len(args), 0, 'Test that no lines follow "mkdir".') |
| 126 | if len(cmdline) > 1: | 131 | if len(cmdline) > 1: |
| 127 | dirname = gammalib.strip_whitespace(cmdline[1]) | 132 | dirname = gammalib.strip_whitespace(cmdline[1]) |
| @@ -129,15 +134,24 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -129,15 +134,24 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 129 | 134 | ||
| 130 | # Handle "cd" command | 135 | # Handle "cd" command |
| 131 | elif command == 'cd': | 136 | elif command == 'cd': |
| 132 | - self.test_value(len(cmdline), 2, 'Test command "cd".') | 137 | + self.test_value(len(cmdline), 2, 'Test number of arguments for "cd".') |
| 133 | self.test_value(len(args), 0, 'Test that no lines follow "cd".') | 138 | self.test_value(len(args), 0, 'Test that no lines follow "cd".') |
| 134 | if len(cmdline) > 1: | 139 | if len(cmdline) > 1: |
| 135 | dirname = gammalib.strip_whitespace(cmdline[1]) | 140 | dirname = gammalib.strip_whitespace(cmdline[1]) |
| 136 | os.chdir(dirname) | 141 | os.chdir(dirname) |
| 137 | 142 | ||
| 143 | + # Handle "cp" command | ||
| 144 | + elif command == 'cp': | ||
| 145 | + self.test_value(len(cmdline), 3, 'Test number of arguments for "cp".') | ||
| 146 | + self.test_value(len(args), 0, 'Test that no lines follow "cp".') | ||
| 147 | + if len(cmdline) > 2: | ||
| 148 | + src = gammalib.expand_env(gammalib.strip_whitespace(cmdline[1])) | ||
| 149 | + dst = gammalib.expand_env(gammalib.strip_whitespace(cmdline[2])) | ||
| 150 | + os.system('cp %s %s' % (src, dst)) | ||
| 151 | + | ||
| 138 | # Handle "nano" command | 152 | # Handle "nano" command |
| 139 | elif command == 'nano': | 153 | elif command == 'nano': |
| 140 | - self.test_value(len(cmdline), 2, 'Test command "nano".') | 154 | + self.test_value(len(cmdline), 2, 'Test number of arguments for "nano".') |
| 141 | self.test_assert((len(args) > 0), 'Test that lines follow "nano".') | 155 | self.test_assert((len(args) > 0), 'Test that lines follow "nano".') |
| 142 | if len(cmdline) > 1: | 156 | if len(cmdline) > 1: |
| 143 | fname = gammalib.strip_whitespace(cmdline[1]) | 157 | fname = gammalib.strip_whitespace(cmdline[1]) |
| @@ -146,11 +160,22 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -146,11 +160,22 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 146 | f.write(arg) | 160 | f.write(arg) |
| 147 | f.close() | 161 | f.close() |
| 148 | 162 | ||
| 149 | - # Handle special plotting scripts | 163 | + # Handle script execution |
| 150 | elif command[0:2] == './': | 164 | elif command[0:2] == './': |
| 151 | 165 | ||
| 166 | + # Set script name. If the script does not exist in result | ||
| 167 | + # directory then assume it exists in Sphinx rst directory | ||
| 168 | + if os.path.isfile(command[2:]): | ||
| 169 | + script = './%s' % (command[2:]) | ||
| 170 | + else: | ||
| 171 | + script = '%s/%s' % (self._rst_path, command[2:]) | ||
| 172 | + | ||
| 173 | + # Make sure that script is executable | ||
| 174 | + mode = os.stat(script).st_mode | ||
| 175 | + mode |= (mode & 0o444) >> 2 | ||
| 176 | + os.chmod(script, mode) | ||
| 177 | + | ||
| 152 | # Build command line | 178 | # Build command line |
| 153 | - script = '%s/%s' % (self._rst_path, command[2:]) | ||
| 154 | plotname, _ = os.path.splitext(command[2:]) | 179 | plotname, _ = os.path.splitext(command[2:]) |
| 155 | cmd = '%s -p %s.png' % (script, plotname) | 180 | cmd = '%s -p %s.png' % (script, plotname) |
| 156 | self.test_assert((len(args) == 0), 'Test script "%s".' % command[2:]) | 181 | self.test_assert((len(args) == 0), 'Test script "%s".' % command[2:]) |
| @@ -173,7 +198,7 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -173,7 +198,7 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 173 | os.remove('tutorials_test_output.dmp') | 198 | os.remove('tutorials_test_output.dmp') |
| 174 | 199 | ||
| 175 | # Set error flag and text | 200 | # Set error flag and text |
| 176 | - name = 'Test execution of %s.' % command[2:] | 201 | + name = 'Test execution of "%s".' % command[2:] |
| 177 | self.test_value(rc, 0, name, msg) | 202 | self.test_value(rc, 0, name, msg) |
| 178 | 203 | ||
| 179 | # Handle plotting scripts | 204 | # Handle plotting scripts |
| @@ -204,9 +229,13 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -204,9 +229,13 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 204 | os.remove('tutorials_test_output.dmp') | 229 | os.remove('tutorials_test_output.dmp') |
| 205 | 230 | ||
| 206 | # Set error flag and text | 231 | # Set error flag and text |
| 207 | - name = 'Test execution of %s.' % script | 232 | + name = 'Test execution of "%s".' % script |
| 208 | self.test_value(rc, 0, name, msg) | 233 | self.test_value(rc, 0, name, msg) |
| 209 | 234 | ||
| 235 | + # Handle unsupported Xspec commands | ||
| 236 | + elif command[0:5] == 'xspec': | ||
| 237 | + pass | ||
| 238 | + | ||
| 210 | # Signal that the command was not known | 239 | # Signal that the command was not known |
| 211 | else: | 240 | else: |
| 212 | name = 'Test command "%s".' % command | 241 | name = 'Test command "%s".' % command |
| @@ -288,13 +317,10 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -288,13 +317,10 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 288 | arg = gammalib.strip_whitespace(line[pos+1:]) | 317 | arg = gammalib.strip_whitespace(line[pos+1:]) |
| 289 | args += '%s\n' % arg | 318 | args += '%s\n' % arg |
| 290 | 319 | ||
| 291 | - # Debug: show tool | ||
| 292 | - #print cmd, | ||
| 293 | - | ||
| 294 | # Create subprocess for tool | 320 | # Create subprocess for tool |
| 295 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, | 321 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 296 | - stdin=subprocess.PIPE, | ||
| 297 | - stderr=subprocess.PIPE) | 322 | + stdin=subprocess.PIPE, |
| 323 | + stderr=subprocess.PIPE) | ||
| 298 | 324 | ||
| 299 | # Write command line parameters | 325 | # Write command line parameters |
| 300 | p.stdin.write(b'%s' % args) | 326 | p.stdin.write(b'%s' % args) |
| @@ -305,9 +331,18 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -305,9 +331,18 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 305 | # Close pipeline | 331 | # Close pipeline |
| 306 | p.stdin.close() | 332 | p.stdin.close() |
| 307 | 333 | ||
| 308 | - # Set error flag and text | ||
| 309 | - name = 'Test execution of %s.' % tool | ||
| 310 | - self.test_assert((len(res[1]) == 0), name, res[1]) | 334 | + # Set error flag and message |
| 335 | + if '*** ERROR' in res[0]: | ||
| 336 | + success = False | ||
| 337 | + msg = res[0] | ||
| 338 | + elif len(res[1]) > 0: | ||
| 339 | + success = False | ||
| 340 | + msg = res[1] | ||
| 341 | + else: | ||
| 342 | + success = True | ||
| 343 | + msg = '' | ||
| 344 | + name = 'Test execution of "%s".' % tool | ||
| 345 | + self.test_assert(success, name, msg) | ||
| 311 | 346 | ||
| 312 | # Preprend step counter to logfile | 347 | # Preprend step counter to logfile |
| 313 | logfile = gammalib.GFilename('%s.log' % (cmd[0])) | 348 | logfile = gammalib.GFilename('%s.log' % (cmd[0])) |
| @@ -436,11 +471,15 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -436,11 +471,15 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 436 | """ | 471 | """ |
| 437 | Set all test functions | 472 | Set all test functions |
| 438 | """ | 473 | """ |
| 474 | + # Set current working directory | ||
| 475 | + self._cwd = os.path.abspath(os.getcwd()) | ||
| 476 | + | ||
| 439 | # Set test name | 477 | # Set test name |
| 440 | self.name('Tutorials Verification') | 478 | self.name('Tutorials Verification') |
| 441 | 479 | ||
| 442 | # Append tutorials | 480 | # Append tutorials |
| 443 | self.append(self.tutorials_quickstart, 'Test quickstart tutorial') | 481 | self.append(self.tutorials_quickstart, 'Test quickstart tutorial') |
| 482 | + self.append(self.tutorials_howto, 'Test howto tutorial') | ||
| 444 | self.append(self.tutorials_1dc, 'Test 1DC tutorial') | 483 | self.append(self.tutorials_1dc, 'Test 1DC tutorial') |
| 445 | 484 | ||
| 446 | # Return | 485 | # Return |
| @@ -452,14 +491,12 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -452,14 +491,12 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 452 | Test quickstart tutorials | 491 | Test quickstart tutorials |
| 453 | """ | 492 | """ |
| 454 | # Set Sphinx rst file path | 493 | # Set Sphinx rst file path |
| 494 | + os.chdir(self._cwd) | ||
| 455 | path = os.path.abspath('../doc/source/users/tutorials/quickstart') | 495 | path = os.path.abspath('../doc/source/users/tutorials/quickstart') |
| 456 | 496 | ||
| 457 | # Set result directory | 497 | # Set result directory |
| 458 | self._set_result_dir('tutorials/quickstart') | 498 | self._set_result_dir('tutorials/quickstart') |
| 459 | 499 | ||
| 460 | - # Get current working directory | ||
| 461 | - cwd = os.getcwd() | ||
| 462 | - | ||
| 463 | # Clean pfiles | 500 | # Clean pfiles |
| 464 | self._clean_pfiles() | 501 | self._clean_pfiles() |
| 465 | 502 | ||
| @@ -467,22 +504,22 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -467,22 +504,22 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 467 | self._rst_step = 0 | 504 | self._rst_step = 0 |
| 468 | 505 | ||
| 469 | # Test Sphinx rst files | 506 | # Test Sphinx rst files |
| 470 | - self._test_rst_file('%s/simulating.rst' % path) | ||
| 471 | - self._test_rst_file('%s/selecting.rst' % path) | ||
| 472 | - self._test_rst_file('%s/skymap.rst' % path) | ||
| 473 | - self._test_rst_file('%s/binning.rst' % path) | ||
| 474 | - self._test_rst_file('%s/response.rst' % path) | ||
| 475 | - self._test_rst_file('%s/fitting.rst' % path) | ||
| 476 | - self._test_rst_file('%s/residual_map.rst' % path) | 507 | + self._test_rst_file('%s/simulating.rst' % path) |
| 508 | + self._test_rst_file('%s/selecting.rst' % path) | ||
| 509 | + self._test_rst_file('%s/skymap.rst' % path) | ||
| 510 | + self._test_rst_file('%s/binning.rst' % path) | ||
| 511 | + self._test_rst_file('%s/response.rst' % path) | ||
| 512 | + self._test_rst_file('%s/fitting.rst' % path) | ||
| 513 | + self._test_rst_file('%s/residual_map.rst' % path) | ||
| 477 | self._test_rst_file('%s/residual_spectrum.rst' % path) | 514 | self._test_rst_file('%s/residual_spectrum.rst' % path) |
| 478 | - self._test_rst_file('%s/butterfly.rst' % path) | ||
| 479 | - self._test_rst_file('%s/spectrum.rst' % path) | ||
| 480 | - self._test_rst_file('%s/unbinned.rst' % path) | 515 | + self._test_rst_file('%s/butterfly.rst' % path) |
| 516 | + self._test_rst_file('%s/spectrum.rst' % path) | ||
| 517 | + self._test_rst_file('%s/unbinned.rst' % path) | ||
| 481 | self._test_rst_file('%s/energy_dispersion.rst' % path) | 518 | self._test_rst_file('%s/energy_dispersion.rst' % path) |
| 482 | - self._test_rst_file('%s/onoff.rst' % path) | 519 | + self._test_rst_file('%s/onoff.rst' % path) |
| 483 | 520 | ||
| 484 | # Reset working directory | 521 | # Reset working directory |
| 485 | - os.chdir(cwd) | 522 | + os.chdir(self._cwd) |
| 486 | 523 | ||
| 487 | # Return | 524 | # Return |
| 488 | return | 525 | return |
| @@ -499,15 +536,14 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -499,15 +536,14 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 499 | os.environ['CTADATA'] = os.environ['CTADATA1DC'] | 536 | os.environ['CTADATA'] = os.environ['CTADATA1DC'] |
| 500 | os.environ['CALDB'] = os.environ['CTADATA1DC']+'/caldb' | 537 | os.environ['CALDB'] = os.environ['CTADATA1DC']+'/caldb' |
| 501 | 538 | ||
| 502 | - # Set Sphinx rst file path | ||
| 503 | - path = os.path.abspath('../doc/source/users/tutorials/1dc') | 539 | + # Set Sphinx rst file paths |
| 540 | + os.chdir(self._cwd) | ||
| 541 | + path_1dc = os.path.abspath('../doc/source/users/tutorials/1dc') | ||
| 542 | + path_howto = os.path.abspath('../doc/source/users/tutorials/howto') | ||
| 504 | 543 | ||
| 505 | # Set result directory | 544 | # Set result directory |
| 506 | self._set_result_dir('tutorials/1dc') | 545 | self._set_result_dir('tutorials/1dc') |
| 507 | 546 | ||
| 508 | - # Get current working directory | ||
| 509 | - cwd = os.getcwd() | ||
| 510 | - | ||
| 511 | # Clean pfiles | 547 | # Clean pfiles |
| 512 | self._clean_pfiles() | 548 | self._clean_pfiles() |
| 513 | 549 | ||
| @@ -515,17 +551,26 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -515,17 +551,26 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 515 | self._rst_step = 0 | 551 | self._rst_step = 0 |
| 516 | 552 | ||
| 517 | # Test Sphinx rst files | 553 | # Test Sphinx rst files |
| 518 | - self._test_rst_file('%s/first_select_obs.rst' % path) | ||
| 519 | - self._test_rst_file('%s/first_select_events.rst' % path) | ||
| 520 | - self._test_rst_file('%s/first_skymap.rst' % path) | ||
| 521 | - self._test_rst_file('%s/first_detect.rst' % path) | ||
| 522 | - self._test_rst_file('%s/first_stacked.rst' % path) | ||
| 523 | - self._test_rst_file('%s/first_fitting.rst' % path) | ||
| 524 | - self._test_rst_file('%s/first_improving.rst' % path) | ||
| 525 | - self._test_rst_file('%s/first_unbinned.rst' % path) | 554 | + self._test_rst_file('%s/first_select_obs.rst' % path_1dc) |
| 555 | + self._test_rst_file('%s/first_select_events.rst' % path_1dc) | ||
| 556 | + self._test_rst_file('%s/first_skymap.rst' % path_1dc) | ||
| 557 | + self._test_rst_file('%s/first_detect.rst' % path_1dc) | ||
| 558 | + self._test_rst_file('%s/first_stacked.rst' % path_1dc) | ||
| 559 | + self._test_rst_file('%s/first_fitting.rst' % path_1dc) | ||
| 560 | + self._test_rst_file('%s/first_improving.rst' % path_1dc) | ||
| 561 | + self._test_rst_file('%s/first_unbinned.rst' % path_1dc) | ||
| 562 | + | ||
| 563 | + # Test Sphinx rst files | ||
| 564 | + self._test_rst_file('%s/howto_ts.rst' % path_howto) | ||
| 565 | + self._test_rst_file('%s/howto_tsmap.rst' % path_howto) | ||
| 566 | + self._test_rst_file('%s/howto_extent.rst' % path_howto) | ||
| 567 | + self._test_rst_file('%s/howto_ulimit.rst' % path_howto) | ||
| 568 | + self._test_rst_file('%s/howto_lightcurve.rst' % path_howto) | ||
| 569 | + self._test_rst_file('%s/howto_phasecurve.rst' % path_howto) | ||
| 570 | + self._test_rst_file('%s/howto_exclude.rst' % path_howto) | ||
| 526 | 571 | ||
| 527 | # Reset working directory | 572 | # Reset working directory |
| 528 | - os.chdir(cwd) | 573 | + os.chdir(self._cwd) |
| 529 | 574 | ||
| 530 | # Clean pfiles | 575 | # Clean pfiles |
| 531 | self._clean_pfiles() | 576 | self._clean_pfiles() |
| @@ -534,12 +579,43 @@ class tutorials(gammalib.GPythonTestSuite): | @@ -534,12 +579,43 @@ class tutorials(gammalib.GPythonTestSuite): | ||
| 534 | self._rst_step = 0 | 579 | self._rst_step = 0 |
| 535 | 580 | ||
| 536 | # Test Sphinx rst file for On/Off analysis | 581 | # Test Sphinx rst file for On/Off analysis |
| 537 | - self._test_rst_file('%s/first_onoff.rst' % path) | 582 | + self._test_rst_file('%s/first_onoff.rst' % path_1dc) |
| 583 | + | ||
| 584 | + # Reset working directory | ||
| 585 | + os.chdir(self._cwd) | ||
| 586 | + | ||
| 587 | + # Return | ||
| 588 | + return | ||
| 589 | + | ||
| 590 | + # Test howto tutorials | ||
| 591 | + def tutorials_howto(self): | ||
| 592 | + """ | ||
| 593 | + Test howto tutorials | ||
| 594 | + """ | ||
| 595 | + # Set Sphinx rst file path | ||
| 596 | + os.chdir(self._cwd) | ||
| 597 | + path = os.path.abspath('../doc/source/users/tutorials/howto') | ||
| 598 | + | ||
| 599 | + # Set result directory | ||
| 600 | + self._set_result_dir('tutorials/howto') | ||
| 601 | + | ||
| 602 | + # Initialise step counter | ||
| 603 | + self._rst_step = 0 | ||
| 604 | + | ||
| 605 | + # Test Sphinx rst files | ||
| 606 | + self._clean_pfiles() | ||
| 607 | + self._test_rst_file('%s/howto_connect_irfs.rst' % path) | ||
| 608 | + self._clean_pfiles() | ||
| 609 | + self._test_rst_file('%s/howto_xspec.rst' % path) | ||
| 610 | + | ||
| 611 | + # Reset working directory | ||
| 612 | + os.chdir(self._cwd) | ||
| 538 | 613 | ||
| 539 | # Return | 614 | # Return |
| 540 | return | 615 | return |
| 541 | 616 | ||
| 542 | 617 | ||
| 618 | + | ||
| 543 | # ======================== # | 619 | # ======================== # |
| 544 | # Main routine entry point # | 620 | # Main routine entry point # |
| 545 | # ======================== # | 621 | # ======================== # |