-
Notifications
You must be signed in to change notification settings - Fork 9
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
Flux Column plugin #77
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9b797c8
basic plugin to toggle actively selected flux column per-dataset
kecnry 1842c0d
basic test coverage
kecnry 39d861a
changelog entry
kecnry 861134a
fix typo in docs
kecnry 0bff08d
rework flatten plugin to use flux columns
kecnry 4a1795c
mention API breaking change in changelog
kecnry 070f663
API example in docs
kecnry 09c5b5a
update binning live-preview on change to flux-origin
kecnry 040c9cc
move to components.py
kecnry d7882a8
re-rename origin->column
kecnry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .components import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from astropy import units as u | ||
from ipyvuetify import VuetifyTemplate | ||
from glue.core import HubListener | ||
from traitlets import List, Unicode | ||
|
||
from jdaviz.core.template_mixin import SelectPluginComponent | ||
|
||
from lcviz.events import FluxOriginChangedMessage | ||
|
||
__all__ = ['FluxOriginSelect', 'FluxOriginSelectMixin'] | ||
|
||
|
||
class FluxOriginSelect(SelectPluginComponent): | ||
def __init__(self, plugin, items, selected, dataset): | ||
super().__init__(plugin, | ||
items=items, | ||
selected=selected, | ||
dataset=dataset) | ||
|
||
self.add_observe(selected, self._on_change_selected) | ||
self.add_observe(self.dataset._plugin_traitlets['selected'], | ||
self._on_change_dataset) | ||
|
||
# sync between instances in different plugins | ||
self.hub.subscribe(self, FluxOriginChangedMessage, | ||
handler=self._on_flux_origin_changed_msg) | ||
|
||
def _on_change_dataset(self, *args): | ||
def _include_col(lk_obj, col): | ||
if col == 'flux' and lk_obj.meta.get('FLUX_ORIGIN') != 'flux': | ||
# this is the currently active column (and should be copied elsewhere unless) | ||
return False | ||
if col in ('time', 'cadn', 'cadenceno', 'quality'): | ||
return False | ||
if col.startswith('phase:'): | ||
# internal jdaviz ephemeris phase columns | ||
return False | ||
if col.startswith('time'): | ||
return False | ||
if col.startswith('centroid'): | ||
return False | ||
if col.startswith('cbv'): | ||
# cotrending basis vector | ||
return False | ||
if col.endswith('_err'): | ||
return False | ||
if col.endswith('quality'): | ||
return False | ||
# TODO: need to think about flatten losing units in the flux column | ||
return lk_obj[col].unit != u.pix | ||
|
||
lk_obj = self.dataset.selected_obj | ||
if lk_obj is None: | ||
return | ||
self.choices = [col for col in lk_obj.columns if _include_col(lk_obj, col)] | ||
flux_origin = lk_obj.meta.get('FLUX_ORIGIN') | ||
if flux_origin in self.choices: | ||
self.selected = flux_origin | ||
else: | ||
self.selected = '' | ||
|
||
def _on_flux_origin_changed_msg(self, msg): | ||
if msg.dataset != self.dataset.selected: | ||
return | ||
|
||
# need to clear the cache due to the change in metadata made to the data-collection entry | ||
self.dataset._clear_cache('selected_obj', 'selected_dc_item') | ||
self._on_change_dataset() | ||
self.selected = msg.flux_origin | ||
|
||
def _on_change_selected(self, *args): | ||
if self.selected == '': | ||
return | ||
|
||
dc_item = self.dataset.selected_dc_item | ||
old_flux_origin = dc_item.meta.get('FLUX_ORIGIN') | ||
if self.selected == old_flux_origin: | ||
# nothing to do here! | ||
return | ||
|
||
# instead of using lightkurve's select_flux and having to reparse the data entry, we'll | ||
# manipulate the arrays in the data-collection directly, and modify FLUX_ORIGIN so that | ||
# exporting back to a lightkurve object works as expected | ||
self.app._jdaviz_helper._set_data_component(dc_item, 'flux', dc_item[self.selected]) | ||
self.app._jdaviz_helper._set_data_component(dc_item, 'flux_err', dc_item[self.selected+"_err"]) # noqa | ||
dc_item.meta['FLUX_ORIGIN'] = self.selected | ||
|
||
self.hub.broadcast(FluxOriginChangedMessage(dataset=self.dataset.selected, | ||
flux_origin=self.selected, | ||
sender=self)) | ||
|
||
def add_new_flux_column(self, flux, flux_err, label, selected=False): | ||
dc_item = self.dataset.selected_dc_item | ||
self.app._jdaviz_helper._set_data_component(dc_item, | ||
label, | ||
flux) | ||
self.app._jdaviz_helper._set_data_component(dc_item, | ||
f"{label}_err", | ||
flux_err) | ||
|
||
# broadcast so all instances update to get the new column and selection (if applicable) | ||
self.hub.broadcast(FluxOriginChangedMessage(dataset=self.dataset.selected, | ||
flux_origin=label if selected else self.selected, # noqa | ||
sender=self)) | ||
|
||
|
||
class FluxOriginSelectMixin(VuetifyTemplate, HubListener): | ||
flux_origin_items = List().tag(sync=True) | ||
flux_origin_selected = Unicode().tag(sync=True) | ||
# assumes DatasetSelectMixin is also used (DatasetSelectMixin must appear after in inheritance) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.flux_origin = FluxOriginSelect(self, | ||
'flux_origin_items', | ||
'flux_origin_selected', | ||
dataset='dataset') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know what you mean by
origin
but the term used throughout lightkurve iscolumn
. Is there a reason to introduce another term?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm I actually originally had column, but then changed it because its exposed as "FLUX_COLUMN" in the metadata and the string representation of the
LightCurve
object 🤔I guess this and this both use "column", but this tutorial shows how many times "origin" also appears.
Ultimately it's not too difficult to change (now or before this makes a release - significantly more difficult after a release)... so we can either decide which one we think is better or exposed more publicly or ask if they'd ever consider moving to be more self-consistent within lightkurve and go with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Personally, I'd reserve "origin" for the origin of the axis, which might be, e.g., zero or one, depending on units and normalization.