Exemplo n.º 1
0
    def build(self):
        model_edges_t = C.Points( self.model_edges, ns=self.namespace )
        model_edges_t.points.setLabel('Spectra interpolation edges')
        self.context.objects['edges'] = model_edges_t
        self.shared.reactor_anu_edges = model_edges_t.single()

        if self.cfg.free_params:
            with self.reac_ns:
                tmp = C.VarArray(self.variables, ns=self.reac_ns, labels='Spec pars:\nlog(n_i)')
            if self.cfg.varmode == 'log':
                self.context.objects['npar_log'] = tmp
                self.free_weights = R.Exp(ns=self.reac_ns)
                self.free_weights.exp.points( tmp )
                self.free_weights.exp.setLabel('n_i')
            else:
                tmp.vararray.setLabel('n_i')
                self.free_weights = tmp

        self.interp_expo = interp_expo = R.InterpExpo(ns=self.reac_ns)
        sampler = interp_expo.transformations.front()
        model_edges_t >> sampler.inputs.edges
        sampler_input = sampler.inputs.points

        interp_expo_t = interp_expo.transformations.back()
        for i, it in enumerate(self.nidx_major):
            isotope, = it.current_values()

            spectrum_raw_t = C.Points( self.spectra[isotope], ns=self.reac_ns )
            spectrum_raw_t.points.setLabel('%s spectrum, original'%isotope)
            self.context.objects[('spectrum_raw', isotope)] = spectrum_raw_t

            if self.cfg.free_params:
                spectrum_t = C.Product(ns=self.reac_ns)
                spectrum_t.multiply( spectrum_raw_t )
                spectrum_t.multiply( self.free_weights.single() )
                spectrum_t.product.setLabel('%s spectrum, corrected'%isotope)
            else:
                spectrum_t = spectrum_raw_t

            if i>0:
                interp_expo_t = interp_expo.add_transformation()

            model_edges_t >> interp_expo_t.inputs.x
            interp_output = interp_expo.add_input(spectrum_t)
            interp_input  = interp_expo_t.inputs.newx

            if i>0:
                self.set_input(self.cfg.name, it, interp_input, argument_number=0)
            else:
                self.set_input(self.cfg.name, it, (sampler_input, interp_input), argument_number=0)

            interp_expo_t.setLabel('%s spectrum, interpolated'%isotope)

            """Store data"""
            self.set_output(self.cfg.name, it, interp_output)

            self.context.objects[('spectrum', isotope)] = spectrum_t
Exemplo n.º 2
0
def test_01():
    arrays = ([[1.5, 1.5, 1.5], [1.5, 1.5, 1.5]], [[2.0, 2.0, 2.0],
                                                   [2.0, 2.0, 2.0]])
    objects = [C.Points(a) for a in arrays]
    prod = C.Product(outputs=[p.single() for p in objects])
    prod.product.switchFunction('gpu')

    prod.print()
    print(prod.single().data())

    entry = R.OpenHandle(prod.product).getEntry()
    entry.functionargs.gpu.dump()
Exemplo n.º 3
0
def check_product(arrays):
    print('Test ', len(arrays), ':', sep='')
    for array in arrays:
        print(array)
    print()

    truth=1.0
    for a in arrays:
        if a.size==1:
            truth*=a[0]
        else:
            truth*=a

    print('Truth:\n', truth, end='\n\n')

    points = [C.Points(array) for array in arrays]
    prod = C.Product(outputs=[p.points.points for p in points])

    calc =  prod.single().data()
    print('Result', calc, calc.dtype, end='\n\n')

    assert (calc==truth).all()
Exemplo n.º 4
0
    def build(self):
        for idx in self.nidx:
            reac, = idx.current_values()
            name = "snf_correction" + idx.current_format()
            try:
                _snf_energy, _snf_spectra = list(
                    map(C.Points, self.snf_raw_data[reac]))
            except KeyError:
                # U238 doesn't have offequilibrium correction so just pass 1.
                _snf_energy, _snf_spectra = list(
                    map(C.Points, self.snf_raw_data['average']))

            _snf_energy.points.setLabel(
                "Original energies for SNF spectrum of {}".format(reac))

            snf_spectra = C.InterpLinear(
                labels='Correction for spectra in {}'.format(reac))
            snf_spectra.set_overflow_strategy(
                R.GNA.Interpolation.Strategy.Constant)
            snf_spectra.set_underflow_strategy(
                R.GNA.Interpolation.Strategy.Constant)

            insegment = snf_spectra.transformations.front()
            insegment.setLabel("Segments")

            interpolator_trans = snf_spectra.transformations.back()
            interpolator_trans.setLabel(
                "Interpolated SNF correction for {}".format(reac))

            passthrough = C.Identity(
                labels="Nominal spectra for {}".format(reac))
            _snf_energy >> (insegment.edges, interpolator_trans.x)
            _snf_spectra >> interpolator_trans.y

            self.set_input('snf_correction',
                           idx, (insegment.points, interpolator_trans.newx),
                           argument_number=0)
            self.set_input('snf_correction',
                           idx, (passthrough.single_input()),
                           argument_number=1)

            snap = C.Snapshot(
                passthrough.single(),
                labels='Snapshot of nominal spectra for SNF in {}'.format(
                    reac))
            product = C.Product(
                outputs=[snap.single(),
                         interpolator_trans.single()],
                labels='Product of nominal spectrum to SNF correction in {}'.
                format(reac))

            par_name = "snf_scale"
            self.reqparameter(par_name,
                              idx,
                              central=1.,
                              relsigma=1,
                              labels="SNF norm for reactor {0}".format(reac))

            outputs = [product.single()]
            weights = ['.'.join((par_name, idx.current_format()))]

            with self.namespace:
                final_sum = C.WeightedSum(
                    weights,
                    outputs,
                    labels='SNF spectrum from {0} reactor'.format(reac))

            self.context.objects[name] = final_sum
            self.set_output("snf_correction", idx, final_sum.single())
