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

gta.lightcurve issue #591

Open
Aaydee0555 opened this issue May 8, 2024 · 4 comments
Open

gta.lightcurve issue #591

Aaydee0555 opened this issue May 8, 2024 · 4 comments

Comments

@Aaydee0555
Copy link

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

omodei commented May 13, 2024

Can you send a simple script that illustrates your issue?

@Aaydee0555
Copy link
Author

Aaydee0555 commented May 14, 2024 via email

@omodei
Copy link
Member

omodei commented May 21, 2024

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
Copy link
Author

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants