Beispiel #1
0
def main():
    out_file = 'out_waxml.aida'
    writer = inlib.waxml_file()
    if writer.open(out_file) == False:
        print("can't open " + out_file)
        return EXIT_FAILURE

    entries = 1000000

    rg = inlib.rgaussd(1, 2)

    h = inlib.histo_h1d('Gauss', 100, -5, 5)
    for count in range(0, entries):
        h.fill(rg.shoot(), 1.4)
    if writer.write(h, '/histo', 'rg') == False:
        print("can't write h1d.")
        return EXIT_FAILURE
    del rg, h, count

    rg = inlib.rgaussd(1, 2)
    rbw = inlib.rbwd(0, 1)
    h = inlib.histo_p1d('Profile', 100, -5, 5, -2, 2)
    for count in range(0, entries):
        h.fill(rg.shoot(), rbw.shoot(), 1)
    if writer.write(h, '/histo', 'prof') == False:
        print("can't write prof.")
        return EXIT_FAILURE
    del rg, rbw, h, count

    rg = inlib.rgaussd(1, 2)
    rbw = inlib.rbwd(0, 1)
    h = inlib.histo_h2d('Gauss_BW', 20, -5, 5, 20, -2, 2)
    for count in range(0, entries):
        h.fill(rg.shoot(), rbw.shoot(), 0.8)
    if writer.write(h, '/histo', 'rgbw') == False:
        print("can't write h2d.")
        return EXIT_FAILURE
    del rg, rbw, h, count

    writer.close()
    del writer
    return EXIT_SUCCESS
Beispiel #2
0
#//////////////////////////////////////////
#/// same as inlib/exa/hrand //////////////
#//////////////////////////////////////////

#//////////////////////////////////////////
#//////////////////////////////////////////
#//////////////////////////////////////////
import inlib

h1 = inlib.histo_h1d('The famous normal distribution', 100, -5, 5)

r = inlib.rgaussd(0, 1)
for I in range(0, 10000):
    h1.fill(r.shoot(), 1)

#print h1.entries(),h.mean(),h.rms()

h2 = inlib.histo_h2d('Gauss_BW', 100, -5, 5, 100, -2, 2)
rg = inlib.rgaussd(1, 2)
rbw = inlib.rbwd(0, 1)
for I in range(0, 10000):
    h2.fill(rg.shoot(), rbw.shoot(), 1)

#//////////////////////////////////////////////////////////
#/// plotting : ///////////////////////////////////////////
#//////////////////////////////////////////////////////////
import exlib_sg_view_Python as vp

viewer = inlib.cast_viewer(vp.get_viewer_string_pointer())
gv = inlib.cast_gui_viewer(viewer)
Beispiel #3
0
# Copyright (C) 2010, Guy Barrand. All rights reserved.
# See the file exlib.license for terms.

import inlib

h = inlib.histo_h1d('Rand gauss',100,-5,5)

r = inlib.rgaussd(0,1)
for I in range(0,10000):
  h.fill(r.shoot(),1)

print(h.entries());print(h.mean());print(h.rms())

del r
del h

                
Beispiel #4
0
def tree_main():
    rfile = inlib.rroot_file(inlib.get_cout(), path, False)
    if rfile.is_open() == False:
        print "can't open out.root"
        return EXIT_FAILURE

    keys = rfile.dir().keys()
    #print 'number of keys = ',keys.size()

    dir = inlib.rroot_find_dir(rfile.dir(), 'STAFF')
    if dir == None:
        print 'directory not found'
        return EXIT_FAILURE

    key = dir.find_key('h10')
    if key == None:
        print 'tree not found'
        return EXIT_FAILURE

    fac = inlib.rroot_fac(gv.out())
    tree = inlib.rroot_key_to_tree(rfile, fac, key)
    if tree == None:
        print 'key is not a tree.'
        return EXIT_FAILURE

    #tree.show(gv.out(),1)
    #print tree.entries()

    leaf = tree.find_leaf("Age")
    if leaf == None:
        print 'leaf not found.'
        return EXIT_FAILURE

    #print 'leaf type : ',leaf.s_cls()

    li = inlib.rroot_cast_leaf_int(leaf)
    if leaf == None:
        print 'leaf not a leaf<int>.'
        return EXIT_FAILURE

    branch = tree.find_leaf_branch(leaf)
    if branch == None:
        print 'branch of leaf not found.'
        return EXIT_FAILURE

    h_age = inlib.histo_h1d('CERN/Age', 100, 0, 100)

    for i in range(0, tree.entries()):
        if branch.find_entry(rfile, i) == False:
            print 'branch.find_entry failed.'
            return EXIT_FAILURE
        v = li.value(0)
        #print 'li ',i,' ',v
        h_age.fill(v, 1)

    rfile.close()

    #//////////////////////////////////////////////////
    #// plot : ////////////////////////////////////////
    #//////////////////////////////////////////////////

    plots = inlib.get_sg_plots(gv)
    if plots == None:
        print 'sg::plots not found.'
        return EXIT_FAILURE

    plots.set_current_plotter(0)

    plotter = plots.current_plotter()
    plotter.clear()
    plotter.plot_cp(h_age)

    gv.hide_main_menu()
Beispiel #5
0
def tree_main():
    rfile = inlib.rroot_file(inlib.get_cout(), file, False)
    if rfile.is_open() == False:
        print("can't open file")
        return EXIT_FAILURE

    keys = rfile.dir().keys()
    #print('number of keys = ');print(keys.size())

    dir = inlib.rroot_find_dir(rfile.dir(), 'STAFF')
    if dir == None:
        print('directory not found')
        return EXIT_FAILURE

    key = dir.find_key('h10')
    if key == None:
        print('tree not found')
        return EXIT_FAILURE

    fac = inlib.rroot_fac(out)
    tree = inlib.rroot_key_to_tree(rfile, fac, key)
    if tree == None:
        print('key is not a tree.')
        return EXIT_FAILURE

    #tree.show(gv.out(),1)
    #print(tree.entries())

    leaf = tree.find_leaf("Age")
    if leaf == None:
        print('leaf not found.')
        return EXIT_FAILURE

    #print('leaf type : ');print(leaf.s_cls())

    li = inlib.rroot_cast_leaf_int(leaf)
    if leaf == None:
        print('leaf not a leaf<int>.')
        return EXIT_FAILURE

    branch = tree.find_leaf_branch(leaf)
    if branch == None:
        print('branch of leaf not found.')
        return EXIT_FAILURE

    h_age = inlib.histo_h1d('CERN/Age', 100, 0, 100)

    for i in range(0, tree.entries()):
        if branch.find_entry(rfile, i) == False:
            print('branch.find_entry failed.')
            return EXIT_FAILURE
        v = li.value(0)
        h_age.fill(v, 1)

    rfile.close()

    print(h_age.entries())
    print(h_age.mean())
    print(h_age.rms())

    #//////////////////////////////////////////////////
    #// plot : ////////////////////////////////////////
    #//////////////////////////////////////////////////

    if args.vis_mode == "offscreen":
        import offscreen
        p = offscreen.plotter(inlib.get_cout(), 1, 1, 700, 500)
        p.plot_histo(h_age)
        if args.vis_format == "bsg":
            p.out_bsg('out_tree.bsg')
        else:
            p.write_paper('out_tree.ps', 'INZB_PS')
            p.write_paper('out_tree.png', 'INZB_PNG')
        del p

    elif args.vis_mode == "client":
        import inexlib_client

        style_file = "./res/ioda.style"
        p = inexlib_client.plotter(inlib.get_cout(), 1, 1, args.vis_host,
                                   int(args.vis_port), style_file)
        p.plot_histo(h_age)

        #p.set_plotters_style("ROOT_default")
        if args.vis_host == "134.158.76.71":  #LAL/wallino.
            p.set_plotters_style("wall_ROOT_default")
        p.send_clear_static_scene()
        p.send_plots()
        del p

    else:
        import exlib_window as exlib
        gl2ps_mgr = exlib.sg_gl2ps_manager()
        smgr = exlib.session(inlib.get_cout())  # screen manager
        if smgr.is_valid() == True:
            plotter = exlib.plotter(smgr, 1, 1, 0, 0, 700, 500)
            if plotter.has_window() == True:
                sgp = plotter.plots().current_plotter()
                sgp.bins_style(0).color.value(inlib.colorf_blue())

                sgp.infos_style().font.value(inlib.font_arialbd_ttf())

                sgp.infos_x_margin.value(0.01)  #percent of plotter width.
                sgp.infos_y_margin.value(0.01)  #percent of plotter height.

                plotter.plot(h_age)

                plotter.plots().view_border.value(False)

                waction = exlib.sg_gl2ps_action(gl2ps_mgr, inlib.get_cout(),
                                                plotter.width(),
                                                plotter.height())
                waction.open('out.ps')
                plotter.sg().render(waction)
                waction.close()
                del waction

                plotter.show()

                plotter.steer()

            del plotter

        del smgr
    df = spark.read.format("fits").option("hdu", args.hdu).load(args.file_name)
    #print("df.count() : "+str(df.count())+". Should be 10000.")
    df_count_ref = 10000
    if df.count() != df_count_ref:
        print("spark_fits_vis.py : df.count() " + str(df.count()) +
              ", expected " + str(df_count_ref))
        exit()

    data = df.collect()

    #///////////////////////////////////////////////////////////////////////////////////////////////
    #/// plotting : ////////////////////////////////////////////////////////////////////////////////
    #///////////////////////////////////////////////////////////////////////////////////////////////
    import inlib

    h_y = inlib.histo_h1d('y', 100, -5, 5)
    [h_y.fill(row[1], 1) for row in data if row is not None]

    h_z = inlib.histo_h1d('z', 100, -5, 5)
    [h_z.fill(row[2], 1) for row in data if row is not None]

    #data = df.repartition(256).rdd.map(lambda row: row[1]+row[2]).collect()
    data = df.rdd.map(lambda row: project(row)).collect()
    #print(data.__class__.__name__)       # list
    #print(data[0].__class__.__name__)    # float

    h_result = inlib.histo_h1d('z', 100, -5, 5)
    [h_result.fill(real, 1) for real in data if real is not None]

    if args.vis_mode == "window":
        #print("plot (window) ...")
Beispiel #7
0
dec_max = center_dec + half_dec

z_min = 1
z_max = 1.04

y_max = 100
dec_step = -0.1
nbin = 100

if verbose == True:
    print(ra_min)
    print(ra_max)
    print(dec_min)
    print(dec_max)

h1_0 = inlib.histo_h1d('0', nbin, ra_min, ra_max)
h1_1 = inlib.histo_h1d('1', nbin, ra_min, ra_max)
h1_2 = inlib.histo_h1d('2', nbin, ra_min, ra_max)
h1_3 = inlib.histo_h1d('3', nbin, ra_min, ra_max)

import csv
file = open(file_name)
csv_reader = csv.reader(file, delimiter=',')
first_line = False
for row in csv_reader:
    if first_line == False:
        first_line = True
        #print(row[0])
    else:
        ra = float(row[0])
        dec = float(row[1])