Created
September 3, 2019 21:24
-
-
Save pont-us/a71eae88a18d35407bef40b73f9c1ff5 to your computer and use it in GitHub Desktop.
Read and summarize data from Irmunmix output files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Read and summarize data from Irmunmix output files. | |
This script reads data from one or more Irmunmix output files and prints | |
summary statistics of the mean coercivities to the standard output. | |
Currently, it analyses all components from all specified files, and does | |
not allow the selection of a particular component from each file. | |
By Pontus Lurcock, 2019. Released into the public domain. | |
""" | |
import argparse | |
import re | |
import numpy as np | |
def main(): | |
parser = argparse.ArgumentParser(description="Analyse CLG data", | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
parser.add_argument("filenames", metavar="filename", type=str, nargs="+", | |
help="irmunmix output file") | |
args = parser.parse_args() | |
regex = re.compile(r"Rel Cont= *([0-9.]+) *Mean= *([0-9.]+) " | |
"*DP= *([0-9.]+)") | |
coercivities = [] | |
for filename in args.filenames: | |
with open(filename, "r") as fh: | |
lines = fh.readlines() | |
for line in lines: | |
match = re.search(regex, line) | |
if (match): | |
coercivities.append(10 ** float(match.group(2))) | |
print("N: {:d} Min: {:.2f} Max: {:.2f} Mean: {:.2f} SD: {:.2f}".\ | |
format(len(coercivities), min(coercivities), max(coercivities), | |
np.mean(coercivities), np.std(coercivities))) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment