Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: need at least one array to concatenate #225

Open
Haoxiang-Lin opened this issue Nov 15, 2022 · 0 comments
Open

ValueError: need at least one array to concatenate #225

Haoxiang-Lin opened this issue Nov 15, 2022 · 0 comments

Comments

@Haoxiang-Lin
Copy link

Hi,

I got this error message whenever the values of Eemin and Eemax
of naima.models.Synchrotron is too close (encountered in some
extreme parameter choices in GRB study). An example code to
reproduce this error is as below:

from naima.models import ExponentialCutoffBrokenPowerLaw, Synchrotron
import astropy.units as u
from astropy.constants import c, m_e

mec2 = (m_e * c**2).to(u.MeV)
Eemin = (1e6 * mec2).to(u.eV)
Eebrk = (1.005e6 * mec2).to(u.eV)
Eemax = (1.01e6 * mec2).to(u.eV)

electrons = ExponentialCutoffBrokenPowerLaw(
    amplitude=1 * 1/u.eV,
    e_0=Eemin,
    e_break=Eebrk,
    alpha_1=2,
    alpha_2=3,
    e_cutoff=Eemax,
    beta=2,
)

SYN = Synchrotron(
    electrons,
    B=0.1 * u.G,
    Eemax=Eemax,
    Eemin=Eemin,
    nEed=100,
)

SYN.flux(1*u.keV, distance=0 * u.cm)

I believe it arises from the zero length of the Lorentz factor sequence
in the source code:

log10gmin = np.log10(self.Eemin / mec2).value
log10gmax = np.log10(self.Eemax / mec2).value
return np.logspace(
            log10gmin, log10gmax, int(self.nEed * (log10gmax - log10gmin))
        )

For example, if Eemax = 1.01*Eemin, and by default nEed = 100, then
self.nEed * (log10gmax - log10gmin) = 100*log10(1.01) = 0.432, and
int(0.432) = 0, which creates the error.

While increasing nEed solves the problem, I wonder if it is better to
avoid this by restricting the length of sequence to be at least 2, e.g.

log10gmin = np.log10(self.Eemin / mec2).value
log10gmax = np.log10(self.Eemax / mec2).value
return np.logspace(
            log10gmin, log10gmax, max(2, int(self.nEed * (log10gmax - log10gmin)))
        )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant