diff --git a/gcn_classic_to_json/notices/GECAM_FLT/__init__.py b/gcn_classic_to_json/notices/GECAM_FLT/__init__.py new file mode 100644 index 0000000..c509aaa --- /dev/null +++ b/gcn_classic_to_json/notices/GECAM_FLT/__init__.py @@ -0,0 +1,23 @@ +import numpy as np + +from ..GECAM_GND import parse_gecam_gnd + + +def parse(bin): + bin[15] # Unused. According to docs: '4 bytes for the future' + bin[27:39] # Unused. According to docs: '32 bytes for the future' + bin[21] # Temporarily Unused. This is trigger_duration; currently no keyword + bin[22:24] # Unused. Equivalent to rate_energy_range + + detector_options = ["on", "triggered"] + detector_bits = np.flip(np.unpackbits(bin[26:27].view(dtype="u1"))) + detector_status = [detector_options[bit] for bit in detector_bits[:25]] + detectors = dict(zip(range(1, 26), detector_status)) + + return { + **parse_gecam_gnd(bin), + "rate_snr": bin[20] * 1e-2, + "trigger_duration": bin[21] * 1e-4, + "rate_energy_range": [bin[24], bin[25]], + "detector_status": detectors, + } diff --git a/gcn_classic_to_json/notices/GECAM_FLT/example.json b/gcn_classic_to_json/notices/GECAM_FLT/example.json new file mode 100644 index 0000000..a22e124 --- /dev/null +++ b/gcn_classic_to_json/notices/GECAM_FLT/example.json @@ -0,0 +1,59 @@ +{ + "mission": "GECAM", + "id": [ + 368 + ], + "alert_tense": "current", + "messenger": "EM", + "mission_type": "B", + "trigger_time": "2024-05-17T13:01:22.550Z", + "trigger_type": "rate", + "net_count_rate": 550, + "rate_duration": 10.0, + "ra": 57.830000000000005, + "dec": 17.400000000000002, + "ra_dec_error": 1.4899, + "containment_probability": 0.6826894921370859, + "instrument_phi": 7.46, + "instrument_theta": 51.27, + "latitude": 11.09, + "longitude": -8.55, + "classification": [ + { + "SFLARE": 1 + } + ], + "rate_snr": 5.09, + "trigger_duration": 2.0, + "rate_energy_range": [ + 30, + 140 + ], + "detector_status": { + "1": "triggered", + "2": "on", + "3": "on", + "4": "on", + "5": "on", + "6": "on", + "7": "on", + "8": "on", + "9": "on", + "10": "on", + "11": "triggered", + "12": "on", + "13": "on", + "14": "on", + "15": "on", + "16": "on", + "17": "triggered", + "18": "on", + "19": "on", + "20": "on", + "21": "on", + "22": "on", + "23": "on", + "24": "on", + "25": "on" + } +} diff --git a/gcn_classic_to_json/notices/GECAM_GND/__init__.py b/gcn_classic_to_json/notices/GECAM_GND/__init__.py new file mode 100644 index 0000000..2230833 --- /dev/null +++ b/gcn_classic_to_json/notices/GECAM_GND/__init__.py @@ -0,0 +1,41 @@ +import numpy as np +from scipy.stats import norm + +from ... import utils + +src_class_vals = ["GRB", "SFLARE", "KNOWN_SOURCE", "GENERIC_SOURCE"] + +containment_prob = norm().cdf(1) - norm.cdf(-1) + + +def parse_gecam_gnd(bin): + soln_status_bits = np.flip(np.unpackbits(bin[18:19].view(dtype="u1"))) + return { + "mission": "GECAM", + "id": [bin[4]], + "alert_tense": "test" if soln_status_bits[0] == 1 else "current", + "messenger": "EM", + "mission_type": chr(bin[19] + 64), + # There is an error here; You are supposed to divide by 8640000 to get the correct value + # But it only seems to work if you divide by 864000000; I'm assuming it's some error in encoding the packets + "trigger_time": utils.datetime_to_iso8601(bin[5], bin[6] * 1e-2), + "trigger_type": "rate", + "net_count_rate": bin[9], + "rate_duration": bin[14] * 1e-4, + "ra": bin[7] * 1e-4, + "dec": bin[8] * 1e-4, + "ra_dec_error": bin[10] * 1e-4, + "containment_probability": containment_prob, + "instrument_phi": bin[12] * 1e-2, + "instrument_theta": bin[13] * 1e-2, + "latitude": bin[16] * 1e-2, + "longitude": bin[17] * 1e-2, + "classification": ({src_class_vals[bin[11] - 1]: 1},), + } + + +def parse(bin): + bin[15] # Unused. According to docs: '4 bytes for the future' + bin[20:39] # Unused. According to docs: '76 bytes for the future' + + return {**parse_gecam_gnd(bin)} diff --git a/gcn_classic_to_json/notices/GECAM_GND/example.json b/gcn_classic_to_json/notices/GECAM_GND/example.json new file mode 100644 index 0000000..461b744 --- /dev/null +++ b/gcn_classic_to_json/notices/GECAM_GND/example.json @@ -0,0 +1,26 @@ +{ + "mission": "GECAM", + "id": [ + 368 + ], + "alert_tense": "current", + "messenger": "EM", + "mission_type": "B", + "trigger_time": "2024-05-17T13:01:22.550Z", + "trigger_type": "rate", + "net_count_rate": 1306, + "rate_duration": 27.0, + "ra": 56.25, + "dec": 16.21, + "ra_dec_error": 1.57, + "containment_probability": 0.6826894921370859, + "instrument_phi": 5.98, + "instrument_theta": 52.83, + "latitude": 11.09, + "longitude": -8.55, + "classification": [ + { + "SFLARE": 1 + } + ] +}