-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter.py
More file actions
74 lines (57 loc) · 2.21 KB
/
writer.py
File metadata and controls
74 lines (57 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pandas as pd
import numpy as np
from fact.io import to_h5py
import os
from datetime import datetime
# Add locations of each telescope based on given lat/long
def add_tel_location(telescope_events, site_location, positions):
telescope_location_list = []
site_lat = site_location[0]
site_lon = site_location[1]
site_alt = site_location[2]
r_earth = 6371000.0
pi = np.pi
for i in range(len(telescope_events.index)):
tel_id = telescope_events['telescope_event_id'][i]
tel_north = positions[tel_id][0].value
tel_east = - positions[tel_id][1].value
tel_height = positions[tel_id][2].value
tel_lat = site_lat + (tel_north / r_earth) * (180 / pi)
tel_lon = site_lon + (tel_east / r_earth) * \
(180 / pi) / np.cos(site_lat * pi / 180)
tel_alt = site_alt + tel_height
dict_temp = {
'tel_x': tel_north,
'tel_y': -tel_east,
'tel_latitude': tel_lat,
'tel_longitude': tel_lon,
'tel_altitude': tel_alt}
telescope_location_list.append(dict_temp)
telescope_events = telescope_events.join(
pd.DataFrame(telescope_location_list))
return telescope_events
def write(
typename,
output_path,
site_location,
array_events_data,
telescope_events_data,
runs_all,
positions,
stereo,
id_no):
print('Writing ' + typename + " data...",datetime.now().time().strftime("%H:%M:%S"))
telescope_events = pd.DataFrame(telescope_events_data)
array_events = pd.DataFrame(array_events_data)
runs = pd.DataFrame(runs_all)
# Calculate and add telescope location to telescope_events
telescope_events = add_tel_location(
telescope_events, site_location, positions)
if typename == 'gamma-diffuse':
output_file = output_path + 'gammas-diffuse' + str(id_no) + '.hdf5'
else:
output_file = output_path + typename + 's' + str(id_no) + '.hdf5'
# Save to hdf5 file
to_h5py(telescope_events, output_file, key='telescope_events', mode='w')
to_h5py(array_events, output_file, key='array_events', mode='a')
to_h5py(runs, output_file, key='runs', mode='a')