当前位置: 首页>>代码示例>>Python>>正文


Python ascii.read方法代码示例

本文整理汇总了Python中astropy.io.ascii.read方法的典型用法代码示例。如果您正苦于以下问题:Python ascii.read方法的具体用法?Python ascii.read怎么用?Python ascii.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy.io.ascii的用法示例。


在下文中一共展示了ascii.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: vizier

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def vizier(cat,filePath,ReadMePath,
           catalogname='catalog.dat',readmename='ReadMe'):
    """
    NAME:
       vizier
    PURPOSE:
       download a catalog and its associated ReadMe from Vizier
    INPUT:
       cat - name of the catalog (e.g., 'III/272' for RAVE, or J/A+A/... for journal-specific catalogs)
       filePath - path of the file where you want to store the catalog (note: you need to keep the name of the file the same as the catalogname to be able to read the file with astropy.io.ascii)
       ReadMePath - path of the file where you want to store the ReadMe file
       catalogname= (catalog.dat) name of the catalog on the Vizier server
       readmename= (ReadMe) name of the ReadMe file on the Vizier server
    OUTPUT:
       (nothing, just downloads)
    HISTORY:
       2016-09-12 - Written - Bovy (UofT)
    """
    _download_file_vizier(cat,filePath,catalogname=catalogname)
    _download_file_vizier(cat,ReadMePath,catalogname=readmename)
    return None 
开发者ID:jobovy,项目名称:gaia_tools,代码行数:23,代码来源:download.py

示例2: test_get_all_catalogs

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_get_all_catalogs():
    """Test the wrapper that queries anc combines catalogs from all sources"""
    ra = 80.4
    dec = -69.8
    width = 120.
    ins = 'NIRCAM'
    filters = ['F150W', 'F356W', 'F444W', 'F480M']

    cat, headers = create_catalog.get_all_catalogs(ra, dec, width, kmag_limits=(13, 29),
                                                   email='hilbert@stsci.edu', instrument=ins, filters=filters,
                                                   besancon_seed=1234)
    comparison_file = os.path.join(TEST_DATA_DIR, 'catalog_generation/get_all_catalogs.cat')
    comparison_data = ascii.read(comparison_file)

    # Note that if Besancon/WISE/GAIA/2MASS query results change, this will
    # fail without there being a problem with Mirage.
    for col in cat.table.colnames:
        try:
            assert all(cat.table[col].data == comparison_data[col].data), \
                "Retrieved catalog does not match expected."
        except TypeError:
            assert False, "Retrieved catalog does not match expected." 
开发者ID:spacetelescope,项目名称:mirage,代码行数:24,代码来源:test_catalog_generation.py

示例3: read_subarray_definition_file

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def read_subarray_definition_file(filename):
    """Read in the file that contains a list of subarray names and related information

    Parameters:
    -----------
    filename : str
        Name of the ascii file containing the table of subarray information

    Returns:
    --------
    data : astropy.table.Table
        Table containing subarray information
    """
    try:
        data = asc.read(filename, data_start=1, header_start=0)
    except:
        raise RuntimeError(("Error: could not read in subarray definitions file: {}"
                            .format(filename)))
    return data 
开发者ID:spacetelescope,项目名称:mirage,代码行数:21,代码来源:utils.py

示例4: read_yaml

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def read_yaml(filename):
    """Read the contents of a yaml file into a nested dictionary

    Parameters
    ----------
    filename : str
        Name of yaml file to be read in

    Returns
    -------
    data : dict
        Nested dictionary of file contents
    """
    try:
        with open(filename, 'r') as f:
            data = yaml.load(f, Loader=yaml.FullLoader)
    except FileNotFoundError as e:
            print(e)
    return data 
开发者ID:spacetelescope,项目名称:mirage,代码行数:21,代码来源:utils.py

示例5: read_filter_throughput

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def read_filter_throughput(filename):
    """Read in the ascii file containing a filter throughput curve

    Parameters
    ----------
    filename : str
        Name of ascii file containing throughput info

    Returns
    -------
    (wavelengths, throughput) : tup
        Tuple of 1D numpy arrays containing the wavelength and throughput
        values from the file
    """
    tab = ascii.read(filename)
    return tab['Wavelength_microns'].data, tab['Throughput'].data 
开发者ID:spacetelescope,项目名称:mirage,代码行数:18,代码来源:file_io.py

示例6: read_linear_dark

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def read_linear_dark(self, input_file):
        """Read in the linearized version of the dark current ramp
        using the read_fits class"""
        try:
            print(('Reading in linearized dark current ramp from {}'
                   .format(input_file)))
            self.linDark = read_fits.Read_fits()
            #self.linDark.file = self.params['Reffiles']['linearized_darkfile']
            self.linDark.file = input_file
            self.linDark.read_astropy()
        except:
            raise IOError('WARNING: Unable to read in linearized dark ramp.')

        # Finally, collect information about the detector, which will be needed for astrometry later
        self.detector = self.linDark.header['DETECTOR']
        self.instrument = self.linDark.header['INSTRUME']
        self.fastaxis = self.linDark.header['FASTAXIS']
        self.slowaxis = self.linDark.header['SLOWAXIS'] 
开发者ID:spacetelescope,项目名称:mirage,代码行数:20,代码来源:dark_prep.py

示例7: get_nonlinearity_coeffs

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def get_nonlinearity_coeffs(self):
        """Wrapper around get_nonlin_coeffs. If the file can't
        be opened, or no file is given, the code falls back to some
        average non-linearity coefficients. This would probably be
        bad to use...
        """
        if self.params['Reffiles']['linearity'] is not None:
            try:
                nonlin = self.get_nonlin_coeffs(self.params['Reffiles']['linearity'])
            except:
                print("Unable to read in non-linearity correction coefficients")
                print("from {}.".format(self.params['Reffiles']['linearity']))
                print("Using a set of mean coefficients.")
                nonlin = np.array([0., 1.0, 9.69903112e-07, 3.85263835e-11,
                                   1.09267058e-16, -5.30613939e-20, 9.27963411e-25])
        else:
            print("No linearity coefficient file provided. Proceeding using a")
            print("set of mean coefficients derived from CV3 data.")
            nonlin = np.array([0., 1.0, 9.69903112e-07, 3.85263835e-11,
                               1.09267058e-16, -5.30613939e-20, 9.27963411e-25])
        # print('Nonlinearity coefficients: ', nonlin)
        return nonlin 
开发者ID:spacetelescope,项目名称:mirage,代码行数:24,代码来源:obs_generator.py

示例8: read_crosstalk_file

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def read_crosstalk_file(self, file, detector):
        """Read in appropriate line from the xtalk coefficients
        file for the given detector and return the coeffs

        Parameters
        ----------
        file : str
            Name of ascii file containing the crosstalk coefficients

        detector : str
            Name of the detector being simulated

        Returns
        -------
        xtcoeffs : list
            Collection of crosstalk coefficients associated with detector
        """
        xtcoeffs = ascii.read(file, header_start=0)

        coeffs = []
        mtch = xtcoeffs['Det'] == detector.upper()
        if np.any(mtch) is False:
            raise ValueError('Detector {} not found in xtalk file {}'.format(detector, file))

        return xtcoeffs[mtch] 
开发者ID:spacetelescope,项目名称:mirage,代码行数:27,代码来源:obs_generator.py

示例9: filter_check

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def filter_check(self, inst_name, filt_name):
        """Make sure the requested instrument/filter pair is valid
        """
        if inst_name == 'nircam':
            filter_file = 'nircam_filter_pupil_pairings.list'
        elif inst_name == 'niriss':
            filter_file = 'niriss_dual_wheel_list.txt'

        if inst_name in ['nircam', 'niriss']:
            filter_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../config/',
                                                            filter_file))
            filter_table = ascii.read(filter_file_path)
            if filt_name.upper() not in filter_table['filter']:
                raise ValueError("WARNING: {} is not a valid filter for {}.".format(filt_name,
                                                                                    inst_name.upper()))
        if inst_name == 'fgs':
            if filt_name.lower() not in ['guider1', 'guider2']:
                raise ValueError("WARNING: {} is not a valid filter for FGS.".format(filt_name)) 
开发者ID:spacetelescope,项目名称:mirage,代码行数:20,代码来源:catalog_generator.py

示例10: test_read_write_format

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_read_write_format(fmt):
    """
    Test round-trip through pandas write/read for supported formats.

    :param fmt: format name, e.g. csv, html, json
    :return:
    """
    # Skip the reading tests
    if fmt == 'html' and not HAS_HTML_DEPS:
        pytest.skip('Missing lxml or bs4 + html5lib for HTML read/write test')

    pandas_fmt = 'pandas.' + fmt
    # Explicitly provide dtype to avoid casting 'a' to int32.
    # See https://github.com/astropy/astropy/issues/8682
    t = Table([[1, 2, 3], [1.0, 2.5, 5.0], ['a', 'b', 'c']],
              dtype=(np.int64, np.float64, np.str))
    buf = StringIO()
    t.write(buf, format=pandas_fmt)

    buf.seek(0)
    t2 = Table.read(buf, format=pandas_fmt)

    assert t.colnames == t2.colnames
    assert np.all(t == t2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:test_pandas.py

示例11: test_read_fixed_width_format

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_read_fixed_width_format():
    """Test reading with pandas read_fwf()

    """
    tbl = """\
    a   b   c
    1  2.0  a
    2  3.0  b"""
    buf = StringIO()
    buf.write(tbl)

    # Explicitly provide converters to avoid casting 'a' to int32.
    # See https://github.com/astropy/astropy/issues/8682
    t = Table.read(tbl, format='ascii', guess=False,
                   converters={'a': [ascii.convert_numpy(np.int64)]})

    buf.seek(0)
    t2 = Table.read(buf, format='pandas.fwf')

    assert t.colnames == t2.colnames
    assert np.all(t == t2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_pandas.py

示例12: test_write_with_mixins

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_write_with_mixins():
    """Writing a table with mixins just drops them via to_pandas()

    This also tests passing a kwarg to pandas read and write.
    """
    sc = SkyCoord([1, 2], [3, 4], unit='deg')
    q = [5, 6] * u.m
    qt = QTable([[1, 2], q, sc], names=['i', 'q', 'sc'])

    buf = StringIO()
    qt.write(buf, format='pandas.csv', sep=' ')
    exp = ['i q sc.ra sc.dec',
           '1 5.0 1.0 3.0',
           '2 6.0 2.0 4.0']
    assert buf.getvalue().splitlines() == exp

    # Read it back
    buf.seek(0)
    qt2 = Table.read(buf, format='pandas.csv', sep=' ')
    # Explicitly provide converters to avoid casting 'i' to int32.
    # See https://github.com/astropy/astropy/issues/8682
    exp_t = ascii.read(exp, converters={'i': [ascii.convert_numpy(np.int64)]})
    assert qt2.colnames == exp_t.colnames
    assert np.all(qt2 == exp_t) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:test_pandas.py

示例13: test_doubled_quotes

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_doubled_quotes(read_csv):
    """
    Test #8283 (fix for #8281), parsing doubled-quotes "ab""cd" in a quoted
    field was incorrect.

    """
    tbl = '\n'.join(['a,b',
                     '"d""","d""q"',
                     '"""q",""""'])
    expected = Table([['d"', '"q'],
                      ['d"q', '"']],
                     names=('a', 'b'))

    dat = read_csv(tbl)
    assert_table_equal(dat, expected)

    # In addition to the local read_csv wrapper, check that default
    # parsing with guessing gives the right answer.
    for fast_reader in True, False:
        dat = ascii.read(tbl, fast_reader=fast_reader)
        assert_table_equal(dat, expected) 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_c_reader.py

示例14: test_not_enough_cols

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_not_enough_cols(parallel, read_csv):
    """
    If a row does not have enough columns, the FastCsv reader should add empty
    fields while the FastBasic reader should raise an error.
    """
    text = """
A,B,C
1,2,3
4,5
6,7,8
"""
    table = read_csv(text, parallel=parallel)
    assert table['B'][1] is not ma.masked
    assert table['C'][1] is ma.masked

    with pytest.raises(InconsistentTableError) as e:
        table = FastBasic(delimiter=',').read(text) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_c_reader.py

示例15: test_strip_line_trailing_whitespace

# 需要导入模块: from astropy.io import ascii [as 别名]
# 或者: from astropy.io.ascii import read [as 别名]
def test_strip_line_trailing_whitespace(parallel, read_basic):
    """
    Readers that strip whitespace from lines should ignore
    trailing whitespace after the last data value of each
    row.
    """
    text = 'a b c\n1 2 \n3 4 5'
    with pytest.raises(InconsistentTableError) as e:
        ascii.read(StringIO(text), format='fast_basic', guess=False)
    assert 'header columns (3) inconsistent with data columns in data line 0' \
        in str(e.value)

    text = 'a b c\n 1 2 3   \t \n 4 5 6 '
    table = read_basic(text, parallel=parallel)
    expected = Table([[1, 4], [2, 5], [3, 6]], names=('a', 'b', 'c'))
    assert_table_equal(table, expected) 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_c_reader.py


注:本文中的astropy.io.ascii.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。