Peano
Loading...
Searching...
No Matches
tarch.plotter.api.input.PatchFileParser.PatchFileParser Class Reference

Parser for Peano block file output. More...

Public Member Functions

 __init__ (self, file_path, set_identifier, subdomain_number, show_progress=False, patch_filter=None)
 show_progress: Boolean Print a single-line, in-place progress bar (percentage plus patch count) to the terminal while parse_file() works through this file's patches -
 __repr__ (self)
 parse_file (self)
 Read file and return cell data, dimensions, number of degrees of freedom and number of unknowns.
 render_or_validate_for_each_unknown (self, render_or_validate)
 We need to call the render function for each filter on a variety of attributes, and then return them if they are modified.

Data Fields

 file_path = file_path
 patch_filter = patch_filter
bool is_data_associated_to_cell = None
int dimensions = -1
str file_format = "ASCII"
str set_identifier = set_identifier
 subdomain_number = subdomain_number
bool parsed = False
bool file_contains_patches = False
 show_progress = show_progress
dict unknown_attributes = {}

Protected Attributes

dict _doubles_per_patch = {}

Private Member Functions

 __parse_meta_data_region (self, current_line, file_object, end_condition)
 Pass in file object, move it along and return it.
 __read_values (self, unknown_name, file_object)
 Read the quantities of one patch of one dataset.
 __skip_values_if_binary (self, current_line, file_object)
 If current_line opens the quantities of a dataset in a binary file, step over them.
 __record_doubles_per_patch (self, current_line, file_object, end_condition)
 Binary files only: Run through a metadata block of a dataset which we do not parse and remember how many doubles each of its patches holds, so we can step over them.
 __parse_patch_region (self, current_line, file_object, end_condition="end patch")
 Pass in file object, run it until we encounter the end condition, and then return it.
 __count_patches (self)
 Quick pre-scan (just a substring search per line, no numpy parsing) to count "begin patch" occurrences, i.e.
 __print_progress (self, current, total)
 Render current/total as an in-place, single-line percentage/bar on the terminal (\r-terminated, so nothing else may write to stdout while this runs -.

Detailed Description

Parser for Peano block file output.

This class should be instantiated from within the Visualiser class. This class should be called once per patch file that contains patch data that we want to render. The main method that is called is parse_file().

This method doesn't return anything. Rather, it sets unknown_attributes to capture all the patch data for each of the unknowns that we find.

Then, the Visualiser class will steal this data, and combine it into its own helper class.

Attributes:

file_path: String String of input file path (including filename and extension)

dimensions: Integer Dimension of domains

mapping: series of d-dimensional tuples Distorts the domain

set_identifier: String Can be empty to parse everything.

unknown_attributes: Dict{ String, UnknownAttributes } Dictionary that has the names of each unknown we wanna capture as its keys, and the values are the helper class which captures dimensions, cell data etc. Each of the unknowns should be listed during the metadata part of the patch file, ie between "begin cell-metadata" and "end cell-metadata".

Definition at line 208 of file PatchFileParser.py.

Constructor & Destructor Documentation

◆ __init__()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.__init__ ( self,
file_path,
set_identifier,
subdomain_number,
show_progress = False,
patch_filter = None )

show_progress: Boolean Print a single-line, in-place progress bar (percentage plus patch count) to the terminal while parse_file() works through this file's patches -

See also
__count_patches()/__print_progress(). Off by default: it writes \r-terminated lines, so it only produces clean output when nothing else concurrently writes to the same terminal - the caller (Visualiser.show_progress) is responsible for only turning this on when that is guaranteed (e.g. sequential, single-worker processing).

patch_filter: Callable (offset, size) -> Boolean, or None If set, parse_file() calls this predicate on each patch as soon as it has read the patch's offset and size, and skips the patch's values without converting them if the predicate returns False. This is way cheaper than parsing everything and throwing the data away afterwards, if a postprocessing script needs only a few patches (

See also
output.PointProbe). With multiple worker processes, the predicate has to be picklable, i.e. no lambda.

Definition at line 246 of file PatchFileParser.py.

Member Function Documentation

◆ __count_patches()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.__count_patches ( self)
private

Quick pre-scan (just a substring search per line, no numpy parsing) to count "begin patch" occurrences, i.e.

the number of cells/patches this file holds, so parse_file() can show progress against a known total instead of an estimate. Reads the file a second time, but that is negligible next to the actual parse below, which parses a numpy array per patch.

Definition at line 483 of file PatchFileParser.py.

References file_path.

Referenced by parse_file().

Here is the caller graph for this function:

◆ __parse_meta_data_region()

◆ __parse_patch_region()

◆ __print_progress()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.__print_progress ( self,
current,
total )
private

Render current/total as an in-place, single-line percentage/bar on the terminal (\r-terminated, so nothing else may write to stdout while this runs -.

See also
show_progress).

Definition at line 501 of file PatchFileParser.py.

Referenced by parse_file().

Here is the caller graph for this function:

◆ __read_values()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.__read_values ( self,
unknown_name,
file_object )
private

Read the quantities of one patch of one dataset.

The line "begin cell-values" or "begin vertex-values" has just been read.

Definition at line 358 of file PatchFileParser.py.

References _doubles_per_patch, and file_format.

Referenced by __parse_patch_region().

Here is the caller graph for this function:

◆ __record_doubles_per_patch()

◆ __repr__()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.__repr__ ( self)

Definition at line 299 of file PatchFileParser.py.

◆ __skip_values_if_binary()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.__skip_values_if_binary ( self,
current_line,
file_object )
private

If current_line opens the quantities of a dataset in a binary file, step over them.

Definition at line 369 of file PatchFileParser.py.

References _doubles_per_patch, and file_format.

Referenced by __parse_patch_region().

Here is the caller graph for this function:

◆ parse_file()

◆ render_or_validate_for_each_unknown()

tarch.plotter.api.input.PatchFileParser.PatchFileParser.render_or_validate_for_each_unknown ( self,
render_or_validate )

We need to call the render function for each filter on a variety of attributes, and then return them if they are modified.

We do this in a functional style, ie the Visualiser class contains all of the filters we wish to apply, and we pass the render function that we intend to use back to this layer. Ugly, but we need to do some looping over the different unknowns we see in the patch files, and I thought it best to hide that from the parse_snapshot region of the vis code.

The same apply for the validate function from the Visualiser file as well.

Definition at line 642 of file PatchFileParser.py.

References unknown_attributes.

Field Documentation

◆ _doubles_per_patch

dict tarch.plotter.api.input.PatchFileParser.PatchFileParser._doubles_per_patch = {}
protected

◆ dimensions

◆ file_contains_patches

bool tarch.plotter.api.input.PatchFileParser.PatchFileParser.file_contains_patches = False

Definition at line 289 of file PatchFileParser.py.

Referenced by __parse_patch_region().

◆ file_format

str tarch.plotter.api.input.PatchFileParser.PatchFileParser.file_format = "ASCII"

Definition at line 281 of file PatchFileParser.py.

Referenced by __read_values(), __skip_values_if_binary(), and parse_file().

◆ file_path

tarch.plotter.api.input.PatchFileParser.PatchFileParser.file_path = file_path

Definition at line 276 of file PatchFileParser.py.

Referenced by __count_patches(), and parse_file().

◆ is_data_associated_to_cell

bool tarch.plotter.api.input.PatchFileParser.PatchFileParser.is_data_associated_to_cell = None

Definition at line 278 of file PatchFileParser.py.

Referenced by __parse_meta_data_region(), __parse_patch_region(), and parse_file().

◆ parsed

bool tarch.plotter.api.input.PatchFileParser.PatchFileParser.parsed = False

Definition at line 288 of file PatchFileParser.py.

Referenced by parse_file().

◆ patch_filter

tarch.plotter.api.input.PatchFileParser.PatchFileParser.patch_filter = patch_filter

◆ set_identifier

str tarch.plotter.api.input.PatchFileParser.PatchFileParser.set_identifier = set_identifier

Definition at line 286 of file PatchFileParser.py.

Referenced by __parse_patch_region(), and parse_file().

◆ show_progress

tarch.plotter.api.input.PatchFileParser.PatchFileParser.show_progress = show_progress

◆ subdomain_number

tarch.plotter.api.input.PatchFileParser.PatchFileParser.subdomain_number = subdomain_number

Definition at line 287 of file PatchFileParser.py.

Referenced by __parse_patch_region().

◆ unknown_attributes

dict tarch.plotter.api.input.PatchFileParser.PatchFileParser.unknown_attributes = {}

The documentation for this class was generated from the following file: