andreatramacere / jetset

JetSeT a framework for self-consistent modeling and fitting of astrophysical relativistic jets
BSD 3-Clause "New" or "Revised" License
30 stars 15 forks source link

constrains parameters from observable ----- N_res was negative nan #80

Closed Ayon2001 closed 4 months ago

Ayon2001 commented 6 months ago

Hi @andreatramacere , I am Ayon Mondal, a final year Master's student in Astrophysics at Presidency University, Kolkata, India. I am using Jetset for modeling the multi-epoch SED of Blazars as a part of my Msc thesis work. When I am using a very well data the code works fine. But my multi-epoch data has many gaps in different wavebands. For this the pre-fit part works fine, but, after that in the constrains parameters from observable section it shows N_res was negative nan. How can I solve this ?

I am attaching the screenshots herewith. Screenshot from 2024-03-01 11-52-24 plot

Your response in this matter would be much appreciated. I am sincerely waiting for your reply.

andreatramacere commented 6 months ago

Dear @Ayon2001, thanks a lot for using jetset. I need to know which version you are using. I suggest you use the latest stable version https://jetset.readthedocs.io/en/latest/ v1.2.2. The message is from the minimizer, I suspect there is some issue with the error of the data. In any case, it looks like a warning from minuit or lsb, not a major issue.

Ayon2001 commented 6 months ago

Dear @andreatramacere , I am already using latest stable version https://jetset.readthedocs.io/en/latest/ v1.2.2. But the same error happening. please help! Screenshot from 2024-03-04 11-50-21

andreatramacere commented 6 months ago

@Ayon2001, to understand the issue I need to reproduce it. Can you share the data?

Ayon2001 commented 6 months ago

Dear @andreatramacere here is the some data sets 0_54685.6058098_54831.1866574_0.csv 0_54685.6058098_54831.1866574_0.txt 0_54685.6058098_54831.1866574_1.csv 0_54685.6058098_54831.1866574_2.csv 0_54685.6058098_54831.1866574_3.csv 0_54685.6058098_54831.1866574_4.csv 0_54685.6058098_54831.1866574_5.csv

andreatramacere commented 6 months ago

@Ayon2001, please send me also a notebook where the error shows up with one of the dataset above

Ayon2001 commented 6 months ago

Here it is in the google drive link @andreatramacere https://drive.google.com/drive/folders/1q1YX4gmDe9A3_uJSAiUZ07Y0R4Zbq9f1?usp=sharing

andreatramacere commented 6 months ago

@Ayon2001 The problem was that when you built your sed data you forgot to set the redshift! Please update the creation of the data object as follows

d=np.genfromtxt('0_54685.6058098_54831.1866574_0.txt')
data=Data(n_rows=d.shape[0])
data.set_field('x',d[:,0])
data.set_field('y',d[:,1])
data.set_field('dy',value=d[:,2])
data.set_meta_data('z',0.07)

Moreover, for the Synch bump, where the points are very unevenly sampled, I would suggest you to force log-par fit

mm,best_fit=my_shape.sync_fit(check_host_gal_template=False,
                  use_log_par=True,
                  Ep_start=None,
                  minimizer='minuit',
                  silent=True,
                  fit_range=[10.,16.])
Ayon2001 commented 6 months ago

Dear @andreatramacere, Thanks a lot for your comment. This works fine. But I have an another problem. I have encounterd the seme problem for an another set of data. I am attaching the notebook and data file in the google drive link herewith for your reference. It will be very helpful if you kindly take a look. The error is showing in the line '87' of the code.

https://drive.google.com/drive/folders/1wLoFxIjVZJ7L5PCDIeSTcPRGrgDdxLJi?usp=sharing

andreatramacere commented 6 months ago

Dear @Ayon2001,

1) you are missing radio data, so please add radio data 2) remind to add the evaluations of spectral indices (my_shape.eval_indices(minimizer='lsb',silent=True)) 3) inspect always the plots at each step 4) the phenomenological constrain is not a magic or black box step, it requires inspection and understanding of the underlying physics (please have a look here and here) 5) if you do not have enough data, it will not work 6) once you add the radio data (close in time if possible) you can ignore them during the model fitting, by setting the fit_range accordingly

Ayon2001 commented 4 months ago

Dear @andreatramacere In case of SED data where radio observation is not available, then how can I fit that with JetSeT. I can add the radio data from some close time observations from that epoch, then how can I set the fit_range ??

andreatramacere commented 4 months ago

In principle, one would add data close in time, or averaged over a long period, if close-in-time data are not available. Regarding fit rage, just set the lower bound in order to exclude radio data.

Ayon2001 commented 4 months ago

Thats great ! @andreatramacere

import jetset 
from jetset.data_loader import Data
from jetset.data_loader import ObsData, Data
from jetset.plot_sedfit import PlotSED
from jetset.test_data_helper import  test_SEDs
from jetset.sed_shaper import  SEDShape
import warnings 
warnings.filterwarnings('ignore')
from jetset.minimizer import fit_SED, ModelMinimizer
from jetset.jet_model import Jet
from jetset.obs_constrain import ObsConstrain
from jetset.model_manager import  FitModel
from jetset.minimizer import ModelMinimizer

#data.table
from jetset.data_loader import Data
import numpy as np

d=np.genfromtxt('5_54989.2883969_55014.9052868_1.txt')
data=Data(n_rows=d.shape[0])
data.set_field('x',d[:,0])
data.set_field('y',d[:,1])
data.set_field('dy',value=d[:,2])
data.set_meta_data('z',0.069)

#data.table
sed_data = ObsData(data_table= data)
sed_data.group_data(bin_width= 0.01) 

sed_data.add_systematics(0.1,[10.**6,10.**29])

my_shape=SEDShape(sed_data)

my_shape.eval_indices(minimizer='lsb',silent=True)

p=my_shape.plot_indices()

Here I can't give the object name. I want to give the object name as "BL Lac". But in the plot JetSeT is showing new-src

How to solve this ?? I am using the data as a .txt file

you can see that in the image attached here.

image

andreatramacere commented 4 months ago

sed_data = ObsData(data_table= data, obj_name='BL Lac') you should read the documentation 🙂https://jetset.readthedocs.io/en/latest/user_guide/documentation_notebooks/load_data/Jet_example_load_data.html