diff --git a/GUIs/zgui/__pycache__/guess_transition.cpython-39.pyc b/GUIs/zgui/__pycache__/guess_transition.cpython-39.pyc index ec5a40f..03f0c62 100644 Binary files a/GUIs/zgui/__pycache__/guess_transition.cpython-39.pyc and b/GUIs/zgui/__pycache__/guess_transition.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/linelist_selection.cpython-39.pyc b/GUIs/zgui/__pycache__/linelist_selection.cpython-39.pyc index f00357e..07dd7cf 100644 Binary files a/GUIs/zgui/__pycache__/linelist_selection.cpython-39.pyc and b/GUIs/zgui/__pycache__/linelist_selection.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/menu_toolbars.cpython-39.pyc b/GUIs/zgui/__pycache__/menu_toolbars.cpython-39.pyc index 03979ca..7b4dcd8 100644 Binary files a/GUIs/zgui/__pycache__/menu_toolbars.cpython-39.pyc and b/GUIs/zgui/__pycache__/menu_toolbars.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/message_box.cpython-39.pyc b/GUIs/zgui/__pycache__/message_box.cpython-39.pyc index 1e5f91a..4d77e9d 100644 Binary files a/GUIs/zgui/__pycache__/message_box.cpython-39.pyc and b/GUIs/zgui/__pycache__/message_box.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/spec_advanced2d.cpython-39.pyc b/GUIs/zgui/__pycache__/spec_advanced2d.cpython-39.pyc index e72c195..fcf70b1 100644 Binary files a/GUIs/zgui/__pycache__/spec_advanced2d.cpython-39.pyc and b/GUIs/zgui/__pycache__/spec_advanced2d.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/spec_fit_gauss2d.cpython-39.pyc b/GUIs/zgui/__pycache__/spec_fit_gauss2d.cpython-39.pyc index 63b42dd..d957664 100644 Binary files a/GUIs/zgui/__pycache__/spec_fit_gauss2d.cpython-39.pyc and b/GUIs/zgui/__pycache__/spec_fit_gauss2d.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/spec_hist.cpython-39.pyc b/GUIs/zgui/__pycache__/spec_hist.cpython-39.pyc index dfe9092..ae8d341 100644 Binary files a/GUIs/zgui/__pycache__/spec_hist.cpython-39.pyc and b/GUIs/zgui/__pycache__/spec_hist.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/spec_plot.cpython-39.pyc b/GUIs/zgui/__pycache__/spec_plot.cpython-39.pyc index 92c8abf..488ef00 100644 Binary files a/GUIs/zgui/__pycache__/spec_plot.cpython-39.pyc and b/GUIs/zgui/__pycache__/spec_plot.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/tableview_pandas.cpython-39.pyc b/GUIs/zgui/__pycache__/tableview_pandas.cpython-39.pyc index 2087e9e..c09925c 100644 Binary files a/GUIs/zgui/__pycache__/tableview_pandas.cpython-39.pyc and b/GUIs/zgui/__pycache__/tableview_pandas.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/user_manual.cpython-39.pyc b/GUIs/zgui/__pycache__/user_manual.cpython-39.pyc index 0d5a1e3..032a66e 100644 Binary files a/GUIs/zgui/__pycache__/user_manual.cpython-39.pyc and b/GUIs/zgui/__pycache__/user_manual.cpython-39.pyc differ diff --git a/GUIs/zgui/__pycache__/utils.cpython-39.pyc b/GUIs/zgui/__pycache__/utils.cpython-39.pyc index c9bbe39..2d45ca3 100644 Binary files a/GUIs/zgui/__pycache__/utils.cpython-39.pyc and b/GUIs/zgui/__pycache__/utils.cpython-39.pyc differ diff --git a/GUIs/zgui_2d/bokeh_example.py b/GUIs/zgui_2d/bokeh_example.py new file mode 100644 index 0000000..19d8a1d --- /dev/null +++ b/GUIs/zgui_2d/bokeh_example.py @@ -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_()) \ No newline at end of file diff --git a/GUIs/zgui_2d/eiger-mock-data/spec2d_coadd_QSO_J0100_sID010242.fits b/GUIs/zgui_2d/eiger-mock-data/spec2d_coadd_QSO_J0100_sID010242.fits new file mode 100644 index 0000000..48ff852 Binary files /dev/null and b/GUIs/zgui_2d/eiger-mock-data/spec2d_coadd_QSO_J0100_sID010242.fits differ diff --git a/GUIs/zgui_2d/plotly_example.py b/GUIs/zgui_2d/plotly_example.py new file mode 100644 index 0000000..33016c8 --- /dev/null +++ b/GUIs/zgui_2d/plotly_example.py @@ -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_()) \ No newline at end of file diff --git a/GUIs/zgui_2d/readme.md b/GUIs/zgui_2d/readme.md new file mode 100644 index 0000000..85738b8 --- /dev/null +++ b/GUIs/zgui_2d/readme.md @@ -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 /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. \ No newline at end of file