Пример #1
0
def test_scrip_runs_and_produces_correct_outputs(folder_test_dst,
                                                 test_dst_file,
                                                 output_maps_tmdir,
                                                 test_map_file):
    """
    Run map creation script and check if an ASectormap is the output.
    """
    map_file_out = os.path.join(output_maps_tmdir, 'test_out_map.h5')
    histo_file_out = os.path.join(output_maps_tmdir, 'test_out_histo.h5')
    default_n_bins = 15
    run_number = 7517
    config = configure(
        'maps $ICARO/krcal/map_builder/config_LBphys.conf'.split())
    map_params_new = copy.copy(config.as_namespace.map_params)
    map_params_new['nmin'] = 100
    map_params_new['nStimeprofile'] = 1200
    map_params_new['z_range'] = (0, 10000)
    config.update(
        dict(folder=folder_test_dst,
             file_in=test_dst_file,
             file_out_map=map_file_out,
             file_out_hists=histo_file_out,
             default_n_bins=default_n_bins,
             run_number=run_number,
             map_params=map_params_new))
    map_builder(config.as_namespace)
    maps = read_maps(map_file_out)
    assert type(maps) == ASectorMap

    old_maps = read_maps(test_map_file)
    assert_dataframes_close(maps.e0, old_maps.e0, rtol=1e-5)
    assert_dataframes_close(maps.e0u, old_maps.e0u, rtol=1e-1)
    assert_dataframes_close(maps.lt, old_maps.lt, rtol=1e-5)
    assert_dataframes_close(maps.ltu, old_maps.ltu, rtol=1e-1)
Пример #2
0
def test_correct_map_with_unsorted_dst(folder_test_dst, test_dst_file,
                                       output_maps_tmdir):
    """
    This test shuffles the input dst, and checks that the map is the same
    as the one created with the same sorted dst.
    """
    map_file_sort = os.path.join(output_maps_tmdir, 'test_out_map.h5')
    map_file_unsort = os.path.join(output_maps_tmdir, 'test_out_unsort.h5')
    histo_file_out = os.path.join(output_maps_tmdir, 'test_out_histo.h5')

    dst = load_dst(folder_test_dst + test_dst_file, 'DST', 'Events')
    if "index" in dst: del dst["index"]
    dst = dst.sort_values(by=['S2e'])
    tmp_unsorted_dst = 'unsorted_dst.h5'
    dst.to_hdf(output_maps_tmdir + tmp_unsorted_dst,
               key="DST",
               mode="w",
               format="table",
               data_columns=True,
               complib="zlib",
               complevel=4)
    with tb.open_file(output_maps_tmdir + tmp_unsorted_dst, "r+") as file:
        file.rename_node(file.root.DST.table, "Events")
        file.root.DST.Events.title = "Events"

    default_n_bins = 15
    run_number = 7517
    config = configure(
        'maps $ICARO/krcal/map_builder/config_LBphys.conf'.split())
    map_params_new = config.as_namespace.map_params
    map_params_new['nmin'] = 100
    map_params_new['z_range'] = (0, 10000)
    config.update(
        dict(folder=output_maps_tmdir,
             file_in=tmp_unsorted_dst,
             file_out_map=map_file_unsort,
             file_out_hists=histo_file_out,
             default_n_bins=default_n_bins,
             run_number=run_number,
             map_params=map_params_new))
    map_builder(config.as_namespace)
    unsorted_maps = read_maps(map_file_unsort)
    sorted_maps = read_maps(map_file_sort)

    assert_dataframes_close(unsorted_maps.e0, sorted_maps.e0, rtol=1e-5)
    assert_dataframes_close(unsorted_maps.e0u, sorted_maps.e0u, rtol=1e-5)
    assert_dataframes_close(unsorted_maps.lt, sorted_maps.lt, rtol=1e-5)
    assert_dataframes_close(unsorted_maps.ltu, sorted_maps.ltu, rtol=1e-5)
Пример #3
0
def load_data(input_path         : str ,
              input_dsts         : str ,
              file_bootstrap_map : str ,
              ref_histo_file     : str ,
              key_Z_histo        : str ,
              quality_ranges     : dict ) -> Tuple[pd.DataFrame,
                                                   ASectorMap  ,
                                                   ref_hist_container]:
    """
    Reads kdst files and applies basic R cut. Outputs kdst as pd.DataFrame,
    bootstrap map, and reference histograms

    Parameters
    ----------
    input_path : str
        Path to the input map_folder
    input_dsts : str
        Name criteria for the dst to be read
    file_bootstrap_map : str
        Path to the bootstrap map file
    ref_Z_histo_file : str
        Path to the reference histogram file
    quality_ranges : dict
        Dictionary containing ranges for the quality cuts

    Returns
    ----------
    dst_filtered : pd.DataFrame
        Dst containing all the events once filtered
    bootstrap_map : ASectorMap
        Bootstrap map
    ref_hist_container : ref_hist_container
        To be completed
    """

    input_path         = os.path.expandvars(input_path)
    dst_files          = glob.glob(input_path + input_dsts)
    dst_full           = load_dsts(dst_files, "DST", "Events")
    dst_full           = dst_full.sort_values(by=['time'])
    mask_quality       = quality_cut(dst_full, **quality_ranges)
    dst_filtered       = dst_full[mask_quality]

    file_bootstrap_map = os.path.expandvars(file_bootstrap_map)
    bootstrap_map      = read_maps(file_bootstrap_map)

    ref_histo_file     = os.path.expandvars(ref_histo_file)
    z_pd               = pd.read_hdf(ref_histo_file, key=key_Z_histo)
    z_histo            = ref_hist(bin_centres     = z_pd.bin_centres,
                                  bin_entries     = z_pd.bin_entries,
                                  err_bin_entries = z_pd.err_bin_entries)
    ref_histos         =  ref_hist_container(Z_dist_hist = z_histo)

    return dst_filtered, bootstrap_map, ref_histos
Пример #4
0
def test_time_evol_table_correct_elements(output_maps_tmdir):
    map_file_out = os.path.join(output_maps_tmdir, 'test_out_map.h5')
    emaps = read_maps(map_file_out)
    time_table = emaps.t_evol
    columns = time_table.columns
    elements = [
        'ts', 'e0', 'e0u', 'lt', 'ltu', 'dv', 'dvu', 'resol', 'resolu', 's1w',
        's1wu', 's1h', 's1hu', 's1e', 's1eu', 's2w', 's2wu', 's2h', 's2hu',
        's2e', 's2eu', 's2q', 's2qu', 'Nsipm', 'Nsipmu', 'Xrms', 'Xrmsu',
        'Yrms', 'Yrmsu', 'S1eff', 'S2eff', 'Bandeff'
    ]
    for element in elements:
        assert element in columns
Пример #5
0
def test_maps_nans_outside_rmax(xy_pos, output_maps_tmdir):
    map_file_out = os.path.join(output_maps_tmdir, 'test_out_map.h5')
    xs, ys = xy_pos

    emaps = read_maps(map_file_out)
    get_coef = maps_coefficient_getter(emaps.mapinfo, emaps.e0)
    r_max = emaps.mapinfo.xmax
    nbins = emaps.mapinfo.nx
    bins = np.linspace(-200, 200, nbins)
    xs = bins[np.digitize(xs, bins, right=True)]
    ys = bins[np.digitize(ys, bins, right=True)]
    coefs = get_coef(xs, ys)
    maskin = np.sqrt(xs**2 + ys**2) < r_max
    maskout = np.sqrt(xs**2 + ys**2) >= r_max + 2 * r_max / nbins

    assert all(np.isnan(coefs[maskout]))
    assert all(np.isfinite(coefs[maskin]))
Пример #6
0
def apply_corrections(dst, map_file):
        """
        ### E0 correction:
        - Computes the energy vector corrected by geometry in bins of XY
        (from the XY map above).
        - e0_xy_correction The signal correction factor f (x, y) is simply the inverse of the
        mean of the gaussian distribution in each (x, y) bin, normalized to
        a constant factor which can be chosen as
        the maximum energy bin: E0M = emaps.e0 / norm.e0
        """

        map = read_maps(map_file)
        geom_corr = e0_xy_correction(map)

        total_correction = apply_all_correction(map, apply_temp=True)
        corr_geo = geom_corr(dst.X, dst.Y)
        corr_tot = total_correction(dst.X, dst.Y, dst.Z, dst.time)

        return corr_tot
def load_and_sel_data(fname):
    kdst = load_dst(fname, 'DST', 'Events')
    kdst = kdst[(kdst.nS1 == 1) & (kdst.nS2 == 1) & (kdst.R <= 198)]
    maxZ = np.quantile(kdst.Z, 0.99)
    kdst = kdst[kdst.Z < maxZ]

    file_bootstrap_map = '$ICDIR/database/test_data/kr_emap_xy_100_100_r_6573_time.h5'
    file_bootstrap_map = os.path.expandvars(file_bootstrap_map)
    boot_map = read_maps(file_bootstrap_map)
    emaps = e0_xy_correction(boot_map, norm_strat=norm_strategy.max)
    E0 = kdst.S2e.values * emaps(kdst.X.values, kdst.Y.values)

    sel_krband, _, _, _, _ = selection_in_band(kdst.Z,
                                               E0,
                                               range_z=(10, maxZ),
                                               range_e=(10.0e+3, 14e+3),
                                               nbins_z=50,
                                               nbins_e=50,
                                               nsigma=3.5)

    kdst = kdst[sel_krband].reset_index(drop=True)
    return kdst
Пример #8
0
def test_time_evol_eff_less_one(output_maps_tmdir):
    map_file_out = os.path.join(output_maps_tmdir, 'test_out_map.h5')
    emaps = read_maps(map_file_out)
    assert np.all(emaps.t_evol.S1eff <= 1.)
    assert np.all(emaps.t_evol.S2eff <= 1.)
    assert np.all(emaps.t_evol.Bandeff <= 1.)
Пример #9
0
def test_time_evol_table_exact_numbers(t_evol_table, output_maps_tmdir):
    map_file_out = os.path.join(output_maps_tmdir, 'test_out_map.h5')
    emaps = read_maps(map_file_out)
    t_evol = pd.pandas.read_hdf(t_evol_table, 't_evol')
    assert_dataframes_close(emaps.t_evol, t_evol, rtol=1e-5)