pdatafile¶
Combined datafile and parameterfile
All lines before the header line (starting with
#!
) that begin with#\
are interpreted as parameter file dataif these are present a parameterfile object is created : pf.par (pf is the name of the pdatafile object) if nothing was present the value of pf.par is None
Example data:
#\ my_var = 5.0
#\ my_other_var = 10.0
#
# just a regular comment
#
# the data start below
#! p_miss[0]/ siglt[2]/ s01[3]/ alt[4]/
200. 1.35e-4 -1.e-3 0.1
220. 2.56e-4 -2.e-4 -0.1
230. 3.47e-6 -3.e-5 1.1
Opening this file as following
>>> from LT.pdatafile import pdfile
>>> pp = pdfile('my_file.data')
To get the raw (string) values
>>> pp.par.get_data('my_var')
To see all variables and their values
>>> pp.par.show_all_data()
To convert the value to e.g. a float or a bool
>>> x = pp.par.get_value('my_var')
To convert to an int:
>>> i = pp.par.get_value('my_var', var_type = int)
>>> j = pp.par.get_value('my_var', var_type = int)
In general pp.par is a pfile
object attached to a
dfile
.
- class LT.pdatafile.pdfile(filename, debug=False, **kwargs)¶
open a pdata file an scan the contents for for a format that can be interpreted
example:
>>> pp=pdfile('my_datafile')
- add_parameter(name, value)¶
add a parameter to the file, it will be saved into a new file with write_all(file_o, complete_header = True)
- set_parameter(name, value)¶
set a parameters value in the header so that it is saved when the file is saved with full header
name: variable name value: the value to be stored this MUST be a string