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


Python astropy.table方法代码示例

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


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

示例1: get_drpall_row

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def get_drpall_row(plateifu, drpver=None, drpall=None):
    """Returns a dictionary from drpall matching the plateifu."""

    # get the drpall table
    drpall_table = get_drpall_table(drpver=drpver, drpall=drpall, hdu='MANGA')
    in_table = plateifu in drpall_table['plateifu']
    # check the mastar extension
    if not in_table:
        drpall_table = get_drpall_table(drpver=drpver, drpall=drpall, hdu='MASTAR')
        in_table = plateifu in drpall_table['plateifu']
        if not in_table:
            raise ValueError('No results found for {0} in drpall table'.format(plateifu))

    row = drpall_table[drpall_table['plateifu'] == plateifu]

    return row[0] 
开发者ID:sdss,项目名称:marvin,代码行数:18,代码来源:general.py

示例2: get_plates

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def get_plates(drpver=None, drpall=None, release=None):
    ''' Get a list of unique plates from the drpall file

    Parameters:
        drpver (str):
            The DRP release version to load.  Defaults to current marvin release
        drpall (str):
            The full path to the drpall table. Defaults to current marvin release.
        release (str):
            The marvin release

    Returns:
        A list of plate ids

    '''
    assert not all([drpver, release]), 'Cannot set both drpver and release '

    if release:
        drpver, __ = marvin.config.lookUpVersions(release)

    drpall_table = get_drpall_table(drpver=drpver, drpall=drpall)
    plates = list(set(drpall_table['plate']))
    return plates 
开发者ID:sdss,项目名称:marvin,代码行数:25,代码来源:general.py

示例3: _base_repr_

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def _base_repr_(self, html=False, show_name=True, **kwargs):
        """
        Override the method in the astropy.Table class
        to avoid displaying the description, and the format
        of the columns
        """

        table_id = 'table{id}'.format(id=id(self))

        data_lines, outs = self.formatter._pformat_table(self,
                                                         tableid=table_id, html=html, max_width=(-1 if html else None),
                                                         show_name=show_name, show_unit=None, show_dtype=False)

        out = '\n'.join(data_lines)

        # if astropy.table.six.PY2 and isinstance(out, astropy.table.six.text_type):
        #    out = out.encode('utf-8')

        return out 
开发者ID:threeML,项目名称:astromodels,代码行数:21,代码来源:table.py

示例4: search_around_source

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def search_around_source(self, source_name, radius):
        """
        Search for sources around the named source. The coordinates of the provided source are resolved using the
        astropy.coordinates.name_resolve facility.

        :param source_name: name of the source, like "Crab"
        :param radius: radius of the search, in degrees
        :return: (ra, dec, table), where ra,dec are the coordinates of the source as resolved by astropy, and table is
        a table with the list of sources
        """

        sky_coord = get_icrs_coordinates(source_name)

        ra, dec = (sky_coord.fk5.ra.value, sky_coord.fk5.dec.value)

        return ra, dec, self.cone_search(ra, dec, radius) 
开发者ID:threeML,项目名称:threeML,代码行数:18,代码来源:VirtualObservatoryCatalog.py

示例5: query

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def query(self, query):
        """
        query the entire VO table for the given logical argument. Queries are in the form of pandas
        queries: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.query.html

        To obtain a preview of the availble columns, try catalog.variables


        :param query: pandas style query string
        :return:
        """

        assert type(query) == str, "query must be a string"

        query_results = self._vo_dataframe.query(query)

        table = astro_table.Table.from_pandas(query_results)
        name_column = astro_table.Column(name="name", data=query_results.index)
        table.add_column(name_column, index=0)

        out = self.apply_format(table)

        self._last_query_results = query_results

        return out 
开发者ID:threeML,项目名称:threeML,代码行数:27,代码来源:VirtualObservatoryCatalog.py

示例6: _base_repr_

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def _base_repr_(self, html=False, show_name=True, **kwargs):
        """Override the method in the astropy.Table class
        to avoid displaying the description, and the format
        of the columns"""

        tableid = "table{id}".format(id=id(self))

        data_lines, outs = self.formatter._pformat_table(
            self,
            tableid=tableid,
            html=html,
            max_width=(-1 if html else None),
            show_name=show_name,
            show_unit=None,
            show_dtype=False,
        )

        out = "\n".join(data_lines)
        # if astropy.table.six.PY2 and isinstance(out, astropy.table.six.text_type):
        #     out = out.encode('utf-8')

        return out 
开发者ID:threeML,项目名称:threeML,代码行数:24,代码来源:table.py

示例7: to_table

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def to_table(self):
        """Exports the Periodogram as an Astropy Table.

        Returns
        -------
        table : `~astropy.table.Table` object
            An AstroPy Table with columns 'frequency', 'period', and 'power'.
        """
        return Table(data=(self.frequency, self.period, self.power),
                     names=('frequency', 'period', 'power'),
                     meta=self.meta) 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:13,代码来源:periodogram.py

示例8: test_writeFITSTable

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def test_writeFITSTable():
    """Test that we can write a fits table"""
    tab = table.Table.read('tests/test_files/1904_comp.fits')
    outfile = 'dlme.fits'
    tab.meta ={'test':'test'}
    cat.writeFITSTable(outfile, tab)
    if not os.path.exists(outfile):
        raise AssertionError()
    os.remove(outfile) 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:11,代码来源:test_catalogs.py

示例9: apply_format

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def apply_format(self, table):

        raise NotImplementedError("You have to override this!") 
开发者ID:threeML,项目名称:threeML,代码行数:5,代码来源:VirtualObservatoryCatalog.py

