コード例 #1
0
def test_lens_finite_sources(lens_model='nfw', mass_scale=np.random.uniform(0.03, 0.9, 1), model_param_8=np.random.uniform(34, 94, 1), model_param_9=0, model_param_10=0, dimpix=np.random.uniform(0.35, 0.45), source_centers=[[0,0]], ref_magzpt=30, reference_band='g', source_model=[{'source_type': 'sersic', 'nover': 1, 'rs': 0.1, 'thetas': 0, 'es': 0.4, 'ns': 0.5, 'mag': 24.}], galaxy_position=[0,0], e_L=0.5, theta_L=np.random.uniform(0, 180, 1), shear=0, theta_shear=0, gravlens_params={}, caustic_CC_file='crit.txt',  gravlens_input_file='gravlens_CC_input.txt', rad_curves_file='lens_curves_rad.dat', tan_curves_file='lens_curves_tan.dat', curves_plot='caustic_CC_curves.png', show_plot=0, write_to_file=0, max_delta_count=20, delta_increment=1.1, grid_factor=5., grid_factor2=3., max_iter_number=20, min_n_lines=200, gridhi1_CC_factor=1.2, accept_res_limit=2E-4, nover_max=3, SE_params={}, SE_args={}, preset='sims', base_name='sbmap'):




    from sltools.io.log import init


    init(debug=True) # verbose=True)


    for i in range( len(mass_scale)):
        for j in range( len(model_param_8)):
            for k in range( len(theta_L)):	
                lens_finite_sources(lens_model, mass_scale[i], model_param_8[j], model_param_9, model_param_10, dimpix, source_centers, ref_magzpt, reference_band, source_model, galaxy_position, e_L, theta_L[k], shear, theta_shear, gravlens_params, caustic_CC_file,  gravlens_input_file, rad_curves_file, tan_curves_file, curves_plot, show_plot, write_to_file, max_delta_count, delta_increment, grid_factor, grid_factor2, max_iter_number, min_n_lines, gridhi1_CC_factor, accept_res_limit, nover_max, SE_params, SE_args, preset, base_name) 
