Skip to content

Commit

Permalink
Merge pull request #84 from lblogan14/GUI_dev
Browse files Browse the repository at this point in the history
GUI dev: new spec2d demo with Plotly
  • Loading branch information
rongmon authored Feb 21, 2025
2 parents 81ca995 + 2c7a56c commit 2a8122c
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 0 deletions.
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.

0 comments on commit 2a8122c

Please sign in to comment.