
Hi, I am trying to use odr. I was able to get my programme to run on my data, I can see the data using pprint. Now the newbie problem: How do I use the data? I want need to calculate stuff with it, I want to save it to a file. I was trying to figure out the odr.Output, but I failed. Could someone copy and paste a working example code, so that I can work with that and the help included in the help? Thanks a lot, Jack K.

Here's a routine to fit an exponential of the form sign*(A*e^{-t/tau} + offset) using scipy.optimize.odr. def fitExponentialODR(y, x0, t, sign, fitType, verbose, maxIterations): """ Fit exponential of form y = sign * (A*e^(-t/tau) + offset) using S.optimize.odr y: target array (must be rank 1) x0: initial guess of (A, tau, offset) t: array sign: +/-1 fitType: ODR_LSQ or ODR_EXP @returns (A, tau, offset, fit, sd_amp, sd_tau, sd_offset) """ assert(0<=fitType<=2) R = fitODR(exponentialDecay, t, y, x0, fitType, verbose, maxIterations, sign) if(R==None): return None else: (output, fit) = R A = output.beta[0] tau = output.beta[1] offset = output.beta[2] sd_amp = output.sd_beta[0] sd_tau = output.sd_beta[1] sd_offset = output.sd_beta[2] return (A, tau, offset, fit, sd_amp, sd_tau, sd_offset) def fitODR(fn, x, y, x0, fitType, verbose, maxIterations, *args): """ fn function to fit x function input y target function output x0 initial parameters fitType One of ODR_LSQ (least squares) or ODR_EXP (explicit ODR) verbose If true, print verbose output on error. Else, fail silently (return None) maxIterations Maximum number of iterations without convergence. Re-run will use double @returns (odr.output, fit) """ assert(0 <= fitType <= 2) model = S.odr.Model(fn, extra_args=args) data = S.odr.Data(x, y) odr = S.odr.ODR(data, model, x0, maxit=maxIterations) odr.set_job(fit_type=fitType) output = odr.run() if(output.info >= 4): #no convergence or ODRPACK thinks results are "questionable" if(verbose): print 'ODRPACK unable to find solution:\n', '\n'.join(output.stopreason) print 'Retrying fit...' odr.maxit = 2*maxIterations output = odr.restart() if(output.info >= 4): if(verbose): print 'ODRPACK still unable to find solution: \n', '\n\t\t'.join(output.stopreason) return None return (output, fn(output.beta, x, *args)) On 9/5/07, J. K. <ryan2057@gmx.de> wrote:
Hi,
I am trying to use odr. I was able to get my programme to run on my data, I can see the data using pprint. Now the newbie problem: How do I use the data? I want need to calculate stuff with it, I want to save it to a file. I was trying to figure out the odr.Output, but I failed. Could someone copy and paste a working example code, so that I can work with that and the help included in the help?
Thanks a lot, Jack K.
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user

Thank you for your code example, I now understand how to grab the output. Jack K.

J. K. wrote:
Hi,
I am trying to use odr. I was able to get my programme to run on my data, I can see the data using pprint. Now the newbie problem: How do I use the data? I want need to calculate stuff with it, I want to save it to a file. I was trying to figure out the odr.Output, but I failed. Could someone copy and paste a working example code, so that I can work with that and the help included in the help?
I don't know how to make the Output docstring any clearer than it is. And without knowing what you want to "use the data" for, I can't give you a meaningful example. Can you be more specific about what is confusing? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

I don't know how to make the Output docstring any clearer than it is. And without knowing what you want to "use the data" for, I can't give you a meaningful example. Can you be more specific about what is confusing?
I think it is a combination of me being new to python and the fact that english is not my mother tongue. While I understand everyday english (movies, books, newspapers), technical english is much harder to understand. That's why examples in the man pages help me most. I learned how to input data into odr by using the short example given. Maybe you could expand the example in the "basic use" section a bit: mybeta = myoutput.beta[1] I know, my problem is pretty basic, but I studied chemistry and I am just now getting acquainted to Python. (I need to process a large number of files and fit a polynom to it) Jack K. PS: I am pretty amazed that the developer of the module answers question and helps end users in a newsgroup. That's one of the major reasons I love Open Source. Thank you.
participants (3)
-
Barry Wark
-
J. K.
-
Robert Kern