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

GECAM_FLT and GECAM_GND conversions #35

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions gcn_classic_to_json/notices/GECAM_FLT/__init__.py
lpsinger marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np

from ..GECAM_GND import parse as 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please work with @Vidushi-GitHub to create a schema entry for this field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I should have removed this line! After speaking with @Vidushi-GitHub, we decided to name this trigger_duration i.e. keep the name from the source code which is present in the return statement.

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]]
lpsinger marked this conversation as resolved.
Show resolved Hide resolved
detectors = dict(zip(np.arange(25.0) + 1, detector_status))

return {
**parse_gecam_gnd(bin),
"rate_snr": bin[20] * 1e-2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is called trig_signif. Do we know that this is equivalent to SNR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't documented, so we can't be completely certain. I was mainly going of the text notices which had the following:
TRIGGER_SIGNIF: 5.1 [sigma] (Signif of the Trigger)
Linked here

Copy link
Member

@lpsinger lpsinger Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not documented, but we do have the source code. Also we can contact the GECAM mission.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the source code: "Height of the triggering peak"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could mean SNR if it is the height of an SNR time series, but it could equally well be the height of the the count rate time series. @Vidushi-GitHub, @jracusin, some help here please.

Copy link
Member

@Vidushi-GitHub Vidushi-GitHub Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a best match with rate_snr in Statistics schema. Most likely height of the peak value from the light curve i.e. counts/s or rate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't sound like we reached a definite answer on this yet. @Vidushi-GitHub, how would you like to resolve this?

"rate_energy_range": [bin[24], bin[25]],
"detector_status": detectors,
}
58 changes: 58 additions & 0 deletions gcn_classic_to_json/notices/GECAM_FLT/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"mission": "GECAM",
"id": [
368
],
"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
}
],
"additional_info": null,
"rate_snr": 5.09,
"rate_energy_range": [
30,
140
],
"detector_status": {
"1.0": "triggered",
"2.0": "on",
"3.0": "on",
"4.0": "on",
"5.0": "on",
"6.0": "on",
"7.0": "on",
"8.0": "on",
"9.0": "on",
"10.0": "on",
"11.0": "triggered",
"12.0": "on",
"13.0": "on",
"14.0": "on",
"15.0": "on",
"16.0": "on",
"17.0": "triggered",
"18.0": "on",
"19.0": "on",
"20.0": "on",
"21.0": "on",
"22.0": "on",
"23.0": "on",
"24.0": "on",
"25.0": "on"
}
}
41 changes: 41 additions & 0 deletions gcn_classic_to_json/notices/GECAM_GND/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]


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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields are unused by GECAM_GND, but some of them are used by GECAM_FLT. This line here will defeat the coverage tests for GECAM_FLT. Please refactor the common parsing code for both GECAM_FLT and GECAM_GND into a single function that is reused by both parsers.


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

containment_prob = norm().cdf(1) - norm.cdf(-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lift to module scope.


return {
"mission": "GECAM",
"id": [bin[4]],
"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),
lpsinger marked this conversation as resolved.
Show resolved Hide resolved
"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},),
# "classification": ({str(bin[11]) : 1}, ),
"additional_info": (
"This is a test notice." if soln_status_bits[0] == 1 else None
),
}
26 changes: 26 additions & 0 deletions gcn_classic_to_json/notices/GECAM_GND/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"mission": "GECAM",
"id": [
368
],
"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
}
],
"additional_info": null
}
Loading