How to use the lightkurve.utils.LightkurveWarning function in lightkurve

To help you get started, we’ve selected a few lightkurve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KeplerGO / lightkurve / lightkurve / interact_bls.py View on Github external
of the form "localhost:8888", then "http" will be used.
    minimum_period : float or None
        Minimum period to assess the BLS to. If None, default value of 0.3 days
        will be used.
    maximum_period : float or None
        Maximum period to evaluate the BLS to. If None, the time coverage of the
        lightcurve / 4 will be used.
    resolution : int
        Number of points to use in the BLS panel. Lower this value to have a faster
        but less accurate compute time. You can also vary this value using the
        Resolution Slider.
    """
    try:
        import bokeh
        if bokeh.__version__[0] == '0':
            warnings.warn("interact_bls() requires Bokeh version 1.0 or later", LightkurveWarning)
    except ImportError:
        log.error("The interact_bls() tool requires the `bokeh` package; "
                  "you can install bokeh using e.g. `conda install bokeh`.")
        return None

    try:
        from astropy.timeseries import BoxLeastSquares
    except ImportError:
        try:
            from astropy.stats import BoxLeastSquares
        except ImportError:
            log.error("The `interact_bls()` tool requires AstroPy v3.1 or later.")

    def _create_interact_ui(doc, minp=minimum_period, maxp=maximum_period, resolution=resolution):
        """Create BLS interact user interface."""
        if minp is None:
github KeplerGO / lightkurve / lightkurve / seismology / core.py View on Github external
if smooth_filter_width:
            pgsmooth = self.periodogram.smooth(filter_width=smooth_filter_width)
            freq = pgsmooth.frequency  # Makes code below more readable below
            power = pgsmooth.power     # Makes code below more readable below
        else:
            freq = self.periodogram.frequency  # Makes code below more readable
            power = self.periodogram.power     # Makes code below more readable

        fmin = freq[0]
        fmax = freq[-1]

        # Check for any superfluous input
        if (numax is not None) & (any([a is not None for a in [minimum_frequency, maximum_frequency]])):
            warnings.warn("You have passed both a numax and a frequency limit. "
                          "The frequency limit will override the numax input.",
                          LightkurveWarning)

        # Ensure input numax is in the correct units (if there is one)
        if numax is not None:
            numax = u.Quantity(numax, freq.unit).value
            if numax > freq[-1].value:
                raise ValueError("You can't pass in a numax outside the"
                                "frequency range of the periodogram.")

            fwhm = utils.get_fwhm(self.periodogram, numax)

            fmin = numax - 2*fwhm
            if fmin < freq[0].value:
                fmin = freq[0].value

            fmax = numax + 2*fwhm
            if fmax > freq[-1].value:
github KeplerGO / lightkurve / lightkurve / correctors / designmatrix.py View on Github external
def _validate(self):
        """Raises a `LightkurveWarning` if the matrix has a low rank."""
        # Matrix rank shouldn't be significantly smaller than the # of columns
        if self.rank < (0.5*self.shape[1]):
            warnings.warn("The design matrix has low rank ({}) compared to the "
                          "number of columns ({}), which suggests that the "
                          "matrix contains duplicate or correlated columns. "
                          "This may prevent the regression from succeeding. "
                          "Consider reducing the dimensionality by calling the "
                          "`pca()` method.".format(self.rank, self.shape[1]),
                          LightkurveWarning)
github KeplerGO / lightkurve / lightkurve / search.py View on Github external
raise HTTPError('The TESS FFI cutout service at MAST appears '
                                    'to be temporarily unavailable. It returned '
                                    'the following error: {}'.format(exc))
                else:
                    raise SearchError('Unable to download FFI cutout. Desired target '
                                    'coordinates may be too near the edge of the FFI.'
                                    'Error: {}'.format(exc))

            return _open_downloaded_file(path,
                                         quality_bitmask=quality_bitmask,
                                         targetid=table[0]['targetid'])

        else:
            if cutout_size is not None:
                warnings.warn('`cutout_size` can only be specified for TESS '
                              'Full Frame Image cutouts.', LightkurveWarning)
            from astroquery.mast import Observations
            log.debug("Started downloading {}.".format(table[:1]['dataURL'][0]))
            path = Observations.download_products(table[:1], mrp_only=False,
                                                  download_dir=download_dir)['Local Path'][0]
            log.debug("Finished downloading.")
            # open() will determine filetype and return
            return _open_downloaded_file(path, quality_bitmask=quality_bitmask)
github KeplerGO / lightkurve / lightkurve / search.py View on Github external
-------
        collection : `~lightkurve.collections.Collection` object
            Returns a `~lightkurve.collections.LightCurveFileCollection` or
            `~lightkurve.collections.TargetPixelFileCollection`,
            containing all entries in the products table

        Raises
        ------
        HTTPError
            If the TESSCut service times out (i.e. returns HTTP status 504).
        SearchError
            If any other error occurs.
        """
        if len(self.table) == 0:
            warnings.warn("Cannot download from an empty search result.",
                          LightkurveWarning)
            return None
        log.debug("{} files will be downloaded.".format(len(self.table)))

        products = []
        for idx in range(len(self.table)):
            products.append(self._download_one(table=self.table[idx:idx+1],
                                               quality_bitmask=quality_bitmask,
                                               download_dir=download_dir,
                                               cutout_size=cutout_size))
        if isinstance(products[0], TargetPixelFile):
            return TargetPixelFileCollection(products)
        else:
            return LightCurveFileCollection(products)
