Exemplo n.º 1
0
def prepare_neutron_data(infpn, output_preview=False):
    # load the neutron dataframe
    ndata = pd.read_csv(infpn)

    # select only neutrons produced by the interaction
    # proton + Be9 --> proton + neutron + Be8
    ndata = ndata[(ndata.particle_name == 'neutron') & (
        ndata.equation == 'proton + Be9 --> proton + neutron + Be8')]

    if output_preview:
        ndata.to_csv(
            os.path.join(data_utilities.get_git_root(__file__),
                         'data/p_on_be/pandas/be8_neutrons.csv'))

    # track_id is categorical. Might be useful, but skip for now.
    # Be9 is also categorical and skipped for now.
    sel_cols = ['posx', 'posy', 'posz', 'px', 'py', 'pz', 'ke']

    return ndata[sel_cols]
Exemplo n.º 2
0
        print(vargroupname, 'finished!')

    def simplify_process_categories(self, eqn_str):
        '''
        Since it is quite cumbersome to track processes in which neutrons are produced by secondary particles,
        they are simply grouped into one category called "neutrons produced by secondaries".
        '''
        _, daughters = data_utilities.parse_equation(eqn_str)
        if not 'neutron' in daughters:
            return 'neutrons produced by secondaries'
        return eqn_str

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--input_file', type=str, default=os.path.join(data_utilities.get_git_root(__file__), 'data/p_on_be/pandas/neutron_preview.csv'))
    args = parser.parse_args()
    infpn = args.input_file

    # configure pandas to print all rows
    # pd.set_option('display.max_rows', None)

    # load dataframe
    ndata = neutron_from_target(infpn)
    # print(ndata.df_neutron)

    # create output folder
    outdir = 'plots'
    if not os.path.exists(outdir):
        os.makedirs(outdir)
Exemplo n.º 3
0
    # track_id is categorical. Might be useful, but skip for now.
    # Be9 is also categorical and skipped for now.
    sel_cols = ['posx', 'posy', 'posz', 'px', 'py', 'pz', 'ke']

    return ndata[sel_cols]


if __name__ == '__main__':
    # command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-i',
                        '--input_file',
                        type=str,
                        default=os.path.join(
                            data_utilities.get_git_root(__file__),
                            'data/p_on_be/pandas/neutron_preview.csv'))
    args = parser.parse_args()
    infpn = args.input_file

    # preprocess data
    X = prepare_neutron_data(infpn, output_preview=True)
    print('Before standardization')
    print(X)
    standarized_X = StandardScaler().fit_transform(X)
    print('After standardization')
    print(standarized_X)

    # Create figure
    fig = plt.figure(figsize=(12, 8))
    fig.suptitle('Manifold Learning comparison', fontsize=14)
    cosine_edges = list(cosines)
    for cos in list(cosines):
        edge = cos - min_cos_interval
        if not edge in cosine_edges:
            cosine_edges.append(cos - min_cos_interval)
    return sorted(np.round(np.arccos(np.array(cosine_edges)) * 180 / np.pi, 4))


if __name__ == '__main__':
    # command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-i',
                        '--input_file',
                        type=str,
                        default=os.path.join(
                            data_utilities.get_git_root(__file__),
                            'data/p_on_be/pandas/neutron_preview.csv'))
    parser.add_argument('--equal_angle_bin', action='store_true')
    args = parser.parse_args()
    infpn = args.input_file

    # load data from file into a dataframe
    df_neutron = pd.read_csv(infpn)
    df_neutron = df_neutron[df_neutron.particle_name == 'neutron']
    df_neutron['theta_p_degree'] = df_neutron.theta_p * 180 / np.pi

    if args.equal_angle_bin:
        angle_edges = [
            0., 20., 40., 60., 80., 90., 100., 120., 140., 160., 180.
        ]
    else: