fermiPy / fermipy

Fermi-LAT Python Analysis Framework
http://fermipy.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
50 stars 51 forks source link

gta.lightcurve issue #591

Open Aaydee0555 opened 2 months ago

Aaydee0555 commented 2 months ago

I am writing to seek your guidance regarding an issue I am facing with my Fermipy analysis. I use the gta.lightcurve command to obtain the 10-day binned gamma-ray light curve.    A broken power law model is used for the source model. My goal is to fix the break energy of the model to the specific values in each bin. In each time bin, I have a specific value of the break energy.  However, I have encountered a challenge where the break energy takes the value by default, and I cannot fix it to the energy as intended. I have reviewed the Fermipy documentation and explored various options within the code, but I have not been able to resolve this issue. I believe there might be a specific approach or parameter setting that I am overlooking. I would greatly appreciate it if you could provide me with guidance or suggestions on addressing this issue.

omodei commented 1 month ago

Can you send a simple script that illustrates your issue?

Aaydee0555 commented 1 month ago

Thank you for your response. Please find the Python script attached below where I am facing the issue. I am looking forward to your assistance in resolving this issue.

Regards, Athar Ahmad Dar Research Scholar Department of Physics University of Kashmir, 190006 +91-7006361913

On Tue, May 14, 2024 at 2:34 AM Nicola Omodei @.***> wrote:

Can you send a simple script that illustrates your issue?

— Reply to this email directly, view it on GitHub https://github.com/fermiPy/fermipy/issues/591#issuecomment-2108796817, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXSOYO5VJJRM2Z2ANCILNGLZCETFDAVCNFSM6AAAAABHMKESSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYG44TMOBRG4 . You are receiving this because you authored the thread.Message ID: @.***>

omodei commented 1 month ago

I am sorry, there is no script attached here, probably you attached via email, can you use the web interface to upload a test sample? Thank you!

Aaydee0555 commented 1 month ago

from fermipy.gtanalysis import GTAnalysis import numpy as np import shutil

Initialize GTAnalysis

gta = GTAnalysis('config.yaml', logging={'verbosity': 3}) gta.setup() gta.free_sources(distance=3.0, pars='norm') gta.free_source('galdiff') gta.free_source('isodiff') gta.free_sources(minmax_ts=[10, None], pars='norm') gta.free_source('4FGL J1642.9+3948')

Print source parameters

source_name = 4FGL J1642.9+3948' source = gta.roi.get_source_by_name(source_name) print(f"Source: {source_name}") param_names = ['Prefactor', 'Index1', 'Index2', 'BreakValue'] param_values = source['param_values']

gta.fit()

break energy values to be fixed for the source in each time bin

break_energies = np.loadtxt('break_energy.txt')

Generate light curve for each break energy

tmin = 620581417 n = 6 # Assuming 46 one-month bins time_bins = [tmin + 30 i 86400 for i in range(n)]

for i in range(len(time_bins)-1):

Load the model from the configuration file

#gta.load_roi('config.yaml')

# Fix the break energy for this time bin
param_values[3] = break_energies[i]

time_bin=[time_bins[i], time_bins[i+1]]
# Generate the light curve
lc = gta.lightcurve('4FGL J1642.9+3948', time_bins=time_bin, free_radius=3.0, use_local_ltcube=False, multithread=True) # I want to freeze the break energy of my source to the break_energies[i] value, please suggest if we can do it in gta.lightcurve
shutil.copy(f'4fgl_j1642.9+3948_lightcurve.npy', f'{i}.npy')
shutil.copy(f'4fgl_j1642.9+3948_lightcurve.fits', f'{i}.fits')