def test_apcorrect1_FUV(self): aper = np.array([1.5,2.3,3.8,6.0,9.0,12.8,17.3,30.,60.,90.])/3600. dmag = [1.65,0.96,0.36,0.15,0.1,0.09,0.07,0.06,0.03,0.01] for i in np.arange(len(aper)): self.assertAlmostEqual(gt.apcorrect1(aper[i],'FUV'),dmag[i]) if aper[i]<aper[-1]: self.assertAlmostEqual(gt.apcorrect1((aper[i]+aper[i+1])/2.,'FUV'),(dmag[i]+dmag[i+1])/2.) self.assertAlmostEqual(gt.apcorrect1(aper[-1]+10,'FUV'),0.)
def test_apcorrect1_NUV(self): aper = np.array([1.5,2.3,3.8,6.0,9.0,12.8,17.3,30.,60.,90.])/3600. dmag = [2.09,1.33,0.59,0.23,0.13,0.09,0.07,0.04,-0.00,-0.01] for i,a in enumerate(aper[:-1]): self.assertAlmostEqual(gt.apcorrect1(aper[i],'NUV'),dmag[i]) if aper[i]<aper[-2]: self.assertAlmostEqual(gt.apcorrect1((aper[i]+aper[i+1])/2.,'NUV'),(dmag[i]+dmag[i+1])/2.) self.assertAlmostEqual(gt.apcorrect1(aper[-1],'NUV'),0.) self.assertAlmostEqual(gt.apcorrect1(aper[-1]+10,'NUV'),0.)
def apcorrect_cps(lc, band, aper=gt.aper2deg(7)): """ Apply the aperture correction in units of linear counts-per-second. Aperture correction is linear in magnitude units, so convert the count rate into AB mag, correct it, and then convert it back. """ return (gt.mag2counts( gt.counts2mag(lc['cps'].values, band) - gt.apcorrect1(aper, band), band))
def gphot_params(band, skypos, radius, annulus=None, verbose=0, detsize=1.25, stepsz=None, trange=None): """ Populate a dict() with parameters that are constant over all bins. :param band: The band being used, either 'FUV' or 'NUV'. :type band: str :param skypos: A two-element list containing the RA and DEC. :type skypos: list :param radius: Radius of the photometric aperture in degrees. :type radius: float :param annulus: A two-element list containing the inner and outer radius to use for background subtraction during aperture photometry, in degrees. :type annulus: list :param verbose: Level of verbosity, 0 = minimum verbosity. :type verbose: int :param detsize: Effective diameter, in degrees, of the field-of-view. :type detsize: float :param stepsz: Size of time bin to use, in seconds. :type stepsz: float :param trange: The start and end timestamps to consider, in GALEX time :type trange: list :returns: dict -- The set of parameters that are constant across all bins. """ apsourcecnt, bgsourcecnt, bgsourcemag = bg_contamination( band, skypos, radius, annulus=annulus) return {'band':band, 'ra0':skypos[0], 'dec0':skypos[1], 'skypos':skypos, 'trange':trange, 'radius':radius, 'annulus':annulus, 'stepsz':stepsz, 'verbose':verbose, 'detsize':detsize, 'apcorrect1':gxt.apcorrect1(radius, band), 'apcorrect2':gxt.apcorrect2(radius, band), 'detbg':gxt.detbg(mc.area(radius), band), 'n_apersources':apsourcecnt,'n_bgsources':bgsourcecnt, 'max_bgmag':bgsourcemag,'version':__version__,}
def calculate_flare_energy(lc, frange, distance, binsize=30, band='NUV', effective_widths={ 'NUV': 729.94, 'FUV': 255.45 }, quiescence=None): """ Calculates the energy of a flare in erg. """ if not quiescence: q, _ = get_inff(lc) # Convert to aperture-corrected flux q = gt.mag2counts( gt.counts2mag(q, band) - gt.apcorrect1(gt.aper2deg(6), band), band) else: q = quiescence[0] # Convert from parsecs to cm distance_cm = distance * 3.086e+18 if 'cps_apcorrected' in lc.keys(): # Converting from counts / sec to flux units. flare_flux = (np.array( gt.counts2flux(np.array(lc.iloc[frange]['cps_apcorrected']), band)) - gt.counts2flux(q, band)) else: # Really need to have aperture-corrected counts/sec. raise ValueError("Need aperture-corrected cps fluxes to continue.") # Zero any flux values where the flux is below the INFF so that we don't subtract from the total flux! flare_flux = np.array([0 if f < 0 else f for f in flare_flux]) flare_flux_err = gt.counts2flux(np.array(lc.iloc[frange]['cps_err']), band) tbins = (np.array(lc.iloc[frange]['t1'].values) - np.array(lc.iloc[frange]['t0'].values)) # Caluclate the area under the curve. integrated_flux = (binsize * flare_flux).sum() """ GALEX effective widths from http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?id=GALEX/GALEX.NUV width = 729.94 A http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?id=GALEX/GALEX.FUV width = 255.45 A """ # Convert integrated flux to a fluence using the GALEX effective widths. fluence = integrated_flux * effective_widths[band] fluence_err = (np.sqrt( ((gt.counts2flux(lc.iloc[frange]['cps_err'], band) * binsize)** 2).sum()) * effective_widths[band]) energy = (4 * np.pi * (distance_cm**2) * fluence) energy_err = (4 * np.pi * (distance_cm**2) * fluence_err) return energy, energy_err
def gphot_params(band, skypos, radius, annulus=None, verbose=0, detsize=1.25, stepsz=None, trange=None): """ Populate a dict() with parameters that are constant over all bins. :param band: The band being used, either 'FUV' or 'NUV'. :type band: str :param skypos: A two-element list containing the RA and DEC. :type skypos: list :param radius: Radius of the photometric aperture in degrees. :type radius: float :param annulus: A two-element list containing the inner and outer radius to use for background subtraction during aperture photometry, in degrees. :type annulus: list :param verbose: Level of verbosity, 0 = minimum verbosity. :type verbose: int :param detsize: Effective diameter, in degrees, of the field-of-view. :type detsize: float :param stepsz: Size of time bin to use, in seconds. :type stepsz: float :param trange: The start and end timestamps to consider, in GALEX time :type trange: list :returns: dict -- The set of parameters that are constant across all bins. """ apsourcecnt, bgsourcecnt, bgsourcemag = bg_contamination(band, skypos, radius, annulus=annulus) return { 'band': band, 'ra0': skypos[0], 'dec0': skypos[1], 'skypos': skypos, 'trange': trange, 'radius': radius, 'annulus': annulus, 'stepsz': stepsz, 'verbose': verbose, 'detsize': detsize, 'apcorrect1': gxt.apcorrect1(radius, band), 'apcorrect2': gxt.apcorrect2(radius, band), 'detbg': gxt.detbg(mc.area(radius), band), 'n_apersources': apsourcecnt, 'n_bgsources': bgsourcecnt, 'max_bgmag': bgsourcemag, 'version': __version__, }