示例#1
0
文件: pi_prob3.py 项目: terliuk/pisa
    def setup_function(self):

        # object for oscillation parameters
        self.osc_params = OscParams()

        # setup the layers
        #if self.params.earth_model.value is not None:
        earth_model = find_resource(self.params.earth_model.value)
        YeI = self.params.YeI.value.m_as('dimensionless')
        YeO = self.params.YeO.value.m_as('dimensionless')
        YeM = self.params.YeM.value.m_as('dimensionless')
        prop_height = self.params.prop_height.value.m_as('km')
        detector_depth = self.params.detector_depth.value.m_as('km')
        self.layers = Layers(earth_model, detector_depth, prop_height)
        self.layers.setElecFrac(YeI, YeO, YeM)

        # set the correct data mode
        self.data.data_specs = self.calc_specs

        # --- calculate the layers ---
        if self.calc_mode == 'binned':
            # speed up calculation by adding links
            # as layers don't care about flavour
            self.data.link_containers('nu', [
                'nue_cc', 'numu_cc', 'nutau_cc', 'nue_nc', 'numu_nc',
                'nutau_nc', 'nuebar_cc', 'numubar_cc', 'nutaubar_cc',
                'nuebar_nc', 'numubar_nc', 'nutaubar_nc'
            ])

        for container in self.data:
            self.layers.calcLayers(container['true_coszen'].get('host'))
            container['densities'] = self.layers.density.reshape(
                (container.size, self.layers.max_layers))
            container['distances'] = self.layers.distance.reshape(
                (container.size, self.layers.max_layers))

        # don't forget to un-link everything again
        self.data.unlink_containers()

        # --- setup empty arrays ---
        if self.calc_mode == 'binned':
            self.data.link_containers('nu', [
                'nue_cc', 'numu_cc', 'nutau_cc', 'nue_nc', 'numu_nc',
                'nutau_nc'
            ])
            self.data.link_containers('nubar', [
                'nuebar_cc', 'numubar_cc', 'nutaubar_cc', 'nuebar_nc',
                'numubar_nc', 'nutaubar_nc'
            ])
        for container in self.data:
            container['probability'] = np.empty((container.size, 3, 3),
                                                dtype=FTYPE)
        self.data.unlink_containers()

        # setup more empty arrays
        for container in self.data:
            container['prob_e'] = np.empty((container.size), dtype=FTYPE)
            container['prob_mu'] = np.empty((container.size), dtype=FTYPE)
示例#2
0
    def setup_function(self):

        # set the correct data mode
        self.data.data_specs = self.eval_specs

        # check the calc binning
        validate_calc_grid(self.calc_specs)
        #TODO Check grid encompasses all events... (maybe needs to be in `compute_function`)

        # pad the grid to make sure we can later on evaluate osc. probs.
        # *anywhere* in between of the outermost bin edges
        self.en_calc_grid, self.cz_calc_grid = compute_binning_constants(
            self.calc_specs
        )  #TODO Check what this actually does, and if I need it

        #TODO enforce all events within grid

        # set up initial states, get the nuSQuIDS "propagator" instances (one per flavor)
        self.ini_states, self.props = init_nusquids_prop(
            cz_nodes=self.cz_calc_grid,
            en_nodes=self.en_calc_grid,
            nu_flav_no=self.num_neutrinos,
            rel_err=self.params.rel_err.value.m_as('dimensionless'),
            abs_err=self.params.abs_err.value.m_as('dimensionless'),
            progress_bar=False,
            use_nsi=self.use_nsi,
            use_decoherence=self.use_decoherence,
        )

        # make an Earth model  #TODO handle vacuum option
        self.earth_atm = earth_model(
            YeI=self.params.YeI.value.m_as('dimensionless'),
            YeM=self.params.YeM.value.m_as('dimensionless'),
            YeO=self.params.YeO.value.m_as('dimensionless'),
            PREM_file=self.params.earth_model.value)

        #TODO Need to take prop_height and detector_depth into account

        # create oscillation parameter value holder (values actually set later)
        self.osc_params = OscParams()

        # setup empty arrays to hold the calculated probabilities #TODO SHould these be in the linked containers?
        for container in self.data:
            container['prob_e'] = np.full((container.size),
                                          np.NaN,
                                          dtype=FTYPE)
            container['prob_mu'] = np.full((container.size),
                                           np.NaN,
                                           dtype=FTYPE)
