Tuesday 15 June 2010

matplotlib - Extracting and plotting tabulated plaintext data using Python 3 -


The context in which I am referring to the purposes of clarity is an abstract of the example of that format:

After some other irrelevant data, many of these are tabulated blocks in the output file, one directly after the other, the header section is repeated every time. Up to eight sets of headings are readings, including a block. In the header, the organization of values ​​for the readings of the organization of quantities shows the value.

Given this, I need to remove the values ​​of some quantities given in the header, put them in a file with them, and the matplotlib plot volume vs. one set versus the other. For example, Eg_Tot vs. Time (PS).

I'm completely lost because it is okay to use Python or Maplibtb out of my experience, so any help is welcome.

This is not a complete answer, but you should start it.

  #! / Bin / env # Some functions that determine whether a line is a separator def / CSP (line): return (line CO ('-')> 80) # Some functions that parse "block" DRR parse_block (Lines for lines in: parsed_lines = [] in lines: matches = re.findall ('(\ S +)', line) parsed_lines.append (mail) return parsed_lines if __name__ == "__main__": # data Open with 'Data.txt', 'r') as FH: data = fh.read () # divide the data into the rows, then the rows in the "block" block and Split [=] block_lines = [] to line in data.splitlines (): if (is_sep (line)): block.append (block_lines) block_lines = [] other: block_lines.append (line) # This partition method is a Empt will form the first element of the "block" list, block it to block = block [1:] # block for block, but header block, block it in "parse_block" parsed_blocks = [] block [1: ]: Parsed_blocks For example, the last block of your data will be parsed:  
  

Code> [['1', '2.6814 E + 03', '3.3117E +02', '1.6616E +03', '-1.1814 A +02 ',' 1.8312E +03 ',' 3.5247E +03 ',' 2.5879E + 02 ',' -3.8350E +03 ',' 0.0000E + 00 '], [' 0.0 ',' 2.5785E + 04 ',' 6.8687 E +01 ',' -6.7273 E +04 ',' -7.6310E +3 ',' -1.8316E +03 ',' -5.7811E +04 ',' 0.0000E +00 ',' 0.0000 E + 00 ',' 0.0000E + 00 '], [4.9]', '1.3300E +04', '0.0000E + 00', '0.0000E + 00', '0.0000E + 00', '9.0000E + '01', '9.0000 E + 01', '9.0000E + 01', '0.0000E + 00', '1.1 911E + 02'], [], ['Rolling', '2.6814 A + 03' '3.3117 E +2', '1.6616E +03', '-1.1814E + 02', '1.8312E +03', '3.5247E +03', '2.5879E02', '-3.8350E +03' , '0.0000 E + 00'], ['Avg', '2.5785 E + 04', '6.8687E + 01', '-6.77273E +04', '-7.6310E +3', '-1.8316E +03 ',' -5.7811 E +04 ',' 0.0000 E + 00 ',' 0.0000E + 00 ',' 0.0000E + 00 '], [' 1.3300E + 04 ',' 0.0000E + 00 ',' 0.0000 E + 00 ',' 0.0000 E + 00 ',' 9.0000E + 01 ',' 9.0000E + 01 ',' 9.0000 E + 01 ',' 0.0000 E + 00 ',' 1.1 9 11E + 02 ']]

No comments:

Post a Comment