How to use the fitsio.header.FITSHDR function in fitsio

To help you get started, we’ve selected a few fitsio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esheldon / fitsio / fitsio / hdu / base.py View on Github external
def read_header(self):
        """
        Read the header as a FITSHDR

        The FITSHDR allows access to the values and comments by name and
        number.
        """
        # note converting strings
        return FITSHDR(self.read_header_list())
github esheldon / fitsio / fitsio / hdu / base.py View on Github external
in this case, and the order is arbitrary.
        clean: boolean
            If True, trim out the standard fits header keywords that are
            created on HDU creation, such as EXTEND, SIMPLE, STTYPE, TFORM,
            TDIM, XTENSION, BITPIX, NAXIS, etc.

        Notes
        -----
        Input keys named COMMENT and HISTORY are written using the
        write_comment and write_history methods.
        """

        if isinstance(records_in, FITSHDR):
            hdr = records_in
        else:
            hdr = FITSHDR(records_in)

        if clean:
            is_table = hasattr(self, '_table_type_str')
            # is_table = isinstance(self, TableHDU)
            hdr.clean(is_table=is_table)

        for r in hdr.records():
            name = r['name']
            if name is not None:
                name = name.upper()

            value = r['value']

            if name == 'COMMENT':
                self.write_comment(value)
            elif name == 'HISTORY':
github esheldon / fitsio / fitsio / header.py View on Github external
def __init__(self, record_list=None):

        self._record_list = []
        self._record_map = {}
        self._index_map = {}

        if isinstance(record_list, FITSHDR):
            for r in record_list.records():
                self.add_record(r)
        elif isinstance(record_list, dict):
            for k in record_list:
                r = {'name': k, 'value': record_list[k]}
                self.add_record(r)
        elif isinstance(record_list, list):
            for r in record_list:
                self.add_record(r)
        elif record_list is not None:
            raise ValueError("expected a dict or list of dicts or FITSHDR")
github esheldon / fitsio / fitsio / fitslib.py View on Github external
Optionally combine the header with the input one. The input can
        be any object convertable to a FITSHDR object

    returns
    -------
    header: FITSHDR
        A fits header object of type FITSHDR
    """

    with open(fname) as fobj:
        lines = fobj.readlines()

    lines = [l.strip() for l in lines if l[0:3] != 'END']

    # if header is None an empty FITSHDR is created
    hdr = FITSHDR(header)

    for l in lines:
        hdr.add_record(l)

    return hdr
github esheldon / fitsio / fitsio / hdu / base.py View on Github external
- list of dictionaries containing 'name','value' and optionally
                  a 'comment' field; the order is preserved.
                - a dictionary of keyword-value pairs; no comments are written
                  in this case, and the order is arbitrary.
        clean: boolean
            If True, trim out the standard fits header keywords that are
            created on HDU creation, such as EXTEND, SIMPLE, STTYPE, TFORM,
            TDIM, XTENSION, BITPIX, NAXIS, etc.

        Notes
        -----
        Input keys named COMMENT and HISTORY are written using the
        write_comment and write_history methods.
        """

        if isinstance(records_in, FITSHDR):
            hdr = records_in
        else:
            hdr = FITSHDR(records_in)

        if clean:
            is_table = hasattr(self, '_table_type_str')
            # is_table = isinstance(self, TableHDU)
            hdr.clean(is_table=is_table)

        for r in hdr.records():
            name = r['name']
            if name is not None:
                name = name.upper()

            value = r['value']
github esheldon / fitsio / fitsio / fitslib.py View on Github external
found = True
                            break
                        else:
                            if extver_num == vers:
                                found = True
                                break
                except OSError:
                    break

                current_ext += 1

            if not found:
                raise IOError(
                    'hdu not found: %s (extver %s)' % (extname, extver))

    return FITSHDR(_fits.read_header(hdunum))