Exemplo n.º 5
0
#!/usr/bin/env python

from load import ROOT as R
import gna.constructors as C
import numpy as np
# Create several points instances
n, n1, n2 = 12, 3, 4
points_list = [C.Points(np.arange(i, i + n).reshape(n1, n2)) for i in range(5)]

# Create product instances
tproduct_constructor = C.Product([p.points.points for p in points_list])
tproduct_multiply = C.Product()
tproduct_add_input = C.Product()

for i, p in enumerate(points_list):
    out = p.points.points
    tproduct_multiply.multiply(out)

    an_input = tproduct_add_input.add_input('input_{:02d}'.format(i))
    an_input(out)

# Print the structure of Product object
print('Product, configured via constructor')
tproduct_constructor.print()
print()

# Print the structure of Product object
print('Product, configured via multiply() method')
tproduct_multiply.print()
print()
Exemplo n.º 6
0
    def build(self):
        for idx in self.nidx.iterate():
            if 'isotope' in idx.names()[0]:
                iso, reac = idx.current_values()
            else:
                reac, iso = idx.current_values()
            name = "offeq_correction." + idx.current_format()
            try:
                _offeq_energy, _offeq_spectra = list(map(C.Points, self.offeq_raw_spectra[iso]))
                _offeq_energy.points.setLabel("Original energies for offeq spectrum of {}".format(iso))
            except KeyError:
            # U238 doesn't have offequilibrium correction so just pass 1.
                if iso != 'U238':
                    raise
                passthrough = C.Identity(labels='Nominal {0} spectrum in {1} reactor'.format(iso, reac))
                self.context.objects[name] = passthrough
                dummy = C.Identity() #just to serve 1 input
                self.set_input('offeq_correction', idx, dummy.single_input(), argument_number=0)
                self.set_input('offeq_correction', idx, passthrough.single_input(), argument_number=1)
                self.set_output("offeq_correction", idx, passthrough.single())
                continue

            offeq_spectra = C.InterpLinear(labels='Correction for {} spectra'.format(iso))
            offeq_spectra.set_overflow_strategy(R.GNA.Interpolation.Strategy.Constant)
            offeq_spectra.set_underflow_strategy(R.GNA.Interpolation.Strategy.Constant)

            insegment = offeq_spectra.transformations.front()
            insegment.setLabel("Offequilibrium segments")

            interpolator_trans = offeq_spectra.transformations.back()
            interpolator_trans.setLabel("Interpolated spectral correction for {}".format(iso))

            passthrough = C.Identity(labels="Nominal {0} spectrum in {1} reactor".format(iso, reac))
            _offeq_energy >> (insegment.edges, interpolator_trans.x)
            _offeq_spectra >> interpolator_trans.y

            # Enu
            self.set_input('offeq_correction', idx, (insegment.points, interpolator_trans.newx),
                            argument_number=0)
            # Anue spectra
            self.set_input('offeq_correction', idx, ( passthrough.single_input()), argument_number=1)

            par_name = "offeq_scale"
            self.reqparameter(par_name, idx, central=1., relsigma=0.3,
                    labels="Offequilibrium norm for reactor {1} and iso "
                    "{0}".format(iso, reac))
            self.reqparameter("dummy_scale", idx, central=1,
                    fixed=True, labels="Dummy weight for reactor {1} and iso "
                    "{0} for offeq correction".format(iso, reac))

            snap = C.Snapshot(passthrough.single(), labels='Snapshot of {} spectra in reac {}'.format(iso, reac))

            prod = C.Product(labels='Product of initial {} spectra and '
                             'offequilibrium corr in {} reactor'.format(iso, reac))
            prod.multiply(interpolator_trans.single())
            prod.multiply(snap.single())


            outputs = [passthrough.single(), prod.single()]
            weights = ['.'.join(("dummy_scale", idx.current_format())),
                       '.'.join((par_name, idx.current_format()))]

            with self.namespace:
                final_sum = C.WeightedSum(weights, outputs, labels='Corrected to offequilibrium '
                            '{0} spectrum in {1} reactor'.format(iso, reac))


            self.context.objects[name] = final_sum
            self.set_output("offeq_correction", idx, final_sum.single())
