Skip to content

Commit

Permalink
Add normalization button
Browse files Browse the repository at this point in the history
  • Loading branch information
astrocuellar committed Jan 29, 2024
1 parent 12d8dfc commit 6d0cfaf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
30 changes: 30 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
QGridLayout,
QTabWidget,
QTabBar,
QPushButton,
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QAction
Expand All @@ -31,6 +32,10 @@
from data import Points, PlotPoints, PlotHorizo, Plot


import astropy.units as u
from specutils.spectra.spectrum1d import Spectrum1D
from specutils.fitting.continuum import fit_continuum

class Window(QMainWindow): # pylint: disable=R0902
def __init__(self): # pylint: disable=R0915
super().__init__()
Expand All @@ -42,6 +47,8 @@ def __init__(self): # pylint: disable=R0915
self.plot = Plot()
self.plot_points = None
self.plot_horizo = PlotHorizo(names=[], x=[])
self.plot_normalization = []


self._create_actions()
self._create_menu_bar()
Expand Down Expand Up @@ -108,6 +115,11 @@ def __init__(self): # pylint: disable=R0915
# Plot Setting
self.mpl_plot_settings = MplPlotSettings()
self.controls_layout.addWidget(self.mpl_plot_settings)
# Normalization Button
self.normalization = QPushButton("Normalization")
self.controls_layout.addWidget(self.normalization)
self.normalization.clicked.connect(self.normal_plot)


self.controls_layout.addStretch()

Expand Down Expand Up @@ -188,6 +200,7 @@ def open_file(self, file_name=None, file_dir=None):
self.output_console.print_output(
f"{len(self.plot_points.points.x)} data points."
)
self.plot_normalization = []

if isinstance(plot_data, PlotHorizo):
self.plot_horizo = plot_data
Expand Down Expand Up @@ -237,6 +250,23 @@ def close_tab(self, idx):
def reload_files(self):
self.files_menu.open_folder(self.last_dir_open)

def normal_plot(self):
x = self.plot_points.points.x
y = self.plot_points.points.y
x_range_plot = []
y_range_plot = []
for i in range(len(x)):
if self.plot_points.x_limit[0] <= x[i] <= self.plot_points.x_limit[1]:
x_range_plot.append(x[i])
y_range_plot.append(y[i])
spectrum = Spectrum1D(flux=y_range_plot * u.Jy, spectral_axis=x_range_plot * u.um)
fitted_continuum = fit_continuum(spectrum)
y_fit = fitted_continuum(x_range_plot*u.um)
y_fit_new = y_fit.value
self.plot_normalization = [x_range_plot, y_fit_new]
self.canvas_plot.update_plot()



if __name__ == "__main__":
app = QApplication([])
Expand Down
22 changes: 21 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
aiohttp==3.9.1
aiosignal==1.3.1
asdf==3.0.1
asdf-astropy==0.5.0
asdf-coordinates-schemas==0.2.0
asdf-standard==1.0.3
asdf-transform-schemas==0.4.0
asdf-unit-schemas==0.1.0
asdf-wcs-schemas==0.3.0
astroid==3.0.2
astropy==6.0.0
astropy-iers-data==0.2024.1.29.0.30.37
async-timeout==4.0.3
asyncio==3.4.3
attrs==23.2.0
contourpy==1.2.0
Expand All @@ -9,29 +19,39 @@ dill==0.3.7
disutils==1.4.32.post2
fonttools==4.47.2
frozenlist==1.4.1
gwcs==0.20.0
idna==3.6
importlib-metadata==7.0.1
isort==5.13.2
jmespath==1.0.1
kiwisolver==1.4.5
matplotlib==3.8.2
mccabe==0.7.0
multidict==6.0.4
ndcube==2.2.0
numpy==1.26.3
packaging==23.2
pep8==1.7.1
pillow==10.2.0
platformdirs==4.1.0
pyerfa==2.0.1.1
Pygments==2.17.2
pylint==3.0.3
pyparsing==3.1.1
PyQt6==6.6.1
PyQt6-Qt6==6.6.1
PyQt6-sip==13.6.0
python-dateutil==2.8.2
PyYAML==6.0.1
QtAwesome==1.3.0
QtPy==2.4.1
setuptools==69.0.3
scipy==1.12.0
semantic-version==2.10.0
six==1.16.0
specutils==1.12.0
superqt==0.6.1
tomli==2.0.1
tomlkit==0.12.3
typing_extensions==4.9.0
yarl==1.9.4
zipp==3.17.0
5 changes: 5 additions & 0 deletions widgets/mpl_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def update_plot(self):
linewidth=app.plot_horizo.width,
)


# Plot normalization
if len(app.plot_normalization):
self.axes.plot(app.plot_normalization[0], app.plot_normalization[1], c='orange')

# Fix lim
self.update_xlim()
self.update_ylim()
Expand Down
2 changes: 1 addition & 1 deletion widgets/mpl_plot_vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
box = CollapsibleBox("Plot vertical")
box = CollapsibleBox("Absorption Metals")
layout.addWidget(box)
box_layout = QFormLayout()

Expand Down

0 comments on commit 6d0cfaf

Please sign in to comment.