Beispiel #1
0
def test_build_components_from_lines():
    # Lines
    abscomp,HIlines = mk_comp('HI')
    abscomp,SiIIlines = mk_comp('SiII', vlim=[-250,80.]*u.km/u.s, add_spec=True)
    # Components
    comps = ltiu.build_components_from_abslines([HIlines[0],HIlines[1],SiIIlines[0],SiIIlines[1]])
    assert len(comps) == 2
Beispiel #2
0
def test_build_components_from_lines():
    # Lines
    abscomp, HIlines = mk_comp('HI')
    abscomp, SiIIlines = mk_comp('SiII',
                                 vlim=[-250, 80.] * u.km / u.s,
                                 add_spec=True)
    # Components
    comps = ltiu.build_components_from_abslines(
        [HIlines[0], HIlines[1], SiIIlines[0], SiIIlines[1]])
    assert len(comps) == 2
Beispiel #3
0
    def write_out(self):
        # Add components
        comps = ltiu.build_components_from_abslines(self.vplt_widg.abs_lines)
        self.vplt_widg.abs_sys._components = comps
        # Dict
        adict = self.vplt_widg.abs_sys.to_dict()

        with io.open(self.outfil, 'w', encoding='utf-8') as f:
            f.write(unicode(json.dumps(adict, sort_keys=True, indent=4,
                                       separators=(',', ': '))))
Beispiel #4
0
    def from_abslines(cls, abslines, vlim=None, **kwargs):
        """Instantiate from a list of AbsLines

        Parameters
        ----------
        components : list
          List of AbsComponent objects
        """
        # Generate components
        components = ltiu.build_components_from_abslines(abslines, **kwargs)
        # Instantiate
        slf = cls.from_components(components, vlim=vlim)
        # Return
        return slf
Beispiel #5
0
 def set_new_comps(self):
     """ Generate new components and fill into abs_sys
     Ignores velocity limits when building
     """
     # Add spectrum filename, coord
     abs_lines = self.vplt_widg.abs_lines
     for line in abs_lines:
         line.analy['datafile'] = self.vplt_widg.spec_fil
         line.attrib['coord'] = self.abs_sys.coord
     # Components
     comps = ltiu.build_components_from_abslines(abs_lines, chk_vel=False)
     self.abs_sys._components = comps
     # Return
     return
Beispiel #6
0
    def from_abslines(cls, abslines, vlim=None, **kwargs):
        """Instantiate from a list of AbsLines

        Parameters
        ----------
        components : list
          List of AbsComponent objects
        """
        # Generate components
        components = ltiu.build_components_from_abslines(abslines, **kwargs)
        # Instantiate
        slf = cls.from_components(components, vlim=vlim)
        # Return
        return slf
Beispiel #7
0
    def write_out(self):
        # Generate components
        comps = ltiu.build_components_from_abslines(self.vplt_widg.abs_lines, chk_vel=False)
        self.vplt_widg.abs_sys._components = comps
        # Dict
        adict = self.vplt_widg.abs_sys.to_dict()

        #QtCore.pyqtRemoveInputHook()
        #xdb.set_trace()
        #QtCore.pyqtRestoreInputHook()
        print("Wrote abs_sys to {:s}".format(self.outfil))
        with io.open(self.outfil, 'w', encoding='utf-8') as f:
            f.write(json.dumps(adict, sort_keys=True, indent=4,
                                       separators=(',', ': ')))
 def set_new_comps(self):
     """ Generate new components and fill into abs_sys
     Ignores velocity limits when building
     """
     # Add spectrum filename, coord
     abs_lines = self.vplt_widg.abs_lines
     for line in abs_lines:
         line.analy['datafile'] = self.vplt_widg.spec_fil
         line.attrib['coord'] = self.abs_sys.coord
     # Components
     comps = ltiu.build_components_from_abslines(abs_lines, chk_vel=False)
     self.abs_sys._components = comps
     # Return
     return
Beispiel #9
0
    def write_out(self):
        # Generate components
        comps = ltiu.build_components_from_abslines(self.vplt_widg.abs_lines,
                                                    chk_vel=False)
        self.vplt_widg.abs_sys._components = comps
        # Dict
        adict = self.vplt_widg.abs_sys.to_dict()

        #QtCore.pyqtRemoveInputHook()
        #xdb.set_trace()
        #QtCore.pyqtRestoreInputHook()
        print("Wrote abs_sys to {:s}".format(self.outfil))
        with io.open(self.outfil, 'w', encoding='utf-8') as f:
            f.write(
                json.dumps(adict,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': ')))
