Esempio n. 1
0
 def conversion(value, from_units, to_units):
     try:
         return Decimal(str(convert_length(value, from_units,
                                           to_units))).quantize(
                                               Decimal('.01'))
     except ValueError:
         return None
 def conversion(value, from_units, to_units):
     try:
         if isinstance(value, (list, tuple)):
             q = int(value[0]) * pq.ft # convert feet / inches into centimeters
             value = float(q.rescale(pq.inch) + float(value[1]) * pq.inch)
         return Decimal(str(convert_length(value, from_units, to_units))).quantize(Decimal('.01'))
     except ValueError:
         return None
Esempio n. 3
0
 def conversion(value, from_units, to_units):
     try:
         if isinstance(value, (list, tuple)):
             q = int(
                 value[0]) * pq.ft  # convert feet / inches into centimeters
             value = float(q.rescale(pq.inch) + float(value[1]) * pq.inch)
         return Decimal(str(convert_length(value, from_units,
                                           to_units))).quantize(
                                               Decimal('.01'))
     except ValueError:
         return None
 def _get_FIELD_display(cls, field):
     if isinstance(field, HeightField):
         value = getattr(cls, field.attname)
         if value:
             if cls.units != DATABASE_UNITS:
                 value = round(convert_length(value, DATABASE_UNITS, cls.units), 2)
                 q = float(value) * pq.inch # rescale inches to feet and inches
                 return _('%s ft %s in' % (
                     int(q.rescale(pq.ft)), int(float((q.rescale(pq.ft) % pq.ft).rescale(pq.inch)))))
             else:
                 return _('%s cm' % value)
         return value
     return super(self.model, cls)._get_FIELD_display(field)
Esempio n. 5
0
 def _get_FIELD_display(cls, field):
     if isinstance(field, HeightField):
         value = getattr(cls, field.attname)
         if value:
             if cls.units != DATABASE_UNITS:
                 value = round(
                     convert_length(value, DATABASE_UNITS, cls.units),
                     2)
                 q = float(
                     value
                 ) * pq.inch  # rescale inches to feet and inches
                 return _('%s ft %s in' %
                          (int(q.rescale(pq.ft)),
                           int(
                               float((q.rescale(pq.ft) % pq.ft).rescale(
                                   pq.inch)))))
             else:
                 return _('%s cm' % value)
         return value
     return super(self.model, cls)._get_FIELD_display(field)
 def conversion(value, from_units, to_units):
     try:
         return Decimal(str(convert_length(value, from_units, to_units))).quantize(Decimal('.01'))
     except ValueError:
         return None
Esempio n. 7
0
        break
# tau?
if sfh:
    tau = parts[sfh_index + 1] if sfh == 'Exponential' else ''
# metallicity
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

# speed of light
c = utils.convert_length(utils.c, incoming='m', outgoing='a')

# read in model
fi = open(filein, 'r')
res = []
for line in fi:
    if line[0] == '#': continue
    res.extend(line.strip().split())
fi.close()

# convert to float and return original shape (m, 3)
arr = np.array(res).reshape((-1, 3)).astype('float')
# grab unique ages
ages = np.unique(arr[:, 0]) * 1e9
# and unique ls
ls = np.unique(arr[:, 1])
		sfh_index = parts.index( check )
		break
# tau?
if sfh:
	tau = parts[sfh_index+1] if sfh == 'Exponential' else ''
# metallicity
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

# speed of light
c = utils.convert_length( utils.c, incoming='m', outgoing='a' )

# read in model
fi = open( filein, 'r' )
res = []
for line in fi:
	if line[0] == '#': continue
	res.extend( line.strip().split() )
fi.close()

# convert to float and return original shape (m, 3)
arr = np.array( res ).reshape( (-1,3) ).astype( 'float' )
# grab unique ages
ages = np.unique( arr[:,0] )*1e9
# and unique ls
ls = np.unique( arr[:,1] )
Esempio n. 9
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 = []
Esempio n. 10
0
	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

# read in wavelengths
ls = []
fp = open( lambdas, 'r' )
ls = np.array( [ line.strip() for line in fp ] ).astype( 'float' )
fp.close()
nls = ls.size

# conversion from Lo/Hz to ergs/s/Hz/cm^2.0
conv = 3.826e33/(4.0*math.pi*utils.convert_length( 10, incoming='pc', outgoing='cm' )**2.0)
vs = utils.convert_length( utils.c, incoming='m', outgoing='a' )/ls

# now read in the model file
fp = open( filein, 'r' )
ages = []
masses = []
c = 0
while True:

	# each age takes up two lines
	descr = fp.readline()
	if not descr: break
	if descr[0] == '#': continue

	# skip the first data line (it just gives the number of ages)
Esempio n. 11
0
        seds = np.empty((nls, nages))

    # convert to ergs/s/angstrom
    seds[:, i] = np.array(this) / 4.3607e-33 / 1e10

# convert to numpy
ages = np.array(ages)
ls = np.array(ls) * 10.0

# make sure we are sorted in age
sinds = ages.argsort()
ages = ages[sinds]
seds = seds[:, sinds]

# speed of light
c = utils.convert_length(utils.c, incoming='m', outgoing='a')

# 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()

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