示例#3
0
    def setup_function(self):
        sys.path.append(self.globes_wrapper)
        import GLoBES
        ### you need to start GLoBES from the folder containing a dummy experiment
        # therefore we go to the folder, load GLoBES and then go back
        curdir = os.getcwd()
        os.chdir(self.globes_wrapper)
        self.globes_calc =  GLoBES.GLoBESCalculator("calc")
        os.chdir(curdir)
        self.globes_calc.InitSteriles(2)
        # object for oscillation parameters
        self.osc_params = OscParams()
        earth_model = find_resource(self.earth_model)
        prop_height = self.prop_height.m_as('km')
        detector_depth = self.detector_depth.m_as('km')
        self.layers = Layers(earth_model, detector_depth, prop_height)
        # The electron fractions are taken into account internally by GLoBES/SNU.
        # See the SNU patch for details. It uses the density to decide
        # whether it is in the core or in the mantle. Therefore, we just multiply by
        # one to give GLoBES the raw densities.
        self.layers.setElecFrac(1., 1., 1.)

        # set the correct data mode
        self.data.data_specs = self.calc_specs

        # --- calculate the layers ---
        if self.calc_mode == 'binned':
            # speed up calculation by adding links
            # as layers don't care about flavour
            self.data.link_containers('nu', ['nue_cc', 'numu_cc', 'nutau_cc',
                                             'nue_nc', 'numu_nc', 'nutau_nc',
                                             'nuebar_cc', 'numubar_cc', 'nutaubar_cc',
                                             'nuebar_nc', 'numubar_nc', 'nutaubar_nc'])

        for container in self.data:
            self.layers.calcLayers(container['true_coszen'].get('host'))
            container['densities'] = self.layers.density.reshape((container.size, self.layers.max_layers))
            container['distances'] = self.layers.distance.reshape((container.size, self.layers.max_layers))

        # don't forget to un-link everything again
        self.data.unlink_containers()

        # setup probability containers
        for container in self.data:
            container['prob_e'] = np.empty((container.size), dtype=FTYPE)
            container['prob_mu'] = np.empty((container.size), dtype=FTYPE)
            container['prob_nonsterile'] = np.empty((container.size), dtype=FTYPE)
示例#4
0
def test_nusquids_osc():
    """Test nuSQuIDS functions."""
    from pisa.core.binning import OneDimBinning
    # define binning for nuSQuIDS nodes (where master eqn. is solved)
    en_calc_binning = OneDimBinning(
        name='true_energy',
        bin_edges=np.logspace(0.99, 2.01, 40)*ureg.GeV,
    )
    cz_calc_binning = OneDimBinning(
        name='true_coszen',
        domain=[-1, 1]*ureg.dimensionless,
        is_lin=True,
        num_bins=21
    )
    # make 2D binning
    binning_2d_calc = en_calc_binning*cz_calc_binning
    # check it has necessary entries
    validate_calc_grid(binning_2d_calc)
    # pad the grid to make sure we can later on evaluate osc. probs.
    # *anywhere* in between of the outermost bin edges
    en_calc_grid, cz_calc_grid = compute_binning_constants(binning_2d_calc)
    # set up initial states, get the nuSQuIDS "propagator" instances
    ini_states, props = init_nusquids_prop(
        cz_nodes=cz_calc_grid,
        en_nodes=en_calc_grid,
        nu_flav_no=3,
        rel_err=1.0e-5,
        abs_err=1.0e-5,
        progress_bar=True
    )
    # make an Earth model
    YeI, YeM, YeO = 0.4656, 0.4957, 0.4656
    earth_atm = earth_model(YeI=YeI, YeM=YeM, YeO=YeO)

    # define some oscillation parameter values
    osc_params = OscParams()
    osc_params.theta23 = np.deg2rad(48.7)
    osc_params.theta12 = np.deg2rad(33.63)
    osc_params.theta13 = np.deg2rad(8.52)
    osc_params.theta14 = np.deg2rad(0.0)
    osc_params.dm21 = 7.40e-5
    osc_params.dm31 = 2.515e-3
    osc_params.dm41 = 0.
    osc_params.eps_ee = 0.
    osc_params.eps_emu = 0.
    osc_params.eps_etau = 0.
    osc_params.eps_mumu = 0.
    osc_params.eps_mutau = 0.005
    osc_params.eps_tautau = 0.
    # evolve the states starting from initial ones
    evolve_states(
        cz_shape=cz_calc_grid.shape[0],
        propagators=props,
        ini_states=ini_states,
        nsq_earth_atm=earth_atm,
        osc_params=osc_params
    )

    # define some points where osc. probs. are to be
    # evaluated
    en_eval = np.logspace(1, 2, 500) * NSQ_CONST.GeV
    cz_eval = np.linspace(-0.95, 0.95, 500)
    # look them up for appearing tau neutrinos
    nuflav = 'nutau'
    # collect the transition probabilities from
    # muon and electron neutrinos
    prob_e, prob_mu = osc_probs(  # pylint: disable=unused-variable
        nuflav=nuflav,
        propagators=props,
        true_energies=en_eval,
        true_coszens=cz_eval,
    )