flaredetector: util: add helper functions to calculate timespans of valid data
This commit is contained in:
@@ -22,6 +22,38 @@ def findMaxIndices(lc, num=3, distance=100, height=(None, None), sortByHighest=F
|
||||
else:
|
||||
return peak_indices[0:num]
|
||||
|
||||
def findNonNanTimeDeltas(lc, column):
|
||||
timedeltas = []
|
||||
nonNanIndices = np.where(~np.isnan(lc[column]))[0]
|
||||
|
||||
if len(nonNanIndices) == 0:
|
||||
return timedeltas
|
||||
|
||||
start = nonNanIndices[0]
|
||||
end = start
|
||||
|
||||
for i in range(1, len(nonNanIndices)):
|
||||
if nonNanIndices[i] == nonNanIndices[i-1] + 1:
|
||||
end = nonNanIndices[i]
|
||||
else:
|
||||
timedeltas.append((lc.time[start], lc.time[end]))
|
||||
start = nonNanIndices[i]
|
||||
end = start
|
||||
|
||||
timedeltas.append((lc.time[start], lc.time[end]))
|
||||
|
||||
return [timedelta[1] - timedelta[0] for timedelta in timedeltas]
|
||||
|
||||
def getTimeDeltaInSeconds(timedelta):
|
||||
return int(timedelta.to_value("sec"))
|
||||
|
||||
def getTotalValidDataInSeconds(lc, column):
|
||||
tds = findNonNanTimeDeltas(lc, column)
|
||||
validDataTime = 0
|
||||
for td in tds:
|
||||
validDataTime += getTimeDeltaInSeconds(td)
|
||||
return validDataTime, tds
|
||||
|
||||
def plotFlarePeaks(ax, peaks, flux = None):
|
||||
if(flux is None):
|
||||
for peak in peaks:
|
||||
|
||||
Reference in New Issue
Block a user