Skip to content

Commit

Permalink
speeding up more
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed May 16, 2016
1 parent cd2655d commit e332857
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion linetools/isgm/abscomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from astropy import constants as const
from astropy import units as u
from astropy.units import Quantity
from astropy.coordinates import SkyCoord
from astropy.table import QTable, Column

Expand Down Expand Up @@ -126,6 +127,7 @@ def from_dict(cls, idict, coord=None, **kwargs):
else:
radec = SkyCoord(ra=idict['RA']*u.deg, dec=idict['DEC']*u.deg)
# Init
#slf = cls(radec, tuple(idict['Zion']), idict['zcomp'], Quantity(idict['vlim'], unit='km/s'),
slf = cls(radec, tuple(idict['Zion']), idict['zcomp'], idict['vlim']*u.km/u.s,
Ej=idict['Ej']/u.cm, A=idict['A'],
Ntup = tuple([idict[key] for key in ['flag_N', 'logN', 'sig_logN']]),
Expand All @@ -137,7 +139,7 @@ def from_dict(cls, idict, coord=None, **kwargs):
# Return
return slf

def __init__(self, radec, Zion, z, vlim, Ej=0./u.cm, A=None,
def __init__(self, radec, Zion, z, vlim, Ej=Quantity(0., unit='1/cm'), A=None,
Ntup=None, comment='', name=None, stars=None):
""" Initiator
Expand Down
6 changes: 4 additions & 2 deletions linetools/isgm/abssystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from linetools.spectralline import AbsLine
from linetools.abund import ions

# Globals to speed things up
constckms = const.c.to('km/s')

class AbsSystem(object):
"""
Expand Down Expand Up @@ -224,8 +226,8 @@ def add_component(self, abscomp, toler=0.2*u.arcsec, chk_sep=True, **kwargs):
else:
test = True
# Now redshift/velocity
zlim_comp = (1+abscomp.zcomp)*abscomp.vlim/const.c.to('km/s')
zlim_sys = (1+self.zabs)*self.vlim/const.c.to('km/s')
zlim_comp = (1+abscomp.zcomp)*abscomp.vlim/constckms
zlim_sys = (1+self.zabs)*self.vlim/constckms
test = test & (zlim_comp[0]>=zlim_sys[0]) & (zlim_comp[1]<=zlim_sys[1])

# Additional checks (specific to AbsSystem type)
Expand Down
14 changes: 6 additions & 8 deletions linetools/spectralline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from linetools.lists.linelist import LineList
from linetools import utils as ltu

# A few globals to speed performace
# A few globals to speed up performance (astropy.Quantity issue)
zero_coord = SkyCoord(ra=0.*u.deg, dec=0.*u.deg) # Coords
init_analy = {
'spec': None, # Analysis inputs (e.g. spectrum; from .clm file or AbsID)
Expand All @@ -38,9 +38,9 @@
'EW': 0.*u.AA, 'sig_EW': 0.*u.AA, 'flag_EW': 0 # EW
}

#abs_attrib = {'N': 0./u.cm**2, 'sig_N': 0./u.cm**2, 'flag_N': 0, # Column ## NOT ENOUGH SPEED-UP
# 'b': 0.*u.km/u.s, 'sig_b': 0.*u.km/u.s # Doppler
# }
abs_attrib = {'N': 0./u.cm**2, 'sig_N': 0./u.cm**2, 'flag_N': 0, # Column ## NOT ENOUGH SPEED-UP
'b': 0.*u.km/u.s, 'sig_b': 0.*u.km/u.s # Doppler
}

# Class for Spectral line
class SpectralLine(object):
Expand Down Expand Up @@ -156,7 +156,7 @@ def __init__(self, ltype, trans, linelist=None, closest=False, z=0.,
# Other
self.data = {} # Atomic/Molecular Data (e.g. f-value, A coefficient, Elow)
self.analy = init_analy
self.attrib = init_attrib #{
self.attrib = init_attrib

# Fill data
self.fill_data(trans, linelist=linelist, closest=closest, verbose=verbose)
Expand Down Expand Up @@ -455,9 +455,7 @@ def fill_data(self, trans, linelist=None, closest=False, verbose=True):
})

# Additional fundamental attributes for Absorption Line
self.attrib.update({'N': 0./u.cm**2, 'sig_N': 0./u.cm**2, 'flag_N': 0, # Column
'b': 0.*u.km/u.s, 'sig_b': 0.*u.km/u.s # Doppler
} )
self.attrib.update(abs_attrib)

# Voigt
def generate_voigt(self, wave=None, **kwargs):
Expand Down

0 comments on commit e332857

Please sign in to comment.