Example #1
0
#!/usr/bin/env python
"""
Test isochrone functionality. These tests require that ugali has been
installed with the '--isochrones' option.
"""
import os
import numpy as np

from ugali import isochrone
from ugali.utils.logger import logger
logger.setLevel(logger.WARN)

# Default parameters
default_kwargs = dict(age=12,metallicity=0.0002, distance_modulus=18)
# Alternate parameters
alt_kwargs = dict(age=10, metallicity=0.0001, distance_modulus=16)
# Parameter abbreviations
abbr_kwargs = dict(a=10, z=0.0001, mod=17)

padova = ['Padova','Bressan2012','Marigo2017']
dotter = ['Dotter','Dotter2008','Dotter2016']
isochrones = padova + dotter
survey = ['des','sdss']

def set_parameters(name):
    iso = isochrone.factory(name,**default_kwargs)

    # Test that parameters are set in construction
    for k,v in default_kwargs.items():
        assert getattr(iso,k) == v
Example #2
0
#!/usr/bin/env python
"""
Generic python script.
"""
__author__ = "Alex Drlica-Wagner"
import numpy as np
import fitsio
from ugali.utils.logger import logger
logger.setLevel(logger.WARN)

CONFIG = 'tests/config.yaml'
LON = RA = 53.92
LAT = DEC = -54.05
IDX = [1, 2537, 9000]


def test_loglike():
    """ Test ugali.analysis.loglike """
    import ugali.analysis.loglike
    loglike = ugali.analysis.loglike.createLoglike(CONFIG, lon=LON, lat=LAT)

    source = loglike.source
    np.testing.assert_equal(source.isochrone.name, 'Bressan2012')
    np.testing.assert_equal(source.kernel.name, 'RadialPlummer')
    np.testing.assert_equal(source.richness, 1000.)

    # Probability calculations
    np.testing.assert_allclose(loglike.f, 0.08614111, rtol=1e-6)

    np.testing.assert_allclose(
        loglike.u[IDX], [5.29605173e-03, 1.80040569e-03, 5.52283081e-09],
Example #3
0
 def _parse_verbose(self, opts):
     if vars(opts).get('verbose') or vars(opts).get('debug'):
         logger.setLevel(logger.DEBUG)
Example #4
0
                        help='name of output object identifier')
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        help='overwrite output columns if they exist')
    parser.add_argument('-s',
                        '--split',
                        action='store_true',
                        help='split double objects')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='output verbosity')
    args = parser.parse_args()

    if args.verbose: logger.setLevel(logging.DEBUG)

    if args.mlimit:
        logger.info("Setting memory limit: %.1fGB" % (args.mlimit))
        soft, hard = set_memory_limit(args.mlimit * 1024**3)
        logger.info("Memory limit: %.1fGB" % (soft / 1024.**3))

    logger.info("Matching files: %s" % args.infiles)
    radius = args.radius
    fileidx = odict()

    data = []
    for i, f in enumerate(args.infiles):
        d, hdr = fitsio.read(f, header=True, columns=MATCHCOLS)
        if i == 0:
            imin = 0
Example #5
0
    parser.add_argument('--coeff',
                        default='DR1',
                        choices=['Y3A1', 'PS1', 'DESDM', 'DR1'],
                        help='reddening coefficients')
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        help='overwrite output columns if they exist')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='output verbosity')
    args = parser.parse_args()

    if args.verbose:
        logger.setLevel(logging.DEBUG)

    if args.coeff == 'Y3A1':
        COEFF = Y3A1
    elif args.coeff == 'DESDM':
        COEFF = DESDM
    elif args.coeff == 'PS1':
        COEFF = PS1
    elif args.coeff == 'DR1':
        COEFF = DR1
    else:
        raise Exception('Unrecognized coefficient set: %s' % args.coeff)
    logger.info("Using %s coefficients." % args.coeff)

    columns = [args.ra, args.dec]
    if len(args.bands) == 0:
Example #6
0
    ],
)

if __name__ == "__main__":
    from optparse import OptionParser
    usage = "Usage: %prog  [options] input"
    description = "python script"
    parser = OptionParser(usage=usage, description=description)
    parser.add_option('-o', '--outfile', default='allsky_maglims.png')
    parser.add_option('-t', '--targets', default=None)
    parser.add_option('-c', '--coord', default='GAL')
    parser.add_option('-p', '--proj', default='MOL', choices=['MOL', 'CAR'])
    parser.add_option('-f', '--field', default='MAGLIM')
    parser.add_option('-v', '--verbose', action='store_true')
    (opts, args) = parser.parse_args()
    if opts.verbose: logger.setLevel(logger.DEBUG)

    map = ugali.utils.skymap.readSparseHealpixMaps(args, opts.field)
    if opts.coord.upper() == "GAL":
        coord = 'G'
    elif opts.coord.upper() == "CEL":
        coord = 'GC'
    if opts.proj.upper() == "MOL":
        #map = numpy.where( map < 20, healpy.UNSEEN, map)
        healpy.mollview(map, coord=coord, xsize=1000, min=20)
    elif opts.proj.upper() == "CAR":
        healpy.cartview(map, coord=coord, xsize=1000)
    else:
        raise Exception("...")
    healpy.graticule()
Example #7
0
#!/usr/bin/env python

import ugali.utils.skymap
from ugali.utils.logger import logger

if __name__ == "__main__":
    from optparse import OptionParser
    usage = "Usage: %prog  [options] results1.fits results2.fits ... "
    description = "Script for merging multiple results files."
    parser = OptionParser(usage=usage,description=description)
    parser.add_option('-o','--outfile',default="merged.fits")
    parser.add_option('-v','--verbose',action='store_true')
    (opts, args) = parser.parse_args()
    if opts.verbose: logger.setLevel(logger.DEBUG)
    else:            logger.setLevel(logger.INFO)

    ugali.utils.skymap.mergeSparseHealpixMaps(args,opts.outfile)
Example #8
0
 def _parse_verbose(self,opts):
     if vars(opts).get('verbose'): 
         logger.setLevel(logger.DEBUG)
Example #9
0

if __name__ == "__main__":
    import argparse
    description = "python script"
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('infiles',nargs='+')
    parser.add_argument('-o','--outfile')
    parser.add_argument('-k','--keyfile')
    parser.add_argument('-f','--force',action='store_true')
    parser.add_argument('-v','--verbose',action='store_true')
    parser.add_argument('-b','--bands',default=None,action='append')
    parser.add_argument('--min-bands',default=None,type=int)
    opts = parser.parse_args()

    if vars(opts).get('verbose'): logger.setLevel(logger.DEBUG)
    if opts.bands: BANDS = opts.bands
    if opts.min_bands: MINBANDS = opts.min_bands

    if os.path.exists(opts.outfile) and not opts.force:
        logger.warning("Found %s; skipping..."%opts.outfile)
        sys.exit()

    logger.info("Loading files: %s"%opts.infiles)
    data = load_infiles(opts.infiles,INPUT_COLS)
    logger.info("All objects: %i"%len(data))

    good = good_objects(data)
    logger.info("Good objects: %i"%len(good))

    if len(good) == 0:
Example #10
0
#!/usr/bin/env python

import ugali.utils.skymap
from ugali.utils.logger import logger

if __name__ == "__main__":
    from optparse import OptionParser
    usage = "Usage: %prog  [options] results1.fits results2.fits ... "
    description = "Script for merging multiple results files."
    parser = OptionParser(usage=usage, description=description)
    parser.add_option('-o', '--outfile', default="merged.fits")
    parser.add_option('-v', '--verbose', action='store_true')
    (opts, args) = parser.parse_args()
    if opts.verbose: logger.setLevel(logger.DEBUG)
    else: logger.setLevel(logger.INFO)

    ugali.utils.skymap.mergeSparseHealpixMaps(args, opts.outfile)