Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion GUIs/PlotSpec_Integrated.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,8 @@ def cellchanged(self):
except: pass
def zabs_changed(self):
try: self.zabs = np.double(self.active_zabs.text())
except: self.active_zabs.setText("Please input numerical redshift")
except: pass
#self.active_zabs.setText("Please input numerical redshift")

def saveCatalog_fn(self,parent):
self.saving = SaveCatalog(parent)
Expand Down
33 changes: 24 additions & 9 deletions GUIs/rb_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
import os
import pdb

import json

def load_rb_spec_object(filename):
with open(filename, 'r') as f:
data = json.load(f)
from GUIs.rb_spec import rb_spec as r
sp_n=r.from_data(np.array(data['wave_slice'])*(1.+data['zabs']),np.array(data['flux_slice']),np.array(data['error_slice']))
zabs=data['zabs']
transition=data['trans_wave']
sp_n.shift_spec(zabs)
sp_n.slice_spec(transition,data['slice_spec_lam_min'],data['slice_spec_lam_max'],use_vel=data['slice_spec_method'],method=data['line_sel_flag'],linelist=data['linelist'])
sp_n.fit_continuum(prefit_cont=np.array(data['cont']))
sp_n.compute_EW(transition,vmin=data['vmin'],vmax=data['vmax'],plot=False)
print('---Finished loading saved rb_spec object----')

return sp_n



# Calculate the confidence bounds
def calculate_confidence_bounds(x, model, cov_matrix):
# Evaluate the Legendre basis functions at the given x values
Expand Down Expand Up @@ -435,15 +454,17 @@ def fit_continuum(self,mask=False,domain=False,Legendre=False,**kwargs):
#return self.cont,self.fnorm,self.enorm


def fit_continuum_ransac(self,window=149,mednorm=False):
def fit_continuum_ransac(self,window=149,mednorm=False,tweak=False):
"""Alternate continuum fitting method. Does iterative ransac continumm fitting.

"""
from IGM import ransac_contfit as cf
#sp=cf.cont_fitter()
sp=cf.cont_fitter.from_data(self.wave_slice,self.flux_slice,error=self.error_slice,mednorm=mednorm)
sp.fit_continuum(window=window)

if tweak:
sp.tweak_continuum()

self.cont=sp.cont
self.fnorm=self.flux_slice/self.cont
self.enorm=self.error_slice/self.cont
Expand Down Expand Up @@ -568,10 +589,4 @@ def vpfit_singlet(self,FWHM=6.5):
"""Test Wrapper to call vpfit GUI
"""
from GUIs import rb_interactive_vpfit_singlet as vf
vt=vf.rb_interactive_vpfit_singlet(self.wave_slice,self.fnorm,self.enorm,self.transition);






vt=vf.rb_interactive_vpfit_singlet(self.wave_slice,self.fnorm,self.enorm,self.transition)
11 changes: 10 additions & 1 deletion GUIs/rb_specgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@

#sp=XSpectrum1D.from_file('PG0832+251_nbin3_coadd.fits')
#r.rb_plot_spec(wave,flux/np.nanmedian(flux),error/np.nanmedian(flux))
r.rb_plotspec(wave,flux/np.nanmedian(flux),error/np.nanmedian(flux))
if np.nanmedian(flux)==0:
cnt=np.nanmean(flux)
elif (np.nanmedian(flux)==0) & (np.nanmean(flux)==0):
cnt= 1.
else:
cnt=np.nanmedian(flux)



r.rb_plotspec(wave,flux/cnt,error/cnt)

plt.show() # show the window

14 changes: 7 additions & 7 deletions IGM/compute_EW.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def compute_EW(lam,flx,wrest,lmts,flx_err,plot=False,**kwargs):
RB April 28, 2021, changed med_vel to weight be EW & vel_disp
------------------------------------------------------------------------------------------
"""
defnorm=1.0;
defnorm=1.0
spl=2.9979e5; #speed of light
if 'zabs' in kwargs:
zabs=kwargs['zabs']
Expand All @@ -62,18 +62,18 @@ def compute_EW(lam,flx,wrest,lmts,flx_err,plot=False,**kwargs):

norm=defnorm

norm_flx=flx/norm;
flx_err=flx_err/norm;
sq=np.isnan(norm_flx);
norm_flx=flx/norm
flx_err=flx_err/norm
sq=np.isnan(norm_flx)
tmp_flx=flx_err[sq]
norm_flx[sq]=tmp_flx
#clip the spectrum. If the flux is less than 0+N*sigma, then we're saturated. Clip the flux array(to avoid inifinite optical depth) and set the saturated flag
q=np.where(norm_flx<=sat_limit);
q=np.where(norm_flx<=sat_limit)
tmp_flx=flx_err[q]
norm_flx[q]=tmp_flx
q=np.where(norm_flx<=0.);
q=np.where(norm_flx<=0.)
tmp_flx=flx_err[q]+0.01
norm_flx[q]=tmp_flx;
norm_flx[q]=tmp_flx


del_lam_j=np.diff(lambda_r);
Expand Down
Loading