Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWIFT_BAT_GRB_POS_ACK conversion #36

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
62 changes: 62 additions & 0 deletions gcn_classic_to_json/notices/SWIFT_BAT_GRB_LC/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import numpy as np

from ... import utils
from ..SWIFT_BAT_GRB_POS_ACK import parse_swift_bat

start_tracker_status = ["locked", "not locked"]


def parse(bin):
bin[9:12] # Unused. According to docs: '12 bytes for the future'
bin[19] # Unused. Flags are either internal or equivalent to bin[18]

soln_status_bits = np.flip(np.unpackbits(bin[18:19].view(dtype="u1")))

if soln_status_bits[11]:
grb_status = (
"It is probably not a GRB or transient due to very low image significance"
)
elif soln_status_bits[7]:
grb_status = (
"It is probably not a GRB or transient due to low image significance"
)
elif soln_status_bits[9]:
grb_status = (
"It is probably not a GRB or transient due to negative background slope"
)
elif soln_status_bits[6]:
grb_status = (
"It is probably not a GRB or transient due to high background level"
)
elif soln_status_bits[1]:
grb_status = "It is a GRB"
else:
grb_status = "It is not a GRB"

integ_time = bin[15] * 4 / 1000

lat, lon = bin[16:17].view(">i2")

return {
**parse_swift_bat(bin),
"latitude": lat * 1e-2,
"longitude": lon * 1e-2,
"trigger_type": "image" if soln_status_bits[4] else "rate",
"rate_duration": integ_time if not soln_status_bits[4] else None,
"rate_energy_range": integ_time if not soln_status_bits[4] else None,
"instrument_phi": 1e-2 * bin[12],
"instrument_theta": 1e-2 * bin[13],
"rate_snr": bin[21] * 1e-2,
"image_snr": bin[20] * 1e-2,
"delta_time": bin[14] * 1e-2,
"trigger_index": bin[17],
"url": "http://gcn.gsfc.nasa.gov/gcn/notices_s/"
+ utils.binary_to_string(bin[22:39]),
"grb_status": grb_status,
"point_source": bool(soln_status_bits[0]),
"flaring_known_source": bool(soln_status_bits[2]),
"star_tracker_status": start_tracker_status[soln_status_bits[10]],
"bright_star_nearby": bool(soln_status_bits[13]),
"removed_from_catalog": bool(soln_status_bits[15]),
"galaxy_nearby": bool(soln_status_bits[16]),
}
29 changes: 29 additions & 0 deletions gcn_classic_to_json/notices/SWIFT_BAT_GRB_LC/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"mission": "SWIFT",
"instrument": "BAT",
"id": [
1227767
],
"trigger_time": "2024-05-11T18:06:53.220Z",
"ra": 336.66450000000003,
"dec": 8.5135,
"rate_snr": 14.89,
"latitude": -11.14,
"longitude": 151.31,
"trigger_type": "rate",
"rate_duration": 2.048,
"rate_energy_range": 2.048,
"instrument_phi": -173.54,
"instrument_theta": 28.38,
"image_snr": 8.52,
"delta_time": -24.0,
"trigger_index": 262,
"url": "http://gcn.gsfc.nasa.gov/gcn/notices_s/sw01227767000msb.lc",
"grb_status": "It is a GRB",
"point_source": true,
"flaring_known_source": false,
"star_tracker_status": "locked",
"bright_star_nearby": false,
"removed_from_catalog": false,
"galaxy_nearby": false
}
88 changes: 87 additions & 1 deletion gcn_classic_to_json/notices/SWIFT_BAT_GRB_POS_ACK/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
import numpy as np

from ... import utils

energy_ranges = [[15, 25], [15, 50], [25, 100], [50, 350]]
start_tracker_status = ["locked", "not locked"]

def parse(bin):

def parse_swift_bat(bin):
return {
"mission": "SWIFT",
"instrument": "BAT",
"id": [bin[4]],
"trigger_time": utils.datetime_to_iso8601(bin[5], bin[6]),
"ra": 1e-4 * bin[7],
"dec": 1e-4 * bin[8],
"rate_snr": bin[21] * 1e-2,
}


def parse(bin):
bin[15] # Unused. According to docs: '4 bytes for the future'
bin[19] # Unused. Flags are either internal or equivalent to bin[18]
bin[26:36] # Unused. According to docs: '40 bytes for the future'
bin[36] # Unused. Flags Equivalent to bin[18]
bin[38] # Intentionally omitted. Sun/Moon parameters

integ_time = bin[14] * 4 / 1000

lat, lon = bin[16:17].view(">i2")

