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

GUI dev: new spec2d demo with Plotly #84

Merged
merged 7 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified GUIs/zgui/__pycache__/guess_transition.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/linelist_selection.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/menu_toolbars.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/message_box.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/spec_advanced2d.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/spec_fit_gauss2d.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/spec_hist.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/spec_plot.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/tableview_pandas.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/user_manual.cpython-39.pyc
Binary file not shown.
Binary file modified GUIs/zgui/__pycache__/utils.cpython-39.pyc
Binary file not shown.
62 changes: 62 additions & 0 deletions GUIs/zgui_2d/bokeh_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import sys
import os
from bokeh.plotting import figure, output_file, save
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl

from astropy.io import fits


class MainWindow(QMainWindow):
def __init__(self):
super().__init__()

# Create a QWebEngineView widget to display the Plotly plot
view = QWebEngineView()
view.setGeometry(100, 100, 800, 600)


# create a simple Plotly image plot
fitsfile = fits.open('./eiger-mock-data/spec2d_coadd_QSO_J0100_sID010242.fits')
image = fitsfile['SCI'].data

# get the absolute path of the current directory
script_dir = os.path.dirname(os.path.abspath(__file__))
# define the full path to the HTML file
html_file_path = os.path.join(script_dir, 'bokeh_plot.html')
output_file(html_file_path, mode='cdn')

# create a simple Bokeh image plot

'''
p = figure(title='Bokeh Image Plot: spec2d_coadd_QSO_J0100_sID010242.fits',
width=800, height=400)
img = p.image(image=[image], # flip the image
x=0, y=0, # set the origin at the bottom left corner
dw=800, dh=400, # set the width and height of the image
palette="Spectral11", # set the color palette
)
'''
p = figure(title="Bokeh Plot", width=800, height=400)
r = p.line([1, 2, 3], [4, 1, 2], line_width=2)
save(p, html_file_path)

# Load the HTML file in the QWebEngineView
view.setUrl(QUrl.fromLocalFile(html_file_path))

self.setCentralWidget(view)


# function to delete the HTML file when the application is closed
def delete_html_file():
if os.path.exists('bokeh_plot.html'):
os.remove('bokeh_plot.html')

app = QApplication(sys.argv)
window = MainWindow()
window.show()

# delete the HTML file when the application is closed
app.aboutToQuit.connect(delete_html_file)
sys.exit(app.exec_())
Binary file not shown.
64 changes: 64 additions & 0 deletions GUIs/zgui_2d/plotly_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
import os
import plotly.graph_objs as go
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl

from astropy.io import fits


class MainWindow(QMainWindow):
def __init__(self):
super().__init__()

# Create a QWebEngineView widget to display the Plotly plot
view = QWebEngineView()
view.setGeometry(100, 100, 2000, 600)

# Create a simple Plotly scatter plot
#data = [go.Scatter(x=[1, 2, 3], y=[4, 1, 2], mode='markers', text=["Point 1", "Point 2", "Point 3"])]
#go_layout = go.Layout(title='Plotly Scatter Plot')

# create a simple Plotly image plot
fitsfile = fits.open('./eiger-mock-data/spec2d_coadd_QSO_J0100_sID010242.fits')
image = fitsfile['SCI'].data
#print(image)
data = [go.Heatmap(z=image)]
go_layout = go.Layout(title='Plotly Image Plot: spec2d_coadd_QSO_J0100_sID010242.fits')

fig = go.Figure(data=data, layout=go_layout)

# Set hoverinfo to display point values
fig.update_traces(hoverinfo='text+x+y')

# get the absolute path of the current directory
script_dir = os.path.dirname(os.path.abspath(__file__))

# define the full path to the HTML file
html_file_path = os.path.join(script_dir, 'plotly_plot.html')

# Export the plot as an HTML file
fig.write_html(html_file_path)

# Load the HTML file in the QWebEngineView
view.setUrl(QUrl.fromLocalFile(html_file_path))




self.setCentralWidget(view)


# function to delete the HTML file when the application is closed
def delete_html_file():
if os.path.exists('plotly_plot.html'):
os.remove('plotly_plot.html')

app = QApplication(sys.argv)
window = MainWindow()
window.show()

# delete the HTML file when the application is closed
app.aboutToQuit.connect(delete_html_file)
sys.exit(app.exec_())
17 changes: 17 additions & 0 deletions GUIs/zgui_2d/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# GUI Development specifically for 2D

Integrate with Plotly Dash or Bokeh in PyQt5.

## Installation
Besides the packages in `requirements_simple.txt`, the following packages are required:
* `plotly`: `conda install -c plotly plotly=5.17`
* `bokeh` : `conda install bokeh=2.4.3`

## `Plotly` demo
For demo purpose, the `plotly_example.py` worked well. It uses `spec2d_coadd_QSO_J0100_sID010242.fits` as an example. To run the demo, simply type
```bash
python <path to plotly_example.py>/plotly_example.py
```

## `rbcodes` installation
* Window users: Click Control Panel > System and Security > System > Advanced System Settings > Environment Variables > System variables > Path > Edit > New > Paste the path of `rbcodes` folder > OK > OK > OK.