cmillion / gPhoton

The GALEX photon database and tools project.
Other
21 stars 11 forks source link

Missing exposure time #278

Closed cmillion closed 6 years ago

cmillion commented 6 years ago

The exposure time calculation during light curve creation in v1.28.7 erroneously returns less exposure time in a bin than the equivalent call to dbasetools.compute_exptime(). The bug is testable / reproducible with the following code, in which all of the print() statements should return True.

from gPhoton import gAperture
from gPhoton.gphoton_utils import read_lc
from gPhoton import dbasetools as dt
import numpy as np
skypos = [176.919525856024,0.255696872807351]
trange = [766525332.995,766526576.995]

data = gAperture('NUV',skypos,0.01,verbose=0,trange=trange)
print(data['t0'][0]==trange[0])
print(data['t1'][-1]==trange[1])

data = gAperture('NUV',skypos,0.01,verbose=0,trange=trange,stepsz=30)
print(data['t0'][0]==trange[0])
print(data['t1'][-1]==trange[1])
print(dt.compute_exptime('NUV',[data['t0'][10],data['t1'][10]])[0]==data['exptime'][10])

trange_int = [np.floor(trange[0]),np.ceil(trange[1])]
data = gAperture('NUV',skypos,0.01,verbose=0,trange=trange_int,stepsz=30)
print(data['t0'][0]==trange_int[0])
print(data['t1'][-1]==trange_int[1])
print(dt.compute_exptime('NUV',[data['t0'][10],data['t1'][10]])[0]==data['exptime'][10])

skypos = (170.04661625965298, 9.85073479305886)
trange = (891393965.0, 891395611.0)
#data = gAperture('NUV',skypos,0.01,verbose=0,trange=trange,stepsz=30)

trange_bad = (891394895.0, 891394925.0)

print(dt.compute_exptime('NUV',trange_bad)==dt.compute_exptime('NUV',trange_bad,skypos=skypos))
cmillion commented 6 years ago

The problem is related to `dbasetools.fGetTimeRanges' and has two components.

  1. 'fGetTimeRanges' queries the aspect solution tables to estimate the time ranges during which a specific source was "on" the actively observing detector (as defined by the detsize parameter). You can pass a time range to it (as a two-element trange) to limit the temporal extent of the search. This gets called when the skypos parameter is passed to dbasetools.compute_exptime(), which is how gAperture computes exposure time in a bin. But 'fGetTimeRanges' was not taking into account that the initial or final times of trange might fall between two valid aspect timestamps, and so should be set as the true initial or final timestamps returned by 'fGetTimeRanges' always returned timestamps from the aspect file, so some fraction of a second could be missed on either side of each time bin.

  2. The aspect solutions have one second resolution. fGetTimeRanges fails to include the final second in a classic failure-to-include-the-edge style bug.