Exemplo n.º 7
0
    def define_variables(self):
        daq = self.namespace('daq')
        daq.reqparameter('first_day',
                         central=self.info['first_day'],
                         fixed=True,
                         label='First DAQ day start: %s' %
                         self.info['str_first_day'])
        daq.reqparameter('last_day',
                         central=self.info['last_day'],
                         fixed=True,
                         label='Last DAQ day end:    %s' %
                         self.info['str_last_day'])
        daq.reqparameter('ndays',
                         central=self.info['days'],
                         fixed=True,
                         label='Total number of days')

        self.reqparameter('seconds_in_day',
                          None,
                          central=24. * 60. * 60.,
                          fixed=True,
                          label='Number of seconds in day')
        self.reqparameter('days_in_second',
                          None,
                          central=1.0 / (24. * 60. * 60.),
                          fixed=True,
                          label='Number of days in a second')

        data_lt = 0.0
        for it in self.nidx:
            ad, = it.current_values()
            data = self.data.get(ad, None)
            if data is None:
                raise self.exception('Failed to retrieve data for %s from %s' %
                                     (ad, self.cfg.file))

            data_lt = data['livetime'] + data_lt
            if self.cfg.get('scale_to_ext_livetime'):
                scale = self.cfg.scale_to_ext_livetime
                livetime_external = scale[ad]
                scaled = data['livetime'] * (livetime_external /
                                             data['livetime'].sum())
                livetime = C.Points(
                    scaled, labels=it.current_format('Livetime\n{autoindex}'))
            else:
                livetime = C.Points(
                    data['livetime'],
                    labels=it.current_format('Livetime\n{autoindex}'))

            eff = C.Points(
                data['eff'],
                labels=it.current_format('Efficiency (mu*mult)\n{autoindex}'))
            efflivetime = C.Product(
                [livetime, eff],
                labels=it.current_format('Livetime (eff)\n{autoindex}'))

            self.context.objects[('livetime', ad)] = livetime
            self.context.objects[('eff', ad)] = eff
            self.context.objects[('efflivetime', ad)] = efflivetime

            self.set_output('eff_daily', it, eff.single())
            self.set_output('livetime_daily', it, livetime.single())
            self.set_output('efflivetime_daily', it, efflivetime.single())

        ndays_daq = (data_lt > 0.0).sum()
        daq.reqparameter('ndays_daq',
                         central=ndays_daq,
                         fixed=True,
                         sigma=0.01,
                         label='Total number of DAQ days (exclude no DAQ)')
Exemplo n.º 8
0
# Define two sets of scales to correct each value of y0
pars1 = env.globalns('pars1')
pars2 = env.globalns('pars2')
for ns in (pars1, pars2):
    for i in range(nsegments+1):
        ns.defparameter('par_{:02d}'.format(i), central=1, free=True, label='Scale for x_{}={}'.format(i, edges_data[i]))

# Initialize transformations for scales
with pars1:
    varray1=C.VarArray(list(pars1.keys()), labels='Scales 1\n(p1)')

with pars2:
    varray2=C.VarArray(list(pars2.keys()), labels='Scales 2\n(p2)')

# Make two products: y0 scaled by varray1 and varray2
y1 = C.Product([varray1.single(), y0.single()], labels='p1*y')
y2 = C.Product([varray2.single(), y0.single()], labels='p2*y')

# Initialize interpolator
manual = False
labels=('Segment index\n(fine x in coarse x)', 'Interpolator')
if manual:
    # Bind transformations manually
    interpolator = R.InterpExpo(labels=labels)

    edges  >> (interpolator.insegment.edges, interpolator.interp.x)
    points >> (interpolator.insegment.points, interpolator.interp.newx)
    interpolator.insegment.insegment >> interpolator.interp.insegment
    interpolator.insegment.widths    >> interpolator.interp.widths
    y1 >> interpolator.interp.y
    y2 >> interpolator.add_input()
Exemplo n.º 9
0
#!/usr/bin/env python

from tutorial import tutorial_image_name, savegraph
from load import ROOT as R
import gna.constructors as C
import numpy as np

n, n1, n2 = 12, 3, 4

points_list = [C.Points(np.arange(i, i + n).reshape(n1, n2)) for i in range(5)]
tfactor = C.Points(np.linspace(0.5, 2.0, n).reshape(n1, n2))
tsum = C.Sum([p.points.points for p in points_list])
tprod = C.Product([tsum.sum.sum, tfactor.points.points])

for i, p in enumerate(points_list):
    p.points.setLabel('Sum input:\nP{:d}'.format(i))
tfactor.points.setLabel('Scale S')
tsum.sum.setLabel('Sum of matrices')
tprod.product.setLabel('Scaled matrix')
tprod.product.product.setLabel('result')

tsum.print()
print()

tprod.print()
print()

print('The sum:')
print(tsum.transformations[0].outputs[0].data())
print()