def single_star_photometry(img,
                           xc,
                           yc,
                           bkg,
                           filename,
                           images_info,
                           upper_limit=False):

    shortfile = filename.split('.fits')[0]
    ttexp = images_info.loc[0, 'EXPTIME']
    print('exptime = ' + str(ttexp))
    nanmask = pd.isnull(img)
    ap = 0.4 / images_info.loc[0, 'PIXSCALE']
    filt = images_info.loc[images_info['FILENAME'] == filename,
                           'FILTER'].values[0]
    vegazpt = config.VEGA_ZEROPTS[filt]
    pos = [float(xc), float(yc)]
    apertures = CircularAperture(pos, r=ap)

    sigma_clip = SigmaClip(sigma=3.)
    bkg_estimator = MedianBackground()
    bkgimg = Background2D(img, (20, 20),
                          filter_size=(3, 3),
                          sigma_clip=sigma_clip,
                          bkg_estimator=bkg_estimator)
    error = calc_total_error(
        img,
        bkgimg.background,
        effective_gain=images_info.loc[images_info['FILENAME'] == filename,
                                       'CCDGAIN'].values[0])
    #  error = calc_total_error(img, bkgimg.background, effective_gain=config.GAIN[instrument])

    #For sky annuli background
    #sky_inner = 0.8/images_info.loc[0,'PIXSCALE']
    #sky_outer = 0.9/images_info.loc[0,'PIXSCALE']
    #skyannuli = CircularAnnulus(pos, r_in=sky_inner, r_out=sky_outer)
    #phot_apers = [apertures, skyannuli]
    #phot_table2 = Table(aperture_photometry(img, phot_apers, method='exact', error=error, mask=nanmask)).to_pandas()

    #For multiapertures background
    phot = aperture_photometry(img, apertures, method='exact',
                               mask=nanmask)  #error=error,
    phot = Table(phot).to_pandas()

    phot = phot.rename(columns={'aperture_sum': 'APERTURE_FLUX'
                                })  #,'aperture_sum_err':'APERTURE_FLUX_ERR'
    phot['BKG_FLUX'] = bkg[0]
    phot['BKG_FLUX_ERR'] = bkg[1]
    phot['APERTURE_FLUX_ERR'] = np.sqrt(phot['APERTURE_FLUX'] / ttexp +
                                        2 * phot['BKG_FLUX_ERR']**2)
    phot = phot.apply(pd.to_numeric, errors='ignore')
    if upper_limit == True:
        print('this is true')
        print('background flux error = ' + str(bkg[1]))
        phot['STAR_FLUX'] = 3 * bkg[1]
        #3 sigma = 3 * 1.4826 * MAD since distribution is Gaussian - No more MAD, just STD
        phot['STAR_FLUX_ERR'] = np.nan
    else:
        #no need to divide over area because aperture areas for both star flux and backgroun flux are the same
        phot['STAR_FLUX'] = phot['APERTURE_FLUX'] - phot['BKG_FLUX']
        phot['STAR_FLUX_ERR'] = np.sqrt(phot['APERTURE_FLUX_ERR']**2 +
                                        phot['BKG_FLUX_ERR']**2)

        #bkg_mean = phot_table2['aperture_sum_1'] / skyannuli.area
        #bkg_starap_sum = bkg_mean * apertures.area
        #final_sum = phot_table2['aperture_sum_0']-bkg_starap_sum
        #phot_table2['bg_subtracted_star_counts'] = final_sum
        #bkg_mean_err = phot_table2['aperture_sum_err_1'] / skyannuli.area
        #bkg_sum_err = bkg_mean_err * apertures.area
        #phot_table2['bg_sub_star_cts_err'] = np.sqrt((phot_table2['aperture_sum_err_0']**2)+(bkg_sum_err**2))

        #phot['STAR_FLUX_ANNULI'] = final_sum
        #phot['STAR_FLUX_ERR_ANNULI'] = phot_table2['bg_sub_star_cts_err']

    phot['VEGAMAG'] = vegazpt - 2.5 * np.log10(phot['STAR_FLUX'])
    phot['VEGAMAG_UNC'] = 1.0857 * phot['STAR_FLUX_ERR'] / phot['STAR_FLUX']
    #phot['VEGAMAG_UNC_APPHOT_ONLY'] = 1.0857 * phot['APERTURE_FLUX_ERR'] / phot['STAR_FLUX']
    #phot['VEGAMAG_ANNULI'] = vegazpt - 2.5 * np.log10(phot['STAR_FLUX_ANNULI'])
    #phot['VEGAMAG_UNC_ANNULI'] = 1.0857 * phot['STAR_FLUX_ERR_ANNULI'] / phot['STAR_FLUX_ANNULI']
    phot.to_csv('phot_table_' + str(shortfile) + '.csv')

    return phot