Skip to content

Commit

Permalink
Merge branch 'main' into Fixes-for-Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
johnarban committed Jan 14, 2025
2 parents bc94919 + c3cfb54 commit c03eeea
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@
</v-btn>
<v-btn
class="demo-button"
color="error"
depressed
@click="() => {
set_dialog(false);
Expand Down
10 changes: 9 additions & 1 deletion src/hubbleds/components/dotplot_viewer/dotplot_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from glue.viewers.common.viewer import Viewer
from glue_plotly.viewers.common import PlotlyBaseView
from cosmicds.utils import vertical_line_mark, extend_tool
from hubbleds.utils import PLOTLY_MARGINS
from hubbleds.viewer_marker_colors import LIGHT_GENERIC_COLOR
from itertools import chain
from uuid import uuid4
from plotly.graph_objects import Scatter
Expand Down Expand Up @@ -53,7 +55,7 @@ def DotplotViewer(
height=300,
on_click_callback = None,
line_marker_at: Optional[Reactive | int | float] = None,
line_marker_color = 'red',
line_marker_color = LIGHT_GENERIC_COLOR,
vertical_line_visible: Union[Reactive[bool], bool] = True,
unit: Optional[str] = None,
x_label: Optional[str] = None,
Expand Down Expand Up @@ -261,6 +263,7 @@ def _update_lines(value = None):
dotplot_view.figure_widget.update_layout(height=None, width=None)
dotplot_view.figure_widget.update_layout(autosize=True, height=height)
dotplot_view.figure_widget.update_layout(
margin=PLOTLY_MARGINS,
showlegend=False,
hovermode="x",
spikedistance=-1,
Expand All @@ -272,6 +275,11 @@ def _update_lines(value = None):
spikesnap="cursor",
showspikes=True,
tickformat=",.0f",
titlefont_size=16,
),
yaxis=dict(
tickmode="auto",
titlefont_size=16,
),
)

Expand Down
6 changes: 4 additions & 2 deletions src/hubbleds/components/id_slider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import solara
from solara.alias import rv

from hubbleds.viewer_marker_colors import MY_DATA_COLOR, MY_CLASS_COLOR

# NB: I didn't use any of the built-in Solara sliders since none of them really fit our
# use case. Since we often have duplicate values, the only slider that would really work
# is SliderValue, but that doesn't allow all of the customization options that we need.
Expand All @@ -18,8 +20,8 @@ def IdSlider(gjapp,
id_component,
value_component,
on_id,
default_color="#3A86FF",
highlight_color="#FB5607",
default_color=MY_CLASS_COLOR,
highlight_color=MY_DATA_COLOR,
highlight_ids=None,
):

