How to use the fitsio.util.mks 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 / table.py View on Github external
def _extract_colnum(self, col):
        """
        Get the column number for the input column
        """
        if isinteger(col):
            colnum = col

            if (colnum < 0) or (colnum > (self._ncol-1)):
                raise ValueError(
                    "column number should be in [0,%d]" % (0, self._ncol-1))
        else:
            colstr = mks(col)
            try:
                if self.case_sensitive:
                    mess = "column name '%s' not found (case sensitive)" % col
                    colnum = self._colnames.index(colstr)
                else:
                    mess \
                        = "column name '%s' not found (case insensitive)" % col
                    colnum = self._colnames_lower.index(colstr.lower())
            except ValueError:
                raise ValueError(mess)
        return int(colnum)
github esheldon / fitsio / fitsio / fitslib.py View on Github external
def __getitem__(self, item):
        """
        Get an hdu by number, name, and possibly version
        """
        if not hasattr(self, 'hdu_list'):
            self.update_hdu_list()

        ext, ver, ver_sent = self._extract_item(item)

        try:
            # if it is an int
            hdu = self.hdu_list[ext]
        except Exception:
            # might be a string
            ext = mks(ext)
            if not self.case_sensitive:
                mess = '(case insensitive)'
                ext = ext.lower()
            else:
                mess = '(case sensitive)'

            if ver > 0:
                key = '%s-%s' % (ext, ver)
                if key not in self.hdu_map:
                    raise IOError("extension not found: %s, "
                                  "version %s %s" % (ext, ver, mess))
                hdu = self.hdu_map[key]
            else:
                if ext not in self.hdu_map:
                    raise IOError("extension not found: %s %s" % (ext, mess))
                hdu = self.hdu_map[ext]
github esheldon / fitsio / fitsio / fitslib.py View on Github external
if len(dims) != len(names):
                    raise ValueError("names and dims must be same length")

        if units is not None:
            if not isinstance(units, list):
                raise ValueError("units should be a list")
            if len(units) != len(names):
                raise ValueError("names and units must be same length")

        if extname is None:
            # will be ignored
            extname = ""
        else:
            if not isstring(extname):
                raise ValueError("extension name must be a string")
            extname = mks(extname)

        if extname is not None and extver is not None:
            extver = check_extver(extver)
        if extver is None:
            # will be ignored
            extver = 0
        if extname is None:
            # will be ignored
            extname = ""

        if header is not None:
            nkeys = len(header)
        else:
            nkeys = 0

        # note we can create extname in the c code for tables, but not images
github esheldon / fitsio / fitsio / fitslib.py View on Github external
def movnam_hdu(self, extname, hdutype=ANY_HDU, extver=0):
        """
        Move to the indicated HDU by name

        In general, it is not necessary to use this method explicitly.

        returns the one-offset extension number
        """
        extname = mks(extname)
        hdu = self._FITS.movnam_hdu(hdutype, extname, extver)
        return hdu
github esheldon / fitsio / fitsio / fitslib.py View on Github external
def extract_filename(filename):
    filename = mks(filename)
    filename = filename.strip()
    if filename[0] == "!":
        filename = filename[1:]
    filename = os.path.expandvars(filename)
    filename = os.path.expanduser(filename)
    return filename
github esheldon / fitsio / fitsio / fitslib.py View on Github external
def movnam_ext(self, extname, hdutype=ANY_HDU, extver=0):
        """
        Move to the indicated extension by name

        In general, it is not necessary to use this method explicitly.

        returns the zero-offset extension number
        """
        extname = mks(extname)
        hdu = self._FITS.movnam_hdu(hdutype, extname, extver)
        return hdu-1