mpylab.tools.dataparser module¶
This is mpylab.tools.dataparser.
Provides the class DataFile(Parser); used for dat files
- author:
Hans Georg Krauthäuser (main author)
- license:
GPLv3 or higher
- class mpylab.tools.dataparser.DatFile(**kw)
Bases:
ParserParse mpylab calibration and instrument data files.
- Parameters:
**kw (object) – Parser options accepted by
mpylab.tools.plyparser.Parser. Important options arefilenamefor a path or readable file-like object,SearchPathsfor locating relative filenames, anddebugfor PLY diagnostics.
Notes
Call
run()to obtain a dictionary mapping frequencies in hertz to SCUQ quantities in the declared data unit. The DAT grammar supports real values, real/imaginary pairs, magnitude/phase pairs, relative errors, and absolute errors. Syntax and conversion failures raiseDatFileSyntaxErrorwith source, line, and column information.Examples
Parse an in-memory S-parameter data block:
import io from mpylab.tools.dataparser import DatFile source = io.StringIO( "FUNIT: MHz\n" "UNIT: powerratio\n" "RELERROR: 0.01\n" "10 (0.9, 0.1)\n" ) values = DatFile(filename=source).run() s21_at_10_mhz = values[10e6]
- p_absval_ma(p)
absval : LSBRACE FPNUMBER COMMA FPNUMBER RSBRACE
- p_absval_number(p)
absval : FPNUMBER
- p_absval_ri(p)
absval : LBRACE FPNUMBER COMMA FPNUMBER RBRACE
- p_error(p)
p_error method.
- p_idanycase_id(p)
idanycase : ID | UNITSTRING
- p_line_abserr(p)
line : ABSERROR absval NEWLINE
- p_line_data1(p)
line : FPNUMBER val val val NEWLINE
- p_line_data2(p)
line : FPNUMBER val NEWLINE
- p_line_empty(p)
line : NEWLINE
- p_line_funit(p)
line : FUNIT idanycase NEWLINE
- p_line_relerr(p)
line : RELERROR FPNUMBER NEWLINE
- p_line_unit(p)
line : UNIT idanycase NEWLINE
- p_line_unit_with_target(p)
line : UNIT idanycase idanycase NEWLINE
- p_lines_line(p)
lines : line lines | line
- p_number_fpnumber(p)
number : FPNUMBER
- p_val_ma(p)
val : LSBRACE FPNUMBER COMMA FPNUMBER RSBRACE
- p_val_number(p)
val : number
- p_val_ri(p)
val : LBRACE FPNUMBER COMMA FPNUMBER RBRACE
- reserved = ('FUNIT', 'UNIT', 'RELERROR', 'ABSERROR')
- t_COMMA = ','
- t_FPNUMBER(t)
[+-]?[0-9]+(.[0-9]+)?([eE][+-]?[0-9]+)?
- t_FUNIT(t)
FUNIT:
- t_ID(t)
[a-zA-Z][a-zA-Z0-9/]*
- t_LBRACE = '\\('
- t_LSBRACE = '\\['
- t_NEWLINE(t)
[nr]
- t_RBRACE = '\\)'
- t_RSBRACE = '\\]'
- t_UNITSTRING(t)
“([^”\]|\.)*”
- t_error(t)
t_error method.
- t_ignore = ' \t:'
- t_ignore_COMMENT = '\\#.*'
- tokens = ('FUNIT', 'UNIT', 'RELERROR', 'ABSERROR', 'FPNUMBER', 'LBRACE', 'RBRACE', 'LSBRACE', 'RSBRACE', 'ID', 'UNITSTRING', 'COMMA', 'NEWLINE')
- exception mpylab.tools.dataparser.DatFileSyntaxError
Bases:
ValueErrorSyntax or lexical error in a calibration data file.