コード例 #1
0
ファイル: get_args.py プロジェクト: ndaniyar/aphot
def get_args(**defaults):
    ''' --arg_name=value OR pos_arg1 pos_arg2
    '''
    # first look at the command line
    cmd_args = {}
    pos = []
    for arg in sys.argv:
        if arg[0:2] == '--':
            key, val = arg.lstrip('-').split('=', 1)
            cmd_args[key] = tryeval(val)
        else:
            pos += [tryeval(arg)]

    # and then prioritize the entries
    cfg_file = cmd_args.get('cfg', defaults.get('cfg', None))
    args = {}
    if cfg_file is not None: # Use cfg file
        args['cfg'] = cfg_file
        execfile(cfg_file, args)
        del args['__builtins__']
        # args in the cfg file is merged to the function argumet args
        # positional is overriden if it exists in cfg file

    # Override file's entries with command line arguments
    args.update(cmd_args)

    positional = ['script_name'] + args.get('positional',[])
    if len(positional) == len(pos):
        args.update(zip(positional,pos))
    else:
        raise Exception('Wrong number of positional arguments')

    defaults.update(args)
    return sdict(defaults)
コード例 #2
0
ファイル: aphot.py プロジェクト: ndaniyar/aphot
def sample_half_counts(evt0, seed=0):
    evt = sdict(b = evt0.b, d = evt0.d, ims = evt0.ims, ths = evt0.ths,
                bkgr = evt0.bkgr/2)
    N = len(evt0.xc)
    rnd = RandomState(seed)
    m = rnd.randint(low=0, high=N, size=rnd.binomial(N,0.5))

    evt.xc = evt0.xc[m]
    evt.yc = evt0.yc[m]
    evt.w = evt0.w[m]

    return evt
コード例 #3
0
ファイル: aphot.py プロジェクト: ndaniyar/aphot
from sys import stdout

from common import sdict, find_core, kpc2pix
from get_args import get_args
from chandra import process_multiple_obs
from libaphot import aphot


# Default parameters
p = sdict( 
    H = 70,
    Om = 0.27,
    Eband = [500, 5000],        # Energy filter: Eband[0] < E < Eband[1]
    R_bkgr = [2, 4],            # Annulus for background estimation in units of R500 
    annuli = [0.05, 0.12, 0.2, 0.3, 1.0], # Annuli for A_phot
    inspect = None,             # Filename prefix for visual control images
    Nresamplings = 100,
    path = '',
    evt_files = '',
    exp_files = '',
    reg_files = ''
          )

# Get parameters from the command line and configuration file
p.update(get_args())

kpc2px = kpc2pix(p.H, p.Om, p.z) # kpc to pixels conversion factor
R500px = p.R500 * kpc2px # R500 in pixels

# Convert multiple observations, exposure maps, and region files into
# internal representation of X-ray events (evt) and exposure map (expm)