This is not a Python-specific # problem, it is true for almost every fitting algorithm for # non-linear models. If these are too far away from the solution curve_fit() # will not be able to find a solution. They # are quite different to the known true values, but not *too* # different. ylabel ( 'Intensity (erg/s/cm$^2$/cm/Steradian)' ) # fit two blackbodies to the synthetic data def func ( wa, T1, T2 ): return blackbody_lam ( wa, T1 ) blackbody_lam ( wa, T2 ) # Note the initial guess values for T1 and T2 (p0 keyword below). plot ( wa, ydata, ls = 'steps-mid', lw = 2, label = 'Fake data' ) plt. plot ( wa, ytot, ':', lw = 2, label = 'T1 T2 \n (true model)' ) plt. randn ( len ( wa )) * sigma # plot the input model and synthetic data plt. seed ( 1 ) # make synthetic data with Gaussian errors sigma = np. y1 = blackbody_lam ( wa, T1 ) y2 = blackbody_lam ( wa, T2 ) ytot = y1 y2 np. exp ( h * c / ( lam * k * T )) - 1 )) wa = np. returns units of erg/s/cm^2/cm/Steradian """ from nstants import h, k, c lam = 1e-6 * lam # convert to metres return 2 * h * c ** 2 / ( lam ** 5 * ( np. From scipy.optimize import curve_fit import pylab as plt import numpy as np def blackbody_lam ( lam, T ): """ Blackbody as a function of wavelength (um) and temperature (K).
0 Comments
Leave a Reply. |