def test_stau(): # Generate stau _, velo, fx, sig = dummy_spec() stau = generate_stau(velo, fx, sig) np.testing.assert_allclose(stau[1000], 0.27800134641010432) # Different binning now stau2 = generate_stau(velo, fx, sig, kbin=35*u.km/u.s) np.testing.assert_allclose(stau2[1000], 0.17871515126363854)
def test_pw97(): # Generate stau _, velo, fx, sig = dummy_spec() stau = generate_stau(velo, fx, sig) # pw97 kin_data = pw97_kin(velo, stau) np.testing.assert_allclose(kin_data['Dv'].value, 20.) np.testing.assert_allclose(kin_data['fedg'], 0.37035142148289424)
def measure_kin(self, **kwargs): """ Measure Kinematics """ from linetools.analysis import abskin fx, sig, cdict = self.cut_spec() stau = abskin.generate_stau(cdict['velo'], fx, sig, **kwargs) # Measure kin_data = abskin.pw97_kin(cdict['velo'], stau, **kwargs) # Save self.attrib['kin'] = kin_data
def test_cgmkin(): # Grab spectrum wave, velo, fx, sig = dummy_spec() # stau stau = generate_stau(velo, fx, sig) # CGM kin_data = cgm_kin(velo, stau) for tst in [u'zero_pk', u'delta_v', u'X_fcover', u'JF_fcover', u'v_peak']: assert tst in kin_data.keys() np.testing.assert_allclose(kin_data['delta_v'].value, -164.9989, rtol=1e-5) """
def load_abskin(self, flg=1, kin_file=None, kin_init_file=None): """ Load the absorption-line kinematic data for COS-Halos (or COS-Dwarfs) Calculate from scratch if needed Parameters ---------- flg: int, optional Flag indicating how to load the data 0 = Load from file 1 = Generate kin_init_file: str Name of kinematics driver file kin_file: str Name of kinematics output file [First made for John Forbes] """ if flg == 0: # Load if kin_file is None: kin_file = os.path.abspath( os.environ.get('DROPBOX_DIR') + '/COS-Halos/Kin/' + 'COS-Halos_kin.fits') hdu = fits.open(kin_file) # Metals metals = Table(hdu[1].data) for row in metals: mt = np.where((row['field'] == self.field) & (row['gal_id'] == self.gal_id))[0] pdb.set_trace() elif flg == 1: # Generate # Read init file if kin_init_file is None: kin_init_file = self.kin_init_file kin_init = ascii.read(kin_init_file, guess=False) # Loop to my loop fgal = zip(self.field, self.gal_id) for qq, cgm_abs in enumerate(self.cgm_abs): # Match to kin_init mt = np.where((kin_init['QSO'] == cgm_abs.field) & (kin_init['Galaxy'] == cgm_abs.gal_id))[0] if len(mt) == 0: warnings.warn( 'load_kin: No kinematics for {:s}, {:s}'.format( cgm_abs.field, cgm_abs.gal_id)) continue mt = mt[0] # Metals if kin_init['flgL'][mt] > 0: wrest = kin_init['mtl_wr'][mt] * u.AA if wrest.value <= 1: pdb.set_trace() spec = self.load_bg_cos_spec(qq, wrest) vmnx = (kin_init['L_vmn'][mt], kin_init['L_vmx'][mt]) * u.km / u.s # Process aline = AbsLine(wrest) aline.analy['spec'] = spec aline.analy['vlim'] = vmnx aline.attrib['z'] = cgm_abs.igm_sys.zabs fx, sig, cdict = aline.cut_spec() # Kin stau = laak.generate_stau(cdict['velo'], fx, sig) cgm_abs.igm_sys.kin['Metal'] = laak.pw97_kin(cdict['velo'], stau, per=0.07) cgm_abs.igm_sys.kin['Metal'].update( laak.cgm_kin(cdict['velo'], stau, per=0.07)) # Save spec #cgm_abs.igm_sys.kin['Metal']['spec'] = spec else: cgm_abs.igm_sys.kin['Metal'] = {} # HI if kin_init['flgH'][mt] > 0: wrest = kin_init['HI_wrest'][mt] * u.AA if wrest.value <= 1: pdb.set_trace() spec = self.load_bg_cos_spec(qq, wrest) if spec is None: pdb.set_trace() vmnx = (kin_init['HIvmn'][mt], kin_init['HIvmx'][mt]) * u.km / u.s # Process aline = AbsLine(wrest) aline.analy['spec'] = spec aline.analy['vlim'] = vmnx aline.attrib['z'] = cgm_abs.igm_sys.zabs fx, sig, cdict = aline.cut_spec() # Kin stau = laak.generate_stau(cdict['velo'], fx, sig) cgm_abs.igm_sys.kin['HI'] = laak.pw97_kin(cdict['velo'], stau, per=0.07) cgm_abs.igm_sys.kin['HI'].update( laak.cgm_kin(cdict['velo'], stau, per=0.07)) else: # Fill with zeros (for the keys) cgm_abs.igm_sys.kin['HI'] = {}
def load_abskin(self, flg=1, kin_file=None, kin_init_file=None): """ Load the absorption-line kinematic data for COS-Halos (or COS-Dwarfs) Calculate from scratch if needed Parameters ---------- flg: int, optional Flag indicating how to load the data 0 = Load from file 1 = Generate kin_init_file: str Name of kinematics driver file kin_file: str Name of kinematics output file [First made for John Forbes] """ if flg == 0: # Load if kin_file is None: kin_file = os.path.abspath(os.environ.get('DROPBOX_DIR')+'/COS-Halos/Kin/'+ 'COS-Halos_kin.fits') hdu = fits.open(kin_file) # Metals metals = Table(hdu[1].data) for row in metals: mt = np.where( (row['field']==self.field) & (row['gal_id']==self.gal_id))[0] pdb.set_trace() elif flg == 1: # Generate # Read init file if kin_init_file is None: kin_init_file = self.kin_init_file kin_init = ascii.read(kin_init_file,guess=False) # Loop to my loop fgal = zip(self.field, self.gal_id) for qq,cgm_abs in enumerate(self.cgm_abs): # Match to kin_init mt = np.where((kin_init['QSO'] == cgm_abs.field) & (kin_init['Galaxy'] == cgm_abs.gal_id))[0] if len(mt) == 0: warnings.warn('load_kin: No kinematics for {:s}, {:s}'.format(cgm_abs.field, cgm_abs.gal_id)) continue mt = mt[0] # Metals if kin_init['flgL'][mt] > 0: wrest = kin_init['mtl_wr'][mt]*u.AA if wrest.value <= 1: pdb.set_trace() spec = self.load_bg_cos_spec(qq, wrest) vmnx = (kin_init['L_vmn'][mt], kin_init['L_vmx'][mt])*u.km/u.s # Process aline = AbsLine(wrest) aline.analy['spec'] = spec aline.analy['vlim'] = vmnx aline.attrib['z'] = cgm_abs.igm_sys.zabs fx, sig, cdict = aline.cut_spec() # Kin stau = laak.generate_stau(cdict['velo'], fx, sig) cgm_abs.igm_sys.kin['Metal'] = laak.pw97_kin(cdict['velo'], stau, per=0.07) cgm_abs.igm_sys.kin['Metal'].update(laak.cgm_kin(cdict['velo'], stau, per=0.07)) # Save spec #cgm_abs.igm_sys.kin['Metal']['spec'] = spec else: cgm_abs.igm_sys.kin['Metal'] = {} # HI if kin_init['flgH'][mt] > 0: wrest = kin_init['HI_wrest'][mt]*u.AA if wrest.value <= 1: pdb.set_trace() spec = self.load_bg_cos_spec( qq, wrest ) if spec is None: pdb.set_trace() vmnx = (kin_init['HIvmn'][mt], kin_init['HIvmx'][mt])*u.km/u.s # Process aline = AbsLine(wrest) aline.analy['spec'] = spec aline.analy['vlim'] = vmnx aline.attrib['z'] = cgm_abs.igm_sys.zabs fx, sig, cdict = aline.cut_spec() # Kin stau = laak.generate_stau(cdict['velo'], fx, sig) cgm_abs.igm_sys.kin['HI'] = laak.pw97_kin(cdict['velo'], stau, per=0.07) cgm_abs.igm_sys.kin['HI'].update(laak.cgm_kin(cdict['velo'], stau, per=0.07)) else: # Fill with zeros (for the keys) cgm_abs.igm_sys.kin['HI'] = {}