Esempio n. 1
0
def get_vals_from_header(primary_hdr):
    """ Helper function for ingest_contents to get values from primary header
        for insertion into rasicam_DECam table

        Parameters
        ----------
        primary_hdr : pyfits.Header
            The primary header

        Returns
        -------
        dict containing the needed data
    """

    #  Keyword list needed to update the database.
    #     i=int, f=float, b=bool, s=str, date=date
    keylist = {
        'EXPNUM': 'i',
        'INSTRUME': 's',
        'SKYSTAT': 'b',
        'SKYUPDAT': 'date',
        'GSKYPHOT': 'b',
        'LSKYPHOT': 'b',
        'GSKYVAR': 'f',
        'GSKYHOT': 'f',
        'LSKYVAR': 'f',
        'LSKYHOT': 'f',
        'LSKYPOW': 'f'
    }

    vals = {}
    for key, ktype in keylist.items():
        key = key.upper()
        if key in primary_hdr:
            value = primary_hdr[key]
            if key == 'SKYUPDAT':  # entry_time is time exposure taken
                vals['ENTRY_TIME'] = datetime.strptime(value,
                                                       "%Y-%m-%dT%H:%M:%S")
            elif key == 'INSTRUME':
                vals['CAMSYM'] = spmeta.create_camsym(value)
            elif ktype == 'b':
                if value:
                    vals[key] = 'T'
                else:
                    vals[key] = 'F'
            elif ktype == 'i':
                if value != 'NaN':
                    vals[key] = int(value)
            else:
                if value != 'NaN':
                    vals[key] = float(value)

    return vals
Esempio n. 2
0
def func_camsym(filename, hdulist=None, whichhdu=None):
    """ Create camsys from the INSTRUME keyword """

    hdulist2 = None
    if hdulist is None:
        hdulist2 = pyfits.open(filename, 'readonly')
    else:
        hdulist2 = hdulist

    instrume = fitsutils.get_hdr_value(hdulist2, 'INSTRUME', whichhdu)

    if hdulist is None:
        hdulist2.close()

    return spmeta.create_camsym(instrume)
Esempio n. 3
0
def func_camsym(filename, hdulist=None, whichhdu=None):
    """ Create camsym from the 'INSTRUME' keyword value.

        Parameters
        ----------
        filename : str
            The file to get the filter keyword from (must be a fits file),
            only used if hdulist is ``None``.

        hdulist : astropy.io.fits.HDUList, optional
            A listing of the HDUs to search for the requested HDU,
            default is ``None``, in which case `filename` is opened and used.

        whichhdu : various, optional
            The HDU being searched for, this can be an int for the HDU index,
            a string for the HDU name, or ``None`` in which case the primary
            HDU is used. The default is ``None``.

        Returns
        -------
        str
            Contains the generated camsym.

    """

    hdulist2 = None
    if hdulist is None:
        hdulist2 = fits.open(filename, 'readonly')
    else:
        hdulist2 = hdulist

    instrume = fitsutils.get_hdr_value(hdulist2, 'INSTRUME', whichhdu)

    if hdulist is None:
        hdulist2.close()

    return spmeta.create_camsym(instrume)