PreProcessing.py 1.94 KB
Newer Older
JGlombitza's avatar
JGlombitza committed
1
2
3
4
import numpy as np
import glob
import tensorflow as tf
import norm
JGlombitza's avatar
v1.2    
JGlombitza committed
5
import os
JGlombitza's avatar
JGlombitza committed
6
7

Folder = './RawData' # Path to simulated shower packages
JGlombitza's avatar
v1.2    
JGlombitza committed
8
9
10
if not os.path.exists('Data_preprocessed'):
    os.makedirs('Data_preprocessed')

JGlombitza's avatar
JGlombitza committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
log_dir = './Data_preprocessed' # Path to preprocessed shower packages
filenames =glob.glob(Folder + "/showers-*")
a = 10000 # packagesize
for i in range(0,len(filenames)):
    data = np.load(filenames[i])
    if i==0:
        signal = data['signal']
        time = data['time']
        logE = data['logE']
        Xmax = data['Xmax']
        showeraxis = data['showeraxis']
        mass = data['mass']
    else:    
        signal = np.append(signal, data['signal'], axis = 0)
        time = np.append(time, data['time'], axis=0)
        logE = np.append(logE, data['logE'], axis=0)
        Xmax = np.append(Xmax, data['Xmax'], axis = 0)
        showeraxis = np.append(showeraxis, data['showeraxis'], axis = 0)
        mass = np.append(mass, data['mass'], axis = 0)

# Normalization of arrival times
time = norm.NormCenter(time)

# Preprocessing of signal
JGlombitza's avatar
v1.2    
JGlombitza committed
35
signal[np.less(signal,0)] = 0
JGlombitza's avatar
JGlombitza committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
SignalSum = norm.NormPhysicalEnergylog10(np.sum(signal, axis=-1))
signal = norm.NormPhysicalTimeTracelog10(signal)

Energy = 10**logE/10**18

# Preprocessed time traces (input1)
Input1 = signal.reshape(len(showeraxis), 9, 9, signal.shape[2], 1)

# Additional preprocessed input maps (arrival times, total signals) (input2)
Input2 = np.stack((time,SignalSum), axis=-1)

# Shuffle data
idx = np.arange(Xmax.shape[0])
np.random.shuffle(idx)
Xmax = Xmax[idx]
showeraxis = showeraxis[idx]
Energy = Energy[idx]
Input1 = Input1[idx]
Input2 = Input2[idx]
mass = mass[idx]

# Store new packages of preprocessed showers
for i in range(len(filenames)):
    np.savez_compressed(log_dir+ "/PlanarWaveShower_PrePro_%i" %i, Xmax=Xmax[a*i:a*(i+1)], Energy = Energy[a*i:a*(i+1)], showeraxis=showeraxis[a*i:a*(i+1)], Input1 = Input1[a*i:a*(i+1)], Input2=Input2[a*i:a*(i+1)], mass=mass[a*i:a*(i+1)])