r113494 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113493‎ | r113494 | r113495 >
Date:18:29, 9 March 2012
Author:giovanni
Status:new
Tags:
Comment:
added signal-to-noise ratio filtering to fitting
Modified paths:
  • /trunk/tools/wsor/editor_lifecycle/scripts/fitting (modified) (history)

Diff [purge]

Index: trunk/tools/wsor/editor_lifecycle/scripts/fitting
@@ -53,6 +53,8 @@
5454 parent.add_argument('-minsize', type=int)
5555 parent.add_argument('-c', '--chop-tail', type=int, default=0, metavar='NUM',
5656 help='remove %(metavar)s tail observations')
 57+parent.add_argument('-xmax', type=int, help='show only (0,xmax) interval')
 58+parent.add_argument('-snr', type=float, help='minimum signal-to-noise ratio')
5759
5860 parser = ArgumentParser(description=__doc__)
5961 subparsers = parser.add_subparsers(help='Parametric models supported')
@@ -80,13 +82,16 @@
8183 yy = model(xx)
8284 kwargs['ecolor'] = 'none'
8385 kwargs['ls'] = 'none'
84 - pp.errorbar(x, y, ye / 2, label=label, **kwargs)
 86+ kwargs['mfc'] = kwargs.get('color', 'k')
 87+ kwargs['ms'] = 4
 88+ pp.errorbar(x, y, ye, label=label, **kwargs)
 89+# pp.plot(x, y, label=label, **kwargs)
8590 model_label = model.name.split()
8691 if len(model_label) > 1:
8792 model_label[1] = model_label[1][:3] + '.'
8893 model_label = ' '.join(model_label[:2]).capitalize()
8994 c = kwargs.get('color', 'r')
90 - pp.plot(xx, yy, '--', color=c, label='{} fit'.format(model_label), lw=2.5)
 95+ pp.plot(xx, yy, '--', color=c, lw=2)
9196 if ns.loglog:
9297 pp.xscale('log')
9398 pp.yscale('log')
@@ -105,6 +110,8 @@
106111 # r /= np.abs(rm)
107112 pp.axhline(y=0, c='k')
108113 kwargs['ls'] = ':'
 114+ kwargs['lw'] = 2
 115+ kwargs['ms'] = 4
109116 pp.plot(x, r, label=label, **kwargs)
110117 pp.title('Fit residuals')
111118 pp.xlabel('Days since registration')
@@ -143,13 +150,17 @@
144151 * both : A = y[0] and C = y[-1]
145152 '''
146153 x, y, ye, n = np.loadtxt(data_file, unpack=True)
147 - x = x[:-ns.chop_tail]
148 - y = y[:-ns.chop_tail]
149 - ye = ye[:-ns.chop_tail]
150 - n = n[:-ns.chop_tail]
151 - idx = ye > 0
152 - if minsize:
153 - idx = idx * (n > minsize)
 154+ # XXX using the S/N ratio to filter out noisy estimates of the ratio
 155+ s = ye / np.sqrt(n)
 156+ snr = y / s
 157+ idx = snr >= ns.snr
 158+# x = x[:-ns.chop_tail]
 159+# y = y[:-ns.chop_tail]
 160+# ye = ye[:-ns.chop_tail]
 161+# n = n[:-ns.chop_tail]
 162+ idx = idx * (ye > 0)
 163+# if minsize:
 164+# idx = idx * (n > minsize)
154165 if not np.any(idx):
155166 raise EmptyDataError()
156167 if np.sum(idx) < len(modelclass.__params__):
@@ -157,6 +168,11 @@
158169 x = x[idx]
159170 y = y[idx]
160171 ye = ye[idx]
 172+ n = n[idx]
 173+ # XXX <Sat Oct 29 17:30:38 CEST 2011> getting the standard error of the
 174+ # mean. This should be really computed in in lifecycle.rates and new data
 175+ # files be produced using mkrates.
 176+ ye = ye / np.sqrt(n)
161177 model = modelclass()
162178 if constrain in ['head', 'both']:
163179 model.A = y[np.argmin(np.abs(x))]
@@ -177,11 +193,14 @@
178194
179195 def main(ns):
180196 # import matploblib
181 - from matplotlib.lines import lineMarkers as markers
182 - markers = dict(filter(
183 - lambda k : isinstance(k[0],str) and k[1] is not '_draw_nothing',
184 - markers.items())).keys()
185 - colors = 'bgcmykw'
 197+# from matplotlib.lines import lineMarkers as markers
 198+# markers = dict(filter(
 199+# lambda k : isinstance(k[0],str) and k[1] is not '_draw_nothing',
 200+# markers.items())).keys()
 201+# markers.remove('.')
 202+# markers.remove(',')
 203+ markers = 'oD^vs*hHpdv<>'
 204+ colors = 'brgkcmyw'
186205
187206 data = []
188207 models = []
@@ -199,7 +218,8 @@
200219 continue
201220 data.append((x,y,ye))
202221 models.append(model)
203 - labels.append(os.path.splitext(f)[0])
 222+ lab = os.path.splitext(os.path.basename(f))[0]
 223+ labels.append(lab.replace('_','\\_'))
204224
205225 # plot fits
206226 pp.figure()
@@ -208,6 +228,8 @@
209229 m = markers[i % len(markers)]
210230 c = colors[i % len(colors)]
211231 plotfit(model, x, y, ye, label, marker=m, color=c)
 232+ if ns.xmax is not None:
 233+ pp.xlim(0, ns.xmax)
212234
213235 # plot residuals
214236 pp.figure()
@@ -216,6 +238,8 @@
217239 m = markers[i % len(markers)]
218240 c = colors[i % len(colors)]
219241 plotresid(model, x, y, label, marker=m, color=c)
 242+ if ns.xmax is not None:
 243+ pp.xlim(0, ns.xmax)
220244
221245 # save figures
222246 if ns.output_file is not None:

Status & tagging log