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.

LightCurve objects store differently in numpy arrays following version 1.2

See original GitHub issue

Problem description

LightCurve objects explode into objects for each row in time/flux when being put into numpy arrays in version 1.2 and above. Before they would just be stored as one LightCurve object. Could this be to do with the changes implemented in #532?

Is there a way to modify my code so that I can store a LightCurve object in a numpy array in the same way as before v1.2? Or, is this a bug / unforeseen impact relating to recent changes to Lightkurve?

Example

import numpy as np
import lightkurve as lk

lc = lk.LightCurve(np.linspace(0, 1, 100), np.random.normal(1.0, 0.01, 100))
print(np.array([lc]))

This outputs:

[[<lightkurve.lightcurve.LightCurve object at 0x102cab490>
 <lightkurve.lightcurve.LightCurve object at 0x102cab690>
 <lightkurve.lightcurve.LightCurve object at 0x102cab890>
 ...
 <lightkurve.lightcurve.LightCurve object at 0x102cb9850>
 <lightkurve.lightcurve.LightCurve object at 0x102cb98d0>
 <lightkurve.lightcurve.LightCurve object at 0x102cb9950>]]

(ellipses added in as output is 100 lines long).

Expected behavior

Before version 1.2, this would just output the following:

[<lightkurve.lightcurve.LightCurve object at 0x7fda3f0b6470>]

Environment

  • platform: MacOS 10.15 and CentOS Linux 7
  • lightkurve version: 1.2 and 1.3
  • installation method: pip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
barentsencommented, Oct 31, 2019

Ha! That’s interesting! The behavior appears to have changed because we added the LightCurve.__len__ method in #532, which triggers np.array to treat a LightCurve as an iterable.

A work-around is to do the following:

ar = np.empty(1, dtype=object)
ar[0] = lc

@alexlyttle Would you be willing to provide a bit more background as to why you are interested in being able to have numpy arrays contain Lightcurve objects?

0reactions
barentsencommented, Nov 19, 2019

Thanks @alexlyttle! We appreciate your feedback!! 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stingray API — stingray v1.1.2.dev8+gdfd899c
A list or array of time stamps for a light curve. Must be a type that can be cast to :class:np.array or :class:List...
Read more >
NumPy: the absolute basics for beginners
Unlike the typical container objects, different arrays can share the same data, so changes made on one array might be visible in another....
Read more >
1.4.1. The NumPy array object
Python objects: ... extension package to Python for multi-dimensional arrays ... Different data-types allow us to store data more compactly in memory, ...
Read more >
Source code for lightkurve.lightcurve
`LightCurve` objects also provide user-friendly attribute access to ... None: raise AssertionError("data should be a numpy structured array") if "time" not ...
Read more >
4. NumPy Basics: Arrays and Vectorized Computation
Here are some of the things it provides: ndarray , a fast and space-efficient multidimensional array providing vectorized arithmetic operations and ...
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