Example #1
0
def gMap(band,cntfile=False,coadd=False,detsize=1.25,intfile=False,
		 rrfile=False,skypos=None,maxgap=1500.,memlight=100.,minexp=1.,
		 overwrite=False,retries=20,skyrange=None,stepsz=0.,trange=None,
		 verbose=0,cntcoaddfile=False,intcoaddfile=False):
	"""Use a mix of strings (if we want to make an output file) and Booleans
	(False if we do not). I don't think this is the best way (I'd rather
	have separate variables for the True/False to create an image, and a
	string with the name of the output image), but for now this is kept since
	this is how the code was originally written.
	"""
	# FIXME: Maybe?
	write_cnt = cntfile if (cntfile) else False
	write_int = intfile if (intfile) else False
	write_rr = rrfile if (rrfile) else False
	write_cnt_coadd = cntcoaddfile if cntcoaddfile else False
	write_int_coadd = intcoaddfile if intcoaddfile else False

	# If gMap is called via an import, and no trange is specified, then use a database
	# call to get the appropriate time range.
	if trange is None:
		trange=dbt.fGetTimeRanges(band, skypos,
					  trange=[6.E8,11.E8],
					  maxgap=maxgap, minexp=minexp,
					  detsize=detsize,
					  retries=retries)

	write_images(band,skypos,trange,skyrange,width=False,height=False,
				 write_cnt=write_cnt,write_int=write_int,write_rr=write_rr,
				 framesz=stepsz,clobber=overwrite,verbose=verbose,
				 memlight=memlight,coadd=coadd,retries=retries,
				 write_cnt_coadd=write_cnt_coadd,
				 write_int_coadd=write_int_coadd)
Example #2
0
def getcurve(band, ra0, dec0, radius, annulus=None, stepsz=None, lcurve={},
             trange=None, tranges=None, verbose=0, coadd=False, minexp=1.,
             maxgap=1., maskdepth=20, maskradius=1.5,
             photonfile=None, detsize=1.1):
    skyrange = [np.array(annulus).max().tolist() if annulus else radius,
                np.array(annulus).max().tolist() if annulus else radius,]
    if verbose:
        mc.print_inline("Getting exposure ranges.")
    if tranges is None:
        tranges = dbt.fGetTimeRanges(band, [ra0, dec0], trange=trange,
                maxgap=maxgap, minexp=minexp, verbose=verbose, detsize=detsize)
    elif not np.array(tranges).shape:
        print "No exposure time at this location: [{ra},{dec}]".format(
                                                            ra=ra0,dec=dec0)
    # FIXME: Everything goes to hell if no exposure time is available...
    # TODO: Add an ability to specify or exclude specific time ranges
    if verbose:
        mc.print_inline("Moving to photon level operations.")
    # FIXME: This error handling is hideous.
    try:
        lcurve = quickmag(band, ra0, dec0, tranges, radius, annulus=annulus,
                          stepsz=stepsz, verbose=verbose, coadd=coadd,
                          maskdepth=maskdepth,
                          maskradius=maskradius,photonfile=photonfile)
        lcurve['cps'] = lcurve['sources']/lcurve['exptime']
        lcurve['cps_bgsub'] = (lcurve['sources']-
                               lcurve['bg']['simple'])/lcurve['exptime']
        lcurve['cps_bgsub_cheese'] = (lcurve['sources']-
                               lcurve['bg']['cheese'])/lcurve['exptime']
        lcurve['mag'] = gxt.counts2mag(lcurve['cps'],band)
        lcurve['mag_bgsub'] = gxt.counts2mag(lcurve['cps_bgsub'],band)
        lcurve['mag_bgsub_cheese'] = gxt.counts2mag(
                                            lcurve['cps_bgsub_cheese'],band)
        lcurve['flux'] = gxt.counts2flux(lcurve['cps'],band)
        lcurve['flux_bgsub'] = gxt.counts2flux(lcurve['cps_bgsub'],band)
        lcurve['flux_bgsub_cheese'] = gxt.counts2flux(
                                            lcurve['cps_bgsub_cheese'],band)
        lcurve['detrad'] = mc.distance(lcurve['detxs'],lcurve['detys'],400,400)
    except ValueError:
        lcurve['cps']=[]
        lcurve['cps_bgsub']=[]
        lcurve['cps_bgsub_cheese']=[]
        lcurve['mag']=[]
        lcurve['mag_bgsub']=[]
        lcurve['mag_bgsub_cheese']=[]
        lcurve['flux']=[]
        lcurve['flux_bgsub']=[]
        lcurve['flux_bgsub_cheese']=[]
        lcurve['detrad']=[]
    if verbose:
        mc.print_inline("Done.")
        mc.print_inline("")
    return lcurve
Example #3
0
def gFind(band='both', detsize=1.25, exponly=False, gaper=False, maxgap=1.0,
		  minexp=1.0, quiet=False, retries=20, skypos=None, trange=None,
		  verbose=0):
	"""Primary program in the module. Prints time ranges to the screen and
    returns the total exposure time as a float.
	"""
	# Determine if we have to loop over both bands or just one.
	if band.upper() == 'BOTH':
		output = {'NUV':None,'FUV':None}
	elif band.upper() in ['NUV','FUV']:
		output = {band.upper():None}
	else:
		raise SystemExit('Invalid band: {b}'.format(b=band))
	all_expt = []

	for this_band in output.keys():
		## Get valid time ranges.
	       	ranges = dbt.fGetTimeRanges(this_band,skypos,maxgap=maxgap,
									minexp=minexp,trange=trange,verbose=verbose,
									detsize=detsize,retries=retries)

		if not len(ranges):
			if not quiet:
				print 'No {band} exposure time in database.'.format(
																band=this_band)
		else:
			expt = (ranges[:,1]-ranges[:,0]).sum()
			if not quiet:
				print "{band}: {expt}s (raw) in {n} exposures.".format(
								band=this_band,expt=expt,n=len(ranges))
			if not exponly:
				if gaper:
					f = '['
					for r in ranges:
						f+='[%.3f' % r[0] + ', %.3f' % r[1] + '],'
					if not quiet: print f[:-1]+']'
				else:
					for r in ranges:
						if not quiet:
							print '    [ %.3f' % r[0] + ', %.3f' % r[1] + ' ], %.3f' % (r[1]-r[0]) + ' seconds'
		output[this_band]={'expt':expt,'t0':ranges[:,0],'t1':ranges[:,1]}
