From: W. Trevor King Date: Sat, 9 Apr 2011 17:15:52 +0000 (-0400) Subject: Add --csv option to pysawsim.parameter_scan. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a70e2c35d65811279ca81f5d6de7a20da1729165;p=sawsim.git Add --csv option to pysawsim.parameter_scan. --- diff --git a/pysawsim/parameter_scan.py b/pysawsim/parameter_scan.py index 3d6e99b..439fd0b 100644 --- a/pysawsim/parameter_scan.py +++ b/pysawsim/parameter_scan.py @@ -260,7 +260,10 @@ class HistogramMatcher (object): log().debug('residual %s: %g' % (params, residual)) return residual - def plot(self, param_ranges, logx=False, logy=False, contour=False): + def plot(self, param_ranges, logx=False, logy=False, contour=False, + csv=None): + if csv: + csv.write(','.join(('param 1', 'param 2', 'fit quality')) + '\n') xranges = param_ranges[0] yranges = param_ranges[1] if logx == False: @@ -281,6 +284,8 @@ class HistogramMatcher (object): % (i, j, i*(len(y)-1) + j, (len(x)-1)*(len(y)-1))) params = (xi,yj) r = self.residual(params) + if csv: + csv.write(','.join([str(v) for v in (xi,yj,r)]) + '\n') C[j,i] = numpy.log(r) # better resolution in valleys if MEM_DEBUG == True: log().debug('RSS: %d KB' % rss()) @@ -412,12 +417,15 @@ def main(argv=None): parser.add_option('-c','--contour-plot', dest='contour_plot', help='Select contour plot (vs. the default pseudocolor plot).', default=False, action='store_true') + parser.add_option('--csv', dest='csv', metavar='FILE', + help='Save fit qualities to a comma-separated value file FILE.'), options,args = parser.parse_args(argv) initial_params = [float(p) for p in options.initial_params.split(",")] param_ranges = parse_param_ranges_string(options.param_range) histogram_file = args[0] + csv = None sr_call_params = sr.initialize_from_options(options) try: @@ -427,7 +435,11 @@ def main(argv=None): sawsim_runner=sr, residual_type=options.residual, plot=options.plot_residuals, **sr_call_params) #hm.fit(initial_params) + if options.csv: + csv = open(options.csv, 'w') hm.plot(param_ranges, logx=options.logx, logy=options.logy, - contour=options.contour_plot) + contour=options.contour_plot, csv=csv) finally: sr.teardown() + if csv: + csv.close()