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

binning plugin #28

Merged
merged 24 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
44e1e86
basic binning plugin
kecnry Jun 5, 2023
1d9013a
binning a phased-lc react to change in ephemeris
kecnry Jun 6, 2023
9ec8d3c
basic test coverage
kecnry Jun 6, 2023
8d0f400
WIP: fix binning in phase-space and support map_to_times
kecnry Jun 14, 2023
7b5e09b
fix loading phase-binned data into app
kecnry Jul 25, 2023
d6c7af4
remove "map_to_times" implementation
kecnry Jul 25, 2023
c4e5ea5
barebones plugin docs entries
kecnry Jul 25, 2023
fef4827
fix failing test
kecnry Jul 25, 2023
28467d6
data component filter for folded data
kecnry Jul 25, 2023
4d29db2
fix failing test on CI
kecnry Jul 27, 2023
5afc057
minor fixes for data-entries when changing ephemeris name
kecnry Jul 27, 2023
64e3e43
larger default marker size for data from binning plugin
kecnry Jul 31, 2023
11394d0
update live-preview behavior for jdaviz 3.6
kecnry Jul 31, 2023
7edc292
fix rebase for reference_time
kecnry Aug 21, 2023
356f4f9
Prototype fix for CID uniqueness (#1)
bmorris3 Sep 6, 2023
9ecbdb7
update binning plugin docs to point to lightkurve
kecnry Sep 6, 2023
7a20152
fix reference time of binned data
kecnry Sep 8, 2023
6db1332
remove unused import
kecnry Sep 8, 2023
ae04c79
fix broken test
kecnry Sep 8, 2023
289908d
fix preview disappearing after phase-binning
kecnry Sep 8, 2023
525e5fc
enable binning plugin API docs
kecnry Sep 8, 2023
9759589
add links from other plugin docs to their respective API
kecnry Sep 8, 2023
2c9bac7
add/fix user-API snippet for binning
kecnry Sep 8, 2023
3eac4bf
improve test coverage
kecnry Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This plugin allows viewing of any metadata associated with the selected data.
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.metadata_viewer.metadata_viewer.MetadataViewer` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand Down Expand Up @@ -44,6 +46,8 @@ This plugin gives access to per-viewer and per-layer plotting options.
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.plot_options.plot_options.PlotOptions` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand Down Expand Up @@ -97,6 +101,8 @@ visible when the plugin is opened.
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.markers.markers.Markers` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand Down Expand Up @@ -132,6 +138,8 @@ can be disabled through the plugin settings.
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.flatten.flatten.Flatten` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand Down Expand Up @@ -166,6 +174,8 @@ This plugin exposes the periodogram (in period or frequency space) for an input
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.frequency_analysis.frequency_analysis.FrequencyAnalysis` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand Down Expand Up @@ -194,7 +204,7 @@ This plugin exposes the periodogram (in period or frequency space) for an input
.. _ephemeris:

Ephemeris
============
==========

The ephemeris plugin allows for setting, finding, and refining the ephemeris or ephemerides used
for phase-folding.
Expand All @@ -203,6 +213,8 @@ for phase-folding.
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.ephemeris.ephemeris.Ephemeris` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand All @@ -218,6 +230,41 @@ for phase-folding.
ephem.rename_component('default', 'my component name')


.. _binning:

Binning
=======

This plugin supports binning a light curve in time or phase-space.


.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.binning.binning.Binning` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
lc = search_lightcurve("HAT-P-11", mission="Kepler",
cadence="long", quarter=10).download().flatten()
lcviz = LCviz()
lcviz.load_data(lc)
lcviz.show()

binning = lcviz.plugins['Binning']
binning.n_bins = 150
binned_lc = binning.bin(add_data=True)
print(binned_lc)


.. seealso::

This plugin uses the following ``lightkurve`` implementations:

* :meth:`lightkurve.LightCurve.bin`


.. _export-plot:

Export Plot
Expand All @@ -229,6 +276,8 @@ This plugin allows exporting the plot in a given viewer to various image formats
.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.export_plot.export_plot.ExportViewer` user API documentation for more details.

.. code-block:: python

from lcviz import LCviz
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/api_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Plugins API
===========

.. automodapi:: lcviz.plugins.binning.binning
:no-inheritance-diagram:

.. automodapi:: lcviz.plugins.ephemeris.ephemeris
:no-inheritance-diagram:

Expand Down
50 changes: 50 additions & 0 deletions lcviz/components/plugin_ephemeris_select.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<div>
<v-row v-if="items.length > 1 || show_if_single_entry">
<v-select
:menu-props="{ left: true }"
attach
:items="items"
v-model="selected"
@change="$emit('update:selected', $event)"
:label="label ? label : 'Ephemeris'"
:hint="hint ? hint : 'Select ephemeris.'"
:rules="rules ? rules : []"
item-text="label"
item-value="label"
persistent-hint
>
<template slot="selection" slot-scope="data">
<div class="single-line">
<span>
{{ data.item.label }}
</span>
</div>
</template>
<template slot="item" slot-scope="data">
<div class="single-line">
<span>
{{ data.item.label }}
</span>
</div>
</template>
</v-select>
</v-row>
</div>
</template>
<script>
module.exports = {
props: ['items', 'selected', 'label', 'hint', 'rules', 'show_if_single_entry']
};
</script>

<style>
.v-select__selections {
flex-wrap: nowrap !important;
}
.single-line {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
36 changes: 27 additions & 9 deletions lcviz/events.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
from glue.core.message import Message

__all__ = ['ViewerRenamedMessage']
__all__ = ['ViewerRenamedMessage', 'EphemerisComponentChangedMessage',
'EphemerisChangedMessage']


class ViewerRenamedMessage(Message):
"""Message emitted after a viewer is destroyed by the application."""
def __init__(self, old_viewer_ref, new_viewer_ref, *args, **kwargs):
super().__init__(*args, **kwargs)

self._old_viewer_ref = old_viewer_ref
self._new_viewer_ref = new_viewer_ref
self.old_viewer_ref = old_viewer_ref
self.new_viewer_ref = new_viewer_ref

@property
def old_viewer_ref(self):
return self._old_viewer_ref

@property
def new_viewer_ref(self):
return self._new_viewer_ref
class EphemerisComponentChangedMessage(Message):
"""Message emitted when an ephemeris component is added/renamed/removed in the
ephemeris plugin"""
def __init__(self, old_lbl, new_lbl, *args, **kwargs):
super().__init__(*args, **kwargs)

self.old_lbl = old_lbl
self.new_lbl = new_lbl
if old_lbl is not None and new_lbl is not None:
self.type = 'rename'
elif old_lbl is None and new_lbl is not None:
self.type = 'add'
elif old_lbl is not None and new_lbl is None:
self.type = 'remove'
else: # pragma: no cover
raise ValueError("must provide at least one of old_lbl or new_lbl")


class EphemerisChangedMessage(Message):
"""Message emitted when the parameters of an ephemeris are updated/changed
in the ephemeris plugin"""
def __init__(self, ephemeris_label, *args, **kwargs):
self.ephemeris_label = ephemeris_label
27 changes: 24 additions & 3 deletions lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

from lightkurve import LightCurve

from glue.core.component_id import ComponentID
from glue.core.link_helpers import LinkSame
from jdaviz.core.helpers import ConfigHelper
from lcviz.events import ViewerRenamedMessage

__all__ = ['LCviz']

custom_components = {'lcviz-editable-select': 'components/plugin_editable_select.vue'}

_default_time_viewer_reference_name = 'flux-vs-time'

custom_components = {'lcviz-editable-select': 'components/plugin_editable_select.vue',
'plugin-ephemeris-select': 'components/plugin_ephemeris_select.vue'}

# Register pure vue component. This allows us to do recursive component instantiation only in the
# vue component file
Expand Down Expand Up @@ -112,16 +117,18 @@ class LCviz(ConfigHelper):
'toolbar': ['g-data-tools', 'g-subset-tools', 'lcviz-coords-info'],
'tray': ['lcviz-metadata-viewer', 'lcviz-plot-options', 'lcviz-subset-plugin',
'lcviz-markers', 'flatten', 'frequency-analysis', 'ephemeris',
'lcviz-export-plot'],
'binning', 'lcviz-export-plot'],
'viewer_area': [{'container': 'col',
'children': [{'container': 'row',
'viewers': [{'name': 'flux-vs-time',
'plot': 'lcviz-time-viewer',
'reference': 'flux-vs-time'}]}]}]}

_component_ids = {}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._default_time_viewer_reference_name = 'flux-vs-time'
self._default_time_viewer_reference_name = _default_time_viewer_reference_name

# override jdaviz behavior to support temporal subsets
self.app._get_range_subset_bounds = (
Expand Down Expand Up @@ -187,3 +194,17 @@ def get_data(self, data_label=None, cls=LightCurve, subset=None):
Data is returned as type cls with subsets applied.
"""
return super()._get_data(data_label=data_label, mask_subset=subset, cls=cls)

def _phase_comp_lbl(self, component):
return f'phase:{component}'

def _set_data_component(self, data, component_label, values):
if component_label not in self._component_ids:
self._component_ids[component_label] = ComponentID(component_label)

if self._component_ids[component_label] in data.components:
data.update_components({self._component_ids[component_label]: values})
else:
data.add_component(values, self._component_ids[component_label])

data.add_component(values, self._component_ids[component_label])
8 changes: 7 additions & 1 deletion lcviz/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from jdaviz.core.marks import PluginLine, PluginScatter
from lcviz.viewers import PhaseScatterView

__all__ = ['LivePreviewTrend', 'LivePreviewFlattened']
__all__ = ['LivePreviewTrend', 'LivePreviewFlattened', 'LivePreviewBinning']


class WithoutPhaseSupport:
Expand Down Expand Up @@ -41,3 +41,9 @@ def __init__(self, viewer, *args, **kwargs):
self.viewer = viewer
kwargs.setdefault('default_size', 16)
super().__init__(viewer, *args, **kwargs)


class LivePreviewBinning(PluginScatter, WithPhaseSupport):
def __init__(self, *args, **kwargs):
kwargs.setdefault('default_size', 16)
super().__init__(*args, **kwargs)
1 change: 1 addition & 0 deletions lcviz/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .binning.binning import * # noqa
from .coords_info.coords_info import * # noqa
from .ephemeris.ephemeris import * # noqa
from .export_plot.export_plot import * # noqa
Expand Down
1 change: 1 addition & 0 deletions lcviz/plugins/binning/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .binning import * # noqa
Loading