USRA-STI / gdt-fermi

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

ModelFit plot - No artists with labels found to put in legend. #39

Open nyctophile-aayu opened 1 month ago

nyctophile-aayu commented 1 month ago

Hi, I am running Modelplot command as shown in the snippet. But everytime I am not getting the legends of the detectors in the plot. Is it a bug or do I need to make any change for that? Since there was no such issue in GBM tools before like this.

Screenshot from 2024-08-08 11-32-31

AdamGoldstein-USRA commented 1 month ago

@nyctophile-aayu In both the GDT and the GBM Data Tools, the legend is updated by the detector name in the response objects that are passed to the spectral fitter. I would need to see how you are reading/extracting the response and how you are passing it to the spectral fitter to see what the problem is.

nyctophile-aayu commented 2 weeks ago

@AdamGoldstein-USRA It is somehow working, but I am generating it using Matplotlib instead of modelfit. But there is an issue while doing background subtraction. I have to provide the energy range that is greater than the energy limit defined for both NaI and BGO detectors. Is it okay to do so, or is it wrong? If you wish, I can mail you my notebook.

AdamGoldstein-USRA commented 1 week ago

@nyctophile-aayu If you provide an energy range that is greater than the range of the data, then it will adjust the range accordingly to be (min, max) of the data range. You can attach your notebook here with an example, if needed.

nyctophile-aayu commented 1 week ago

@AdamGoldstein-USRA I am sharing the notebook. It might require access to open. Please check and lemme know what I am doing wrong in it. However, I can generate the results using this notebook as well.

https://drive.google.com/file/d/14yIteu1NH0UpxYOhowWmxZjcw8BYrfFN/view?usp=sharing

AdamGoldstein-USRA commented 1 week ago

@nyctophile-aayu The link you posted does not appear to work. You should be able to attach it here in the same way you attached a file in this post.

nyctophile-aayu commented 1 week ago

@AdamGoldstein-USRA I'll do that. Once you receive it please acknowledge.

AdamGoldstein-USRA commented 4 days ago

@nyctophile-aayu I ran the notebook, and I think I found the issue with the mission lables on the spectral fit plot. The rebinning of the response does not preserve the detector information, and hence does not propagate to the plot legend. This should be a simple fix in the code.

Regarding the energy selection, the energy selection for the BGO, while larger than the actual energy range of the BGO, will snap to the energy range of the data. However, I suggest setting the BGO energy range to start at no lower than ~250 keV and to exclude the highest energy channel. The highest energy channel is the overflow channel, and the channels below ~250 keV has poor calibration. The low energy channel for the NaI looks good, just make sure again to remove the overflow channels before fitting.

nyctophile-aayu commented 3 days ago

@AdamGoldstein-USRA Thank you for identifying the issue. At this stage, is there anything we can do to address the problem with the legend in the model plot, or do you think we should wait for the bug to be resolved? Additionally, can you suggest which attributes I should apply during the rebinning of the response to mitigate this?

Furthermore, I've encountered an issue setting the BGO energy range from 250 keV to 1 or 10 MeV. The background subtraction performs poorly in this range, with the background line significantly exceeding the source light curve, which I understand should not occur. I attempted this, and the light curve plots appear incorrectly as a result. You can try that as well. Could you please advise on the best approach to correct this?

AdamGoldstein-USRA commented 3 days ago

@nyctophile-aayu I have created a branch on gdt-core that fixes this issue. You can pip install that branch and test to see if it solves your problem with displaying the detectors.

With regards to setting the energy range and background fitting, you are plotting the lightcurve integrated over energy_range, however you are integrating the lightcurve over the full energy range. This is the line in your notebook that is the problem: bkgd_lcs.append(bkgd_map[detector_name].integrate_energy()) # Call without energy_range

Integrate the background over the same energy range as your lightcurve, and that should solve your problem: bkgd_lcs.append(bkgd_map[detector_name].integrate_energy(*energy_range))