Skip to content

Commit

Permalink
magenta and cyan lines included
Browse files Browse the repository at this point in the history
  • Loading branch information
Morisset committed Feb 16, 2016
1 parent 53a81c9 commit afd81dc
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pyssn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

__all__ = []
__version__ = '0.2.12'
__version__ = '0.2.13'

from utils.Config import _Config
config = _Config()
Expand Down
6 changes: 6 additions & 0 deletions pyssn/core/init_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@
y2_plot_lims = (-1.5, 1.)
y3_plot_lims = None

# Color lines
plot_magenta = None
label_magenta = ''
plot_cyan = None
label_cyan = ''

# Scale factor for the plot of the theoretical (individual) spectra:
fact_multi_synth = 1.

Expand Down
38 changes: 20 additions & 18 deletions pyssn/core/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pyneb as pn
import pyssn
from pyssn.utils.physics import CST, Planck, make_cont_Ercolano, gff
from pyssn.utils.misc import execution_path, change_size, convol, rebin, is_absorb, no_red_corr, gauss, carre, lorentz, convolgauss, vactoair
from pyssn.utils.misc import execution_path, change_size, convol, rebin, is_absorb, no_red_corr, gauss, carre, lorentz, convolgauss, vactoair, clean_label
from pyssn.core.profiles import profil_instr
try:
from PyQt4 import QtCore, QtGui
Expand Down Expand Up @@ -86,7 +86,7 @@ def init_vars(self):
self.ax1 = None
self.ax2 = None
self.ax3 = None
self.cursor_width = 0.01
self.cursor_width = 0.02
self.aire_ref = 1.0
self.zoom_fact = 0.1
self._cid = None
Expand All @@ -103,10 +103,6 @@ def init_vars(self):
self.cut_plot2 = 1.
self.ax2_fontsize = 12
self.legend_loc = 1
self.magenta_ref = None
self.magenta_lab = None
self.cyan_ref = None
self.cyan_lab = None
self.fixed_axes = False

def init_obs(self, spectr_obs=None, sp_norm=None, obj_velo=None, limit_sp=None):
Expand Down Expand Up @@ -888,7 +884,7 @@ def print_line(self, line, sort='lambda'):
print('{0[num]:>14d} {0[id]:9s}{0[lambda]:11.3f}{0[l_shift]:6.3f}{0[i_rel]:10.3e}{0[i_cor]:7.3f}'\
' {0[ref]:>14d}{0[profile]:5d}{0[vitesse]:7.2f}{0[comment]:25s}'.format(line))

def line_info(self, line_num, sat_info=True, print_header=True):
def line_info(self, line_num, sat_info=True, print_header=True, sort='lambda'):

if print_header:
print('-------- INFO LINES --------')
Expand All @@ -899,22 +895,22 @@ def line_info(self, line_num, sat_info=True, print_header=True):
to_print = (self.liste_raies['num'] == line_num)
if to_print.sum() == 1:
raie = self.liste_raies[to_print][0]
self.print_line(raie)
self.print_line(raie, sort=sort)
if raie['ref'] != 0 and sat_info:
print('Satellite line of:')
self.line_info(raie['ref'])

to_print = (self.sp_theo['raie_ref']['num'] == line_num)
if to_print.sum() > 0 and sat_info:
raie = self.sp_theo['raie_ref'][to_print][0]
self.print_line(raie)
self.print_line(raie, sort=sort)
print('Reference line')
satellites_tab = (self.liste_raies['ref'] == raie['num'])
Nsat = satellites_tab.sum()
if Nsat > 0:
print('{0} satellites'.format(Nsat))
for raie in self.liste_raies[satellites_tab]:
self.print_line(raie)
self.print_line(raie, sort=sort)
if self.sp_theo['correc'][to_print][0] != 1.0:
print('Intensity corrected by {0}'.format(self.sp_theo['correc'][to_print][0]))

