question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

array size mismatch when using seismology.estimate_numax()

See original GitHub issue

Problem 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
darthoctopuscommented, Jul 16, 2020

This seems a satisfactory resolution to me. Thanks for helping out!

0reactions
barentsencommented, Jul 21, 2020

A solution was merged in #780.

Thank you @darthoctopus for opening the issue, and thank you @ojhall94 for fixing!! 👍 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Size mismatch error when trying to find a row in an array that ...
The array waypoints is just an array with two columns and any amount of rows. I'm trying to find the index at which...
Read more >
Array size mismatch - C - Stack Overflow
I'm writing a program in C to add random numbers to an array. The size of the array is given (say n =...
Read more >
Array argument size mismatch - CodeQL - GitHub
This rule looks for function calls where the size of the array being passed is smaller than the size of the declared array...
Read more >
Array-size dependency of the upper limit wavelength ...
In my analysis, I applied the standard SPAC method to the array data with r = 0.58 m and obtained phase velocities consistent...
Read more >
Wrapping SystemVerilog in VHDL: Size Mismatch for Array Ports
I am trying to wrap a SystemVerilog module in VHDL. The SystemVerilog module has ports which are 3-dimensional arrays. I created VHDL array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found