github KeplerGO / lightkurve / lightkurve / seismology / core.py View on Github external
def __init__(self, periodogram):
        if not isinstance(periodogram, SNRPeriodogram):
            warnings.warn("Seismology received a periodogram which does not appear "
                          "to have been background-corrected. Please consider calling "
                          "`periodogram.flatten()` prior to extracting seismological parameters.",
                          LightkurveWarning)
        self.periodogram = periodogram
github KeplerGO / lightkurve / lightkurve / interact.py View on Github external
Location of the Jupyter notebook page (default: "localhost:8888")
        When showing Bokeh applications, the Bokeh server must be
        explicitly configured to allow connections originating from
        different URLs. This parameter defaults to the standard notebook
        host and port. If you are running on a different location, you
        will need to supply this value for the application to display
        properly. If no protocol is supplied in the URL, e.g. if it is
        of the form "localhost:8888", then "http" will be used.
    magnitude_limit : float
        A value to limit the results in based on Gaia Gmag. Default, 18.
    """
    try:
        import bokeh
        if bokeh.__version__[0] == '0':
            warnings.warn("interact_sky() requires Bokeh version 1.0 or later",
                          LightkurveWarning)
    except ImportError:
        log.error("The interact_sky() tool requires the `bokeh` Python package; "
                  "you can install bokeh using e.g. `conda install bokeh`.")
        return None

    # Try to identify the "fiducial frame", for which the TPF WCS is exact
    zp = (tpf.pos_corr1 == 0) & (tpf.pos_corr2 == 0)
    zp_loc, = np.where(zp)

    if len(zp_loc) == 1:
        fiducial_frame = zp_loc[0]
    else:
        fiducial_frame = 0

    def create_interact_ui(doc):
        # The data source includes metadata for hover-over tooltips
github KeplerGO / lightkurve / lightkurve / factory.py View on Github external
def _check_data(self):
        """Check the data before writing to a TPF for any obvious errors."""
        if len(self.time) != len(np.unique(self.time)):
            warnings.warn('The factory-created TPF contains cadences with '
                          'identical TIME values.', LightkurveWarning)
        if ~np.all(self.time == np.sort(self.time)):
            warnings.warn('Cadences in the factory-created TPF do not appear '
                          'to be sorted in chronological order.', LightkurveWarning)
        if np.sum(self.flux==self.flux) == 0:
            warnings.warn('The factory-created TPF does not appear to contain '
                          'non-zero flux values.', LightkurveWarning)
github KeplerGO / lightkurve / lightkurve / periodogram.py View on Github external
LightkurveWarning)
            minimum_period = kwargs.pop("min_period", None)
        if "max_period" in kwargs:
            warnings.warn("`max_period` keyword is deprecated, "
                          "please use `maximum_period` instead.",
                          LightkurveWarning)
            maximum_period = kwargs.pop("max_period", None)
        if "min_frequency" in kwargs:
            warnings.warn("`min_frequency` keyword is deprecated, "
                          "please use `minimum_frequency` instead.",
                          LightkurveWarning)
            minimum_frequency = kwargs.pop("min_frequency", None)
        if "max_frequency" in kwargs:
            warnings.warn("`max_frequency` keyword is deprecated, "
                          "please use `maximum_frequency` instead.",
                          LightkurveWarning)
            maximum_frequency = kwargs.pop("max_frequency", None)

        # Check if any values of period have been passed and set format accordingly
        if not all(b is None for b in [period, minimum_period, maximum_period]):
            default_view = 'period'
        else:
            default_view = 'frequency'

        # If period and frequency keywords have both been set, throw an error
        if (not all(b is None for b in [period, minimum_period, maximum_period])) & \
           (not all(b is None for b in [frequency, minimum_frequency, maximum_frequency])):
            raise ValueError('You have input keyword arguments for both frequency and period. '
                             'Please only use one.')

        if (~np.isfinite(lc.flux)).any():
            raise ValueError('Lightcurve contains NaN values. Use lc.remove_nans()'
github KeplerGO / lightkurve / lightkurve / factory.py View on Github external
def _check_data(self):
        """Check the data before writing to a TPF for any obvious errors."""
        if len(self.time) != len(np.unique(self.time)):
            warnings.warn('The factory-created TPF contains cadences with '
                          'identical TIME values.', LightkurveWarning)
        if ~np.all(self.time == np.sort(self.time)):
            warnings.warn('Cadences in the factory-created TPF do not appear '
                          'to be sorted in chronological order.', LightkurveWarning)
        if np.sum(self.flux==self.flux) == 0:
            warnings.warn('The factory-created TPF does not appear to contain '
                          'non-zero flux values.', LightkurveWarning)