Expand All @@ -939,17 +935,19 @@ def plot2(self, hr=False, cut=None, split=False, do_ax2 = True, do_ax3 = True,
self.cut_plot2 = cut
self.ax2_fontsize = fontsize
self.legend_loc = legend_loc
self.magenta_ref = magenta_ref
self.magenta_lab = magenta_lab
self.cyan_ref = cyan_ref
self.cyan_lab = cyan_lab

if magenta_ref is not None:
self.plot_magenta = magenta_ref
self.label_magenta = magenta_lab
else:
self.plot_magenta = self.get_conf('plot_magenta')
self.label_magenta = self.get_conf('label_magenta')
if cyan_ref is not None:
self.plot_cyan = cyan_ref
self.label_cyan = cyan_lab
else:
self.plot_cyan = self.get_conf('plot_cyan')
self.label_cyan = self.get_conf('label_cyan')

if fig is None:
self.fig1 = plt.figure()
Expand Down Expand Up @@ -999,17 +997,21 @@ def plot_ax1(self, ax, xlims=None):
if self.plot_magenta is not None:
i_magenta = np.where(self.sp_theo['raie_ref']['num'] == self.plot_magenta)[0]
if self.label_magenta is None:
self.label_magenta = self.sp_theo['raie_ref'][i_magenta]['id']
label_magenta = clean_label(self.sp_theo['raie_ref'][i_magenta]['id'][0])
else:
label_magenta = self.label_magenta
if len(i_magenta) == 1:
self.ax1_line_magenta = ax.step(self.w, self.cont+self.sp_theo['spectr'][i_magenta][0], c='magenta',
label=self.label_magenta, linestyle='--')[0]
label=label_magenta, linestyle='--')[0]
if self.plot_cyan is not None:
i_cyan = np.where(self.sp_theo['raie_ref']['num'] == self.plot_cyan)[0]
if self.label_cyan is None:
self.label_cyan = self.sp_theo['raie_ref'][i_cyan]['id']
label_cyan = clean_label(self.sp_theo['raie_ref'][i_cyan]['id'][0])
else:
label_cyan = self.label_cyan
if len(i_cyan) == 1:
self.ax1_line_cyan = ax.step(self.w, self.cont+self.sp_theo['spectr'][i_cyan][0], c='cyan',
label=self.label_cyan, linestyle='-')[0]
label=label_cyan, linestyle='-')[0]
if xlims is None:
ax.set_xlim(self.get_conf('x_plot_lims'))
else:
Expand Down
61 changes: 55 additions & 6 deletions pyssn/qt/pyssn_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, parent=None):
self.init_file_name = None
self.call_on_draw = True
self.cursor_on = False
self.line_info_ref = 0

self.create_menu()
self.create_main_frame()
Expand Down Expand Up @@ -194,29 +195,41 @@ def create_main_frame(self):

self.sp_norm_box = QtGui.QLineEdit()
self.sp_norm_box.setMinimumWidth(50)
self.connect(self.sp_norm_box, QtCore.SIGNAL('editingFinished ()'), self.sp_norm)
self.connect(self.sp_norm_box, QtCore.SIGNAL('returnPressed()'), self.sp_norm)

self.obj_velo_box = QtGui.QLineEdit()
self.obj_velo_box.setMinimumWidth(50)
self.connect(self.obj_velo_box, QtCore.SIGNAL('editingFinished ()'), self.obj_velo)
self.connect(self.obj_velo_box, QtCore.SIGNAL('returnPressed()'), self.obj_velo)

self.ebv_box = QtGui.QLineEdit()
self.ebv_box.setMinimumWidth(50)
self.connect(self.ebv_box, QtCore.SIGNAL('editingFinished ()'), self.ebv)
self.connect(self.ebv_box, QtCore.SIGNAL('returnPressed()'), self.ebv)

self.resol_box = QtGui.QLineEdit()
self.resol_box.setMinimumWidth(50)
self.connect(self.resol_box, QtCore.SIGNAL('editingFinished ()'), self.resol)
self.connect(self.resol_box, QtCore.SIGNAL('returnPressed()'), self.resol)

self.cut2_box = QtGui.QLineEdit()
self.cut2_box.setMinimumWidth(50)
self.connect(self.cut2_box, QtCore.SIGNAL('editingFinished ()'), self.cut2)
self.connect(self.cut2_box, QtCore.SIGNAL('returnPressed()'), self.cut2)

self.line_info_box = QtGui.QLineEdit()
self.line_info_box.setMinimumWidth(50)
self.connect(self.line_info_box, QtCore.SIGNAL('returnPressed()'), self.line_info)

