array size mismatch when using seismology.estimate_numax()
See original GitHub issueProblem description
For some combinations of values for the keyword arguments window_width and spacing supplied to the acf2d function, estimate_numax() fails with an array size mismatch error. This seems to be because the preallocated array size for the output of utils.autocorrelate does not actually match the size of the array returned by it.
In particular, this seems to happen for red giants observed at short cadence. While I can get the acf2d method to work by masking out frequencies above an (artificial) maximum frequency, this seems like a more subtle issue: just because the code doesn’t break doesn’t mean it’s necessarily not otherwise faulty.
Example
import numpy as np
from astropy import units as u
import lightkurve as lk
def get_PG():
data = np.loadtxt("PSD_all.pow")
ν = data[..., 0] * u.uHz
P = u.Quantity(data[..., -1])
# m = ν.value < 500
m = slice(None, None)
return lk.Periodogram(ν[m], P[m])
pg = get_PG()
seis = pg.flatten().to_seismology()
seis.estimate_numax(window_width=25, spacing=1)
For the provided power spectrum (see here: PSD_all.zip), this fails with spacing < 1.49945671858…, which I don’t have a good explanation for:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-78-76ccb8c22ce8> in <module>
----> 1 seis.estimate_numax(window_width=25, spacing=1.499456718580)
~/.local/lib/python3.8/site-packages/lightkurve/seismology/core.py in estimate_numax(self, method, **kwargs)
544 if method == "acf2d":
545 from .numax_estimators import estimate_numax_acf2d
--> 546 result = estimate_numax_acf2d(self.periodogram, **kwargs)
547 self.numax = result
548 return result
~/.local/lib/python3.8/site-packages/lightkurve/seismology/numax_estimators.py in estimate_numax_acf2d(periodogram, numaxs, window_width, spacing)
150 for idx, numax in enumerate(numaxs):
151 acf = utils.autocorrelate(periodogram, numax, window_width=window_width, frequency_spacing=fs) #Return the acf at this numax
--> 152 acf2d[:, idx] = acf #Store the 2D acf
153 metric[idx] = (np.sum(np.abs(acf)) - 1 ) / len(acf) #Store the max acf power normalised by the length
154
ValueError: could not broadcast input array from shape (554) into shape (584)
(the line numbers don’t match up because I added a bunch of print statements to see what’s going on)
Expected behavior
It should not return a ValueError.
Environment
- Linux (Arch)
- lightkurve version 1.11.1
- installed with pip
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
This seems a satisfactory resolution to me. Thanks for helping out!
A solution was merged in #780.
Thank you @darthoctopus for opening the issue, and thank you @ojhall94 for fixing!! 👍 👍