Commit 278c5c555576fc788d5a01f0c6eeb2f8add2ef61
1 parent
010992e4
No `from gammalib import *` in Python examples
Showing
3 changed files
with
31 additions
and
30 deletions
examples/python/models_howto.py
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | # | 27 | # |
| 28 | # ========================================================================== | 28 | # ========================================================================== |
| 29 | -from gammalib import * | 29 | +import gammalib |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | # =========================================== # | 32 | # =========================================== # |
| @@ -36,14 +36,15 @@ def create_models(): | @@ -36,14 +36,15 @@ def create_models(): | ||
| 36 | """ | 36 | """ |
| 37 | """ | 37 | """ |
| 38 | # Create model container | 38 | # Create model container |
| 39 | - models = GModels() | 39 | + models = gammalib.GModels() |
| 40 | 40 | ||
| 41 | # Create a power law model for the Crab | 41 | # Create a power law model for the Crab |
| 42 | - crabdir = GSkyDir() | 42 | + crabdir = gammalib.GSkyDir() |
| 43 | crabdir.radec_deg(83.6331, 22.0145) | 43 | crabdir.radec_deg(83.6331, 22.0145) |
| 44 | - spatial = GModelSpatialPointSource(crabdir) | ||
| 45 | - spectral = GModelSpectralPlaw(5.7e-16, -2.48, GEnergy(100.0, "MeV")) | ||
| 46 | - model = GModelSky(spatial, spectral) | 44 | + spatial = gammalib.GModelSpatialPointSource(crabdir) |
| 45 | + energy = gammalib.GEnergy(100.0, "MeV") | ||
| 46 | + spectral = gammalib.GModelSpectralPlaw(5.7e-16, -2.48, energy) | ||
| 47 | + model = gammalib.GModelSky(spatial, spectral) | ||
| 47 | models.append(model) | 48 | models.append(model) |
| 48 | 49 | ||
| 49 | # Return models | 50 | # Return models |
examples/python/xml_howto.py
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | # | 27 | # |
| 28 | # ========================================================================== | 28 | # ========================================================================== |
| 29 | -from gammalib import * | 29 | +import gammalib |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | # =================== # | 32 | # =================== # |
| @@ -51,7 +51,7 @@ def create_xml(): | @@ -51,7 +51,7 @@ def create_xml(): | ||
| 51 | (GXmlComment) | 51 | (GXmlComment) |
| 52 | """ | 52 | """ |
| 53 | # Allocate XML document | 53 | # Allocate XML document |
| 54 | - xml = GXml() | 54 | + xml = gammalib.GXml() |
| 55 | 55 | ||
| 56 | # Append first child element to XML document root. The first child | 56 | # Append first child element to XML document root. The first child |
| 57 | # element contains a single child which is an empty-element tag. | 57 | # element contains a single child which is an empty-element tag. |
| @@ -64,21 +64,21 @@ def create_xml(): | @@ -64,21 +64,21 @@ def create_xml(): | ||
| 64 | level1 = xml.append('element') | 64 | level1 = xml.append('element') |
| 65 | level2 = level1.append('list') | 65 | level2 = level1.append('list') |
| 66 | level3 = level2.append('string') | 66 | level3 = level2.append('string') |
| 67 | - level4 = level3.append(GXmlText("This is a text")) | 67 | + level4 = level3.append(gammalib.GXmlText("This is a text")) |
| 68 | level3 = level2.append('integer') | 68 | level3 = level2.append('integer') |
| 69 | - level4 = level3.append(GXmlText("17")) | 69 | + level4 = level3.append(gammalib.GXmlText("17")) |
| 70 | 70 | ||
| 71 | # Append third child element to XML document root. The third child | 71 | # Append third child element to XML document root. The third child |
| 72 | # element contains a single Processing Instruction. | 72 | # element contains a single Processing Instruction. |
| 73 | level1 = xml.append('processing-instruction') | 73 | level1 = xml.append('processing-instruction') |
| 74 | - level2 = level1.append(GXmlPI('<?xml-stylesheet type="text/xsl"?>')) | 74 | + level2 = level1.append(gammalib.GXmlPI('<?xml-stylesheet type="text/xsl"?>')) |
| 75 | 75 | ||
| 76 | # Append forth child element to XML document root. The forth child | 76 | # Append forth child element to XML document root. The forth child |
| 77 | # element contains two comments. The first comment is a single-line | 77 | # element contains two comments. The first comment is a single-line |
| 78 | # comment while the second comment runs over multiple lines. | 78 | # comment while the second comment runs over multiple lines. |
| 79 | level1 = xml.append('comment') | 79 | level1 = xml.append('comment') |
| 80 | - level2 = level1.append(GXmlComment('This is a comment')) | ||
| 81 | - level2 = level1.append(GXmlComment('This is a\ntwo line comment')) | 80 | + level2 = level1.append(gammalib.GXmlComment('This is a comment')) |
| 81 | + level2 = level1.append(gammalib.GXmlComment('This is a\ntwo line comment')) | ||
| 82 | 82 | ||
| 83 | # Return XML document | 83 | # Return XML document |
| 84 | return xml | 84 | return xml |
| @@ -101,7 +101,7 @@ def manipulate_xml(xml): | @@ -101,7 +101,7 @@ def manipulate_xml(xml): | ||
| 101 | # Insert now at the location where we just removed the processing | 101 | # Insert now at the location where we just removed the processing |
| 102 | # instruction a new child element named 'replacement'. This new | 102 | # instruction a new child element named 'replacement'. This new |
| 103 | # child element will have four levels of child nodes. | 103 | # child element will have four levels of child nodes. |
| 104 | - level0 = xml.insert(2, GXmlElement('replacement')) | 104 | + level0 = xml.insert(2, gammalib.GXmlElement('replacement')) |
| 105 | level1 = level0.append('level1') | 105 | level1 = level0.append('level1') |
| 106 | level2 = level1.append('level2') | 106 | level2 = level1.append('level2') |
| 107 | level3 = level2.append('level3') | 107 | level3 = level2.append('level3') |
| @@ -110,7 +110,7 @@ def manipulate_xml(xml): | @@ -110,7 +110,7 @@ def manipulate_xml(xml): | ||
| 110 | # Set now a text node at the place of the level4 child node (the | 110 | # Set now a text node at the place of the level4 child node (the |
| 111 | # level4 child node was sitting in the first slot of the level3 | 111 | # level4 child node was sitting in the first slot of the level3 |
| 112 | # node, hence we have to set the text using the index 0) | 112 | # node, hence we have to set the text using the index 0) |
| 113 | - level4 = level3.set(0, GXmlText('This text replaces the level 4 child node')) | 113 | + level4 = level3.set(0, gammalib.GXmlText('This text replaces the level 4 child node')) |
| 114 | 114 | ||
| 115 | # We extend the level2 child node by adding four further child nodes | 115 | # We extend the level2 child node by adding four further child nodes |
| 116 | # containg a text node, one comment and one processing instruction. | 116 | # containg a text node, one comment and one processing instruction. |
| @@ -124,17 +124,17 @@ def manipulate_xml(xml): | @@ -124,17 +124,17 @@ def manipulate_xml(xml): | ||
| 124 | # will contain a text node. We furthermore append one comment and one | 124 | # will contain a text node. We furthermore append one comment and one |
| 125 | # processing instruction. Once this is setup we call the extend() method | 125 | # processing instruction. Once this is setup we call the extend() method |
| 126 | # to extend the level2 child node. | 126 | # to extend the level2 child node. |
| 127 | - ext = GXmlElement('level2 extension="yes"') | 127 | + ext = gammalib.GXmlElement('level2 extension="yes"') |
| 128 | element1 = ext.append('level3') | 128 | element1 = ext.append('level3') |
| 129 | element2 = ext.append('level3') | 129 | element2 = ext.append('level3') |
| 130 | element3 = ext.append('level3') | 130 | element3 = ext.append('level3') |
| 131 | element4 = ext.append('level3') | 131 | element4 = ext.append('level3') |
| 132 | - comment = ext.append(GXmlComment('This is a comment')) | ||
| 133 | - pi = ext.append(GXmlPI('<?xml-stylesheet type="text/xsl"?>')) | ||
| 134 | - element1.append(GXmlText('This is the first element')) | ||
| 135 | - element2.append(GXmlText('This is the second element')) | ||
| 136 | - element3.append(GXmlText('This is the third element')) | ||
| 137 | - element4.append(GXmlText('This is the forth element')) | 132 | + comment = ext.append(gammalib.GXmlComment('This is a comment')) |
| 133 | + pi = ext.append(gammalib.GXmlPI('<?xml-stylesheet type="text/xsl"?>')) | ||
| 134 | + element1.append(gammalib.GXmlText('This is the first element')) | ||
| 135 | + element2.append(gammalib.GXmlText('This is the second element')) | ||
| 136 | + element3.append(gammalib.GXmlText('This is the third element')) | ||
| 137 | + element4.append(gammalib.GXmlText('This is the forth element')) | ||
| 138 | level2.extend(ext) | 138 | level2.extend(ext) |
| 139 | 139 | ||
| 140 | # Now we replace the text of the last element in the level2 childs. | 140 | # Now we replace the text of the last element in the level2 childs. |
| @@ -215,7 +215,7 @@ def show_xml(xml): | @@ -215,7 +215,7 @@ def show_xml(xml): | ||
| 215 | Show XML document on the screen. | 215 | Show XML document on the screen. |
| 216 | """ | 216 | """ |
| 217 | # Allocate string URL | 217 | # Allocate string URL |
| 218 | - url = GUrlString() | 218 | + url = gammalib.GUrlString() |
| 219 | 219 | ||
| 220 | # Write XML document in URL | 220 | # Write XML document in URL |
| 221 | xml.write(url) | 221 | xml.write(url) |
examples/python/xml_html_create.py
| @@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
| 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 | # | 26 | # |
| 27 | # ========================================================================== | 27 | # ========================================================================== |
| 28 | -from gammalib import * | 28 | +import gammalib |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | # ==================== # | 31 | # ==================== # |
| @@ -47,7 +47,7 @@ def create_html(): | @@ -47,7 +47,7 @@ def create_html(): | ||
| 47 | that is placed in the top-right corner of the page. | 47 | that is placed in the top-right corner of the page. |
| 48 | """ | 48 | """ |
| 49 | # Allocate XML document | 49 | # Allocate XML document |
| 50 | - xml = GXml() | 50 | + xml = gammalib.GXml() |
| 51 | 51 | ||
| 52 | # Creates HTML base | 52 | # Creates HTML base |
| 53 | html = xml.append('html') | 53 | html = xml.append('html') |
| @@ -57,7 +57,7 @@ def create_html(): | @@ -57,7 +57,7 @@ def create_html(): | ||
| 57 | meta = header.append('meta content="text/html; charset=ISO-8859-1" ' | 57 | meta = header.append('meta content="text/html; charset=ISO-8859-1" ' |
| 58 | 'http-equiv="content-type"') | 58 | 'http-equiv="content-type"') |
| 59 | title = header.append('title') | 59 | title = header.append('title') |
| 60 | - text = title.append(GXmlText('GammaLib')) | 60 | + text = title.append(gammalib.GXmlText('GammaLib')) |
| 61 | 61 | ||
| 62 | # Writes body | 62 | # Writes body |
| 63 | body = html.append('body') | 63 | body = html.append('body') |
| @@ -66,10 +66,10 @@ def create_html(): | @@ -66,10 +66,10 @@ def create_html(): | ||
| 66 | big = image.append('big') | 66 | big = image.append('big') |
| 67 | bigger = big.append('big') | 67 | bigger = big.append('big') |
| 68 | span = bigger.append('span style="font-family: Arial; font-weight: bold;"') | 68 | span = bigger.append('span style="font-family: Arial; font-weight: bold;"') |
| 69 | - text = span.append(GXmlText('Gammalib')) | ||
| 70 | - text = image.append(GXmlText('<br>')) | 69 | + text = span.append(gammalib.GXmlText('Gammalib')) |
| 70 | + text = image.append(gammalib.GXmlText('<br>')) | ||
| 71 | span = image.append('span style="font-family: Arial;"') | 71 | span = image.append('span style="font-family: Arial;"') |
| 72 | - text = span.append(GXmlText('A versatile toolbox for the scientific analysis ' | 72 | + text = span.append(gammalib.GXmlText('A versatile toolbox for the scientific analysis ' |
| 73 | 'of astronomical gamma-ray data')) | 73 | 'of astronomical gamma-ray data')) |
| 74 | 74 | ||
| 75 | # Return XML document | 75 | # Return XML document |
| @@ -84,7 +84,7 @@ def show_xml(xml): | @@ -84,7 +84,7 @@ def show_xml(xml): | ||
| 84 | Show XML document on the screen. | 84 | Show XML document on the screen. |
| 85 | """ | 85 | """ |
| 86 | # Allocate string URL | 86 | # Allocate string URL |
| 87 | - url = GUrlString() | 87 | + url = gammalib.GUrlString() |
| 88 | 88 | ||
| 89 | # Write XML document in URL | 89 | # Write XML document in URL |
| 90 | xml.write(url) | 90 | xml.write(url) |