コード例 #1
0
ファイル: zeropoint.py プロジェクト: nblago/kpy
def calibrate_zeropoint(image, plot=True, debug=False, refstars=None):
    
    filt = fitsutils.get_par(image, 'filter')
    exptime = fitsutils.get_par(image, "exptime")
    if fitsutils.has_par(image, "JD"):
        date = fitsutils.get_par(image, "JD")
    elif fitsutils.has_par(image, "MJD"):
        date = fitsutils.get_par(image, "MJD")

    objname = fitsutils.get_par(image, "OBJECT")
    airmass = fitsutils.get_par(image, "AIRMASS")
    
    print "Starting calibration of ZP for image", image,"for object", objname

    if (exptime < 10):
        print "ERROR. Exposure time too short for this image to see anything..."
        return 

    extracted = extract_star_sequence(image, filt, plot=plot, survey='sdss', debug=debug, refstars=refstars)
    if (not extracted):
        print "Field not in SDSS or error when retrieving the catalogue... Skipping."
        return 

    #If extraction worked, we can get the FWHM        
    fwhm = fitsutils.get_par(image, "fwhm")
    fwhm_as = fwhm * 0.394

    app_phot.get_app_phot("/tmp/sdss_cat_det.txt", image, wcsin='logic')
    z, c, err = find_zeropoint_noid("/tmp/sdss_cat_det.txt", image, plot=plot)
    
    #Log the current zeropoint for this image
    logname = os.path.join(os.path.dirname(image), "zeropoint.log")
    
    #Add the data to a later stage zeropoint calibrtion with all-sky data.
    zplogname = os.path.join(os.path.dirname(image), "allstars_zp.log")
    
    add_to_zp_cal("/tmp/sdss_cat_det.txt", image, zplogname)


    if (not os.path.isfile(logname)):
            with open( logname, "a") as f:
                f.write("#filename,exptime,filter,date,airmass,fwhm_pix,fwhm_as,zeropoint,color,err\n")
    with open( logname, "a") as f:
        f.write("%s,%.1f,%s,%3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n"%(image,exptime,filt,date,airmass,fwhm,fwhm_as,z,c,err))
コード例 #2
0
ファイル: zeropoint.py プロジェクト: scizen9/kpy
def calibrate_zeropoint(image, plot=True, plotdir=None, debug=False, refstars=None):
    """
    Calibrates the zeropoint using SDSS catalogue.    
    """

    if plot and plotdir is None:
        plotdir = os.path.join(os.path.dirname(image), "photometry")
        if not os.path.isdir(plotdir):
            os.makedirs(plotdir)

    filt = fitsutils.get_par(image, "filter")
    exptime = fitsutils.get_par(image, "exptime")
    if fitsutils.has_par(image, "JD"):
        date = fitsutils.get_par(image, "JD")
    elif fitsutils.has_par(image, "MJD"):
        date = fitsutils.get_par(image, "MJD")
    elif fitsutils.has_par(image, "MJD-OBS"):
        date = fitsutils.get_par(image, "MJD-OBS")
    else:
        date = 0

    if fitsutils.has_par(image, "AIRMASS"):
        airmass = fitsutils.get_par(image, "AIRMASS")
    else:
        airmass = 1.3
    objname = fitsutils.get_par(image, "OBJECT")
    band = fitsutils.get_par(image, "FILTER")

    logger.info("Starting calibration of ZP for image %s for object %s with filter %s." % (image, objname, band))

    if exptime < 10:
        logger.error("ERROR. Exposure time too short for image (%s) to see anything..." % image)
        return

    extracted = extract_star_sequence(
        os.path.abspath(image), filt, plot=plot, survey="sdss", debug=debug, refstars=refstars, plotdir=plotdir
    )
    if not extracted:
        logger.warn(
            "Field not in SDSS or error when retrieving the catalogue... Skipping. Image %s not zeropoint calibrated."
            % image
        )
        # Add these values to the header.
        pardic = {"IQZEROPT": 0, "ZPCAT": "None", "ZEROPTU": 0, "ZEROPT": 0, "ZP": 0, "ZPERR": 0}
        fitsutils.update_pars(image, pardic)
        return

    # If extraction worked, we can get the FWHM
    fwhm = fitsutils.get_par(image, "fwhm")
    fwhm_as = fwhm * 0.394

    app_phot.get_app_phot("/tmp/sdss_cat_det_%s.txt" % creationdate, image, wcsin="logic", plotdir=plotdir, box=20)

    # Compute the zeropoint for the specific image.
    z, c, err = find_zeropoint_noid("/tmp/sdss_cat_det_%s.txt" % creationdate, image, plot=plot, plotdir=plotdir)

    # Add these values to the header.
    pardic = {"IQZEROPT": 1, "ZPCAT": "SDSS", "ZEROPTU": np.round(err, 3), "ZEROPT": np.round(z, 3)}
    fitsutils.update_pars(image, pardic)

    # Log the current zeropoint for this image
    logname = os.path.join(os.path.dirname(image), "zeropoint.log")

    # Add the data to a later stage zeropoint calibrtion with all-sky data.
    zplogname = os.path.join(os.path.dirname(image), "allstars_zp.log")

    add_to_zp_cal("/tmp/sdss_cat_det_%s.txt" % creationdate, image, zplogname)

    if not os.path.isfile(logname):
        with open(logname, "a") as f:
            f.write("#filename,exptime,filter,date,airmass,fwhm_pix,fwhm_as,zeropoint,color,err\n")
    with open(logname, "a") as f:
        f.write(
            "%s,%.1f,%s,%3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n"
            % (image, exptime, filt, date, airmass, fwhm, fwhm_as, z, c, err)
        )

    clean_tmp_files()