XlookParser¶
-
class
pylook.io.
XlookParser
¶ Xlook R File Parser.
Initialize the parser with 32 empty columns to match the Look data model.
Methods Summary
__init__
()Initialize the parser with 32 empty columns to match the Look data model.
command_begin
(command)Process the begin command.
command_com_file
(command)Process the com_file command.
command_comment
(command)Process a comment line.
command_ec
(command)Perform a linear elastic correction of a column.
command_invalid
(command)Process an invalid command.
command_math
(command)Perform math operations with columns of data.
command_math_int
(command)Perform a math operation on an interval of a column.
command_offset_int
(command)Perform an offset over an interval in the data.
command_power
(command)Compute a column raised to a power.
command_r_col
(command)Remove a given column by setting it to empty and the name/units to None.
command_r_row
(command)Remove a range of rows from all columns of data.
command_read
(command[, …])Read a binary file in for processing.
command_summation
(command)Compute the cumulative sum of a column.
command_zero
(command)Zero a column at a record.
doit
(rfile[, endianness])Run an r-file - naming directly from XLook itself for ease of learning for new users.
get_data_dict
([data_units, ignore_unknown_units])Format the data into a dictionary of quantity arrays.
parse_line
(line)Parse the text in an xlook command and execute the appropriate function.
Methods Documentation
-
__init__
()¶ Initialize the parser with 32 empty columns to match the Look data model.
-
command_begin
(command)¶ Process the begin command.
- Parameters
command (str) – command from r file
Notes
The begin command, while essential in XLook is simply ignored here. It denoted the start of the file.
-
command_com_file
(command)¶ Process the com_file command.
- Parameters
command (str) – command from r file
Notes
The command com_file is ignored here, but indicated that this was a command file to XLook.
-
command_comment
(command)¶ Process a comment line.
- Parameters
command (str) – command from r file
Notes
In XLook, comments are simply ignored, but this function is provided should we find the need to log, or otherwise process them (potentially even for metadata extraction).
-
command_ec
(command)¶ Perform a linear elastic correction of a column.
- Parameters
command (str) – command from r file
Notes
This is not unit safe like the pure Python version would be as we’re shedding units all around in the interpreter. The XLook command was ec displacement_column_number load_column_number new_column_number first_row_index last_row_index
-
command_invalid
(command)¶ Process an invalid command.
- Parameters
command (str) – command from r file
Notes
Issue a warning for invalid commands, but we keep going just like XLook did. Xlook printed a console message, but they were mostly ignored by users, the warning should at least grab attention.
-
command_math
(command)¶ Perform math operations with columns of data.
- Parameters
command (str) – command from r file
Notes
The XLook command is math x_col_number operator y_col_number type new_col_number where the operator can be *, /, +, or -. Type indicates if the operation is between two columns (element-wise calculation) if : or if the operation is between a column and a scalar if =.
-
command_math_int
(command)¶ Perform a math operation on an interval of a column.
- Parameters
command (str) – command from r file
Notes
The Xlook command is math_int x_col_number operator y_col_number type new_col_number first_row_index last_row_index`
-
command_offset_int
(command)¶ Perform an offset over an interval in the data.
- Parameters
command (str) – command from r file
Notes
The Xlook command is offset_int column_number record_start_index record_end_index (y or n) to offset in between during the offset.
-
command_power
(command)¶ Compute a column raised to a power.
- Parameters
command (str) – command from r file
Notes
The Xlook command is power power_value column_number new_column_number
-
command_r_col
(command)¶ Remove a given column by setting it to empty and the name/units to None.
- Parameters
command (str) – command from r file
Notes
The Xlook command is r_col column_number
-
command_r_row
(command)¶ Remove a range of rows from all columns of data.
- Parameters
command (str) – command from r file
Notes
The Xlook command is r_row column_number first_row_index last_row_index.
-
command_read
(command, path_relative_to_r_file=True, endianness=None)¶ Read a binary file in for processing.
- Parameters
command (str) – command from r file
path_relative_to_r_file (boolean) – Determines if the path to be read is relative to the r file as xlook did or if it is relative to the calling Python code. Default True.
Notes
The Xlook command is read filename
-
command_summation
(command)¶ Compute the cumulative sum of a column.
- Parameters
command (str) – command from r file
Notes
The XLook command is summation column_number new_column_number
-
command_zero
(command)¶ Zero a column at a record.
- Parameters
command (str) – command from r file
Notes
The Xlook command is zero column_number record_index.
See also
-
doit
(rfile, endianness=None)¶ Run an r-file - naming directly from XLook itself for ease of learning for new users.
- Parameters
rfile (str) – Path to r file to run
endianness (str) – None, little, or big. Defaults to None which lets the reader try to determine this, but can be forced if needed.
-
get_data_dict
(data_units=None, ignore_unknown_units=False)¶ Format the data into a dictionary of quantity arrays.
Create a data dict like the rest of pylook uses and attach user given units. If we get no user given units we try to parse what we have in Xlook and either error (default) or can assign unitless to everything that is unrecognized.
- Parameters
data_units (list) – List of quantities for each data column. Overwrites and units from the file metadata.
ignore_unknown_units (boolean) – If True any units from the file metadata that we cannot parse are set to dimensionless and a warning issued. If False (default) an error is raised.
- Returns
data (dict) – Dictionary of quantity arrays
-
parse_line
(line)¶ Parse the text in an xlook command and execute the appropriate function.
- Parameters
line (str) – Xlook command line to process
-