# Path: ugali/analysis/scan.py
# class Scan(object):
#     """
#     The base of a likelihood analysis scan.
# 
#     FIXME: This really does nothing now and should be absorbed into
#     GridSearch (confusing now).
#     """
#     def __init__(self, config, coords):
#         self.config = Config(config)
#         # Should only be one coordinate
#         if len(coords) != 1: raise Exception('Must specify one coordinate.')
#         self.lon,self.lat,radius = coords[0]
#         self._setup()
#         
# 
#     def _setup(self):
#         self.observation = createObservation(self.config,self.lon,self.lat)
#         self.source = createSource(self.config,'scan',lon=self.lon,lat=self.lat)
#         loglike=LogLikelihood(self.config,self.observation,self.source)
#         self.grid = GridSearch(self.config,loglike)
# 
#     @property
#     def loglike(self):
#         return self.grid.loglike
# 
#     def run(self, coords=None, debug=False):
#         """
#         Run the likelihood grid search
#         """
#         #self.grid.precompute()
#         self.grid.search(coords=coords)
#         return self.grid
#         
#     def write(self, outfile):
#         self.grid.write(outfile)
# 
# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


import os
import shutil
import matplotlib
import numpy
import numpy as np
import yaml
import fitsio
import ugali.analysis.source
import ugali.analysis.loglike
import ugali.analysis.results
import ugali.utils.config
    import ugali.utils.plotting
    import pylab as plt
from os.path import join,exists,basename,splitext
from collections import OrderedDict as odict
from multiprocessing import Pool
from ugali.analysis.pipeline import Pipeline
from ugali.analysis.scan import Scan
from ugali.utils.logger import logger
from ugali.utils.shell import mkdir
    from ugali.analysis.results import write_results
    from ugali.analysis.loglike import write_membership
            if srcmdl is not None:
                try:      shutil.copy(srcmdl,self.outdir)
                except Exception as e: logger.warn(e.message)
                logger.info('%s (%s)'%(name,srcmdl))
                cmd='%s %s --name %s --srcmdl %s %s' % (
                    script,self.opts.config,name,srcmdl,outfile)
            else:
                logger.info('%s (%.4f,%.4f)'%(name,glon,glat))
                cmd='%s %s --name %s --gal %.4f %.4f --grid %s'% (
                    script,self.opts.config,name,glon,glat,outfile)
            logger.info(cmd)
            self.batch.submit(cmd,jobname,logfile,n=nthreads,a='mpirun')

    if 'results' in self.opts.run:
        logger.info("Running 'results'...")
        if len(args) > 1:
            pool = Pool(maxtasksperchild=1)
            pool.map(do_results,args)
        else:
            do_results(*args)

    if 'membership' in self.opts.run:
        logger.info("Running 'membership'...")
        if len(args) > 1:
            pool = Pool(maxtasksperchild=1)
            pool.map(do_membership,args)
        else:
            do_membership(*args)

    if 'plot' in self.opts.run:

# Path: ugali/analysis/scan.py
# class Scan(object):
#     """
#     The base of a likelihood analysis scan.
# 
#     FIXME: This really does nothing now and should be absorbed into
#     GridSearch (confusing now).
#     """
#     def __init__(self, config, coords):
#         self.config = Config(config)
#         # Should only be one coordinate
#         if len(coords) != 1: raise Exception('Must specify one coordinate.')
#         self.lon,self.lat,radius = coords[0]
#         self._setup()
#         
# 
#     def _setup(self):
#         self.observation = createObservation(self.config,self.lon,self.lat)
#         self.source = createSource(self.config,'scan',lon=self.lon,lat=self.lat)
#         loglike=LogLikelihood(self.config,self.observation,self.source)
#         self.grid = GridSearch(self.config,loglike)
# 
#     @property
#     def loglike(self):
#         return self.grid.loglike
# 
#     def run(self, coords=None, debug=False):
#         """
#         Run the likelihood grid search
#         """
#         #self.grid.precompute()
#         self.grid.search(coords=coords)
#         return self.grid
#         
#     def write(self, outfile):
#         self.grid.write(outfile)
# 
# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


# Path: ugali/pipeline/run_05.0_followup.py
import os
import shutil
import matplotlib
import numpy
import numpy as np
import yaml
import fitsio
import ugali.analysis.source
import ugali.analysis.loglike
import ugali.analysis.results
import ugali.utils.config
    import ugali.utils.plotting
    import pylab as plt
from os.path import join,exists,basename,splitext
from collections import OrderedDict as odict
from multiprocessing import Pool
from ugali.analysis.pipeline import Pipeline
from ugali.analysis.scan import Scan
from ugali.utils.logger import logger
from ugali.utils.shell import mkdir
    from ugali.analysis.results import write_results
    from ugali.analysis.loglike import write_membership

            if srcmdl is not None:
                try:      shutil.copy(srcmdl,self.outdir)
                except Exception as e: logger.warn(e.message)
                logger.info('%s (%s)'%(name,srcmdl))
                cmd='%s %s --name %s --srcmdl %s %s' % (
                    script,self.opts.config,name,srcmdl,outfile)
            else:
                logger.info('%s (%.4f,%.4f)'%(name,glon,glat))
                cmd='%s %s --name %s --gal %.4f %.4f --grid %s'% (
                    script,self.opts.config,name,glon,glat,outfile)
            logger.info(cmd)
            self.batch.submit(cmd,jobname,logfile,n=nthreads,a='mpirun')

    if 'results' in self.opts.run:
        logger.info("Running 'results'...")
        if len(args) > 1:
            pool = Pool(maxtasksperchild=1)
            pool.map(do_results,args)
        else:
            do_results(*args)

    if 'membership' in self.opts.run:
        logger.info("Running 'membership'...")
        if len(args) > 1:
            pool = Pool(maxtasksperchild=1)
            pool.map(do_membership,args)
        else:
            do_membership(*args)

    if 'plot' in self.opts.run:

        logger.info("Running 'plot'...")