-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_features_by_file.py
38 lines (33 loc) · 1.18 KB
/
calculate_features_by_file.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
'''Calculate features for the grid using a file with task config.
Loads a JSON file with configurations of tasks to perform and pass to the
calculate_features script interface.
'''
import json
import rum
import rum.calculate
argparser = rum.defaultArgumentParser(__doc__)
argparser.add_argument('taskfile', help='task definition file')
argparser.add_argument('-o', '--overwrite', action='store_true',
help='overwrite existing attributes'
)
if __name__ == '__main__':
args = argparser.parse_args()
with open(args.taskfile) as infile:
taskconf = json.load(infile)
fcalc = rum.calculate.FeatureCalculator.fromArgs(args)
tableNames = []
for taskdef in taskconf['tasks']:
methdef = taskdef['method']
if not isinstance(methdef, list):
methdef = [methdef]
sourcedef = taskdef.get('source', None)
if not isinstance(sourcedef, list):
sourcedef = [sourcedef]
tableNames.append(fcalc.run(
table=taskdef['table'],
methods=methdef,
sourceFields=sourcedef,
caseField=taskdef.get('case', None),
overwrite=args.overwrite,
bannedNames=tableNames
))