soln_status_bits = np.flip(np.unpackbits(bin[18:19].view(dtype="u1")))
soln_status_bits[8] # Unused. According to docs: 'ground_catalog_source'.
soln_status_bits[12] # Unused. According to docs: 'blocked_catalog_source'.
# These seems to be cross-referenced with a ground catalog with the name of the source printed in the text notices.
# But since the name of this source isn't stored in the these packets, I don't see a reason to include it.
if soln_status_bits[11]:
grb_status = (
"It is probably not a GRB or transient due to very low image significance"
)
elif soln_status_bits[7]:
grb_status = (
"It is probably not a GRB or transient due to low image significance"
)
elif soln_status_bits[9]:
grb_status = (
"It is probably not a GRB or transient due to negative background slope"
)
elif soln_status_bits[6]:
grb_status = (
"It is probably not a GRB or transient due to high background level"
)
elif soln_status_bits[1]:
grb_status = "It is a GRB"
else:
grb_status = "It is not a GRB"

calalog_num = bin[25]

energy_range_idx = np.flip(bin[37:38].view(dtype="i1"))[0]
energy_range = energy_ranges[energy_range_idx]

return {
**parse_swift_bat(bin),
"alert_tense": "test" if soln_status_bits[30] else "current",
"alert_type": "retraction" if soln_status_bits[5] else "initial",
"latitude": lat * 1e-2,
"longitude": lon * 1e-2,
"trigger_type": "image" if soln_status_bits[4] else "rate",
"image_duration": integ_time if soln_status_bits[4] else None,
"image_energy_range": energy_range if soln_status_bits[4] else None,
"rate_duration": integ_time if not soln_status_bits[4] else None,
"rate_energy_range": energy_range if not soln_status_bits[4] else None,
"ra_dec_error": 1e-4 * bin[11],
"instrument_phi": 1e-2 * bin[12],
"instrument_theta": 1e-2 * bin[13],
"rate_snr": bin[21] * 1e-2,
"image_snr": bin[20] * 1e-2,
"n_events": bin[9],
"image_peak": bin[10],
"background_events": bin[22],
"background_start_time": utils.datetime_to_iso8601(bin[5], bin[23]),
"backgroun_duration": bin[24] * 1e-2,
"trigger_index": bin[17],
"catalog_number": calalog_num if soln_status_bits[3] else None,
"grb_status": grb_status,
"point_source": bool(soln_status_bits[0]),
"flaring_known_source": bool(soln_status_bits[2]),
"star_tracker_status": start_tracker_status[soln_status_bits[10]],
"bright_star_nearby": bool(soln_status_bits[13]),
"originally_subtresh": bool(soln_status_bits[14]),
"removed_from_catalog": bool(soln_status_bits[15]),
"galaxy_nearby": bool(soln_status_bits[16]),
"temporal_coincidence": bool(soln_status_bits[28]),
"spatial_coincidence": bool(soln_status_bits[29]),
}
40 changes: 39 additions & 1 deletion gcn_classic_to_json/notices/SWIFT_BAT_GRB_POS_ACK/example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
{
"mission": "SWIFT",
"instrument": "BAT",
"id": [
1227767
],
"trigger_time": "2024-05-11T18:06:53.220Z",
"ra": 336.66450000000003,
"dec": 8.5135,
"ra_dec_error": 0.05
"rate_snr": 14.89,
"alert_tense": "current",
"alert_type": "initial",
"latitude": -11.14,
"longitude": 151.31,
"trigger_type": "rate",
"image_duration": null,
"image_energy_range": null,
"rate_duration": 2.048,
"rate_energy_range": [
25,
100
],
"ra_dec_error": 0.05,
"instrument_phi": -173.54,
"instrument_theta": 28.38,
"image_snr": 8.52,
"n_events": 7538,
"image_peak": 281,
"background_events": 74677,
"background_start_time": "2024-05-11T18:06:22.570Z",
"backgroun_duration": 24.0,
"trigger_index": 262,
"catalog_number": null,
"grb_status": "It is a GRB",
"point_source": true,
"flaring_known_source": false,
"star_tracker_status": "locked",
"bright_star_nearby": false,
"originally_subtresh": false,
"removed_from_catalog": false,
"galaxy_nearby": false,
"temporal_coincidence": false,
"spatial_coincidence": true
}
44 changes: 44 additions & 0 deletions gcn_classic_to_json/notices/SWIFT_BAT_GRB_POS_TEST/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np

from ... import utils
from ..SWIFT_BAT_GRB_POS_ACK import parse_swift_bat

grb_status = ["It is not a GRB", "It is a GRB"]


