-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from lblogan14/GUI_dev
GUI dev: new spec2d demo with Plotly
- Loading branch information
Showing
15 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,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.
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,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_()) |
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,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. |