Commit c30f34a40ff978f4f455ec0f8c618881663e4012
1 parent
de837450
enhance test
Showing
1 changed file
with
56 additions
and
1 deletions
test/test_python.py
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | |
| 3 | 3 | from gammalib import * |
| 4 | - | |
| 4 | +from math import * | |
| 5 | 5 | |
| 6 | 6 | #================# |
| 7 | 7 | # Test FITS file # |
| ... | ... | @@ -101,6 +101,59 @@ def test_fits(): |
| 101 | 101 | fits.saveto("test_python_2.fits") |
| 102 | 102 | |
| 103 | 103 | |
| 104 | +#===================# | |
| 105 | +# Test LAT response # | |
| 106 | +#===================# | |
| 107 | +def test_lat_response(): | |
| 108 | + """ | |
| 109 | + Test GammaLib GLATResponse interface. | |
| 110 | + """ | |
| 111 | + # Allocate LAT response | |
| 112 | + rsp = GLATResponse() | |
| 113 | + | |
| 114 | + # Set calibration database | |
| 115 | + rsp.set_caldb("irf/lat") | |
| 116 | + | |
| 117 | + # Load response | |
| 118 | + rsp.load("Pass5_v0", "front") | |
| 119 | + | |
| 120 | + # Save response | |
| 121 | + rsp.save("test_rsp.fits") | |
| 122 | + | |
| 123 | + | |
| 124 | +#=================# | |
| 125 | +# Test Node array # | |
| 126 | +#=================# | |
| 127 | +def test_node_array(): | |
| 128 | + """ | |
| 129 | + Test GammaLib GNodeArray interface. | |
| 130 | + """ | |
| 131 | + # Set-up vector and data array | |
| 132 | + vector = GVector(20) | |
| 133 | + data = GVector(20) | |
| 134 | + for i in range(20): | |
| 135 | + vector[i] = 10.0 + i*5.0 | |
| 136 | + data[i] = sin(0.15*(vector[i]-10.0)) | |
| 137 | + | |
| 138 | + # Set-up node array | |
| 139 | + array = GNodeArray() | |
| 140 | + array.nodes(vector) | |
| 141 | + | |
| 142 | + # Get values | |
| 143 | + x_val = [] | |
| 144 | + y_val = [] | |
| 145 | + for i in range(100): | |
| 146 | + x = i-10 | |
| 147 | + array.set_value(x) | |
| 148 | + inx_left = array.inx_left() | |
| 149 | + inx_right = array.inx_right() | |
| 150 | + wgt_left = array.wgt_left() | |
| 151 | + wgt_right = array.wgt_right() | |
| 152 | + y = wgt_left*data[inx_left] + wgt_right*data[inx_right] | |
| 153 | + x_val.append(x) | |
| 154 | + y_val.append(y) | |
| 155 | + | |
| 156 | + | |
| 104 | 157 | #==========================# |
| 105 | 158 | # Main routine entry point # |
| 106 | 159 | #==========================# |
| ... | ... | @@ -109,3 +162,5 @@ if __name__ == '__main__': |
| 109 | 162 | Perform testing. |
| 110 | 163 | """ |
| 111 | 164 | test_fits() |
| 165 | + test_node_array() | |
| 166 | + test_lat_response() | ... | ... |