コード例 #1
0
    obj_images = list(list_images["filename"][np.where( (list_images["objname"] == obj))])
    output_db = os.path.join(directory, obj+".db")
    utilities.if_exists_remove(output_db)
    coord_file = utilities.replace_extension(obj_images[0], "radec")
    photometry.main(arguments=["--maximum", str(max_counts), "--uik", "", "--margin", "20", "--gaink", gaink,
                              "--aperture", "4.", "--annulus", "6", "--dannulus", "2", "--individual-fwhm", "--objectk", objectk,
                              "--filterk", filterk, "--datek", datek, "--expk", exptimek, "--fwhmk", seeingk, "--airmk", airmassk,
                              "--coordinates", coord_file, obj_images[0]] + obj_images + [output_db])

print "Find extinction coefficient from photometry of standards"
standards_set = set(x for x,t in zip(list_images["objname"], list_images["type"]) if t == "standards")
coefficient_list = []
for obj in standards_set:
    input_db = os.path.join(directory, obj+".db")
    airmasses, magnitudes, filters, SNR = extract.main(input_db)
    magnitude_errors_minus, magnitude_errors_plus = snr.snr_to_error(SNR)
    mag_errors = (-magnitude_errors_minus + magnitude_errors_plus) / 2.
    for filt in set(filters.flatten()):
        # find columns with the current filter
        columns = [ii for ii in range(len(filters[0, :])) if filters[0,ii] == filt]
        # if there are more than two images
        if len(airmasses[0,columns]) > 0 and len(airmasses[0,columns]) > 2:
            ext_coeff, serror_ext_coeff = calculate_extinction(airmasses[:, columns],
                                                               magnitudes[:, columns],
                                                               err_magnitudes=mag_errors[:,columns])
            coefficient_list.append(ext_coeff)
            #plt.plot(airmasses[:, columns], magnitudes[:, columns], 'o')
            #plt.show()
            print "Extinction coefficient for ", obj, " for filter ", filt, ":", ext_coeff, "+/-", serror_ext_coeff
        else:
            print "Not used ",  obj, " with filter " + filt + ". Too few elements."
コード例 #2
0
def calculate_extinctions(args):
    """ Iterate through the databases and find the extinction coefficient for every filter
    """
    results = {}  # Dictionary for the outputs
    for DB in args.inputdb:
        print "\nStudying database {0}:".format(DB)
        airmass, magnitudes, filters, SNR, im_paths = extract.main(DB)

        # SNR is the signal-to-noise-ratio, we want to use the errors in the magnitudes
        magnitude_errors_minus, magnitude_errors_plus = snr.snr_to_error(SNR)
        mag_errors = (-magnitude_errors_minus + magnitude_errors_plus) / 2.

        # Which filters are present?
        filter_set = set(filters.flatten().tolist())

        # Prepare the figure for the plots.
        if args.plot:
            figure = plt.figure()
            figure.set_label("BD+25")
            ax0 = plt.subplot2grid((2,2),(0, 0))
            ax1 = plt.subplot2grid((2,2),(0, 1))
            ax2 = plt.subplot2grid((2,2),(1, 0))
            ax = [ax0, ax1, ax2]
            plt.subplots_adjust(hspace=0.3)
            plt.subplots_adjust(wspace=0.12)
            plt.subplots_adjust(top=0.95)
            plt.subplots_adjust(bottom=0.05)
            plt.subplots_adjust(left=0.05)
            plt.subplots_adjust(right=0.95)



        for ii, filt in enumerate(filter_set):
            # Select only those data for the particular filter
            whr_filt = numpy.where(filters[0, :] == filt)[0]


            # If the airmass difference is not, at least, 0.2, skip this test because the fit will be meaningless
            airm_diff = numpy.max(airmass[:, whr_filt]) - numpy.min(airmass[:, whr_filt])
            if airm_diff < 0.2:
                print "Airmasses are too close for filter {0} ".format(filt)
                plt.close()
                continue

            # Select the brightest objects and do the fit
            mags_filt, airm_filt, errors_filt = select_brightest(magnitudes[:, whr_filt],
                                                                 airmass[:, whr_filt],
                                                                 mag_errors[:, whr_filt],
                                                                 nstars=args.nstars)
            ext, ext_err = extinction_fit(airm_filt, mags_filt, errors_filt)
            print "Extinction coefficient for filter {0}: {1} +- {2}".format(filt, ext, ext_err)
            results[(DB, filt)] = (ext, ext_err)

            # Do the plot of the selected stars
            if args.plot:
                for star_airmass, star_mag in zip(airm_filt, mags_filt):
                    ax[ii].plot(star_airmass, star_mag, 'o')
                    ax[ii].set_title(filt)
                    ax[ii].set_xlabel("Airmass")

        if args.plot:
            plt.show()

    return results