コード例 #2
0
ファイル: ds92stamps.py プロジェクト: MariaElidaiana/SLtools
    objsfile = opts.objsname
    shape = opts.xy_sizes.split(",")
    segimg = opts.segfile

    if len(args) < 2:
        parser.print_help()
        sys.exit(0)

    regionfile = args[0]
    imagename = args[1]

    shape = (int(shape[0]), int(shape[1]))

    # Logging handler:
    logfile = regionfile + '.log'
    logging = log.init(logfile, debug=True, verbose=True)

    # Read DS9 regionfile..
    #
    D_in = asc.read_ds9cat(regionfile)
    objimg = pyfits.getdata(imagename, header=False)
    if segimg:
        segimg = pyfits.getdata(segimg)

    D_in['filename'] = imagename

    D_out = run(D_in, objimg, segimg, shape=shape, objsfile=objsfile, hdr=None)

    if cattype.upper() == 'FITS':
        outname = catfile + re.sub(".reg", ".fit", regionfile)
        tbhdu = fts.dict_to_tbHDU(D_out, D_out['filename'] + "_stamps",
コード例 #3
0
ファイル: imcp.py プロジェクト: MariaElidaiana/SLtools
            ind_new[0].append(Objects[id_max][i][0])
            ind_new[1].append(Objects[id_max][i][1])
        ind_new[0].remove(-100)
        ind_new[1].remove(-1000)
        ind_n=[np.array(ind_new[0]),np.array(ind_new[1])]
        return ind_n          
# ---

# \cond
# ============================================================================
if __name__ == "__main__" :

    from optparse import OptionParser;
    from sltools.io import log;
    
    logging = log.init(debug=True,verbose=False);
    
    usage="\n  %prog image.fits x y  [options]"
    parser = OptionParser(usage=usage);

    parser.add_option('-j', action='store_true',
                dest='is_coord_deg', default=False,
                help="If given, 'x,y' arguments (i.e, central coordinates) are in degrees. If not given (default), coordinates are expected to be in pixels");
    parser.add_option('-J', action='store_true',
                dest='is_shape_deg', default=False,
                help="If given, cutout 'shape' (see option '-s') are in degrees. If not given (default), cutout shape is expected to be in pixels.");
    parser.add_option('-s',
                dest='dim', default='250,250',
                help="Output stamps shape. Default is 250,250");
    parser.add_option('--increase',
                dest='incr', default=0,
コード例 #4
0
ファイル: imcp.py プロジェクト: chbrandt/bit
    if not len(indxs):
        return None
    
    outimg[indxs] = objimg[indxs]
    
    return outimg

# ---
# \cond
# ============================================================================
if __name__ == "__main__" :

    from optparse import OptionParser;
    from sltools.io import log;
    
    logging = log.init(debug=True,verbose=False);
    
    usage="\n  %prog image.fits x y  [options]"
    parser = OptionParser(usage=usage);

    parser.add_option('-j', action='store_true',
                dest='is_coord_deg', default=False,
                help="If given (x,y) coordinates are in degrees, default is False");
    parser.add_option('-J', action='store_true',
                dest='is_shape_deg', default=False,
                help="If given 'shape' (x,y sizes) are in degrees, default is False");
    parser.add_option('-s',
                dest='dim', default='250,250',
                help="Output stamps shape default is 250,250");
    parser.add_option('--increase',
                dest='incr', default=0,
コード例 #5
0
def test_select_source_positions(
        lens_model='nfw',
        mass_scale=np.random.uniform(0.03, 0.9, 1),
        model_param_8=np.random.uniform(34, 94, 1),
        model_param_9=0,
        model_param_10=0,
        galaxy_position=[0., 0.],
        e_L=0.4,
        theta_L=np.random.uniform(0, 180, 1),
        shear=0,
        theta_shear=0,
        gravlens_params={},
        src_density_or_number=10,
        minimum_distortion=0.,
        control_rhombus=2.,
        caustic_CC_file='crit.txt',
        gravlens_input_file='gravlens_CC_input.txt',
        rad_curves_file='lens_curves_rad.dat',
        tan_curves_file='lens_curves_tan.dat',
        curves_plot='crit-caust_curves.png',
        show_plot=0,
        write_to_file=0,
        max_delta_count=20,
        delta_increment=1.1,
        grid_factor=5.,
        grid_factor2=3.,
        max_iter_number=20,
        min_n_lines=200,
        gridhi1_CC_factor=2.,
        accept_res_limit=2E-4,
        gravlens_mag_input_file='gravlens_magtensor_in.txt',
        gravlens_mag_output_file='gravlens_magtensor_out.txt',
        keep_mag_files=False,
        gravlens_img_input_file='findimg_input.txt',
        gravlens_img_output_file='findimg_out.txt',
        keep_img_files=False):
    """ 
    Tests the pipeline select_source_positions.
    
    The inputs are exactly the ones in select_source_positions, so are the outputs.
    
    All inputs have a predefined value so it is trivial to run.
    """

    from sltools.io.log import init

    init(debug=True)  # verbose=True)

    for i in range(len(mass_scale)):
        for j in range(len(model_param_8)):
            for k in range(len(theta_L)):
                x_src_f, y_src_f, x_img_f, y_img_f, image_distortions = select_source_positions(
                    lens_model, mass_scale[i], model_param_8[j], model_param_9,
                    model_param_10, galaxy_position, e_L, theta_L, shear,
                    theta_shear, gravlens_params, src_density_or_number,
                    minimum_distortion, control_rhombus, caustic_CC_file,
                    gravlens_input_file, rad_curves_file, tan_curves_file,
                    curves_plot, show_plot, write_to_file, max_delta_count,
                    delta_increment, grid_factor, grid_factor2,
                    max_iter_number, min_n_lines, gridhi1_CC_factor,
                    accept_res_limit, gravlens_mag_input_file,
                    gravlens_mag_output_file, keep_mag_files,
                    gravlens_img_input_file, gravlens_img_output_file,
                    keep_img_files)

    return x_src_f, y_src_f, x_img_f, y_img_f, image_distortions
コード例 #6
0
ファイル: imcp.py プロジェクト: CosmoObs/SLtools
parser.add_option('--segimg',
                  dest='segimg',
                  default=None,
                  help="Segmented image (e.g, SE's SEGMENTATION output)")

parser.add_option(
    '--objIDs',
    dest='IDs',
    default='',
    help="Comma-separated list of object IDs found on 'segimg' to extract")

parser.add_option('--hdu-n', default=0, help="HDU position")

(opts, args) = parser.parse_args()

logging = log.init(debug=opts.debug, verbose=opts.verbose)

nrequired = opts.segimg and 1 or 3
if len(args) < nrequired:
    parser.print_help()
    sys.exit(1)

IDs = opts.IDs
prefix = opts.prefix

infits = args[0]

coord_unit = opts.is_coord_deg and 'degrees' or 'pixel'
size_unit = opts.is_shape_deg and 'degrees' or 'pixel'

hdulist = pyfits.open(infits, memmap=True)