-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_report_stuff
executable file
·109 lines (94 loc) · 4.14 KB
/
generate_report_stuff
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
'''Analyze a pism run / supply the tools necessary'''
from argparse import ArgumentParser
import flo_utils as fu
import os
import shutil
import process_config
#import netCDF4 as nc
#mport matplotlib.pyplot as mpl
#import sys
#from scipy import stats
#import seaborn as sns
#import numpy as np
#from smoother import smooth
#from datetime import datetime, timedelta
#import re
def get_output_dir(run, options):
if options.output_dir:
output_dir = options.output_dir
else:
output_dir = "/home/flo/UAF/pism-jif/Runs/Doku/%s/"%(run)
return output_dir
def run_plots(run, options, pism_config):
'''Generate the plots for the documentation'''
miscopts = []
output_dir = get_output_dir(run, options)
output_file = run + ".nc"
ts_runs = [run]
if options.TSA:
ts_runs=options.TSA + ts_runs
ts_files = ["%s/%s_ts.nc"%(x, x) for x in ts_runs ]
ivol_plotfile = "%s/%s_ivol.png"%(output_dir, run)
ivoltemp_plotfile = "%s/%s_ivoltemp.png"%(output_dir, run)
if len(ts_files) == 1:
miscopts.append( "--no_legend")
call = ["plot_ts", "-y", "ivol", "-o", ivol_plotfile, "--white_grid", "--xlabel", "year"] + ts_files + miscopts
print call
fu.qo(call)
call = ["plot_ts", "-y", "ivoltemp", "-o", ivoltemp_plotfile, "--no_legend", "--white_grid", "--xlabel", "year"] + ts_files + miscopts
print call
fu.qo(call)
if os.access(output_file, os.R_OK):
fu.qo(["plotit", "-v", "thk,csurf", output_file, "--overlay", "usurf"])
if "input" in pism_config["io"].keys():
fu.qo(["plotit", "-v", "thk", output_file, "--overlay", "usurf", "--sub", pism_config["io"]["input"], '--levels=-400,-200,-100,-50,50,100,200,400', '--colormap=RdBu' ])
movefiles = ["thk_%s.pdf"%(run), "csurf_%s.pdf"%(run)]
if options.reference:
print (["plotit", "-v", "thk,csurf", output_file, "--overlay", "usurf", "--sub", options.reference+".nc", '--levels=-400,-200,-100,-50,50,100,200,400', '--colormap=RdBu' ])
fu.qo(["plotit", "-v", "thk,csurf", output_file, "--overlay", "usurf", "--sub", options.reference+".nc", '--levels=-400,-200,-100,-50,50,100,200,400', '--colormap=RdBu' ])
movefiles = movefiles + ["thk_%s-%s.pdf"%(run, options.reference), "csurf_%s-%s.pdf"%(run,options.reference)]
for x in movefiles:
fu.rm_if_exist("%s/%s"%(output_dir, x))
shutil.move(x, output_dir)
def proc_conf(run, options):
output_dir = get_output_dir(run, options)
conf_opts = {}
conf_opts["config"] = "%s/%s.conf"%(run, run)
pism_config = process_config.read_config(conf_opts)
out_dict = process_config.process_config(pism_config)
tex_string = process_config.texprint(out_dict)
open(output_dir+"/config.tex","w").write(tex_string)
return out_dict
def parse_args():
'''Parses the command line arguments'''
parser = ArgumentParser()
parser.description = "Scatterplot two variables from a set of files"
parser.add_argument("RUNS", nargs='*')
parser.add_argument("-v", "--verbose",
help='''Be verbose''', action="store_true")
parser.add_argument("-o", "--output_dir",
help='''output directory to save images to''', default=None)
parser.add_argument("-r", "--reference",
help='''reference run''', default=None)
parser.add_argument("-a", "--TSA",
help='''Add time series for runs''', default=None)
parser.add_argument("--skip",
help='''skipping when reading''', default=1, type=int)
parser.add_argument("-t", "--title",
help='''plot title''', default=None)
options = parser.parse_args()
if options.verbose:
fu.debug=True
options.TSA=options.TSA.split(",")
return options
def main():
'''Analyze the run. Call all that's needed.'''
options = parse_args()
for run in options.RUNS:
output_dir = get_output_dir(run, options)
fu.mkdir(output_dir)
pism_config = proc_conf(run, options)
run_plots(run, options, pism_config)
if __name__ == "__main__":
main()