예제 #1
0
    def init(self):
        head = self.opts.plot[0]

        kwargs = dict(self.opts.options, joints=self.opts.joints)
        kwargs.setdefault('rankdir', 'LR')
        kwargs['subgraph']=self.opts.subgraph
        kwargs['include_only']=self.opts.include_only
        if self.opts.splines:
            kwargs['splines']=self.opts.splines

        if self.opts.namespace is not self.undefined:
            kwargs['namespace']=env.globalns(self.opts.namespace)

        graph = GNADot( head, **kwargs )


        for output in self.opts.outputs:
            print( 'Write graph to:', output )

            if output.endswith('.dot'):
                graph.write(output)
            else:
                graph.layout(prog='dot')
                graph.draw(output)

        if self.opts.stdout:
            graph.write()

        if self.opts.stderr:
            import sys
            graph.write( sys.stderr )
예제 #2
0
파일: iav_2.py 프로젝트: gnafit/gna
ax.set_title('IAV effect')

smeared1 = smear1.Nrec.data()
smeared2 = smear2.Nrec.data()
smeared3 = smear3.Nrec.data()
print('Sum check for {} (diff): {}'.format(1.0, phist.sum() - smeared1.sum()))
print('Sum check for {} (diff): {}'.format(2.0, phist.sum() - smeared2.sum()))
print('Sum check for {} (diff): {}'.format(2.0, phist.sum() - smeared3.sum()))

lines = plot_hist(edges, smeared1, linewidth=1.0, label='IAV 1')
lines = plot_hist(edges, smeared2, linewidth=1.0, label='IAV 2')
lines = plot_hist(edges, smeared3, linewidth=1.0, label='IAV 3')

ax.legend(loc='upper right')

#
# Dump graph
#
if args.dot:
    try:
        from gna.graphviz import GNADot

        graph = GNADot(b.transformations_out.values()[0])
        graph.write(args.dot)
        print('Write output to:', args.dot)
    except Exception as e:
        print('\033[31mFailed to plot dot\033[0m')

if args.show:
    P.show()
예제 #3
0
# plot function versus sample points
ax.plot(gl_int.points.x.data(), fcn.rate.rate.data(), label='function')
# plot histogram using GNA to matplotlib interface
hist_output.plot_bar(label='histogram (sum=%g)' % hist.sum(), alpha=0.5)
# plot histogram manually
plot_bar(edges, hist / widths, label='histogram/binwidth', alpha=0.5)

# add legend
ax.legend(loc=opts.legend)

# Our function of interest is a guassian and should give 1 when integrated
# Test it by summing the histogram bins
diff = hist.sum() - 1
print('Integral-1:', diff)
print(
    N.fabs(diff) < 1.e-8 and '\033[32mIntegration is OK!'
    or '\033[31mIntegration FAILED!', '\033[0m')

if opts.dot:
    try:
        from gna.graphviz import GNADot
        graph = GNADot(gl_hist.hist)
        graph.write(opts.dot)
        print('Write output to:', opts.dot)
    except Exception as e:
        print('\033[31mFailed to plot dot\033[0m')
        raise

