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.

Prototype: Adding support for reading CBV files

See original GitHub issue

Over in #672, work is well underway to add a CBVCorrector which would use Kepler/TESS Cotrending Basis Vector data to remove systematics from light curves.

A recent change in Lightkurve v2.x is the use of the astropy.timeseries.TimeSeries class as a container to hold light curve data. For consistency, it would be good to also use TimeSeries objects to store Cotrending Basis Vectors.

I am opening this issue to share a rough prototype of what this implementation could look like.

Prototype

from astropy.io import fits
from astropy.time import Time
from astropy.table import Table
from astropy.timeseries import TimeSeries

from lightkurve.correctors import DesignMatrix


class CotrendingBasisVectors(TimeSeries):
    """Container class for Kepler/TESS Cotrending Basis Vectors (CBVs).
    
    This is a special case of `TimeSeries` in which columns named `VECTOR_X`
    are used to denote cotrending basis vectors.  X is a positive integer
    starting from 1, consistent with the official Kepler/TESS data products.
    """
    def to_designmatrix(self, vectors=None, name="cbv"):
        """Returns a `DesignMatrix` containing the CBVs."""
        if vectors is None:
            vectors = list(range(1, cbv.meta['TFIELDS']-2))
        return DesignMatrix(self[[f"VECTOR_{idx}" for idx in vectors]].as_array(),
                            name=name)
        
    def plot(self):
        """TODO: A nice plotting function for CBVS."""
        pass
        

def read_cbv_file(filename, ext="CBV.single-scale.1.1"):
    """FITS file reader for official `CotrendingBasisVectors` files."""
    hdulist = fits.open(filename)

    # Read the columns and meta data
    tbl = Table.read(hdulist[ext], format="fits")
    tbl.meta.update(hdulist[0].header)
    tbl.meta.update(hdulist[ext].header)

    # TimeSeries-based objects require a dedicated time column
    t = Time(tbl['TIME'].data, format='btjd')
    tbl.remove_column('TIME')
    return CotrendingBasisVectors(time=t, data=tbl)

Example use:

# Reading a CBV file
url = "https://archive.stsci.edu/missions/tess/ffi/s0017/2019/279/1-1/tess2019279210107-s0017-1-1-0161-s_cbv.fits"
cbv = read_cbv_file(url)

# Accessing meta data
print(cbv.meta['TELESCOP'])
print(cbv.meta['CAMERA'])

# Accessing a single vector
cbv['VECTOR_1'].data

# Convert the CBVs into a `DesignMatrix` object
dm = cbv.to_designmatrix()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
barentsencommented, Aug 25, 2020

Yep, you can now do download(flux_column='sap_flux') to make this easier!

0reactions
barentsencommented, Oct 10, 2020

Closing this issue as it has been superseded by #826!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CBFlib Manual - IUCr
CBFlib (Crystallographic Binary File library) is a library of ANSI-C functions providing a simple mechanism for accessing Crystallographic Binary Files (CBF ...
Read more >
Prototyping with Python for Machine Vision Solutions
Python takes care of the management of resources such as memory or files and CVBpy supports this. This avoids the need to manually...
Read more >
Django Tutorial Part 6: Generic list and detail views
This tutorial extends our LocalLibrary website, adding list and detail pages for books and authors. Here we'll learn about generic class-based ...
Read more >
Creating custom components for ag-grid - /var/
An object editor through which you will be able to create cells that can be used to insert flat objects. For example, for...
Read more >
EBOOK - Dangerous Weapons - Sicilian - House Of Staunton
You can now add your own analysis to our e-books! ... With Chessbase Reader, go directly to the File menu and follow the...
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