コード例 #1
0
ファイル: __init__.py プロジェクト: nirinA/kcorrect_python
def load_templates(v="vmatrix.default.dat",
                   l="lambda.default.dat",
                   templates_dir='data/templates'):
    vfile = os.path.join(os.environ['KCORRECT_DIR'], templates_dir, v)
    if not os.path.isfile(vfile):
        raise _kcorrect.error('file: %s not found'%vfile)
    lfile = os.path.join(os.environ['KCORRECT_DIR'], templates_dir, l)
    if not os.path.isfile(lfile):
        raise _kcorrect.error('file: %s not found'%lfile)
    _kcorrect.load_templates(vfile, lfile)
コード例 #2
0
def load_templates(v="vmatrix.default.dat",
                   l="lambda.default.dat",
                   templates_dir='data/templates'):
    vfile = os.path.join(os.environ['KCORRECT_DIR'], templates_dir, v)
    if not os.path.isfile(vfile):
        raise _kcorrect.error('file: %s not found' % vfile)
    lfile = os.path.join(os.environ['KCORRECT_DIR'], templates_dir, l)
    if not os.path.isfile(lfile):
        raise _kcorrect.error('file: %s not found' % lfile)
    _kcorrect.load_templates(vfile, lfile)
コード例 #3
0
ファイル: __init__.py プロジェクト: nirinA/kcorrect_python
def read_basel(solarname, silent=False):
    """
    Read a spectrum from a Basel spectrum file.
    """
    filename = os.path.join(
        os.getenv('KCORRECT_DIR'), 'data/basel', solarname)
    if not os.path.isfile(filename):
        raise _kcorrect.error('%s not found'%filename)
    with open(filename,'r') as f:
        returndata = {'flux':[], 'model':[], 'teff':[], 'logg':[], 'mh':[],
            'vturb':[], 'xh':[]}
        rawdata = f.read()
        alldata = rawdata.replace("\n", '').split()
        returndata['wavelength'] = numpy.array(alldata[0:1221], dtype=numpy.float32)
        del alldata[0:1221]
        nunits = int(len(alldata)/(1227))
        if not silent:
            print ("%d block(s) of spectra" % nunits)
        for u in range(nunits):
            returndata['model'].append(int(alldata[0]))
            returndata['teff'].append(int(alldata[1]))
            returndata['logg'].append(float(alldata[2]))
            returndata['mh'].append(float(alldata[3]))
            returndata['vturb'].append(float(alldata[4]))
            returndata['xh'].append(float(alldata[5]))
            returndata['flux'].append(numpy.array(alldata[6:1227], dtype=numpy.float32))
            del alldata[0:1227]
    return returndata
コード例 #4
0
def fit_coeffs(c):
    c = numpy.array(c, dtype='float32')
    if len(c) == 11:
        return _kcorrect.fit_coeffs(c)
    else:
        raise _kcorrect.error(
            'for this deault sdss filters, number of argument should be 11')
コード例 #5
0
def load_filters(f="sdss_filters.dat",
                 band_shift=0.,
                 filters_dir='data/templates'):
    ffile = os.path.join(os.environ['KCORRECT_DIR'], filters_dir, f)
    if not os.path.isfile(ffile):
        raise _kcorrect.error('file: %s not found' % ffile)
    _kcorrect.load_filters(ffile, band_shift)
コード例 #6
0
ファイル: __init__.py プロジェクト: nirinA/kcorrect_python
def project_filters(wavelength, flux, band_shift=0.,
                     filterlist='sdss_filters.dat',
                     filterlist_dir='data/templates',
                     zmin=0., zmax=1.,nz=100):
    filename = os.path.join(
        os.getenv('KCORRECT_DIR'), filterlist_dir, filterlist)
    if not os.path.isfile(filename):
        raise _kcorrect.error('filter list %s not found.'%filename)
    return _kcorrect.projection_table(wavelength, flux, \
                                      band_shift, \
                                      filename, \
                                      zmin, zmax, nz)
コード例 #7
0
def project_filters(wavelength,
                    flux,
                    band_shift=0.,
                    filterlist='sdss_filters.dat',
                    filterlist_dir='data/templates',
                    zmin=0.,
                    zmax=1.,
                    nz=100):
    filename = os.path.join(os.getenv('KCORRECT_DIR'), filterlist_dir,
                            filterlist)
    if not os.path.isfile(filename):
        raise _kcorrect.error('filter list %s not found.' % filename)
    return _kcorrect.projection_table(wavelength, flux, \
                                      band_shift, \
                                      filename, \
                                      zmin, zmax, nz)
コード例 #8
0
def read_basel(solarname, silent=False):
    """
    Read a spectrum from a Basel spectrum file.
    """
    filename = os.path.join(os.getenv('KCORRECT_DIR'), 'data/basel', solarname)
    if not os.path.isfile(filename):
        raise _kcorrect.error('%s not found' % filename)
    with open(filename, 'r') as f:
        returndata = {
            'flux': [],
            'model': [],
            'teff': [],
            'logg': [],
            'mh': [],
            'vturb': [],
            'xh': []
        }
        rawdata = f.read()
        alldata = rawdata.replace("\n", '').split()
        returndata['wavelength'] = numpy.array(alldata[0:1221],
                                               dtype=numpy.float32)
        del alldata[0:1221]
        nunits = int(len(alldata) / (1227))
        if not silent:
            print("%d block(s) of spectra" % nunits)
        for u in range(nunits):
            returndata['model'].append(int(alldata[0]))
            returndata['teff'].append(int(alldata[1]))
            returndata['logg'].append(float(alldata[2]))
            returndata['mh'].append(float(alldata[3]))
            returndata['vturb'].append(float(alldata[4]))
            returndata['xh'].append(float(alldata[5]))
            returndata['flux'].append(
                numpy.array(alldata[6:1227], dtype=numpy.float32))
            del alldata[0:1227]
    return returndata
コード例 #9
0
def template(t, templates_dir='data/templates'):
    tfile = os.path.join(os.environ['KCORRECT_DIR'], templates_dir, t)
    if not os.path.isfile(tfile):
        raise _kcorrect.error('file: %s not found' % tfile)
    return _kcorrect.template(tfile)
コード例 #10
0
ファイル: __init__.py プロジェクト: nirinA/kcorrect_python
def template(t, templates_dir='data/templates'):
    tfile = os.path.join(os.environ['KCORRECT_DIR'], templates_dir, t)
    if not os.path.isfile(tfile):
        raise _kcorrect.error('file: %s not found'%tfile)
    return _kcorrect.template(tfile)
コード例 #11
0
ファイル: __init__.py プロジェクト: nirinA/kcorrect_python
def fit_coeffs(c):
    c = numpy.array(c, dtype='float32')    
    if len(c) == 11:
        return _kcorrect.fit_coeffs(c)
    else:
        raise _kcorrect.error('for this deault sdss filters, number of argument should be 11')
コード例 #12
0
ファイル: __init__.py プロジェクト: nirinA/kcorrect_python
def load_filters(f="sdss_filters.dat", band_shift=0.,
                 filters_dir='data/templates'):
    ffile = os.path.join(os.environ['KCORRECT_DIR'], filters_dir, f)
    if not os.path.isfile(ffile):
        raise _kcorrect.error('file: %s not found'%ffile)
    _kcorrect.load_filters(ffile, band_shift)