#			all_expt.append(expt)
	return output #{this_band:{'t0':ranges[:,0],'t1':ranges[:,1],'expt':all_expt}}
Example #4
0
def check_common_args(args,function_name,
                      valid_functions=['gaperture','gmap','gfind'],
                      allow_no_coords=False):
    """Checks validity of some command line arguments used in gFind,
    gAperture, gMap, etc.  Returns the appropriate arguments as variables back
    to the calling procedure.
    """
    try:
        function_name = function_name.strip().lower()
    except AttributeError:
        raise gPhotonArgsError("Invalid function: {f}".format(f=function_name))

    if not function_name in valid_functions:
        raise gPhotonArgsError("Invalid function: {f}".format(f=function_name))

    try:
        args.band = args.band.strip()
    except AttributeError:
        raise SystemExit("Invalid band: {b}".format(b=args.band))

    """ This will ensure calpath has a trailing '/'. """
    if function_name in ['gaperture','gmap']:
        args.calpath = os.path.join(args.calpath,'')
        #FIXME: This is breaking nosetests, but it's not a bad idea...
        #if not os.path.isdir(args.calpath):
        #    raise SystemExit("Calibration path not found: " + args.calpath)

    if (not (args.ra and args.dec) and not args.skypos and
        not allow_no_coords):
        raise SystemExit("Must specify either both RA/DEC or SKYPOS.")
    elif (args.ra and args.dec) and args.skypos:
        if not (args.ra==args.skypos[0] and args.dec==args.skypos[1]):
            raise SystemExit("Must specify either RA/DEC or SKYPOS, not both.")
    elif (args.ra and args.dec) and not args.skypos:
        args.skypos = [args.ra,args.dec]
    elif not (args.ra and args.dec) and args.skypos:
        args.ra, args.dec = args.skypos

    if args.suggest and function_name in ['gfind','gaperture']:
        (args.ra, args.dec, args.radius, args.annulus1,
            args.annulus2) = dbt.suggest_parameters(args.band, args.skypos,
                                                    retries=args.retries,
                                                    verbose=0)
        args.skypos = [args.ra, args.dec]
        if args.verbose:
            print "Recentering on ["+str(args.ra)+", "+str(args.dec)+"]"
            print "Setting radius to "+str(args.radius)
            print "Setting annulus to ["+str(args.annulus1)+", "+str(args.annulus2)+"]"

    if args.skypos:
        if np.array(args.skypos).shape != (2,):
            raise gPhotonArgsError(
                "Skypos (--skypos) must be a 2-element array.")
        args.ra, args.dec = args.skypos

    if args.ra and not (0. <= args.ra <= 360.):
        raise SystemExit(
            "RA of {ra} does not satisfy 0 <= RA <= 360".format(ra=args.ra))

    if args.dec and not (-90 <= args.dec <= 90):
        raise SystemExit(
            "Dec of {dec} does not satisfy -90 <= DEC <= 90".format(
                                                                dec=args.dec))

    if args.detsize and args.detsize <= 0.:
        raise SystemExit(
            "Effective field diameter (--detsize) must be > 0")

    if args.maxgap and args.maxgap <= 0.:
        raise SystemExit(
            "Maximum gap length (--maxgap) must be > 0 seconds.")
    if args.minexp and args.minexp <= 0.:
        raise SystemExit(
            "Minimum valid exposure depth (--minexp) must be > 0 seconds.")

    if args.retries and args.retries <= 0.:
        raise SystemExit("Number of retries (--retries) must be > 0.")

    # tmin / tmax must be defined and reasonable
    if not args.tmin or args.tmin <= 0.:
        raise SystemExit("T0 (--t0) must be > 0.")
    if not args.tmax or args.tmax <= 0.:
        raise SystemExit("T1 (--t1) must be > 0.")
    if args.tmin >= args.tmax:
        raise SystemExit(
            "Minimum time (--t0) must be < maximum time (--t1).")

    if args.trange:
        if np.array(args.trange).shape==(2,):
            args.trange=[args.trange]
        if not (len(np.array(args.trange).shape)==2 and
                                            np.array(args.trange).shape[1]==2):
            raise SystemExit(
                "trange (--trange) must be a pairwise list.")
        # Individually check the entries for sanity
        for t in args.trange:
            if t[0]<=0 or t[1]<=0:
                raise SystemExit('Times must be positive: {t}'.format(t=t))
            if t[1]<=t[0]:
                raise SystemExit('Start time ({t0}) must preceed end time ({t1})'.format(t0=t[0],t1=t[1]))
    elif not allow_no_coords and function_name in ['gmap','gaperture']:
        args.trange=dbt.fGetTimeRanges(args.band,args.skypos,
                                       trange=[args.tmin,args.tmax],
                                       maxgap=args.maxgap,minexp=args.minexp,
                                       detsize=args.detsize,
                                       retries=args.retries)
    else:
        """ If no coordinates specified then use a huge time range for
        now. """
        args.trange = [args.tmin, args.tmax]

    return args