Beispiel #10
0
    def add_DLA(self,
                z,
                NHI=20.3,
                bval=30. * u.km / u.s,
                comment='None',
                model=True):
        """Generate a new DLA
        """
        # Lya, Lyb
        dla_lines = []  # For convenience
        for trans in ['HI 1025', 'HI 1215']:
            iline = AbsLine(trans, z=z)
            iline.attrib['flag_N'] = 1
            iline.attrib['N'] = 10**NHI / u.cm**2
            iline.attrib['sig_N'] = 1 / u.cm**2  # Avoid nan
            iline.attrib['b'] = bval
            iline.attrib['coord'] = SkyCoord(ra=0 * u.deg, dec=0 * u.deg)
            dla_lines.append(iline)
        # Generate system
        HIcomponent = ltiu.build_components_from_abslines(dla_lines)[0]
        HIcomponent.synthesize_colm()
        new_sys = DLASystem.from_components([HIcomponent
                                             ])  #(0*u.deg,0*u.deg),z,None,NHI)
        #QtCore.pyqtRemoveInputHook()
        #import pdb; pdb.set_trace()
        #QtCore.pyqtRestoreInputHook()
        new_sys.bval = bval  # This is not standard, but for convenience
        new_sys.comment = comment
        new_sys.dla_lines = dla_lines  # Also for convenience
        # Name
        self.count_dla += 1
        new_sys.label = 'DLA_Sys_{:d}'.format(self.count_dla)
        # Add
        self.abssys_widg.add_fil(new_sys.label)
        self.abssys_widg.all_abssys.append(new_sys)
        self.abssys_widg.abslist_widget.item(len(
            self.abssys_widg.all_abssys)).setSelected(True)

        # Update
        self.llist['Plot'] = False  # Turn off metal-lines
        if model:  # For dealing with initialization
            self.update_model()
Beispiel #11
0
    def load_coolgas(self):
        """ Load data on cool gas (CII, CIV, SiII, SiIII)
        Richter+17
        """
        llist = LineList('ISM')
        # Ricther+17
        print('Loading Richter+17 for CII, CIV, SiII, SiIII')
        r17_a1_file = resource_filename('pyigm',
                                        '/data/CGM/Galaxy/richter17_A1.fits')
        r17_a1 = Table.read(r17_a1_file)
        r17_a2_file = resource_filename('pyigm',
                                        '/data/CGM/Galaxy/richter17_A2.fits')
        r17_a2 = Table.read(r17_a2_file)
        # Coords
        coords = SkyCoord(ra=r17_a1['_RAJ2000'],
                          dec=r17_a1['_DEJ2000'],
                          unit='deg')
        gc = coords.transform_to('galactic')
        ra = np.zeros((len(r17_a2)))
        dec = np.zeros((len(r17_a2)))

        # Loop on Sightlines
        for kk, row in enumerate(r17_a1):
            if self.debug and (kk == 5):
                break
            a2_idx = np.where(r17_a2['Name'] == row['Name'])[0]
            if len(a2_idx) == 0:
                continue
            ra[a2_idx] = row['_RAJ2000']
            dec[a2_idx] = row['_DEJ2000']
            # Generate the components
            icoord = gc[kk]
            alines = []
            for jj, idx in enumerate(a2_idx):
                # Transition
                trans = '{:s} {:d}'.format(r17_a2['Ion'][idx].strip(),
                                           int(r17_a2['lambda0'][idx]))
                try:
                    aline = AbsLine(trans, linelist=llist)
                except ValueError:
                    pdb.set_trace()
                aline.attrib['coord'] = icoord

                # Skip EW=0 lines
                if r17_a2['e_W'][idx] == 0:
                    continue
                # Velocity
                z = 0.
                aline.setz(z)
                vlim = np.array([r17_a2['vmin'][idx], r17_a2['vmax'][idx]
                                 ]) * u.km / u.s

                aline.limits.set(vlim)  # These are v_LSR
                # EW
                aline.attrib['flag_EW'] = 1
                aline.attrib['EW'] = r17_a2['W'][idx] / 1e3 * u.AA
                aline.attrib['sig_EW'] = r17_a2['e_W'][idx] / 1e3 * u.AA
                # Column

                if np.isnan(
                        r17_a2['logN']
                    [idx]):  # Odd that some lines had an error but no value
                    aline.attrib['flag_N'] = 0
                elif r17_a2['l_logN'][idx] == '>':
                    aline.attrib['flag_N'] = 2
                    aline.attrib['sig_logN'] = 99.99
                else:
                    aline.attrib['flag_N'] = 1
                    aline.attrib['sig_logN'] = r17_a2['e_logN'][idx]
                aline.attrib['logN'] = r17_a2['logN'][idx]
                # Fill linear
                _, _ = linear_clm(aline.attrib)
                alines.append(aline)
            # Generate components from abslines
            comps = ltiu.build_components_from_abslines(alines,
                                                        chk_sep=False,
                                                        chk_vel=False)
            # Limits
            vmin = np.min([icomp.limits.vmin.value for icomp in comps])
            vmax = np.max([icomp.limits.vmax.value for icomp in comps])
            # Instantiate
            s_kwargs = dict(name=row['Name'] + '_z0')
            c_kwargs = dict(chk_sep=False, chk_z=False)
            abssys = IGMSystem.from_components(comps,
                                               vlim=[vmin, vmax] * u.km / u.s,
                                               s_kwargs=s_kwargs,
                                               c_kwargs=c_kwargs)
            # CGM Abs
            rho, ang_sep = calc_Galactic_rho(abssys.coord)
            cgmabs = CGMAbsSys(self.galaxy,
                               abssys,
                               rho=rho,
                               ang_sep=ang_sep,
                               cosmo=self.cosmo)
            # Add to cgm_abs
            self.abs.cgm_abs.append(cgmabs)
        # Finish
        r17_a2['RA'] = ra
        r17_a2['DEC'] = dec
        self.richter17 = r17_a2
        # Reference
        if len(self.refs) > 0:
            self.refs += ','
        self.refs += 'Richter+17'