self.magenta_box = QtGui.QLineEdit()
self.magenta_box.setMinimumWidth(50)
self.connect(self.magenta_box, QtCore.SIGNAL('returnPressed()'), self.magenta_line)

self.cyan_box = QtGui.QLineEdit()
self.cyan_box.setMinimumWidth(50)
self.connect(self.cyan_box, QtCore.SIGNAL('returnPressed()'), self.cyan_line)
#
# Layout with box sizers
#
hbox = QtGui.QHBoxLayout()
hbox2 = QtGui.QHBoxLayout()
hbox3 = QtGui.QHBoxLayout()

for w in [self.select_init_button, self.draw_button, self.pl_ax2_cb, self.pl_ax3_cb, self.fix_axes_cb, self.adjust_button]:
hbox.addWidget(w)
Expand All @@ -226,12 +239,17 @@ def create_main_frame(self):
hbox2.addWidget(w)
hbox2.setAlignment(w, QtCore.Qt.AlignVCenter)

for w in [self.line_info_box, self.magenta_box, self.cyan_box]:
hbox3.addWidget(w)
hbox3.setAlignment(w, QtCore.Qt.AlignVCenter)

vbox = QtGui.QVBoxLayout()

vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
vbox.addLayout(hbox)
vbox.addLayout(hbox2)
vbox.addLayout(hbox3)

self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
Expand Down Expand Up @@ -334,8 +352,11 @@ def make_axes(self):
self.axes = self.fig.add_subplot(n_subplots, 1, 1)
if self.pl_ax2_cb.isChecked():
self.axes2 = self.fig.add_subplot(n_subplots, 1, i_ax2, sharex=self.axes)
self.axes.get_xaxis().set_visible(False)
if self.pl_ax3_cb.isChecked():
self.axes3 = self.fig.add_subplot(n_subplots, 1, i_ax3, sharex=self.axes)
if self.pl_ax2_cb.isChecked():
self.axes2.get_xaxis().set_visible(False)
if self.sp.fixed_axes:
self.sp.restore_axes()
self.fig.subplots_adjust(hspace=0.0)
Expand Down Expand Up @@ -364,7 +385,9 @@ def start_spectrum(self):
self.obj_velo_box.setText('{}'.format(self.sp.get_conf('obj_velo')))
self.ebv_box.setText('{}'.format(self.sp.get_conf('e_bv')))
self.resol_box.setText('{}'.format(self.sp.get_conf('resol')))
self.cut2_box.setText('{}'.format(self.sp.cut_plot2))
self.cut2_box.setText('{}'.format(self.sp.cut_plot2))
self.magenta_box.setText('{}'.format(self.sp.plot_magenta))
self.cyan_box.setText('{}'.format(self.sp.plot_cyan))

def fix_axes(self):
if self.sp is None:
Expand Down Expand Up @@ -443,6 +466,32 @@ def cut2(self):
self.sp.cut_plot2 = np.float(self.cut2_box.text())
self.on_draw()

def line_info(self):
if self.sp is None:
return
new_ref = np.int(self.line_info_box.text())
if new_ref != self.line_info_ref:
self.line_info_ref = new_ref
self.sp.line_info(new_ref)

def magenta_line(self):
if self.sp is None:
return
new_ref = np.int(self.magenta_box.text())
if new_ref != self.sp.plot_magenta:
self.sp.plot_magenta = new_ref
self.on_draw()

def cyan_line(self):
if self.sp is None:
return
new_ref = np.int(self.cyan_box.text())
if new_ref != self.sp.plot_cyan:
self.sp.plot_cyan = new_ref
self.on_draw()



def main():
app = QtGui.QApplication(sys.argv)
form = AppForm()
Expand Down
4 changes: 4 additions & 0 deletions pyssn/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''
import os
import sys
import re
from scipy import interpolate
import numpy as np
import pyssn
Expand Down Expand Up @@ -173,4 +174,7 @@ def rebin_tapas(file_ = None, cut=1e-5):
with open(fout, 'w') as f:
for r in res:
f.write('{} {}\n'.format(r[0]*10., r[1]))

def clean_label(str_):
return(re.sub("_", " ", str_))

0 comments on commit afd81dc

Please sign in to comment.