Commit e568245ac76c07d1ab9c7f2fdb80413e28210fbb
1 parent
070fb313
update
Showing
1 changed file
with
56 additions
and
20 deletions
test/test_python.py
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | from gammalib import * |
| 4 | 4 | from math import * |
| 5 | +import os | |
| 5 | 6 | |
| 6 | 7 | #================# |
| 7 | 8 | # Test FITS file # |
| ... | ... | @@ -10,6 +11,13 @@ def test_fits(): |
| 10 | 11 | """ |
| 11 | 12 | Test GammaLib GFits interface. |
| 12 | 13 | """ |
| 14 | + # Remove test files | |
| 15 | + try: | |
| 16 | + os.remove("test_python.fits") | |
| 17 | + os.remove("test_python_2.fits") | |
| 18 | + except: | |
| 19 | + pass | |
| 20 | + | |
| 13 | 21 | # Create FITS file |
| 14 | 22 | fits = GFits() |
| 15 | 23 | fits.open("test_python.fits") |
| ... | ... | @@ -59,17 +67,20 @@ def test_fits(): |
| 59 | 67 | col3 = GFitsTableLngCol("LONG", 10) |
| 60 | 68 | col4 = GFitsTableShtCol("SHORT", 10) |
| 61 | 69 | col5 = GFitsTableStrCol("STRING", 10, 20) |
| 70 | + col6 = GFitsTableLogCol("LOGICAL", 10) | |
| 62 | 71 | for i in range(10): |
| 63 | 72 | col1.set(i, i*0.01) |
| 64 | 73 | col2.set(i, i*0.01) |
| 65 | 74 | col3.set(i, i*100) |
| 66 | 75 | col4.set(i, i*100) |
| 67 | 76 | col5.set(i, str(i*100)) |
| 77 | + col6.set(i, i % 2) | |
| 68 | 78 | tbl1.append_column(col1) |
| 69 | 79 | #tbl1.append_column(col2) # FLOAT: datatype conversion overflow (status=412) |
| 70 | 80 | #tbl1.append_column(col3) # LONG: unknown TFORM datatype code (status=262) |
| 71 | 81 | #tbl1.append_column(col4) # SHORT: datatype conversion overflow (status=412) |
| 72 | 82 | tbl1.append_column(col5) |
| 83 | + #tbl1.append_column(col6) # LOGICAL: unknown TFORM datatype code (status=262) | |
| 73 | 84 | fits.append_hdu(GFitsHDU(tbl1)) |
| 74 | 85 | |
| 75 | 86 | # Set binary table |
| ... | ... | @@ -79,17 +90,20 @@ def test_fits(): |
| 79 | 90 | col3 = GFitsTableLngCol("LONG", 10) |
| 80 | 91 | col4 = GFitsTableShtCol("SHORT", 10) |
| 81 | 92 | col5 = GFitsTableStrCol("STRING", 10, 20) |
| 93 | + col6 = GFitsTableLogCol("LOGICAL", 10) | |
| 82 | 94 | for i in range(10): |
| 83 | 95 | col1.set(i, i*0.01) |
| 84 | 96 | col2.set(i, i*0.01) |
| 85 | 97 | col3.set(i, i*100) |
| 86 | 98 | col4.set(i, i*100) |
| 87 | 99 | col5.set(i, str(i*100)) |
| 100 | + col6.set(i, i % 2) | |
| 88 | 101 | tbl2.append_column(col1) |
| 89 | 102 | tbl2.append_column(col2) |
| 90 | 103 | tbl2.append_column(col3) |
| 91 | 104 | tbl2.append_column(col4) |
| 92 | 105 | tbl2.append_column(col5) |
| 106 | + tbl2.append_column(col6) | |
| 93 | 107 | fits.append_hdu(GFitsHDU(tbl2)) |
| 94 | 108 | |
| 95 | 109 | #print fits |
| ... | ... | @@ -101,26 +115,6 @@ def test_fits(): |
| 101 | 115 | fits.saveto("test_python_2.fits") |
| 102 | 116 | |
| 103 | 117 | |
| 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 | 118 | #=================# |
| 125 | 119 | # Test Node array # |
| 126 | 120 | #=================# |
| ... | ... | @@ -152,7 +146,47 @@ def test_node_array(): |
| 152 | 146 | y = wgt_left*data[inx_left] + wgt_right*data[inx_right] |
| 153 | 147 | x_val.append(x) |
| 154 | 148 | y_val.append(y) |
| 149 | + | |
| 150 | + | |
| 151 | +#===================# | |
| 152 | +# Test LAT response # | |
| 153 | +#===================# | |
| 154 | +def test_lat_response(): | |
| 155 | + """ | |
| 156 | + Test GammaLib GLATResponse interface. | |
| 157 | + """ | |
| 158 | + # Remove test file | |
| 159 | + try: | |
| 160 | + os.remove("test_rsp.fits") | |
| 161 | + except: | |
| 162 | + pass | |
| 163 | + | |
| 164 | + # Allocate LAT response | |
| 165 | + rsp = GLATResponse() | |
| 155 | 166 | |
| 167 | + # Set calibration database | |
| 168 | + rsp.set_caldb("irf/lat") | |
| 169 | + | |
| 170 | + # Load response | |
| 171 | + rsp.load("Pass5_v0", "front") | |
| 172 | + | |
| 173 | + # Save response | |
| 174 | + rsp.save("test_rsp.fits") | |
| 175 | + | |
| 176 | + | |
| 177 | +#======================# | |
| 178 | +# Test LAT observation # | |
| 179 | +#======================# | |
| 180 | +def test_lat_observation(): | |
| 181 | + """ | |
| 182 | + Test GammaLib GLATObservation interface. | |
| 183 | + """ | |
| 184 | + # Allocate LAT Observation | |
| 185 | + obs = GLATObservation("data/FT1_253582800.fits.gz", "data/FT2_253582800.fits.gz") | |
| 186 | + | |
| 187 | + # | |
| 188 | + print obs.ft1() | |
| 189 | + print obs.ft2() | |
| 156 | 190 | |
| 157 | 191 | #==========================# |
| 158 | 192 | # Main routine entry point # |
| ... | ... | @@ -164,3 +198,5 @@ if __name__ == '__main__': |
| 164 | 198 | test_fits() |
| 165 | 199 | test_node_array() |
| 166 | 200 | test_lat_response() |
| 201 | + test_lat_observation() | |
| 202 | + | |
| 167 | 203 | \ No newline at end of file | ... | ... |