I have a code in which I need the solar radiance. To calculate it I use the Planck function, which I have defined as:
def planck_W(self, x, t):
return (2*self.h*self.c**2/x**5) / (np.exp(self.h*self.c / (self.k*x*t)) -1)
Where x
is the wavelength and t
is the temperature, and the output is the radiance value.
However I want to be able to use also values coming from a CSV
with different solar spectra, which already provides radiance values for different wavelengths. The sturcture of the CSV
is Name of the spectrum used, _xx (wavelength), _yy (radiance)
self.spectra_list= pd.read_csv('solar.csv',converters={'_xx': literal_eval, '_yy':literal_eval)
def planck_W(self):
self.spectra_list= pd.read_csv('solar.csv',converters={'_xx':literal_eval, '_yy':literal_eval)
return interp1d( np.array(self._xx)*1e-9,
np.array(self._yy),
kind='linear')
Later I need to use this curve for a calculation at a wavelength range given by another variable, it starts with:
n0 = simpson((planck_W(s.wavelength)...
and I get the error:
planck_W() takes 1 positional argument but 2 were given
I'm kinda new to programming and don't have much idea what I'm doing, how do I manage to make it take the CSV values?
CodePudding user response:
def planck_W(self):
This is the function signature which expects only self
. But, while calling the function s.wavelength
is supplied.
This causes the the error takes 1 positional argument but 2 were given
.
CodePudding user response:
self is not an argument but this is the place where the error happens. Self is provided automatically, by adding wavelength argument you specified second parameter.
If this is the case your function call should look like:
n0 = simpson(planck_W())
after all you're not using wavelength variable anywhere. Otherwise you have to add wavelength parameter like this:
def planck_W(self, wavelength):
and then use it inside the function
I hope this explains the situation