ellawang44 / Breidablik

Interpolate lithium spectra and predict lithium abundance for late-type stars
MIT License
3 stars 0 forks source link

TypeError: float() argument must be a string or a number, not 'OrdinaryKriging3D' #1

Closed CognitiveQualia closed 2 years ago

CognitiveQualia commented 3 years ago

When executing this line of code in the first example:

abund, errs = models.find_abund(wl, flux, flux_err, t_eff, log_g, met)

I am met with this issue:

TypeError: float() argument must be a string or a number, not 'OrdinaryKriging3D'

I'm using Python 3.6. What might be the problem here?

ellawang44 commented 3 years ago

I'm not able to replicate this issue on Python 3.7.6 or Python 3.6.12.

Could you post the full error log please? Can I also get what version of PyKrige you have installed?

astahl7 commented 2 years ago

I am having the same issue. The full error:

/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/grid_check.py:18: UserWarning: Input stellar parameters are outside of the grid, results are extrapolated and may not be reliable. Stellar parameters inputted were: teff = 3504.00, surfg = 4.25, met = 0.00 warnings.warn('Input stellar parameters are outside of the grid, results are extrapolated and may not be reliable. Stellar parameters inputted were: teff = {0:.2f}, surfg = {1:.2f}, met = {2:.2f}'.format(eff_t, surf_g, met)) Traceback (most recent call last): File "breidablik_EW_Li_isochrones.py", line 114, in pred_flux = models.predict_flux(bteffs[i], g[i], 0., newabund) File "/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 305, in predict_flux return self._predict_flux(eff_t, surf_g, met, [abundance], user_call = True)[0] File "/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 323, in _predict_flux splines = self._create_cspline(eff_t, surf_g, met, cut = cut) File "/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 363, in _create_cspline splines.append(CubicSpline(abunds, spec)) File "/home/asa/.local/lib/python3.7/site-packages/scipy/interpolate/cubic.py", line 619, in init x, dx, y, axis, = prepare_input(x, y, axis) File "/home/asa/.local/lib/python3.7/site-packages/scipy/interpolate/_cubic.py", line 46, in prepare_input y = y.astype(dtype, copy=False) TypeError: float() argument must be a string or a number, not 'OrdinaryKriging3D'

Also -- it looks like your link to http://www.mso.anu.edu.au/~ellawang/ no longer works, so I was unable to run the demo with example.txt.

ellawang44 commented 2 years ago

It looks like a call to predict_flux under breidablik.interpolate.spectra went wrong, would you happen to know the inputs you used for predict_flux to cause this? I've tried a few different inputs and I can't replicate this. Looking at your error log it should be this line of code: pred_flux = models.predict_flux(bteffs[i], g[i], 0., newabund). It would be helpful to know what bteffs[i], g[i], and newabund is.

About the link to http://www.mso.anu.edu.au/~ellawang/ this is working for me simply clicking on it. There is however, no such file called example.txt and I can't find where I reference it. Did you mean example_spec.txt perhaps?

astahl7 commented 2 years ago

Huh - for some reason that link works for me now. Before the whole
thing would 404.

I also get the same error when running the example step 1 with
example_spec.txt:

from breidablik.interpolate.spectra import Spectra from breidablik.analysis import read pred_wl = read.get_wavelengths() models = Spectra() wl, flux, flux_err = np.loadtxt('example_spec.txt', unpack = True) abund, errs = models.find_abund(wl, flux, flux_err, 5777, 4.4, 0)

Gives

Traceback (most recent call last): File "breidablik_EW_Li_isochrones.py", line 102, in abund, errs = models.find_abund(wl, flux, flux_err, 5777, 4.4, 0) File
"/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 145, in
find_abund abundance, err = self._coarse_search(wavelength, flux, flux_err,
eff_t, surf_g, met, min_abund = min_abund, max_abund = max_abund,
accuracy = accuracy) File
"/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 183, in
_coarse_search probs = self._bayesian_inference(wavelength, flux, flux_err,
eff_t, surf_g, met, abunds) File
"/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 241, in
_bayesian_inference guess_fluxes = self._predict_flux(eff_t, surf_g, met, abunds) File
"/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 323, in
_predict_flux splines = self._create_cspline(eff_t, surf_g, met, cut = cut) File
"/home/asa/miniconda2/envs/lightkurve/lib/python3.7/site-packages/breidablik/interpolate/spectra.py", line 363, in
_create_cspline splines.append(CubicSpline(abunds, spec)) File
"/home/asa/.local/lib/python3.7/site-packages/scipy/interpolate/cubic.py",
line 619, in init x, dx, y, axis,
= prepare_input(x, y, axis) File
"/home/asa/.local/lib/python3.7/site-packages/scipy/interpolate/_cubic.py",
line 46, in prepare_input y = y.astype(dtype, copy=False) TypeError: float() argument must be a string or a number, not
'OrdinaryKriging3D'

The inputs should be totally uniform with the example...

Quoting Ella Xi Wang @.***>:

It looks like a call to predict_flux under
breidablik.interpolate.spectra went wrong, would you happen to
know the inputs you used for predict_flux to cause this? I've
tried a few different inputs and I can't replicate this.

About the link to http://www.mso.anu.edu.au/~ellawang/ this
is working for me simply clicking on it. There is however, no such
file called example.txt and I can't find where I ever reference
it. Did you mean example_spec.txt perhaps?

-- Reply to this email directly or view it on GitHub: https://github.com/ellawang44/Breidablik/issues/1#issuecomment-1013974386 You are receiving this because you commented.

Message ID: @.***>

ellawang44 commented 2 years ago

It's quite likely that you're running on an old version of the code. Did you install through pip by any chance? I think the code on pip may be old.

I've just updated the pip version of the code, which I think should fix your problems. The code version is now 0.6.5, you can check your version via pip show breidablik or in the setup.py file of the repository, depending on how you've installed the code.

I would recommend a reinstall of the package, if you're running pip: pip uninstall breidablik then pip install breidablik if you've installed through github: delete the repository, then git clone https://github.com/ellawang44/Breidablik, and follow the installation instructions again.

Do let me know if the problem persists, if that's the case then it could be package version issues.