Expand Down
4 changes: 2 additions & 2 deletions src/hubbleds/components/line_draw_viewer/LineDrawPlot.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
export default {
name: "LineDrawPlot",
props: ["chart_id", "draw_active", "fit_active", "line_drawn", "line_fit", "plot_data", "x_axis_label", "y_axis_label", "height", "margins", "display_best_fit_gal", "best_fit_gal_layer_index", "clear_class_layer", "clear_drawn_line", "clear_fit_line"],
props: ["chart_id", "draw_active", "fit_active", "line_drawn", "line_fit", "plot_data", "x_axis_label", "y_axis_label", "height", "margins", "display_best_fit_gal", "best_fit_gal_layer_index", "clear_class_layer", "clear_drawn_line", "clear_fit_line", "bfg_color"],
async mounted() {
await window.plotlyPromise;
Expand Down Expand Up @@ -356,7 +356,7 @@ export default {
x: [Math.round(x_best_fit_galaxy)],
y: [Math.round(y_best_fit_galaxy)],
mode: "markers",
marker: { size: 14, color: "orange" },
marker: { size: 14, color: this.bfg_color },
visible: true,
hoverinfo: "skip"
};
Expand Down
3 changes: 3 additions & 0 deletions src/hubbleds/components/line_draw_viewer/line_draw_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import solara
from solara import Reactive
from typing import Callable, Optional, Dict
from hubbleds.viewer_marker_colors import GENERIC_COLOR


@solara.component_vue("LineDrawPlot.vue")
Expand All @@ -20,6 +21,7 @@ def LineDrawPlot(chart_id: str,
clear_class_layer: Optional[int]=False,
clear_drawn_line: Optional[int]=False,
clear_fit_line: Optional[int]=False,
bfg_color: Optional[str]=GENERIC_COLOR
):
pass

Expand Down Expand Up @@ -111,4 +113,5 @@ def _on_fit_clicked():
clear_class_layer=clear_class_layer,
clear_drawn_line = clear_drawn_line,
clear_fit_line = clear_fit_line,
bfg_color = GENERIC_COLOR
)
24 changes: 16 additions & 8 deletions src/hubbleds/components/selection_tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def SelectionTool(
galaxy_added_callback: Callable,
deselect_galaxy_callback: Callable,
selected_measurement: dict | None,
sdss_12_counter: solara.Reactive[int],
):
with rv.Card() as main:
with rv.Card(class_="pa-0 ma-0", elevation=0):
Expand All @@ -22,14 +23,16 @@ def SelectionTool(
def _add_widget():
selection_tool_widget = SelectionToolWidget(
table_layer_data={
k: [x.dict()[k] for x in LOCAL_STATE.value.galaxies]
for k in LOCAL_STATE.value.galaxies[0].dict()
k: [x.dict()[k] for x in LOCAL_STATE.value.galaxies.values()]
for k in ["id", "ra", "decl"]
}
)

tool_widget = solara.get_widget(tool_container)
tool_widget.children = (selection_tool_widget,)

sdss_12_counter.subscribe(lambda _count: selection_tool_widget.set_sdss_12())

def cleanup():
tool_widget.children = ()
selection_tool_widget.close()
Expand All @@ -38,16 +41,21 @@ def cleanup():

solara.use_effect(_add_widget, dependencies=[])

def _on_galaxy_selected(gal: dict):
data = LOCAL_STATE.value.galaxies[int(gal["id"])]
galaxy_added_callback(data)

def _on_current_galaxy_changed(change: dict):
gal = change["new"]
data = LOCAL_STATE.value.galaxies[int(gal["id"])]
galaxy_selected_callback(data)

def _setup_callbacks():
selection_tool_widget = solara.get_widget(tool_container).children[0]

selection_tool_widget.on_galaxy_selected = (
lambda gal: galaxy_added_callback(GalaxyData(**gal))
)
selection_tool_widget.on_galaxy_selected = _on_galaxy_selected
selection_tool_widget.observe(
lambda change: galaxy_selected_callback(
GalaxyData(**change["new"]) if len(change["new"]) > 0 else None
),
_on_current_galaxy_changed,
["current_galaxy"],
)
selection_tool_widget.deselect_galaxy = deselect_galaxy_callback
Expand Down
95 changes: 60 additions & 35 deletions src/hubbleds/components/spectrum_viewer/spectrum_viewer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Callable, Optional

import plotly.express as px
import plotly.graph_objects as go
import reacton.ipyvuetify as rv
import solara
from hubbleds.state import GalaxyData
from pandas import DataFrame
from hubbleds.components.spectrum_viewer.plotly_figure import FigurePlotly
from cosmicds.logger import setup_logger
from hubbleds.viewer_marker_colors import GENERIC_COLOR, H_ALPHA_COLOR, MY_DATA_COLOR, LIGHT_GENERIC_COLOR
from hubbleds.utils import PLOTLY_MARGINS

from glue_plotly.common import DEFAULT_FONT

Expand All @@ -30,6 +32,7 @@ def SpectrumViewer(
spectrum_bounds: Optional[solara.Reactive[list[float]]] = None,
on_spectrum_bounds_changed: Callable = lambda x: None,
max_spectrum_bounds: Optional[solara.Reactive[list[float]]] = None,
spectrum_color: str = GENERIC_COLOR,
):

logger.info("Creating SpectrumViewer")
Expand Down Expand Up @@ -182,60 +185,71 @@ def _zoom_button_clicked():
logger.info('galaxy_data is None')
return

fig = px.line(spec_data_task.value, x="wave", y="flux",
# template = "plotly_dark" if use_dark_effective else "plotly_white",)
template = "plotly_white",
# hover_data={"wave": False, "flux": False},
# line_shape="hvh", # step line plot
)
fig.update_traces(hovertemplate='Wavelength: %{x:0.0f} Å') #
fig.update_layout(
hoverlabel=dict(
font_size=16,
bgcolor="white"
),
)


fig = go.Figure()
fig.add_trace(go.Scatter(
x= spec_data_task.value["wave"],
y= spec_data_task.value["flux"],
line=dict(
color=spectrum_color,
width=2,
),
mode='lines',
))

fig.update_layout(
plot_bgcolor="white",
font_family=DEFAULT_FONT,
title_font_family=DEFAULT_FONT,
margin=dict(l=0, r=10, t=10, b=0),
margin=PLOTLY_MARGINS,
yaxis=dict(
linecolor="black",
fixedrange=True,
title="Brightness",
showgrid=False,
showline=True,
linewidth=1,
mirror=True,
title_font_family=DEFAULT_FONT,
titlefont_size=20,
tickfont_size=12
titlefont_size=16,
tickfont_size=12,
ticks="outside",
ticklen=5,
tickwidth=1,
tickcolor="black",
),
xaxis=dict(
linecolor="black",
title="Wavelength (Angstroms)",
showgrid=False,
showline=True,
linewidth=1,
mirror=True,
title_font_family=DEFAULT_FONT,
titlefont_size=20,
titlefont_size=16,
tickfont_size=12,
hoverformat=".1f",
hoverformat=".0f",
ticks="outside",
ticklen=5,
tickwidth=1,
tickcolor="black",
ticksuffix=" Å",
),
showlegend=False,
hoverlabel=dict(
font_size=16,
bgcolor="white",
),
)

# This is the line that appears when user first makes observed wavelength measurement
fig.add_vline(
x=obs_wave,
line_width=1,
line_color="red",
# annotation_text="1BASE",
# annotation_font_size=12,
# annotation_position="top right",
line_width=2,
line_color= MY_DATA_COLOR,
visible=vertical_line_visible.value and obs_wave > 0.0 and spectrum_click_enabled,
)

# Orange "Your Measurement" Marker Line & Label
fig.add_shape(
type='line',
x0=obs_wave,
Expand All @@ -244,28 +258,36 @@ def _zoom_button_clicked():
y1=0.2,
xref="x",
yref="paper",
line_color="red",
line_color= MY_DATA_COLOR,
line_width=2,
fillcolor="red",
fillcolor= MY_DATA_COLOR,
label={
"text": f"Your measurement",
"textposition": "top center",
"yanchor": "bottom",
"font": {
"color": MY_DATA_COLOR,
"family": "Arial, sans-serif",
"size": 14,
"weight":"bold"
},
"textposition": "bottom right",
"xanchor": "left",
"yanchor": "top",
"textangle": 0,
"padding": 35,
},
visible=vertical_line_visible.value and obs_wave > 0.0 and not spectrum_click_enabled,
)

# Light gray measurement line
if (marker_position is not None) and (not spectrum_click_enabled):
fig.add_vline(
x = marker_position.value,
line_width = 2,
line_color = "green",
line_color = LIGHT_GENERIC_COLOR,
visible = True,
)


# Red Observed H-alpha Marker Line
fig.add_shape(
editable=False,
x0=galaxy_data.redshift_rest_wave_value - 1.5,
Expand All @@ -274,11 +296,12 @@ def _zoom_button_clicked():
y1=0.99,
yref="paper",
# xref="x",
line_color="red",
fillcolor="red",
line_color=H_ALPHA_COLOR,
fillcolor=H_ALPHA_COLOR,
ysizemode="scaled",
)

# Red Observed H-alpha Marker Label
fig.add_annotation(
x=galaxy_data.redshift_rest_wave_value + 7,
y= 0.99,
Expand All @@ -288,13 +311,14 @@ def _zoom_button_clicked():
font=dict(
family="Arial, sans-serif",
size=14,
color="red",
color=H_ALPHA_COLOR,
weight="bold"
),
xanchor="left",
yanchor="top",
)

# Black Rest H-alpha Marker Line
fig.add_shape(
editable=False,
type="line",
Expand All @@ -313,6 +337,7 @@ def _zoom_button_clicked():
visible=1 in toggle_group_state.value,
)

# Black Rest H-alpha Marker Label
fig.add_annotation(
x=galaxy_data.rest_wave_value - 7,
y= 0.99,
Expand Down
Loading

0 comments on commit c03eeea

Please sign in to comment.