P.show()
예제 #4
0
def build_and_plot(expr, obj, suffix):
    # Initialize the expression and indices
    a = Expression(expr, indices)

    # Dump the information
    print(a.expressions_raw)
    print(a.expressions)

    # Parse the expression
    a.parse()
    # The next step is needed to name all the intermediate variables.
    a.guessname(lib, save=True)
    # Dump the tree.
    a.tree.dump(True)

    cfg = NestedDict(
        kinint2=NestedDict(
            bundle='integral_2d1d_v01',
            variables=('evis', 'ctheta'),
            edges=N.linspace(0.0, 12.0, 241, dtype='d'),
            xorders=3,
            yorder=5,
            provides=['evis', 'ctheta', 'evis_edges'],
        ),
        ibd_xsec=NestedDict(bundle='xsec_ibd_v01',
                            order=1,
                            provides=['ibd_xsec', 'ee', 'enu', 'jacobian']),
        oscprob=NestedDict(bundle='oscprob_v01',
                           name='oscprob',
                           provides=['oscprob', 'pmns']),
        anuspec=NestedDict(
            bundle='reactor_anu_spectra_v02',
            name='anuspec',
            filename=[
                'data/reactor_anu_spectra/Huber/Huber_smooth_extrap_{isotope}_13MeV0.01MeVbin.dat',
                'data/reactor_anu_spectra/Mueller/Mueller_smooth_extrap_{isotope}_13MeV0.01MeVbin.dat'
            ],
            # strategy = dict( underflow='constant', overflow='extrapolate' ),
            edges=N.concatenate((N.arange(1.8, 8.7, 0.5), [12.3])),
        ),
        eff=NestedDict(
            bundle='efficiencies_v01',
            correlated=False,
            uncorrelated=True,
            norm=True,
            names=dict(norm='global_norm'),
            provides=['eff', 'effunc_corr', 'effunc_uncorr', 'global_norm'],
            efficiencies='data/dayabay/efficiency/P15A_efficiency.py'),
        livetime=NestedDict(
            bundle='dayabay_livetime_hdf_v01',
            file=
            'data/dayabay/data/P15A/dubna/dayabay_data_dubna_v15_bcw_adsimple.hdf5',
            provides=['livetime_daily', 'efflivetime_daily']),
        baselines=NestedDict(
            bundle='baselines_v01',
            reactors=
            'data/dayabay/reactor/coordinates/coordinates_docDB_9757.py',
            detectors='data/dayabay/ad/coordinates/coordinates_docDB_9757.py',
            provides=['baseline', 'baselineweight'],
            units="meters"),
        thermal_power=NestedDict(
            bundle='dayabay_reactor_burning_info_v01',
            reactor_info='data/dayabay/reactor/power/WeeklyAvg_P15A_v1.txt.npz',
            provides=['thermal_power', 'fission_fractions']),
        iav=NestedDict(
            bundle='detector_iav_db_root_v02',
            parname='OffdiagScale',
            scale=uncertain(1.0, 4, 'percent'),
            ndiag=1,
            filename='data/dayabay/tmp/detector_iavMatrix_P14A_LS.root',
            matrixname='iav_matrix'),
        eres=NestedDict(
            bundle='detector_eres_common3_v02',
            # pars: sigma_e/e = sqrt( a^2 + b^2/E + c^2/E^2 ),
            pars=uncertaindict([('Eres_a', 0.014764), ('Eres_b', 0.0869),
                                ('Eres_c', 0.0271)],
                               mode='percent',
                               uncertainty=30),
            provides=['eres', 'eres_matrix'],
            expose_matrix=True),
        lsnl=NestedDict(
            bundle='detector_nonlinearity_db_root_v02',
            names=['nominal', 'pull0', 'pull1', 'pull2', 'pull3'],
            filename='data/dayabay/tmp/detector_nl_consModel_450itr.root',
            parnames=dict(lsnl='lsnl_weight', escale='escale'),
            par=uncertain(1.0, 0.2, 'percent'),
            edges='evis_edges',
            provides=[
                'lsnl', 'lsnl_component', 'escale', 'lsnl_weight', 'lsnl_edges'
            ]),
        rebin=NestedDict(bundle='rebin_v02',
                         rounding=3,
                         edges=N.concatenate(([0.7], N.arange(1.2, 8.1,
                                                              0.2), [12.0]))))
    #
    # Put the expression into context
    context = ExpressionContext(cfg, ns=env.globalns)
    a.build(context)

    # # Print the list of outputs, stored for the expression
    # from gna.bindings import OutputDescriptor
    # env.globalns.materializeexpressions(True)
    # env.globalns.printparameters( labels=True )
    # print( 'outputs:' )
    # print( context.outputs )

    try:
        from gna.graphviz import GNADot

        obj = context.outputs[obj]
        if isinstance(obj, NestedDict):
            obj = obj.values()
        if len(expr) < 4:
            label = expr[0]
            if label == 'evis()':
                label = expr[1]
        else:
            label = ''
        graph = GNADot(obj, joints=False, label=label)
        name = args.dot.replace('.dot', '_' + suffix + '.dot')
        graph.write(name)
        print('Write output to:', name)
    except Exception as e:
        print('\033[31mFailed to plot dot\033[0m')
        raise
예제 #5
0
    # step('_03_lsnl')
    # outputs.eres.AD11.plot_hist(label='+eres')
    if args.mode == 'dyboscar':
        out = outputs.sum_sum_sum_eres_cw
    else:
        out = outputs.eres
    out.AD11.plot_hist(label='EH1 AD1')
    step('_04_eres')

if args.show:
    P.show()

#
# Dump the histogram to a dot graph
#
if args.dot:
    try:
        from gna.graphviz import GNADot

        graph = GNADot(context.outputs.ee, joints=False)
        graph.write(args.dot)
        print('Write output to:', args.dot)

        graph = GNADot(context.outputs.thermal_power.values(), joints=False)
        name = args.dot.replace('.dot', '_lt.dot')
        graph.write(name)
        print('Write output to:', name)
    except Exception as e:
        print('\033[31mFailed to plot dot\033[0m')
        raise