I am using lightkurve 2.0.2 library with Python 3.8.5 and astropy 4.2 for processing exoplanet transits. However when I want to bin light curve to fixed number of points, all values in light_curve.flux except first two are nan. What I am doing wrong?

The purpose of code bellow is to obtain transit of Kepler-10 a from light curve of Kepler-10.

import lightkurve as lk  # Import lighkurve package

tp = lk.search_targetpixelfile("Kepler-10", mission="Kepler", exptime="long", quarter=1).download()  # Download target pixel for Kepler-10
lc = tp.to_lightcurve().flatten().remove_outliers()  # Convert target pixel to light curve
fold = lc.fold(0.837)  # Fold light curve to period of Kepler-10 a (0.837 days)
bin = fold.bin(n_bins=101)  # Bin light curve, so it should contains only 101 points.

print(bin.flux)  # [0.99999749 0.99999977 nan nan nan nan nan nan nan ... nan nan nan nan]

lc and fold are valid light curves without NaN values. E. g. fold looks like this:

enter image description here

So if there is any problem, it should be on line with fold.bin. Also, this is not problem only for Kepler-10.

  • 1
    $\begingroup$ At any of those steps something might go wrong. You need to learn to debug your own code. For example, have you tried to bin data of which you know is not-NaN? Have you checked that the output of tp, lc, fold is reasonable? $\endgroup$ Mar 17, 2021 at 12:57
  • 1
    $\begingroup$ Ok, then just to be 100% sure you could do np.count_nonzero(~np.isnan(fold)), as NaNs might not be plotted (although depending on whether you are using jupyer, there should be an alarm if there are NaNs in the array). I guess after that, the next step would be to try and bin some simple, self-created values, see if that works, compare to the real thing. $\endgroup$ Mar 17, 2021 at 13:40
  • 1
    $\begingroup$ @Michal I would appreciate if you could elaborate a bit on what you code is suppose to do (aka commenting each line). Also: Would your code run just like that in my Python console? I mean, is the data included in the packages? I would be more motivated to help you debugging if I would be sure that I do not have to invest loads of time to get it running. Otherwise: It sounds to a very interesting question for me :-) $\endgroup$
    – B--rian
    Mar 17, 2021 at 14:04
  • 1
    $\begingroup$ @B--rian The code can run anywhere, just have Python and the lightkurve library. The data are downloaded from MAST archive using search_targetpixel function. $\endgroup$
    – Michal
    Mar 17, 2021 at 16:22
  • 1
    $\begingroup$ Also docs.lightkurve.org/reference/api/… suggests to me that you call that function with too few parameters. Or rather default time bin size is 0.5 days and your folded curve has a total length of 0.8 days, so only 2 bins can be filled with reasonable values when you request 101 bins. You assume an intelligence of the function it might not have $\endgroup$ Mar 17, 2021 at 16:40

1 Answer 1


Thanks to all for your help. Because of the planetmarker's comment I found out that it is also necessary to set the time_bin_size parameter. After upgrade to lightkurve 2.0.6, there is also parameter bins, which sets time_bin_size automatically.

bin = fold.bin(bins=101)  # bins instead of n_bins

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .