Skip to content

Commit

Permalink
Merge pull request #200 from VERITAS-Observatory/gti-filling
Browse files Browse the repository at this point in the history
Improved readability of eventdisplay gti code
  • Loading branch information
GernotMaier authored Oct 5, 2023
2 parents 13722a8 + 3ebf7db commit e3b59dd
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions pyV2DL3/eventdisplay/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ def duplicate_dimensions(data):


def getGTI(BitArray, run_start_from_reference):
"""Decode the time masks stored as 'TBits' in anasum file and extract GTIs
"""
Decode the time masks stored as 'TBits' in anasum file and extract GTIs
Parameters
----------
maskBits : array of uint8 numbers, read from anasum root file
run_start_from_reference: Start time of the run in second
from reference time
Retuns
------
Returns
-------
gti_start_from_reference : numpy array of start time of GTIs in second
from reference time
gti_end_from_reference: numpy array of stop time of GTIs in second from
Expand All @@ -78,20 +79,19 @@ def getGTI(BitArray, run_start_from_reference):
"""

n = BitArray.size
TimeArray_b = ""
for i in range(n):
TimeArray_b = TimeArray_b + np.binary_repr(BitArray[i], width=8)[::-1]
time_array_sec = ""
for i in range(BitArray.size):
time_array_sec = time_array_sec + np.binary_repr(BitArray[i], width=8)[::-1]

nbits = len(TimeArray_b)
nbits = len(time_array_sec)
for i in range(nbits):
if (TimeArray_b[-1] == "0"):
TimeArray_b = TimeArray_b[:-1]
if (time_array_sec[-1] == "0"):
time_array_sec = time_array_sec[:-1]
else:
break

duration_s = len(TimeArray_b)
ontime_s = TimeArray_b.count("1")
duration_s = len(time_array_sec)
ontime_s = time_array_sec.count("1")
logging.info(
"Duration: {0:.0f} (sec.) {1:.2f} (min)".format(duration_s, duration_s / 60.0)
)
Expand All @@ -102,20 +102,20 @@ def getGTI(BitArray, run_start_from_reference):
gti_start = []
gti_end = []

if TimeArray_b[0] != "0":
if time_array_sec[0] != "0":
gti_start.append(0)

for i in range(1, duration_s - 1):

if (TimeArray_b[i] == "0") and (TimeArray_b[i - 1] == "1"):
if (time_array_sec[i] == "0") and (time_array_sec[i - 1] == "1"):
end = i
gti_end.append(end)

if (TimeArray_b[i] == "0") and (TimeArray_b[i + 1] == "1"):
if (time_array_sec[i] == "0") and (time_array_sec[i + 1] == "1"):
start = i + 1
gti_start.append(start)

if (TimeArray_b[-1] != 0):
if (time_array_sec[-1] != 0):
gti_end.append(duration_s)

logging.info(
Expand Down

0 comments on commit e3b59dd

Please sign in to comment.