Ejemplo n.º 1
0
# generate sed array
seds = arr[:, 2].reshape((ages.size, ls.size)).transpose()
# convert from angstroms to hertz
vs = c / ls
# convert from ergs/s/A to ergs/s/Hz
seds *= ls.reshape((ls.size, 1))**2.0 / c
# and now from ergs/s/Hz to ergs/s/Hz/cm^2.0
seds /= (4.0 * math.pi *
         utils.convert_length(10, incoming='pc', outgoing='cm')**2.0)

# sort in frequency space
sinds = vs.argsort()

# did the masses get passed?
if filemass:
    data = utils.rascii(filemass, silent=True)
    mass_interp = interpolate.interp1d(data[:, 0] * 1e9, data[:, 1])
    masses = mass_interp(ages)

# generate fits frame with sed in it
primary_hdu = pyfits.PrimaryHDU(seds[sinds, :])
primary_hdu.header.update('units', 'ergs/s/cm^2/Hz')
primary_hdu.header.update('has_seds', True)
primary_hdu.header.update('nfilters', 0)
primary_hdu.header.update('nzfs', 0)

# store meta data
if sfh and met and imf:
    primary_hdu.header.update('has_meta', True)
    primary_hdu.header.update('model', 'M05', comment='meta data')
    primary_hdu.header.update('met', met, comment='meta data')
Ejemplo n.º 2
0
if parts.count( 'z' ):
	met = parts[ parts.index( 'z' ) + 1 ]
# imf
for (check,val) in zip( ['krou','salp','chab'], ['Kroupa', 'Salpeter', 'Chabrier'] ):
	if parts.count( check ):
		imf = val
		break

if not os.path.isfile( filein ): raise ValueError( 'Input file does not exist or is not readable!' )
if not os.path.isfile( filemass ): raise ValueError( 'Mass file does not exist or is not readable!' )

# read ised file
( seds, ages, vs ) = utils.read_ised( filein )

# read age-mass relationship
mass = utils.rascii( filemass, silent=True )
# each line in the mass file should exactly correspond to the age, with the exception of the first age (which is zero)
# check that the numbers of lines are the same, and if so assume that the correspondence is perfect.
# otherwise, interpolate
if mass[:,0].size == ages.size-1:
	masses = np.append( 0, mass[:,6] )
else:
	masses = np.zeros( ages.size )
	interp = interpolate.interp1d( 10.0**mass[:,0], mass[:,6] )
	masses[1:] = interp( ages[1:] )

# generate fits frame with sed in it
primary_hdu = pyfits.PrimaryHDU(seds)
primary_hdu.header.update( 'units', 'ergs/s/cm^2/Hz' )
primary_hdu.header.update( 'has_seds', True )
primary_hdu.header.update( 'nfilters', 0 )
Ejemplo n.º 3
0
for (check,val) in zip( ['krou','salp','chab'], ['Kroupa', 'Salpeter', 'Chabrier'] ):
	if parts.count( check ):
		imf = val
		break
if parts.count( 'n' ):
	n = parts[ parts.index( 'n' ) + 1 ]
ae = False
if parts.count( 'ae' ): ae = True

# does the file with masses exist?
has_masses = False
mass_file = glob.glob( 'MLR*.txt' )
if len( mass_file ):
	# read it in!
	print 'Loading masses from %s' % mass_file[0]
	data = utils.rascii( mass_file[0], silent=True )
	masses = data[:,10:14].sum( axis=1 )
	has_masses = True

files = glob.glob( 'SPEC*agb*' )
nages = len( files )
ages = []

for (i,file) in enumerate(files):

	ls = []
	this = []

	# extract the age from the filename and convert to years
	m = re.search( 't60*(\d+)$', file )
	ages.append( int( m.group(1) )*1e6 )
Ejemplo n.º 4
0
    def __init__(self, filename, units='a', cosmology=None, vega=False, solar=False):

        # load additional modules.  Yes, this is strange.  But this way astro_filter_light can inherit astro_filter.
        # this is necessary because astro_filter_light is intended to work without any of these modules
        import scipy.interpolate as interpolate
        import scipy.integrate
        global interpolate
        global scipy

        # check that we were passed a file and it exists
        if type(filename) == type(''):
            if not os.path.isfile(filename): raise ValueError('The specified filter transmission file does not exist!')

            # read it in
            file = utils.rascii(filename)
        elif filename is None:
            # very basic load - no filter response curve
            self.npts = 0
            self.to_vega = vega
            self.has_vega = True
            if cosmology is not None: self.cosmo = cosmology
            self.solar = solar
            self.has_solar = not np.isnan(solar)
            return
        else:
            # is this a numpy array?
            if type(filename) == type(np.array([])):
                file = filename
            else:
                raise ValueError('Please pass the filename for the filter transmission file!')

        ls = file[:,0]

        # calculate wavelengths in both angstroms and hertz
        units = units.lower()
        if units == 'hz':
            vs = ls
            ls = utils.to_lambda(vs, units='a')
        else:
            vs = utils.to_hertz(ls, units=units)
            ls = utils.convert_length(ls, incoming=units, outgoing='a')

        # store everything sorted
        sind = vs.argsort()
        self.vs = vs[sind]        # frequencies
        self.tran = file[sind,1]    # corresponding transmission
        self.ls = ls[sind[::-1]]    # wavelengths (angstroms)
        self.tran_ls = self.tran[::-1]    # corresponding transmission
        self.npts = self.vs.size

        # frequency widths of each datapoint
        self.diffs = np.roll(self.vs, -1) - self.vs
        self.diffs[-1] = self.diffs[-2]

        # calculate filter properties and store in the object
        self.calc_filter_properties()

        # normalization for calculating ab mags for this filter
        self.ab_flux = self.ab_source_flux*scipy.integrate.simps(self.tran/self.vs, self.vs)

        # store the cosmology object if passed
        if cosmology is not None: self.cosmo = cosmology

        # calculate ab-to-vega conversion if vega spectrum was passed
        if type(vega) == type(np.array([])): self.set_vega_conversion(vega)

        # calculate solar magnitude if solar spectrum was passed
        if type(solar) == type(np.array([])): self.set_solar_magnitude(solar)

        self.zfs = np.array([])
        self.zf_grids = []
Ejemplo n.º 5
0
                        ['Kroupa', 'Salpeter', 'Chabrier']):
    if parts.count(check):
        imf = val
        break
if parts.count('n'):
    n = parts[parts.index('n') + 1]
ae = False
if parts.count('ae'): ae = True

# does the file with masses exist?
has_masses = False
mass_file = glob.glob('MLR*.txt')
if len(mass_file):
    # read it in!
    print(('Loading masses from %s' % mass_file[0]))
    data = utils.rascii(mass_file[0], silent=True)
    masses = data[:, 10:14].sum(axis=1)
    has_masses = True

files = glob.glob('SPEC*agb*')
nages = len(files)
ages = []

for (i, file) in enumerate(files):

    ls = []
    this = []

    # extract the age from the filename and convert to years
    m = re.search('t60*(\d+)$', file)
    ages.append(int(m.group(1)) * 1e6)