comparison generate_mfi/generateMFI.py @ 0:2f6dcda6e74e draft

Uploaded
author immport-devteam
date Mon, 27 Feb 2017 13:00:34 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2f6dcda6e74e
1 #!/usr/bin/env python
2 ######################################################################
3 # Copyright (c) 2016 Northrop Grumman.
4 # All rights reserved.
5 ######################################################################
6 from __future__ import print_function
7 import sys
8 from argparse import ArgumentParser
9 import pandas as pd
10 from scipy.stats import gmean
11
12
13 def generate_MFI(input_file_name, output_file_name, mfi_calc):
14 flock_df = pd.read_table(input_file_name)
15 if mfi_calc == "mfi":
16 MFIs = flock_df.groupby('Population').mean().round(decimals=2)
17 elif mfi_calc == "gmfi":
18 MFIs = flock_df.groupby('Population').agg(lambda x: gmean(list(x))).round(decimals=2)
19 else:
20 MFIs = flock_df.groupby('Population').median().round(decimals=2)
21
22 with open(output_file_name, "w") as outf:
23 MFIs.to_csv(outf, sep="\t", float_format='%.0f')
24 return
25
26
27 if __name__ == "__main__":
28 parser = ArgumentParser(
29 prog="removeColumns",
30 description="Generate MFI from Flow Result file.")
31
32 parser.add_argument(
33 '-i',
34 dest="input_file",
35 required=True,
36 help="File location for the Flow Result file.")
37
38 parser.add_argument(
39 '-M',
40 dest="mfi_calc",
41 required=True,
42 help="what to calculate for centroids.")
43
44 parser.add_argument(
45 '-o',
46 dest="output_file",
47 required=True,
48 help="File location for the MFI output file.")
49
50 args = parser.parse_args()
51 generate_MFI(args.input_file, args.output_file, args.mfi_calc)
52 sys.exit(0)