Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import csv
# Description of events table
class _Event(tb.IsDescription):
"""
Description of the table /events/eventTable.
"""
# UIntAtom = uint32
array_row = tb.UIntCol(pos=0) # indicates the corresponding row in the
event_start = tb.UIntCol(itemsize=8, pos=1) # start index of the event in the data
event_length = tb.UIntCol(pos=2)
n_levels = tb.UIntCol(pos=3)
raw_points_per_side = tb.UIntCol(pos=4)
baseline = tb.FloatCol(pos=5)
current_blockage = tb.FloatCol(pos=6)
area = tb.FloatCol(pos=7)
class EventDatabase(tb.file.File):
"""
PyTables HDF5 database storing events and corresponding data.
Inherits from tables.file.File, so you can interact with this
just as you would a PyTables File object. However, this contains
some extra convenience methods for storing/reading events
and event data. Note that EventDatabase allows you to interact
with this PyTables file in the usual PyTables file manner, so you
can potentially mangle the data from the original EventDatabase
format.
Automatically adds a group
/events
t2 = tables.Float32Col()
t3 = tables.Float32Col()
t4 = tables.Float32Col()
n1 = tables.Float32Col()
n2 = tables.Float32Col()
n3 = tables.Float32Col()
n4 = tables.Float32Col()
reference_theta = tables.Float32Col()
reference_phi = tables.Float32Col()
reconstructed_theta = tables.Float32Col()
reconstructed_phi = tables.Float32Col()
min_n134 = tables.Float32Col()
k_energy = tables.FloatCol()
k_core_pos = tables.FloatCol(shape=2)
k_Num_e = tables.FloatCol()
k_Num_mu = tables.FloatCol()
k_dens_e = tables.FloatCol(shape=4)
k_dens_mu = tables.FloatCol(shape=4)
k_P200 = tables.FloatCol()
k_T200 = tables.FloatCol()
os.mkdir(output_dir)
except OSError:
pass
# Open a new empty HDF5 file
hdf5_name = 'links_examples.h5'
filepath_hdf5 = os.path.join(output_dir, hdf5_name)
fileh = tb.open_file(filepath_hdf5, mode = "w")
# Create some groups and add datasets to them
garrays = fileh.create_group('/', 'arrays')
a1 = fileh.create_carray(garrays, 'a1', tb.Int64Atom(shape=(2,)), shape=(100, 3),
title='A linked array')
gtables = fileh.create_group('/', 'tables')
t1 = fileh.create_table(gtables, 't1',
{'field1': tb.FloatCol(), 'field2': tb.IntCol()}, title='A linked table')
# Create a group and put some links there
glinks = fileh.create_group('/', 'links')
# Hard link to table t1. If we remove t1 it will still be accessible via ht1.
# Hard links are not a subclass of tables.link.Link so they don't have a
# target attribute. Because hard links behave like regular nodes one can't
# infer if ht1 is a hard link by calling its __str__ method
ht1 = fileh.create_hard_link(glinks, 'ht1', '/tables/t1')
t1.remove()
# Soft link to array a1
sa1 = fileh.create_soft_link(glinks, 'sa1', '/arrays/a1')
# Soft link to table t1. This is a dangling link because it points to a
# non-existing node. In order to get the pointed node the soft links are
class KascadeEvent(tables.IsDescription):
"""Store events from KASCADE"""
run_id = tables.IntCol()
event_id = tables.Int64Col()
timestamp = tables.Time32Col()
nanoseconds = tables.UInt32Col()
ext_timestamp = tables.UInt64Col()
energy = tables.FloatCol()
core_pos = tables.FloatCol(shape=2)
zenith = tables.FloatCol()
azimuth = tables.FloatCol()
Num_e = tables.FloatCol()
Num_mu = tables.FloatCol()
dens_e = tables.FloatCol(shape=4)
dens_mu = tables.FloatCol(shape=4)
P200 = tables.FloatCol()
T200 = tables.FloatCol()
class ReconstructedKascadeEvent(tables.IsDescription):
"""Store information about reconstructed events"""
# r, phi is core position
id = tables.UInt32Col()
station_id = tables.UInt8Col()
r = tables.Float32Col()
#read the top header and determine the number of histograms
#and the size of the histograms
data_buffer= struct.unpack("i",hstfid.read(struct.calcsize("i")))
nofhists = data_buffer[0]
if config.VERBOSITY >= config.INFO_ALL:
print("XU.io.hst2hdf5: number of histograms found: %d" %nofhists)
#now the table and the EArray
table_dict = {}
table_dict["index"] = tables.IntCol()
table_dict["channels"] = tables.IntCol()
table_dict["type"] = tables.IntCol()
table_dict["name"] = tables.StringCol(itemsize=128)
table_dict["ExpTime"] = tables.FloatCol()
table = h5.createTable(h5path,"MCA_info",table_dict,"MCA info table")
atype = tables.IntAtom()
array = h5.createEArray(h5path,"MCAarray",atype,(0,nofchannels),
"MCA data of file %s" %(hstfilename),filters=filters)
#setup the buffer array for storing a single spectrum
data = numpy.zeros((nofchannels),numpy.int)
#loop over all histograms
for i in range(nofhists):
#read the header structure
data_buffer = struct.unpack(fmt_hist,hstfid.read(fmt_hist_size))
table.row["index"] = i
table.row["type"] = data_buffer[1]
table.row["name"] = (("".join(data_buffer[2:(2+128)])).replace(" ","")).strip()
DETTYPE = tables.StringCol(72)
NEXP = tables.IntCol(shape=(1,5))
CCDPARM = tables.FloatCol(shape=(1,5))
CHEM = tables.StringCol(72)
MORPH = tables.StringCol(72)
CCOLOR = tables.StringCol(72)
CSIZE = tables.StringCol(72)
DNSMET = tables.StringCol(72)
DARK = tables.StringCol(72)
AUTORNG = tables.FloatCol(shape=(1,5))
ZEROADJ = tables.FloatCol(shape=(1,4))
XTRANS = tables.FloatCol(shape=(1,3))
HKL_XY = tables.FloatCol(shape=(1,5))
AXES2 = tables.FloatCol(shape=(1,4))
ENDINGS2 = tables.FloatCol(shape=(1,4))
FILTER2 = tables.FloatCol(shape=(1,2))
def GetIntArray(string):
"""
extracts a list of integer values from a string and converts
it to a integer numpy array.
input arguments:
string .............. the string
return value:
ia .................. a list with integer values
"""
string = blank_remov.sub(' ',string.strip())
strlist = blank_split.findall(string)
for i in range(len(strlist)):
run_id = tables.IntCol()
event_id = tables.Int64Col()
timestamp = tables.Time32Col()
nanoseconds = tables.UInt32Col()
ext_timestamp = tables.UInt64Col()
energy = tables.FloatCol()
core_pos = tables.FloatCol(shape=2)
zenith = tables.FloatCol()
azimuth = tables.FloatCol()
Num_e = tables.FloatCol()
Num_mu = tables.FloatCol()
dens_e = tables.FloatCol(shape=4)
dens_mu = tables.FloatCol(shape=4)
P200 = tables.FloatCol()
T200 = tables.FloatCol()
class ReconstructedKascadeEvent(tables.IsDescription):
"""Store information about reconstructed events"""
# r, phi is core position
id = tables.UInt32Col()
station_id = tables.UInt8Col()
r = tables.Float32Col()
phi = tables.Float32Col()
alpha = tables.Float32Col()
t1 = tables.Float32Col()
t2 = tables.Float32Col()
t3 = tables.Float32Col()
MAXIMUM = tables.IntCol()
NONTIME = tables.IntCol()
NLATE = tables.IntCol()
FILENAM = tables.StringCol(72)
CREATED = tables.StringCol(72)
CUMULAT = tables.FloatCol()
ELAPSDR = tables.FloatCol()
ELAPSDA = tables.FloatCol()
OSCILLA = tables.IntCol()
NSTEPS = tables.IntCol()
RANGE = tables.FloatCol()
START = tables.FloatCol()
INCREME = tables.FloatCol()
NUMBER = tables.IntCol()
NFRAMES = tables.IntCol()
ANGLES = tables.FloatCol(shape=(1,4))
NOVER64 = tables.IntCol(shape=(1,3))
NPIXELB = tables.IntCol(shape=(1,2))
NROWS = tables.IntCol()
NCOLS = tables.IntCol()
WORDORD = tables.IntCol()
LONGORD = tables.IntCol()
TARGET = tables.StringCol(72)
SOURCEK = tables.FloatCol()
SOURCEM = tables.FloatCol()
FILTER = tables.StringCol(72)
CELL = tables.FloatCol(shape=(2,6))
MATRIX = tables.FloatCol(shape=(2,9))
LOWTEMP = tables.IntCol(shape=(1,3))
ZOOM = tables.FloatCol(shape=(1,3))
CENTER = tables.FloatCol(shape=(1,4))
DISTANC = tables.FloatCol(shape=(1,2)) #has to be observed
WORDORD = tables.IntCol()
LONGORD = tables.IntCol()
TARGET = tables.StringCol(72)
SOURCEK = tables.FloatCol()
SOURCEM = tables.FloatCol()
FILTER = tables.StringCol(72)
CELL = tables.FloatCol(shape=(2,6))
MATRIX = tables.FloatCol(shape=(2,9))
LOWTEMP = tables.IntCol(shape=(1,3))
ZOOM = tables.FloatCol(shape=(1,3))
CENTER = tables.FloatCol(shape=(1,4))
DISTANC = tables.FloatCol(shape=(1,2)) #has to be observed
TRAILER = tables.IntCol()
COMPRES = tables.StringCol(72)
LINEAR = tables.StringCol(72)
PHD = tables.FloatCol(shape=(1,2))
PREAMP = tables.FloatCol(shape=(1,2)) #has to be observed
CORRECT = tables.StringCol(72)
WARPFIL = tables.StringCol(72)
WAVELEN = tables.FloatCol(shape=(1,4))
MAXXY = tables.FloatCol(shape=(1,2))
AXIS = tables.IntCol()
ENDING = tables.FloatCol(shape=(1,4))
DETPAR = tables.FloatCol(shape=(2,6))
LUT = tables.StringCol(72)
DISPLIM = tables.FloatCol(shape=(1,2))
PROGRAM = tables.StringCol(72)
ROTATE = tables.IntCol()
BITMASK = tables.StringCol(72)
OCTMASK = tables.IntCol(shape=(2,8))
ESDCELL = tables.FloatCol(shape=(2,6))
DETTYPE = tables.StringCol(72)
event_id = tables.UInt64Col()
k_event_id = tables.UInt64Col()
timestamp = tables.Time32Col()
nanoseconds = tables.UInt32Col()
ext_timestamp = tables.UInt64Col()
pulseheights = tables.Int16Col(shape=4, dflt=-9999)
integrals = tables.Int32Col(shape=4, dflt=-9999)
n_peaks = tables.Int32Col(shape=4, dflt=-9999)
traces = tables.Int32Col(shape=4, dflt=-1)
k_timestamp = tables.Time32Col()
k_nanoseconds = tables.UInt32Col()
k_ext_timestamp = tables.UInt64Col()
k_energy = tables.FloatCol()
k_core_pos = tables.FloatCol(shape=2)
k_zenith = tables.FloatCol()
k_azimuth = tables.FloatCol()
k_Num_e = tables.FloatCol()
k_Num_mu = tables.FloatCol()
k_dens_e = tables.FloatCol(shape=4)
k_dens_mu = tables.FloatCol(shape=4)
k_P200 = tables.FloatCol()
k_T200 = tables.FloatCol()