USRA-STI / gdt-fermi

Gamma-ray Data Tools - Fermi mission components
Apache License 2.0
2 stars 3 forks source link

GbmHealPix.multiply results in a map that cannot be plotted #24

Closed joshuarwood closed 3 months ago

joshuarwood commented 4 months ago

Using the multiply() member of the GbmHealPix class results in a map that cannot be plotted. Here is example code to reproduce the issue:

import matplotlib.pyplot as plt

from gdt.core.plot.sky import EquatorialPlot
from gdt.missions.fermi.gbm.localization import GbmHealPix

# open a file
g = GbmHealPix.open(path)

# multiple
g2 = g.multiply(g, g)

# try to plot
skyplot = EquatorialPlot()
skyplot.add_localization(g2) # <-- fails at this step
plt.show()

where path is a path to any valid GBM localization. Here is the failure trace:

Traceback (most recent call last):
  File "multiply_issue.py", line 18, in <module>
    skyplot.add_localization(g2)
  File "pyvenv-3.8.9/lib/python3.8/site-packages/gdt/core/plot/sky.py", line 323, in add_localization
    detectors = [det.name for det in hpx.frame.detectors]
AttributeError: 'NoneType' object has no attribute 'detectors'

It appears to be a result of the frame object not being generated. I suspect the multiply function might not be preserving scpos and quaternion fields. I'll take a closer look tomorrow. At the moment I can fix the error by adding the following line after multiplication:

g2 = GbmHealPix.from_data(g.prob, trigtime=g.trigtime, scpos=g.scpos, quaternion=g.quaternion)

This forces the creation of the frame object, but seems counterintuitive to me.

AdamGoldstein-USRA commented 4 months ago

Yes, it appears the quaternion and scpos are not being passed on creation. Looks like the fix should be here. Should simply retrieve the values from one of the input objects and pass them as kwargs as in your example calling .from_data().

As an aside, you can get around the plotting issue by with the following: skyplot.add_localization(g2, detectors=[]).
Perhaps the default should be to plot no detectors, but that is a separate issue...