afeinstein20 / stella

For characterizing flares with convolutional neural networks
https://adina.feinste.in/stella
MIT License
26 stars 18 forks source link

ufunc 'isnan' not supported #19

Closed khushlim closed 2 years ago

khushlim commented 2 years ago

Hi Adina, While running the code; [cnn.predict(modelname=ds.models[0], times=lc.time, fluxes=lc.flux, errs=lc.flux_err) single_pred = cnn.predictions[0]]

I get the following error;

TypeError Traceback (most recent call last) /tmp/ipykernel_1860/2162981148.py in ----> 1 cnn.predict(modelname=ds.models[0], 2 times=lc.time, 3 fluxes=lc.flux, 4 errs=lc.flux_err) 5 single_pred = cnn.predictions[0]

~/anaconda3/lib/python3.8/site-packages/stella-0.2.0rc2-py3.8.egg/stella/neural_network.py in predict(self, modelname, times, fluxes, errs, multi_models, injected) 541 err = errs[j] + 0.0 542 --> 543 q = ( (np.isnan(time) == False) & (np.isnan(lc) == False)) 544 time, lc, err = time[q], lc[q], err[q] 545

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I tried to fix it by removing nans from the lightcurve directly and changing the dtype, but get the same error each time. I am using the latest versions of numpy and scipy.

Thanks,

github-actions[bot] commented 2 years ago

Hi there! This is a test of github actions.

afeinstein20 commented 2 years ago

Hi @khushlim ! thanks for bringing this to my attention. Just a first question about what you're passing in -- What version of lightkurve are you using? Can you double check that you're passing in arrays, not lists, and also that there are no units attached to your arrays?

We'll get to the bottom of this! Thanks!

khushlim commented 2 years ago

Hi Adina, Thanks for getting back. I am using lightkurve v2.0. I am passing in the lightcurve (time, flux, flux_err) and using one of the models for prediction. I am following the steps in the Quickstart Tutorial. Is there anything else I have to pass in? May be I am missing out something. I am not changing the lightcurve, so I guess it has to be arrays, unless I change them.

Thank you.

afeinstein20 commented 2 years ago

Hi @khushlim , lightkurve>=2.0.0 has astropy.units attached to their time, flux, and flux_err arrays. Can you try passing in:

cnn.predict(modelname=ds.models[0], times=lc.time.value, fluxes=lc.flux.value, errs=lc.flux_err.value) single_pred = cnn.predictions[0]

instead and see if that works? Thanks!

khushlim commented 2 years ago

Hi Adina, yup that fixed the issue.

But I also changed line 539 in the neural_network.py file from time=times[j] + 0.0 to time=times[j].btjd + 0.0, and that worked too. Seems the error has something to do with the time values only, not the flux values. Thanks for taking time to resolve this issue. Cheers, Khushlim.