示例10: query_sources

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def query_sources(self, *sources):
        """
        query for the specific source names.

        :param sources: source(s) to search for
        :return:
        """

        valid_sources = []

        for source in sources:

            if self._source_is_valid(source):

                valid_sources.append(source)

        if valid_sources:

            query_string = " | ".join(['(index == "%s")' % x for x in valid_sources])

            query_results = self._vo_dataframe.query(query_string)

            table = astro_table.Table.from_pandas(query_results)

            name_column = astro_table.Column(name="name", data=query_results.index)
            table.add_column(name_column, index=0)

            out = self.apply_format(table)

            self._last_query_results = query_results

            return out

        else:

            RuntimeError("There were not valid sources in your search") 
开发者ID:threeML,项目名称:threeML,代码行数:38,代码来源:VirtualObservatoryCatalog.py

示例11: map_dapall

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def map_dapall(header, row):
    ''' Retrieves a dictionary of DAPall db column names

    For a given row in the DAPall file, returns a dictionary
    of corresponding DAPall database columns names with the
    appropriate values.

    Parameters:
        header (Astropy header):
            The primary header of the DAPall file
        row (recarray):
            A row of the DAPall binary table data

    Returns:
        A dictionary with db column names as keys and row data as values

    Example:
        >>> hdu = fits.open('dapall-v2_3_1-2.1.1.fits')
        >>> header = hdu[0].header
        >>> row = hdu[1].data[0]
        >>> dbdict = map_dapall(header, row)

    '''

    # get names from header
    emline_schannels = []
    emline_gchannels = []
    specindex_channels = []
    for key, val in header.items():
        if 'ELS' in key:
            emline_schannels.append(val.lower().replace('-', '_').replace('.', '_'))
        elif 'ELG' in key:
            emline_gchannels.append(val.lower().replace('-', '_').replace('.', '_'))
        elif re.search('SPI([0-9])', key):
            specindex_channels.append(val.lower().replace('-', '_').replace('.', '_'))

    # File column names
    names = row.array.names

    dbdict = {}
    for col in names:
        name = col.lower()
        shape = row[col].shape if hasattr(row[col], 'shape') else ()
        array = ''
        values = row[col]

        if len(shape) > 0:
            channels = shape[0]
            for i in range(channels):
                channame = emline_schannels[i] if 'emline_s' in name else \
                    emline_gchannels[i] if 'emline_g' in name else \
                    specindex_channels[i] if 'specindex' in name else i + 1
                colname = '{0}_{1}'.format(name, channame)
                dbdict[colname] = values[i]
        else:
            dbdict[name] = values

    return dbdict 
开发者ID:sdss,项目名称:marvin,代码行数:60,代码来源:general.py

示例12: get_drpall_table

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def get_drpall_table(drpver=None, drpall=None, hdu='MANGA'):
    ''' Gets the drpall table

    Gets the drpall table either from cache or loads it. For releases
    of MPL-8 and up, galaxies are in the MANGA extension, and mastar
    targets are in the MASTAR extension, specified with the hdu keyword. For
    MPLs 1-7, there is only one data extension, which is read.

    Parameters:
        drpver (str):
            The DRP release version to load.  Defaults to current marvin release
        drpall (str):
            The full path to the drpall table. Defaults to current marvin release.
        hdu (str):
            The name of the HDU to read in.  Default is 'MANGA'

    Returns:
        An Astropy Table
    '''

    from marvin import config
    assert hdu.lower() in ['manga', 'mastar'], 'hdu can either be MANGA or MASTAR'
    hdu = hdu.upper()

    # get the drpall file
    get_drpall_file(drpall=drpall, drpver=drpver)

    # Loads the drpall table if it was not cached from a previous session.
    config_drpver, __ = config.lookUpVersions()
    drpver = drpver if drpver else config_drpver

    # check for drpver
    if drpver not in drpTable:
        drpTable[drpver] = {}

    # check for hdu
    hduext = hdu if check_versions(drpver, 'v2_5_3') else 'MANGA'
    if hdu not in drpTable[drpver]:
        drpall = drpall if drpall else config._getDrpAllPath(drpver=drpver)
        data = {hduext: table.Table.read(drpall, hdu=hduext)}
        drpTable[drpver].update(data)

    drpall_table = drpTable[drpver][hduext]

    return drpall_table 
开发者ID:sdss,项目名称:marvin,代码行数:47,代码来源:general.py

示例13: dict_to_table

# 需要导入模块: import astropy [as 别名]
# 或者: from astropy import table [as 别名]
def dict_to_table(dictionary, list_of_keys=None):
    """
    Return a table representing the dictionary.

    :param dictionary: the dictionary to represent
    :param list_of_keys: optionally, only the keys in this list will be inserted in the table
    :return: a Table instance
    """

    # assert len(dictionary.values()) > 0, "Dictionary cannot be empty"

    # Create an empty table

    table = Table()

    # If the dictionary is not empty, fill the table

    if len(dictionary) > 0:

        # Add the names as first column

        table['name'] = list(dictionary.keys())

        # Now add all other properties

        # Use the first parameter as prototype

        prototype = list(dictionary.values())[0]

        column_names = list(prototype.keys())

        # If we have a white list for the columns, use it

        if list_of_keys is not None:

            column_names = [key for key in column_names if key in list_of_keys]

        # Fill the table

        for column_name in column_names:

            table[column_name] = [x[column_name] for x in list(dictionary.values())]

    return table


# A hack on the astropy Table class to make its output
# more appealing, especially when in the Ipython notebook 
开发者ID:threeML,项目名称:astromodels,代码行数:50,代码来源:table.py


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