def parse(bin):
bin[15] # Unused. According to docs: '4 bytes for the future'
bin[16] # Unused. According to docs: 'always be 0.00,0.00 for this notice'
bin[19] # Unused. Flags are either internal or equivalent to bin[18]
bin[25:36] # Unused. According to docs: '44 bytes for the future'
bin[36:38] # Intentionally Omitted. Flags are redundant with rest of notice
bin[38] # Intentionally omitted. Sun/Moon parameters

integ_time = bin[14] * 4 / 1000

soln_status_bits = np.flip(np.unpackbits(bin[18:19].view(dtype="u1")))
soln_status_bits[8] # Unused. According to docs: 'ground_catalog_source'.
soln_status_bits[12] # Unused. According to docs: 'blocked_catalog_source'.
# These seems to be cross-referenced with a ground catalog with the name of the source printed in the text notices.
# But since the name of this source isn't stored in the these packets, I don't see a reason to include it.

return {
**parse_swift_bat(bin),
"alert_tense": "test",
"ra_dec_error": 1e-4 * bin[11],
"instrument_phi": 1e-2 * bin[12],
"instrument_theta": 1e-2 * bin[13],
"image_duration": integ_time if soln_status_bits[4] else None,
"rate_duration": integ_time if not soln_status_bits[4] else None,
"image_snr": bin[20] * 1e-2,
"n_events": bin[9],
"image_peak": bin[10],
"background_events": bin[22],
"background_start_time": utils.datetime_to_iso8601(bin[5], bin[23]),
"backgroun_duration": bin[24] * 1e-2,
"trigger_index": bin[17],
"grb_status": grb_status[soln_status_bits[1]],
"point_source": bool(soln_status_bits[0]),
"flaring_known_source": bool(soln_status_bits[2]),
"bright_star_nearby": bool(soln_status_bits[13]),
}
28 changes: 28 additions & 0 deletions gcn_classic_to_json/notices/SWIFT_BAT_GRB_POS_TEST/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"mission": "SWIFT",
"instrument": "BAT",
"id": [
99999
],
"trigger_time": "2024-05-12T07:26:09.000Z",
"ra": 180.0,
"dec": -35.0,
"rate_snr": 16.78,
"alert_tense": "test",
"ra_dec_error": 0.05,
"instrument_phi": 123.54,
"instrument_theta": 12.34,
"image_duration": null,
"rate_duration": 0.064,
"image_snr": 12.98,
"n_events": 1000,
"image_peak": 500,
"background_events": 100,
"background_start_time": "2024-05-12T07:25:42.000Z",
"backgroun_duration": 12.0,
"trigger_index": 12,
"grb_status": "It is a GRB",
"point_source": true,
"flaring_known_source": false,
"bright_star_nearby": false
}
34 changes: 34 additions & 0 deletions gcn_classic_to_json/notices/SWIFT_BAT_QL_POS/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy as np

from ..SWIFT_BAT_GRB_POS_ACK import parse_swift_bat


def parse(bin):
bin[12:17] # Unused. According to docs: '20 bytes for the future'
bin[19] # Intentionally Omitted. According to docs: 'miscellaneous bits'
bin[20] # Unused. According to docs: '4 bytes for the future'
bin[22:38] # Unused. According to docs: '64 bytes for the future'

lat, lon = bin[10:11].view(">i2")

at_slew_bits = np.flip(np.unpackbits(bin[18:19].view(dtype="u1")))

at_slew_flag_descriptions = {
0: "This burst is worthy of becoming the new Automated target.",
1: "This burst is of sufficient merit to request a s/c slew.",
}

comments = "".join(
[val for (key, val) in at_slew_flag_descriptions.items() if (at_slew_bits[key])]
)

return {
**parse_swift_bat(bin),
"latitude": lat * 1e-2,
"longitude": lon * 1e-2,
"ra_dec_error": 1e-4 * bin[11],
"roll": bin[9] * 1e-4,
"trigger_index": bin[17],
"merit_value": bin[38] * 1e-2,
"additional_info": comments if comments else None,
}
18 changes: 18 additions & 0 deletions gcn_classic_to_json/notices/SWIFT_BAT_QL_POS/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"mission": "SWIFT",
"instrument": "BAT",
"id": [
1227767
],
"trigger_time": "2024-05-11T18:06:53.340Z",
"ra": 336.66450000000003,
"dec": 8.5135,
"rate_snr": 14.89,
"latitude": -11.14,
"longitude": 151.31,
"ra_dec_error": 0.05,
"roll": 0.0,
"trigger_index": 262,
"merit_value": 100.0,
"additional_info": "This burst is worthy of becoming the new Automated target.This burst is of sufficient merit to request a s/c slew."
}
Loading
Loading