legolason / PyQSOFit

A code to fit the spectrum of quasar
GNU General Public License v3.0
71 stars 36 forks source link

Problem fitting SiIV+OIV line #65

Closed TheDucktective closed 3 months ago

TheDucktective commented 4 months ago

Hello,

I am having issues trying to redo the fitting of the example's quasar plate : 5808 mjd : 56325 fiberid : 560, the code compiles and give similar results as to what is shown in the presentation but the SiIV emission line doesn't appear in the fit :

image

I am using the qsopar.fits parameter file from : https://github.com/QiaoyaWu/sdss4_dr16q_tutorial/blob/main/qsopar_generate.py

After the figures' plot this code :

a=[]
for elem in (list(q_mle.line_result_name)):
    if 'complex' in elem and 'local' not in elem:
        i = list(q_mle.line_result_name).index(elem)
        a.append(list(q_mle.line_result)[i])
print(a)

yields :

['Lya', 'CIV', 'CIII', 'MgII']

The fitting function call is :


q_mle.Fit(name=name,  # customize the name of given targets. Default: plate-mjd-fiber
          # prepocessing parameters
          nsmooth=1,  # do n-pixel smoothing to the raw input flux and err spectra
          and_mask=False,  # delete the and masked pixels
          or_mask=False,  # delete the or masked pixels
          reject_badpix=False,  # reject 10 most possible outliers by the test of pointDistGESD
          deredden=False,  # correct the Galactic extinction
          wave_range=None,  # trim input wavelength
          wave_mask=None,  # 2-D array, mask the given range(s)

          # host decomposition parameters
          decompose_host=False,  # If True, the host galaxy-QSO decomposition will be applied
          host_prior=True,
          # If True, the code will adopt prior-informed method to assist decomposition. Currently, only 'CZBIN1' and 'DZBIN1' model for QSO PCA are available. And the model for galaxy must be PCA too.
          host_prior_scale=0.2,
          # scale of prior panelty. Usually, 0.2 works fine for SDSS spectra. Adjust it smaller if you find the prior affect the fitting results too much.

          host_line_mask=True,
          # If True, the line region of galaxy will be masked when subtracted from original spectra.
          decomp_na_mask=True,  # If True, the narrow line region will be masked when perform decomposition
          qso_type='CZBIN1',  # PCA template name for quasar
          npca_qso=10,  # numebr of quasar templates
          host_type='PCA',  # template name for galaxy
          npca_gal=5,  # number of galaxy templates

          # continuum model fit parameters
          Fe_uv_op=True,  # If True, fit continuum with UV and optical FeII template
          poly=False,  # If True, fit continuum with the polynomial component to account for the dust reddening
          BC=False,  # If True, fit continuum with Balmer continua from 1000 to 3646A
          initial_guess=None,  # Initial parameters for continuum model, read the annotation of this function for detail
          rej_abs_conti=False,  # If True, it will iterately reject 3 sigma outlier absorption pixels in the continuum
          n_pix_min_conti=100,  # Minimum number of negative pixels for host continuuum fit to be rejected.

          # emission line fit parameters
          linefit=True,  # If True, the emission line will be fitted
          rej_abs_line=False,
          # If True, it will iterately reject 3 sigma outlier absorption pixels in the emission lines

          # fitting method selection
          MC=False,
          # If True, do Monte Carlo resampling of the spectrum based on the input error array to produce the MC error array
          MCMC=False,
          # If True, do Markov Chain Monte Carlo sampling of the posterior probability densities to produce the error array
          nsamp=200,
          # The number of trials of the MC process (if MC=True) or number samples to run MCMC chain (if MCMC=True)

          # advanced fitting parameters
          param_file_name='qsopar.fits',  # Name of the qso fitting parameter FITS file.
          nburn=20,  # The number of burn-in samples to run MCMC chain
          nthin=10,  # To set the MCMC chain returns every n samples
          epsilon_jitter=0.,
          # Initial jitter for every initial guass to avoid local minimum. (Under test, not recommanded to change)

          # customize the results
          save_result=False,  # If True, all the fitting results will be saved to a fits file
          save_fits_name=name,  # The output name of the result fits
          save_fits_path=path_test,  # The output path of the result fits
          plot_fig=True,  # If True, the fitting results will be plotted
          save_fig=False,  # If True, the figure will be saved
          plot_corner=True,  # Whether or not to plot the corner plot results if MCMC=True

          # debugging mode
          verbose=False,  # turn on (True) or off (False) debugging output

          # sublevel parameters for figure plot and emcee
          kwargs_plot={
              'save_fig_path': '.',  # The output path of the figure
              'broad_fwhm': 1200  # km/s, lower limit that code decide if a line component belongs to broad component
          },
          kwargs_conti_emcee={},
          kwargs_line_emcee={})

Also I did what was advised there : https://github.com/legolason/PyQSOFit/pull/64 for the overlapping axis but it didn't seem to change much.

If you had any idea regarding these issues it would be greatly appreciated. Thank you again for the code and have a great day !

WenkeRen commented 4 months ago

Hi,

Thanks for your contact.

I may need a little more info from your side. Could you please clarify which version of our code you are using? Since Wu's code is based on an earlier version of ours, the design of the initial parameters is a little changed.

Do you use the qospar.fits generated from Wu's code directly replacing our fits or you transcript her form into our example? I would expect some error raised if you just replace our fits with hers.

If you do transcript her parameter setting to our example.ipynb and generate fits from our script, please attach the code for the line_priors variable. (In the 5th code cell of example.ipynb)

Besides, the matplotlib problem can be solve by downgrading the matplotlib version to 3.7.X. This problem occurs in 3.8 or higher. But the plot section in our code is not perfect, so my current idea is not to patch but to reorganized the plot part in the future. Sorry for the inconvenience.

Best, Wenke

TheDucktective commented 3 months ago

Hi,

In the end it was just a mix-up on my part with the files. I have another issue but I'll make a dedicated post.

Thanks for your response