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

Problem with IC fitting using Minuit #53

Closed AnuvabAstro closed 2 years ago

AnuvabAstro commented 2 years ago

Dear Andrea,

I am using jet set for the broadband spectral modelling of a Blazer source with Synchrotron + IC, but I am getting the following error:

Log-Polynomial fitting of the IC component ---> fit range: [23.0, 29.0] ---> LogCubic fit ---> LogCubic fit failed forced_parameters is not one of the parameters [] ---> try LogParabola

RuntimeError Traceback (most recent call last) ~/anaconda3/envs/jetset/lib/python3.7/site-packages/jetset-1.1.2-py3.7-linux-x86_64.egg/jetset/sed_shaper.py in IC_fit(self, fit_range, use_log_par, Ep_start, minimizer, silent) 878 try: --> 879 mm,best_fit=fit_SED(self.IC_fit_model,self.sed_data,10.fit_range[0],10.fit_range[1],loglog=True,silent=True,fitname='IC-shape-fit',minimizer=minimizer) 880 .................. ..................

~/anaconda3/envs/jetset/lib/python3.7/site-packages/iminuit/minuit.py in _make_init_state(pos2var, args, kwds) 1966 if kw not in pos2var: 1967 raise RuntimeError( -> 1968 f"{kw} is not one of the parameters [{' '.join(pos2var)}]" 1969 ) 1970 nargs = len(kwds)

RuntimeError: forced_parameters is not one of the parameters []

During the piecewise fitting procedure, the Synchrotron segment is not showing any problem, but in IC fit I am getting this issue. What could be the reason and what could be the resolution? Could you kindly suggest?

andreatramacere commented 2 years ago

Dear Banerjee, thanks for using jetset. Which version are you using? I need to have the notebook with the data to reproduce the error. Cheers Andrea

AnuvabAstro commented 2 years ago

Dear Andrea, Thank you for the response. I am using jetset version 1.1.2. The jupyter notebook file is attached here, where I am trying to reproduce exactly what is provided in the tutorial. Please let me know what could be the problem that is causing the issue.

regards, Anuvab

On Tue, Nov 9, 2021 at 6:47 PM andrea tramacere @.***> wrote:

Dear Banerjee, thanks for using jetset. Which version are you using? I need to have the notebook with the data to reproduce the error. Cheers Andrea

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andreatramacere/jetset/issues/53#issuecomment-964142474, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANDCQZ45SRWFV6BW3VH33MDULENNVANCNFSM5HULAMOQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

andreatramacere commented 2 years ago

Hi Anuvab, I don't see the notebook. I need also the data to reproduce everything Cheers Andrea

AnuvabAstro commented 2 years ago

Andrea, I have pasted the script here. I am using test_SEDs[2] from jetset.test_data_helper import test_SEDs, so that I can reproduce exactly the same output provided in the tutorial.

import warnings warnings.filterwarnings('ignore')

import matplotlib.pylab as plt import jetset from jetset.test_data_helper import test_SEDs from jetset.data_loader import ObsData,Data from jetset.plot_sedfit import PlotSED from jetset.test_data_helper import test_SEDs

data=Data.from_file(test_SEDs[2])

%matplotlib inline sed_data=ObsData(data_table=data) sed_data.group_data(bin_width=0.2)

sed_data.add_systematics(0.1,[10.6,10.29]) p=sed_data.plot_sed()

mm,best_fit=my_shape.sync_fit(check_host_gal_template=True, Ep_start=None, minimizer='lsb', silent=True, fit_range=[10. , 21.])

my_shape.IC_fit(fit_range=[21,29],minimizer='minuit') p=my_shape.plot_shape_fit() p.rescale(y_min=-15,x_min=7,x_max=29)

Please let me know if this is ok.

regards, Anuvab

andreatramacere commented 2 years ago

OK, so you have a problem with the tutorial. There is a possibility that your python environment updated to iminuit 2. Please do the following 1) install the new version 1.2.0rc10, that is the pre-release of version 1.2.0, using the instruction here: https://github.com/andreatramacere/jetset-installer 2) just follow the instructions reported there and use this command line 'python jetset-installer 1.2.0rc10'

Now you have the latest version of the jetset. I suggest you to follow the jetset documentation here https://andreatramacere.github.io/jetsetdoc/html/index.html that is updated with the 1.2.0rc10

In a few weeks I will publish v.1.2.0, but using 1.2.0rc10 you are already using it.

AnuvabAstro commented 2 years ago

Andrea, Thank you so much for providing this and it is working perfectly now for the test result. However, another problem I am facing and it would be quite helpful if you can suggest the resolution here as well. In the IC fitting corresponding to my datafile, I am getting the following error:


ValueError Traceback (most recent call last) /tmp/ipykernel_154199/3601055278.py in 1 my_shape.IC_fit(fit_range=[22.,26.],minimizer='lsb',silent=True) ----> 2 p=my_shape.plot_shape_fit() 3 p.rescale(y_min=-15)

........... ...........

~/anaconda3/envs/jetset_new/lib/python3.8/site-packages/matplotlib/axes/_base.py in _validate_converted_limits(self, limit, convert) 3437 if (isinstance(converted_limit, Real) 3438 and not np.isfinite(converted_limit)): -> 3439 raise ValueError("Axis limits cannot be NaN or Inf") 3440 return converted_limit 3441

ValueError: Axis limits cannot be NaN or Inf

However, the range of the frequency provided perfectly contains the data. Why could this error come? Should I change some fitting parameters?

regards, Anuvab

andreatramacere commented 2 years ago

Hi Anuvab, I need to seed the code and the data, otherwise, for me it is difficult to figure out. Cheers Andrea

AnuvabAstro commented 2 years ago

Andrea, I have placed the .ipynb file and the data file in my github page, and the link is here:

https://github.com/Anuvab759/AGN_sed_fitting.git

Please let me know if this is ok.

regards, Anuvab

andreatramacere commented 2 years ago

Hi as soon as I am done with the meetings at work I will investigate. Cheers Andrea

andreatramacere commented 2 years ago

Hi, I fixed the issue. The problem is that you do not have enough points in the synchrotron bump to fit it. Your synch_fit had nan in the best fit pars. Attached you can find the modified version of your notebook (I do not have permission to push to your repo). A few very important points: 1) You have to add radio-optical points to sample the synch bump 2) Once you add them, since this object is a FSRQ (3C454.3 probably), set the synch fit range to fit_range=[9,16]and use the X-ray data for the IC bump ( fit_range=[17,26]) 3) As you can notice from my notebook, both in the sync_fit and in the IC_fit methods you can add the parameter use_log_par=True. This is useful when the log-cubic is failing or providing weird shapes Let me know if you need further help

Cheers Andrea

new_swift_fermi.ipynb.gz

AnuvabAstro commented 2 years ago

Andrea, I have run the notebook and now the issue becomes clear! We did not actually find a radio or optical counterpart (not at least publicly available) for this source, and this was just UV - X-ray - gamma-ray spectra, and maybe in this case we can approximate IC bump only. However, thank you so much for being so helpful and providing detailed comments that clarified the issue completely. I will certainly let you know if further issues come up!

regards, Anuvab

andreatramacere commented 2 years ago

Hi Anuvab, you can find data here: https://tools.ssdc.asi.it/SED/ there is also a method to import their ascii file in jetset. Have a look at the documentation: https://andreatramacere.github.io/jetsetdoc/html/user_guide/documentation_notebooks/load_data/Jet_example_load_data.html Please, let me know if you need any help. Cheers Andrea

AnuvabAstro commented 2 years ago

Andrea, I did not know about this SED builder site and it seems to be quite helpful! I have just glanced through it quickly and I will now check it thoroughly and let you know. Thanks for providing the tools as well. I will try to generate broadband SED if I find the data and accomplish the fitting.

regards, Anuvab

AnuvabAstro commented 2 years ago

Andrea, In the absence of data in the optical or radio, I am attempting to first at least approximate the IC bump using SSC. However, I am getting the following error:

================================================================================

constrains parameters from observable

Exception local variable 's_radio_mm' referenced before assignment

TypeError Traceback (most recent call last) /tmp/ipykernel_240152/2938271014.py in 10 11 ---> 12 prefit_jet=sed_obspar.constrain_SSC_model(electron_distribution_log_values=False,silent=True)

~/anaconda3/envs/jetset_new/lib/python3.8/site-packages/jetset/obs_constrain.py in constrain_SSC_model(self, name, jet_model, params_grid_size, electron_distribution_log_values, silent) 143 print() 144 --> 145 model=self.get_model_constraint(name=name, 146 jet_model=jet_model, 147 params_grid_size=params_grid_size,

~/anaconda3/envs/jetset_new/lib/python3.8/site-packages/jetset/obs_constrain.py in get_model_constraint(self, name, jet_model, EC_componets_list, params_grid_size, electron_distribution_log_values, silent, R_H, R_H_within_BLR, R_H_within_DT, disk_type) 381 LE_spectral_slope_par=jet_model.get_par_by_type('LE_spectral_slope') 382 if LE_spectral_slope_par is not None: --> 383 (s_Plank,s_X,s_Fermi,index_s),completed=find_s(self.class_obj,self.nu_p_S_obs,self.S_LE_slope,self.indices,silent=silent) 384 LE_spectral_slope_par.set(val=index_s) 385 if silent is False:

TypeError: cannot unpack non-iterable NoneType object

I am not getting it properly since 's_radio_mm' which it is showing to be missing has not been explicitly mentioned anywhere. It can happen than since my data starts from nu=14 (log scale), so the radio cut would not apply, but even if I remove that argument, I am getting the same error. Could you kindly let me know how to get around with this issue? The notebook and the data files are uploaded on my github page as before. Link: https://github.com/Anuvab759/AGN_sed_fitting.git

regards, Anuvab

andreatramacere commented 2 years ago

Dear Anuvab I am attaching the notebook with the fix (that you should not use...) A few comments: 1) The problem is that you did not set the redshift in the obsdata (see attached notebook) 2) Using the phenomenological constrain without enough data will never provide a good pre fit model. In the attached notebook I show, for example, how to set indices by hand. But I suggest you to add to the sed, even historical, low energy data . 3) have a look here to have an idea of how the phenomenological constrain works: https://andreatramacere.github.io/jetsetdoc/html/user_guide/documentation_notebooks/phen_constr/SSC_th_bkg.html I am closing the is issue, because this is more related to user support than to bugs. You are very welcome to ask for support by email, I will be very happy to help you. Cheers Andrea

new_swift_fermi.ipynb.gz

andreatramacere commented 2 years ago

Hi, I open again, the issue. Please let me know if once, you add low energy synchrotron data. Everything is going fine. Cheers Andrea

andreatramacere commented 2 years ago

Hi, actually, one of the test datasets in jetset is 3C454.3, so if that is your source, you can grab the data you need from there.

from jetset.test_data_helper import  test_SEDs
test_SEDs
['/Users/orion/anaconda3/envs/jetset/lib/python3.8/site-packages/jetset/test_data/SEDs_data/SED_3C345.ecsv',
 '/Users/orion/anaconda3/envs/jetset/lib/python3.8/site-packages/jetset/test_data/SEDs_data/SED_MW_Mrk421_EBL_DEABS.ecsv',
 '/Users/orion/anaconda3/envs/jetset/lib/python3.8/site-packages/jetset/test_data/SEDs_data/SED_MW_Mrk501_EBL_ABS.ecsv',
 '/Users/orion/anaconda3/envs/jetset/lib/python3.8/site-packages/jetset/test_data/SEDs_data/SED_MW_Mrk501_EBL_DEABS.ecsv']

Cheers Andrea

AnuvabAstro commented 2 years ago

Andrea, Thank you so much for your assistance and inputs. May I contact you via email? Could you kindly share it with me?

regards, Anuvab

andreatramacere commented 2 years ago

andrea.tramacere@gmail.com