Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import sys
import numpy
import tables
# The top level description of a sample table
class Particle(tables.IsDescription):
name = tables.StringCol(16, pos=1) # 16-character String
lati = tables.IntCol(pos=2) # integer
longi = tables.IntCol(pos=3) # integer
pressure = tables.Float32Col(pos=4) # float (single precision)
temperature = tables.FloatCol(pos=5) # double (double precision)
# Define a nested field using a IsDescription descendant
class Info(tables.IsDescription):
"""A substructure of ComplexObject.
"""
name = tables.StringCol(16, pos=0)
value = tables.IntCol()
# Define a nested field using a dictionary
Coord = {
"x": tables.FloatCol(pos=0),
"y": tables.FloatCol(pos=1),
"z": tables.FloatCol(pos=2)}
import tables
# The top level description of a sample table
class Particle(tables.IsDescription):
name = tables.StringCol(16, pos=1) # 16-character String
lati = tables.IntCol(pos=2) # integer
longi = tables.IntCol(pos=3) # integer
pressure = tables.Float32Col(pos=4) # float (single precision)
temperature = tables.FloatCol(pos=5) # double (double precision)
# Define a nested field using a IsDescription descendant
class Info(tables.IsDescription):
"""A substructure of ComplexObject.
"""
name = tables.StringCol(16, pos=0)
value = tables.IntCol()
# Define a nested field using a dictionary
Coord = {
"x": tables.FloatCol(pos=0),
"y": tables.FloatCol(pos=1),
"z": tables.FloatCol(pos=2)}
# The top level description of another sample table
# Dictionaries have an advantage over IsDescription: they allow for
# fields with blanks in their names
ComplexObject = {
"ID": tables.StringCol(8, pos=0), # 8-character String
"long_ID": tables.StringCol(16, pos=1), # 16-character String
"position": tables.IntCol(shape=2, pos=2), # integer
"imag": tables.ComplexCol(16, pos=3), # complex (double precision)
"info": Info(),
HDRBLKS = tables.IntCol()
TYPE = tables.StringCol(72)
SITE = tables.StringCol(72)
MODEL = tables.StringCol(72)
USER = tables.StringCol(72)
SAMPLE = tables.StringCol(72)
SETNAME = tables.StringCol(72)
RUN = tables.IntCol()
SAMPNUM = tables.IntCol()
TITLE = tables.StringCol(72*8)
NCOUNTS = tables.IntCol(shape=(1,2))
NOVERFL = tables.IntCol(shape=(1,3))
MINIMUM = tables.IntCol()
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()
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)
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))
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
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)
def _prm_get_table_col(self, key, column, fullname):
''' Creates a pytables column instance.
The type of column depends on the type of parameter entry.
'''
try:
val = column[0]
## We do not want to loose int_
if type(val) is int:
return pt.IntCol()
if isinstance(val,str):
itemsize = int(self._prm_get_longest_stringsize(column))
return pt.StringCol(itemsize)
if isinstance(val, np.ndarray):
if np.issubdtype(val.dtype,np.str):
itemsize = int(self._prm_get_longest_stringsize(column))
return pt.StringCol(itemsize,shape=val.shape)
else:
return pt.Col.from_dtype(np.dtype((val.dtype,val.shape)))
else:
return pt.Col.from_dtype(np.dtype(type(val)))
except Exception:
self._logger.error('Failure in storing >>%s<< of Parameter/Result >>%s<<. Its type was >>%s<<.' % (key,fullname,str(type(val))))
raise
#in a string
blank_remov = re.compile(r"\s+") #removeing multiple blanks in a string
#table definition for a V11 header table
class V11_header_table(tables.IsDescription):
FNAME = tables.StringCol(100) #the frame number of the file belonging to this header
FORMAT = tables.IntCol()
VERSION = tables.IntCol()
HDRBLKS = tables.IntCol()
TYPE = tables.StringCol(72)
SITE = tables.StringCol(72)
MODEL = tables.StringCol(72)
USER = tables.StringCol(72)
SAMPLE = tables.StringCol(72)
SETNAME = tables.StringCol(72)
RUN = tables.IntCol()
SAMPNUM = tables.IntCol()
TITLE = tables.StringCol(72*8)
NCOUNTS = tables.IntCol(shape=(1,2))
NOVERFL = tables.IntCol(shape=(1,3))
MINIMUM = tables.IntCol()
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()
Booleans indicating which detectors participated in the
reconstruction.
"""
d1 = tables.BoolCol(pos=22)
d2 = tables.BoolCol(pos=23)
d3 = tables.BoolCol(pos=24)
d4 = tables.BoolCol(pos=25)
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()
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
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)
paramdescriptiondict['range']= pt.StringCol(pypetconstants.HDF5_STRCOL_MAX_ARRAY_LENGTH)
expectedrows=len(traj._explored_parameters)
if table_name == 'results_trajectory':
expectedrows=len(traj._results)
if table_name == 'derived_parameters_trajectory':
expectedrows=len(traj._derived_parameters)
if table_name in ['derived_parameters_trajectory','results_trajectory',
'derived_parameters_runs_summary', 'results_runs_summary',
'config', 'parameters', 'explored_parameters']:
if table_name.startswith('derived') or table_name.endswith('parameters'):
paramdescriptiondict['length']= pt.IntCol()
paramdescriptiondict['comment']= pt.StringCol(pypetconstants.HDF5_STRCOL_MAX_COMMENT_LENGTH)
if table_name.endswith('summary'):
paramdescriptiondict['number_of_items']= pt.IntCol(dflt=1)
paramdescriptiondict['example_item_run_name'] = \
pt.StringCol(len(pypetconstants.RUN_NAME)+pypetconstants.FORMAT_ZEROS+3,pos=2)
if table_name.startswith('derived_parameters_runs'):
try:
expectedrows = traj.f_get('config.hdf5.derived_parameters_per_run').f_get()
except AttributeError:
expectedrows = 0