forked from GambitBSM/pippi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pippi_pare.py
51 lines (39 loc) · 1.57 KB
/
pippi_pare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#############################################################
# pippi: parse it, plot it
# ------------------------
# Post-processing module for pippi.
#
# Author: Pat Scott ([email protected])
# Originally developed: March 2012
#############################################################
from __future__ import print_function
from pippi_utils import *
from pippi_read import *
from importlib import import_module
import os
def pare(argstring):
# Make sure all the goods are present
if (len(argstring) != 3):
usage()
return
# Split the requested module into path and name, and
# add the requested directory to the interpreter's search path
[sys.path[0], argstring[1]] = os.path.split(argstring[1])
# Strip trailing .py (if any) on module name
argstring[1] = re.sub(r'\.py$', '', argstring[1])
try:
# Hit up the external module
pareMod = import_module(argstring[1])
except ImportError:
# or not
sys.exit('Error: cannot import module '+argstring[1]+'; it doesn\'t seem to exist.\nQuitting...\n')
try:
# Check that the function is actually good to go
pareFunc = getattr(pareMod, argstring[2])
except:
sys.exit('Error: module '+argstring[1]+' looks OK, but failed to load function '+argstring[2]+'.\nQuitting...\n')
# Open chain for paring
chainArray, column_names, lookup_key, all_best_fit_data = getChainData(argstring[0],silent=True)
# Pump it through the user-supplied function, printing each new point to stdout
for i in range(chainArray.shape[0]):
print('\t'.join([str(x) for x in pareFunc(chainArray[i,:])]))