def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.chart = MatplotlibWidget(self.plot_widget, 1, 1, exportable=False) self.chart.create_axis(0, 0, labels=("X", "Y")) self.chart.axes[0].axis("equal") self.start_btn.setIcon(QtGui.QIcon(constants.PLAY_ICON_PATH)) self.pause_btn.setIcon(QtGui.QIcon(constants.PAUSE_ICON_PATH)) self.next_btn.setIcon(QtGui.QIcon(constants.NEXT_ICON_PATH)) self.prev_btn.setIcon(QtGui.QIcon(constants.PREV_ICON_PATH)) # self.viewport_pixlabel.setScaledContents(True) # animation variables self.frames_per_second = 25.0 # 25 frames per second self.frame_time = 1.0 / self.frames_per_second # 0.04ms per frame (25fps) self.playback = False self.Stopwatch = Stopwatch() self.Stopwatch.wait = self.frame_time self.star_position_data = None self.rendered_frames = None self.current_frame = None self.single_frame = None self.connect_signals()
def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.s1_chart = MatplotlibWidget(self.s1_plot_widget, 1, 1) self.s2_chart = MatplotlibWidget(self.s2_plot_widget, 1, 1) self.s1_chart.create_axis(0, 0, name="Primary Star Dimensions", labels=("", "Fract. Radius")) self.s2_chart.create_axis(0, 0, name="Secondary Star Dimensions", labels=("", "Fract. Radius")) self.s1_pole = [] self.s1_point = [] self.s1_side = [] self.s1_back = [] self.s2_pole = [] self.s2_point = [] self.s2_side = [] self.s2_back = [] self.x = [] self.connect_signals()
def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.obs_widget = self.main_window.loadobservations_widget self.nlc = 0 # setup light_chart area self.light_chart = MatplotlibWidget(self.light_plot_widget, 2, 1, h_ratios=[1.5, 1]) self.light_chart.create_axis(0, 0, name="Synthetic Light Curve") self.light_chart.create_axis(1, 0, sharex=self.light_chart[0]) self.light_chart.figure.subplots_adjust(top=0.95, bottom=0.1, left=0.1, right=0.95, hspace=0, wspace=0) self.light_chart[0].tick_params(labeltop=False, labelbottom=False, bottom=True, top=True, labelright=False, labelleft=True, labelsize=11) # setup velocity_chart area self.velocity_chart = MatplotlibWidget(self.vel_plot_widget, 2, 1, h_ratios=[1.5, 1]) self.velocity_chart.create_axis(0, 0, name="Synthetic Velocity Curve") self.velocity_chart.create_axis(1, 0, sharex=self.velocity_chart[0]) self.velocity_chart.figure.subplots_adjust(top=0.95, bottom=0.1, left=0.1, right=0.95, hspace=0, wspace=0) self.velocity_chart[0].tick_params(labeltop=False, labelbottom=False, bottom=True, top=True, labelright=False, labelleft=True, labelsize=11) self.light_treewidget.header().setSectionResizeMode(3) self.light_treewidget.header().setSectionsMovable(False) self.insert_synthetic_curves() self.connect_signals()
def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.chart = MatplotlibWidget(self.plot_widget, 1, 1, exportable=False) self.chart.create_axis(0, 0, name="", labels=("E", "O - C (Day)")) self.data_treewidget.setFont(parent.monoFont) self.data_treewidget.header().setSectionResizeMode(3) self.cycles = [] self.linear_resid = [] self.dpdt_resid = [] self.connect_signals()
def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.ptm_font = QtGui.QFont(parent.monoFont) self.ptm_font.setPointSize(9) self.history_treewidget.setFont(self.ptm_font) self.history_treewidget.header().setSectionResizeMode(3) header_item = QtWidgets.QTreeWidgetItem() header_item.setText(0, "Iteration #") header_item.setText(1, "Parameters") self.history_treewidget.setHeaderItem(header_item) self.chart = MatplotlibWidget(self.plot_widget, 1, 1, exportable=False) self.chart.create_axis(0, 0) self.solutions = [] self.connect_signals()
class Widget(QtWidgets.QWidget, starpositions_widget.Ui_StarPositionWidget): def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.chart = MatplotlibWidget(self.plot_widget, 1, 1, exportable=False) self.chart.create_axis(0, 0, labels=("X", "Y")) self.chart.axes[0].axis("equal") self.start_btn.setIcon(QtGui.QIcon(constants.PLAY_ICON_PATH)) self.pause_btn.setIcon(QtGui.QIcon(constants.PAUSE_ICON_PATH)) self.next_btn.setIcon(QtGui.QIcon(constants.NEXT_ICON_PATH)) self.prev_btn.setIcon(QtGui.QIcon(constants.PREV_ICON_PATH)) # self.viewport_pixlabel.setScaledContents(True) # animation variables self.frames_per_second = 25.0 # 25 frames per second self.frame_time = 1.0 / self.frames_per_second # 0.04ms per frame (25fps) self.playback = False self.Stopwatch = Stopwatch() self.Stopwatch.wait = self.frame_time self.star_position_data = None self.rendered_frames = None self.current_frame = None self.single_frame = None self.connect_signals() def connect_signals(self): self.roche_groupbox.toggled.connect(self.handle_toggle_roche) self.positions_groupbox.toggled.connect(self.handle_toggle_position) self.plot_btn.clicked.connect(self.plot) # animator self.horizontalSlider.sliderMoved.connect(self.slider_move) self.horizontalSlider.sliderPressed.connect(self.slider_move) self.start_btn.clicked.connect(self.start_playback) self.pause_btn.clicked.connect(self.stop_playback) self.next_btn.clicked.connect(self.next_frame) self.prev_btn.clicked.connect(self.previous_frame) self.Stopwatch.tick.connect(self.advance_frame) self.render_btn.clicked.connect(self.start_render) self.saveframe_btn.clicked.connect(self.save_frame) self.saveall_btn.clicked.connect(self.save_all_frames) def resizeEvent(self, resize_event): self.draw_current_frame() super(Widget, self).resizeEvent(resize_event) def handle_toggle_roche(self): self.roche_groupbox.blockSignals(True) self.positions_groupbox.blockSignals(True) if self.roche_groupbox.isChecked(): self.positions_groupbox.setChecked(False) elif self.positions_groupbox.isChecked() is False: self.roche_groupbox.setChecked(True) self.roche_groupbox.blockSignals(False) self.positions_groupbox.blockSignals(False) def handle_toggle_position(self): self.roche_groupbox.blockSignals(True) self.positions_groupbox.blockSignals(True) if self.positions_groupbox.isChecked(): self.roche_groupbox.setChecked(False) elif self.roche_groupbox.isChecked() is False: self.positions_groupbox.setChecked(True) self.roche_groupbox.blockSignals(False) self.positions_groupbox.blockSignals(False) def plot(self): if self.positions_groupbox.isChecked(): self.plot_positions() elif self.roche_groupbox.isChecked(): self.plot_roche() def plot_positions(self): self.chart.set_axis_title("Star Positions") lc_params = self.main_window.get_lc_params() lc_params["jdphs"] = 2 lc_params["phstrt"] = self.phase_spinbox.value() lc_params["phstop"] = self.phase_spinbox.value() lc_params["phin"] = 0.1 lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_star_positions().save().run( ).read_star_positions()[0] self.chart.plot(results[0], results[1], linestyle="", marker="+", markersize=1, color="black") self.chart.plot([0], [0], clear=False, linestyle="", marker="+", markersize=10, color=constants.COLOR_RED) def plot_roche(self): # compute_roche_potentials(w, e, q, phase, phase_shift, plot_elements=None): self.chart.clear_all() w = self.main_window.perr0_ipt.value() e = self.main_window.e_ipt.value() q = self.main_window.q_ipt.value() phase = self.main_window.p0_ipt.value() pshift = self.main_window.pshift_ipt.value() pot1 = self.main_window.pot1_ipt.value() pot2 = self.main_window.pot2_ipt.value() inner_critical, outer_critical = methods.compute_roche_potentials( w, e, q, phase, pshift, plot_elements=[self.chart.axes[0], pot1, pot2]) self.chart.set_labels("X", "Y") self.chart.set_axis_title("Roche Potentials") self.chart.redraw() self.inner_crit_otpt.setValue(inner_critical) self.outer_crit_otpt.setValue(outer_critical) def setup_slider(self): self.horizontalSlider.setMinimum(0) self.horizontalSlider.setMaximum(len(self.rendered_frames) - 1) self.horizontalSlider.setTickInterval(1) def slider_move(self): self.stop_playback() if self.rendered_frames is not None: self.show_frame( self.rendered_frames[self.horizontalSlider.value()]) def start_playback(self): if self.rendered_frames is not None: self.Stopwatch.start() def stop_playback(self): if self.rendered_frames is not None: self.Stopwatch.stop() def next_frame(self): self.stop_playback() self.advance_frame() def advance_frame(self): if self.rendered_frames is not None: index = self.horizontalSlider.value() + 1 if index == len(self.rendered_frames): index = 0 self.horizontalSlider.setValue(index) self.show_frame(self.rendered_frames[index]) def previous_frame(self): self.stop_playback() if self.rendered_frames is not None: index = self.horizontalSlider.value() - 1 if index == -1: index = len(self.rendered_frames) - 1 self.horizontalSlider.setValue(index) self.show_frame(self.rendered_frames[index]) def clear_animator(self): self.viewport_pixlabel.clear() self.rendered_frames = None self.star_position_data = None def start_render(self): self.clear_animator() if self.single_chk.isChecked() is not True: if self.render_stars() is not 1: self.setup_slider() else: self.render_single() def update_message_label(self, msg): self.message_label.setText(msg) self.message_label.repaint() def update_progress_bar(self, value): self.progressBar.setValue(value) self.progressBar.repaint() def render_stars(self): increment = None fmt = None iterations = None if self.main_window.jd_radiobtn.isChecked(): mn = self.main_window.lc_jd_start_ipt.value() mx = self.main_window.lc_jd_end_ipt.value() increment = self.main_window.lc_jd_incr_ipt.value() fmt = "{:7.6f}" iterations = int((mx - mn) / increment) elif self.main_window.phase_radiobtn.isChecked(): mn = self.main_window.lc_phs_start_ipt.value() mx = self.main_window.lc_phs_stop_ipt.value() increment = self.main_window.lc_phs_incr_ipt.value() fmt = "{:4.3f}" iterations = int((mx - mn) / increment) if iterations > 500: msg = QtWidgets.QMessageBox() msg.setIcon(msg.Warning) msg.setText("Expected iteration count is larger than 500. (" + str(iterations) + ")") msg.setInformativeText( "This might result in a very large lcout file (>100MB), " "take a long time and might crash LC altogether. " "Are you sure you want to render the animation?") msg.setStandardButtons(msg.Ok | msg.Cancel) if msg.exec_() == msg.Cancel: return 1 self.update_message_label("Running LC...") lc_params = self.main_window.get_lc_params() lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_star_positions().save().run( ).read_star_positions() self.rendered_frames = [] self.update_message_label("Rendering plots...") progress_increment = 100.0 / float(len(results)) current_progress = 0.0 for idx, result in enumerate(results): qpixmap = self.render_frame(result[0], result[1], increment * idx, fmt=fmt) self.rendered_frames.append(qpixmap) current_progress = current_progress + progress_increment self.update_progress_bar(current_progress) self.show_frame(self.rendered_frames[0]) self.update_message_label("Done.") self.update_progress_bar(100) self.single_frame = False def render_single(self): lc_params = self.main_window.get_lc_params() lc_params["jdphs"] = 2 lc_params["phstrt"] = self.render_phaseSpinbox.value() lc_params["phstop"] = self.render_phaseSpinbox.value() lc_params["phin"] = 0.1 lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_star_positions().save().run( ).read_star_positions()[0] qpixmap = self.render_frame(results[0], results[1], self.render_phaseSpinbox.value()) self.show_frame(qpixmap) self.single_frame = True def render_frame(self, x, y, t, fmt="{:4.3f}"): pyplot.cla() pyplot.axis("equal") pyplot.xlabel("X") pyplot.ylabel("Y") pyplot.xlim(self.min_spinbox.value(), self.max_spinbox.value()) pyplot.ylim(self.min_spinbox.value(), self.max_spinbox.value()) pyplot.plot(x, y, 'ko', markersize=0.2, label=fmt.format(t)) pyplot.legend(loc="upper right") pyplot.plot([0], [0], linestyle="", marker="+", markersize=10, color="#ff3a3a") image = io.BytesIO() dpi_dict = {"64dpi": 64, "128dpi": 128, "196dpi": 196, "256dpi": 256} pyplot.savefig(image, dpi=dpi_dict[str(self.dpi_combobox.currentText())], format="png") image.seek(0) qbyte = QtCore.QByteArray(image.getvalue()) qpixmap = QtGui.QPixmap() qpixmap.loadFromData(qbyte, "png") return qpixmap def show_frame(self, qpixmap): self.current_frame = qpixmap self.draw_current_frame() def draw_current_frame(self): if self.current_frame is not None: w = self.viewport_pixlabel.width() h = self.viewport_pixlabel.height() # 1 means keep aspect ratio, it is a Qt enum (Qt::KeepAspectRatio) self.viewport_pixlabel.setPixmap( QtGui.QPixmap(self.current_frame).scaled(w, h, 1)) def save_frame(self): frame = None if self.single_frame: frame = self.current_frame elif self.rendered_frames is not None: frame = self.rendered_frames[self.horizontalSlider.value()] if frame is not None: dialog = QtWidgets.QFileDialog() dialog.setDefaultSuffix("png") dialog.setNameFilter("PNG File (*png)") dialog.setAcceptMode(1) return_code = dialog.exec_() file_path = str((dialog.selectedFiles())[0]) if file_path != "" and return_code != 0: frame.save(file_path, "png", 100) msg = QtWidgets.QMessageBox() msg.setText("Frame is saved into " + file_path) msg.exec_() def save_all_frames(self): if self.rendered_frames is not None: dialog = QtWidgets.QFileDialog() dialog.setFileMode(2) return_code = dialog.exec_() file_path = str((dialog.selectedFiles())[0]) if file_path != "" and return_code != 0: for idx, qpixmap in enumerate(self.rendered_frames): qpixmap.save( os.path.join(file_path, "{:0>4d}".format(idx) + ".png"), "png", 100) msg = QtWidgets.QMessageBox() msg.setText("Frames are saved into " + file_path) msg.exec_()
class Widget(QtWidgets.QWidget, oc_widget.Ui_OCWidget): def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.chart = MatplotlibWidget(self.plot_widget, 1, 1, exportable=False) self.chart.create_axis(0, 0, name="", labels=("E", "O - C (Day)")) self.data_treewidget.setFont(parent.monoFont) self.data_treewidget.header().setSectionResizeMode(3) self.cycles = [] self.linear_resid = [] self.dpdt_resid = [] self.connect_signals() def connect_signals(self): self.compute_btn.clicked.connect(self.compute_oc) self.dpdt_chk.toggled.connect(self.update_plots) self.linear_chk.toggled.connect(self.update_plots) self.calculate_btn.clicked.connect(self.calculate_dp_and_dt) self.update_btn.clicked.connect(self.update_ephemeris_and_period) self.export_btn.clicked.connect(self.export_data) def export_data(self): root = self.data_treewidget.invisibleRootItem() if root.childCount() == 0: return 1 filepath = methods.save_file(self, suffix="txt") if filepath is not None: lenght = 3 output = "# HJD" + delimiter + "Linear Residuals" + delimiter + "Residuals with dP/dt\n" root = self.data_treewidget.invisibleRootItem() i = 0 while i < root.childCount(): idx = 0 while idx < lenght: output = output + root.child(i).text(idx) + delimiter idx = idx + 1 output = output + "\n" i = i + 1 with open(filepath, "w") as destination: destination.write(output) msg = messenger.Messenger("info", "File saved:") msg.set_info(filepath) msg.show() def compute_oc(self): eclipse_timings_path = self.main_window.eclipsetimings_widget.filepath_label.text( ) if os.path.isfile(eclipse_timings_path): self.clear() lc_params = self.main_window.get_lc_params() ec_data = numpy.loadtxt(eclipse_timings_path, unpack=True) lc_params.add_eclipse_times(ec_data[0], ec_data[1]) lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_etv().save().run().read_etv() i = 0 while i < len(results[0]): jd = results[0][i] lin_res = results[3][i] dpdt_res = results[5][i] item = QtWidgets.QTreeWidgetItem(self.data_treewidget) item.setText(0, str(jd)) item.setText(1, str(lin_res)) item.setText(2, str(dpdt_res)) i = i + 1 t0 = self.main_window.jd0_ipt.value() p = self.main_window.p0_ipt.value() for t in results[0]: cycle = (t - t0) / p e = numpy.around(cycle * 2.0, decimals=0) / 2.0 self.cycles.append(e) self.linear_resid = results[3] self.dpdt_resid = results[5] self.update_plots() else: msg = messenger.Messenger( "error", "An eclipse timings file must be provided for O - C calculation." ) msg.set_info("You can load eclipse timings from the main tab.") msg.show() def update_plots(self): self.chart.clear_all() if self.linear_chk.isChecked(): self.chart.plot(self.cycles, self.linear_resid, clear=False, markersize=2, marker="o", linestyle="", color=constants.COLOR_BLUE) if self.dpdt_chk.isChecked(): self.chart.plot(self.cycles, self.dpdt_resid, clear=False, markersize=2, marker="o", linestyle="", color=constants.COLOR_RED) def calculate_dp_and_dt(self): if len(self.cycles) != 0 and self.linear_chk.isChecked(): model_coeffs = numpy.polyfit(self.cycles, self.linear_resid, 1) model_y = [(y * model_coeffs[0] + model_coeffs[1]) for y in self.cycles] self.dp_otpt.setValue(model_coeffs[0]) self.dt_otpt.setValue(model_coeffs[1]) self.chart.plot(self.cycles, model_y, clear=False, color=constants.COLOR_RED) def update_ephemeris_and_period(self): if len(self.cycles) != 0: self.main_window.jd0_ipt.setValue( self.main_window.jd0_ipt.value() + self.dt_otpt.value()) self.main_window.p0_ipt.setValue(self.main_window.p0_ipt.value() + self.dp_otpt.value()) self.update_plots() self.dp_otpt.setValue(0.0) self.dt_otpt.setValue(0.0) self.compute_btn.click() def clear(self): self.cycles = [] self.linear_resid = [] self.dpdt_resid = [] self.chart.clear_all() self.data_treewidget.clear() self.dp_otpt.setValue(0.0) self.dt_otpt.setValue(0.0)
class Widget(QtWidgets.QWidget, history_widget.Ui_HistoryWidget): def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.ptm_font = QtGui.QFont(parent.monoFont) self.ptm_font.setPointSize(9) self.history_treewidget.setFont(self.ptm_font) self.history_treewidget.header().setSectionResizeMode(3) header_item = QtWidgets.QTreeWidgetItem() header_item.setText(0, "Iteration #") header_item.setText(1, "Parameters") self.history_treewidget.setHeaderItem(header_item) self.chart = MatplotlibWidget(self.plot_widget, 1, 1, exportable=False) self.chart.create_axis(0, 0) self.solutions = [] self.connect_signals() def connect_signals(self): self.plot_btn.clicked.connect(self.plot_solutions) self.clear_btn.clicked.connect(self.clear) self.export_btn.clicked.connect(self.export_data) def export_data(self): if len(self.solutions) is not None: filepath = methods.save_file(self, suffix="txt") if filepath is not None: output = "# Itr" + delimiter for result in self.solutions[0]: output = output + constants.KEEPS_ID_NAME_DICT[ result[0]] + delimiter output = output + "\n" for idx, solution in enumerate(self.solutions): output = output + str(idx + 1) + delimiter for row in solution: output = output + str(row[4]) + delimiter output = output + "\n" with open(filepath, "w") as destination: destination.write(output) msg = messenger.Messenger("info", "File saved:") msg.set_info(filepath) msg.show() def clear(self): self.chart.clear_all() self.solutions = [] self.history_treewidget.clear() def selected_item(self): selecteditem = self.history_treewidget.selectedItems() if len(selecteditem) > 0: return selecteditem[0] else: return None def receive_solution(self, new_solution): if len(self.solutions) == 0: self.solutions.append(new_solution) elif len(self.solutions[0]) == len(new_solution): same_solution = True old_solution = self.solutions[-1] for old, new in zip(old_solution, new_solution): if old[0] != new[0]: same_solution = False break if not same_solution: self.clear() self.solutions.append(new_solution) elif same_solution: self.solutions.append(new_solution) else: self.clear() self.solutions.append(new_solution) self.update_solutions() def update_solutions(self): if len(self.solutions) == 1: header_item = QtWidgets.QTreeWidgetItem() header_item.setText(0, "Itr #") for index, row in enumerate(self.solutions[0]): par_id = row[0] c_id = row[1] text = constants.KEEPS_ID_NAME_DICT[par_id] if c_id != 0.0: text = text + " (Curve #{0})".format(str(int(c_id))) header_item.setText(index + 1, text) self.history_treewidget.setHeaderItem(header_item) solution = self.solutions[-1] item = QtWidgets.QTreeWidgetItem(self.history_treewidget) item.setText(0, str(len(self.solutions))) for index, row in enumerate(solution): value = row[4] if row[0] in (19.0, 20.0): value = value * 10000.0 item.setText(index + 1, "{:0.5f}".format(value)) if self.auto_chk.isChecked(): self.plot_solutions() def plot_solutions(self): selected_item = self.selected_item() if selected_item is not None and len(self.solutions) > 0: self.chart.clear_all() index = self.history_treewidget.currentColumn() - 1 x = list(range(1, len(self.solutions) + 1)) y = [solution[index][4] for solution in self.solutions] y_w = [solution[index][5] for solution in self.solutions] if self.solutions[0][index][0] in (19.0, 20.0): _y = [yy * 10000.0 for yy in y] _y_w = [yyw * 10000.0 for yyw in y_w] y = _y y_w = _y_w self.chart.axes[0].errorbar(x, y, yerr=y_w, linestyle="-", marker="o", markersize=constants.MARKER_SIZE + 2, color=constants.COLOR_BLUE, ecolor=constants.COLOR_RED) self.chart.axes[0].set_xlabel("Iteration Number") self.chart.axes[0].set_ylabel( constants.KEEPS_ID_NAME_DICT[self.solutions[0][index][0]]) self.chart.axes[0].ticklabel_format(useOffset=False) self.chart.axes[0].get_yaxis().set_major_locator( MaxNLocator(integer=True)) self.chart.redraw()
class Widget(QtWidgets.QWidget, syntheticcurve_widget.Ui_SyntheticCurveWidget): def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.obs_widget = self.main_window.loadobservations_widget self.nlc = 0 # setup light_chart area self.light_chart = MatplotlibWidget(self.light_plot_widget, 2, 1, h_ratios=[1.5, 1]) self.light_chart.create_axis(0, 0, name="Synthetic Light Curve") self.light_chart.create_axis(1, 0, sharex=self.light_chart[0]) self.light_chart.figure.subplots_adjust(top=0.95, bottom=0.1, left=0.1, right=0.95, hspace=0, wspace=0) self.light_chart[0].tick_params(labeltop=False, labelbottom=False, bottom=True, top=True, labelright=False, labelleft=True, labelsize=11) # setup velocity_chart area self.velocity_chart = MatplotlibWidget(self.vel_plot_widget, 2, 1, h_ratios=[1.5, 1]) self.velocity_chart.create_axis(0, 0, name="Synthetic Velocity Curve") self.velocity_chart.create_axis(1, 0, sharex=self.velocity_chart[0]) self.velocity_chart.figure.subplots_adjust(top=0.95, bottom=0.1, left=0.1, right=0.95, hspace=0, wspace=0) self.velocity_chart[0].tick_params(labeltop=False, labelbottom=False, bottom=True, top=True, labelright=False, labelleft=True, labelsize=11) self.light_treewidget.header().setSectionResizeMode(3) self.light_treewidget.header().setSectionsMovable(False) self.insert_synthetic_curves() self.connect_signals() def connect_signals(self): self.light_plot_btn.clicked.connect(self.plot_selected_light_curve) self.vel_plot_btn.clicked.connect(self.plot_selected_velocity_curve) def add_div_to_light(self): item = QtWidgets.QTreeWidgetItem(self.light_treewidget) i = 0 while i < 15: separator = QtWidgets.QFrame(self.light_treewidget) separator.setFrameShape(QtWidgets.QFrame.HLine) separator.setFrameShadow(QtWidgets.QFrame.Sunken) self.light_treewidget.setItemWidget(item, i, separator) i = i + 1 def add_row_to_light(self, filename): # internal functions def _bandpass_button_pressed(btn): selection = methods.create_bandpass_menu(btn).exec_( QtGui.QCursor.pos()) if selection is not None: btn.setText(selection.objectName()) def _bandpass_button_pressed_edit_curve(btn, rw, mw): _bandpass_button_pressed(btn) mw.loadobservations_widget.light_curves[rw].band_id = int( constants.BANDPASS_ID_DICT[str(btn.text())]) mw.loadobservations_widget.update_curve_list() def _spinbox_edited(spnbx, rw, cl, mw): crv = mw.loadobservations_widget.light_curves[rw] if cl == 2: crv.l1 = spnbx.value() elif cl == 3: crv.l2 = spnbx.value() elif cl == 4: crv.l3 = spnbx.value() elif cl == 5: crv.x1 = spnbx.value() elif cl == 6: crv.x2 = spnbx.value() elif cl == 7: crv.y1 = spnbx.value() elif cl == 8: crv.y2 = spnbx.value() elif cl == 9: crv.opsf = spnbx.value() elif cl == 10: crv.aextinc = spnbx.value() elif cl == 11: crv.calib = spnbx.value() item = QtWidgets.QTreeWidgetItem(self.light_treewidget) item.setText(0, filename) bandpass_button = QtWidgets.QPushButton(self.light_treewidget) bandpass_button.setText("Johnson V") if filename != "[Synthetic]": bandpass_button.clicked.connect( partial(_bandpass_button_pressed_edit_curve, bandpass_button, self.nlc, self.main_window)) else: bandpass_button.clicked.connect( partial(_bandpass_button_pressed, bandpass_button)) self.light_treewidget.setItemWidget(item, 1, bandpass_button) i = 2 while i < 14: spinbox = QtWidgets.QDoubleSpinBox(self.light_treewidget) spinbox.setMaximumWidth(90) spinbox.setButtonSymbols(2) spinbox.setDecimals(7) spinbox.setMaximum(999) spinbox.setMinimum(0) if i == 12: spinbox.setValue(1.0) if i == 13: spinbox.setValue(8.0) if filename != "[Synthetic]": spinbox.editingFinished.connect( partial(_spinbox_edited, spinbox, self.nlc, i, self.main_window)) self.light_treewidget.setItemWidget(item, i, spinbox) i = i + 1 if filename != "[Synthetic]": self.nlc = self.nlc + 1 return item def insert_synthetic_curves(self): self.add_row_to_light("[Synthetic]") self.add_div_to_light() self.vel_pri_label.setText("[Synthetic]") self.vel_sec_label.setText("[Synthetic]") def populate_from_loaded_curves(self): if self.obs_widget.velocity_curves[0] is not None: self.vel_pri_label.setText( os.path.basename(self.obs_widget.velocity_curves[0].filepath)) if self.obs_widget.velocity_curves[1] is not None: self.vel_sec_label.setText( os.path.basename(self.obs_widget.velocity_curves[1].filepath)) for lc in self.obs_widget.light_curves: item = self.add_row_to_light(os.path.basename(lc.filepath)) self.light_treewidget.itemWidget(item, 1).setText( constants.ID_BANDPASS_DICT[str(lc.band_id)]) self.light_treewidget.itemWidget(item, 2).setValue(lc.l1) self.light_treewidget.itemWidget(item, 3).setValue(lc.l2) self.light_treewidget.itemWidget(item, 4).setValue(lc.l3) self.light_treewidget.itemWidget(item, 5).setValue(lc.x1) self.light_treewidget.itemWidget(item, 6).setValue(lc.x2) self.light_treewidget.itemWidget(item, 7).setValue(lc.y1) self.light_treewidget.itemWidget(item, 8).setValue(lc.y2) self.light_treewidget.itemWidget(item, 9).setValue(lc.opsf) self.light_treewidget.itemWidget(item, 10).setValue(lc.aextinc) self.light_treewidget.itemWidget(item, 11).setValue(lc.calib) self.light_treewidget.itemWidget(item, 12).setValue(1.0) self.light_treewidget.itemWidget(item, 13).setValue(8.0) def reset_light_treewidget(self): self.nlc = 0 self.light_treewidget.clear() self.insert_synthetic_curves() def reset_widget(self): self.reset_light_treewidget() self.light_chart.clear_all() def reset_and_repopulate(self): self.reset_widget() self.populate_from_loaded_curves() def selected_light_item(self): selecteditem = self.light_treewidget.selectedItems() if len(selecteditem) > 0: return selecteditem[0] else: return None def alias(self, obs, model_start, model_end): obs_x = obs[0] obs_y = obs[1] t0 = self.main_window.jd0_ipt.value() p = self.main_window.p0_ipt.value() n_x = None n_y = None if self.main_window.phase_radiobtn.isChecked(): if self.main_window.jdphs_combobox.currentText() == "Phase": n_x, n_y = methods.alias_phased_obs_with_phase( obs_x, obs_y, model_start, model_end) elif self.main_window.jdphs_combobox.currentText() == "Time": n_x, n_y = methods.alias_jd_obs_with_phase( obs_x, obs_y, model_start, model_end, t0, p) elif self.main_window.jd_radiobtn.isChecked(): if self.main_window.jdphs_combobox.currentText() == "Phase": n_x, n_y = methods.alias_phased_obs_with_jd( obs_x, obs_y, model_start, model_end, t0, p) elif self.main_window.jdphs_combobox.currentText() == "Time": n_x = obs_x n_y = obs_y return n_x, n_y def plot_selected_light_curve(self): selected_item = self.selected_light_item() if selected_item is not None: if self.light_treewidget.invisibleRootItem().indexOfChild( selected_item) == 1: return 0 self.light_chart.clear_all() lc_params = self.main_window.get_lc_params() model_start, model_end = self.main_window.get_lc_boundaries() x_index = None if self.main_window.jd_radiobtn.isChecked(): x_index = 0 elif self.main_window.phase_radiobtn.isChecked(): x_index = 1 y_index = None if self.main_window.maglite_combobox.currentText() == "Magnitude": y_index = 8 elif self.main_window.maglite_combobox.currentText() == "Flux": y_index = 4 lc_params.set_synthetic_curve( int(constants.BANDPASS_ID_DICT[ self.light_treewidget.itemWidget(selected_item, 1).text()]), self.light_treewidget.itemWidget(selected_item, 2).value(), # l1 self.light_treewidget.itemWidget(selected_item, 3).value(), # l2 self.light_treewidget.itemWidget(selected_item, 5).value(), # x1 self.light_treewidget.itemWidget(selected_item, 6).value(), # x2 self.light_treewidget.itemWidget(selected_item, 7).value(), # y1 self.light_treewidget.itemWidget(selected_item, 8).value(), # y2 self.light_treewidget.itemWidget(selected_item, 4).value(), # l3 self.light_treewidget.itemWidget(selected_item, 9).value(), # opsf self.light_treewidget.itemWidget(selected_item, 13).value(), # zero self.light_treewidget.itemWidget(selected_item, 12).value(), # factor 0.55, # wl, dummy self.light_treewidget.itemWidget(selected_item, 10).value(), # aextinc self.light_treewidget.itemWidget(selected_item, 11).value() # calib ) if self.light_plotobs_chk.isChecked( ) and selected_item.text(0) != "[Synthetic]": index = self.light_treewidget.invisibleRootItem().indexOfChild( selected_item) data = self.main_window.loadobservations_widget.light_curves[ index - 2].get_data() lc_obs = data[0], data[1] if self.light_alias_chk.isChecked(): try: lc_obs = self.alias(lc_obs, model_start, model_end) except ValueError as e: msg = messenger.Messenger("error", "A ValueError has occured:") msg.set_info(e.args[0]) msg.show() return 0 self.light_chart.plot(lc_obs[0], lc_obs[1], linestyle="", marker="o", markersize=constants.MARKER_SIZE, color=constants.COLOR_BLUE) if self.light_plotmodel_chk.isChecked(): lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_synthetic_light_curve().save().run( ).read_synthetic_light_curve() self.light_chart.plot(results[x_index], results[y_index], clear=False, color=constants.COLOR_RED) if self.light_plotobs_chk.isChecked() and self.light_plotmodel_chk.isChecked() and \ selected_item.text(0) != "[Synthetic]": residuals = methods.compute_residuals(lc_obs[0], lc_obs[1], results[x_index], results[y_index]) self.light_chart.plot(lc_obs[0], residuals, index=1, linestyle="", marker="o", markersize=constants.MARKER_SIZE, color=constants.COLOR_BLUE) self.light_chart.axes[1].axhline([0], color=constants.COLOR_RED) self.light_chart.redraw() x_label = "" y_label = self.main_window.maglite_combobox.currentText() if y_label == "Magnitude": self.light_chart.axes[0].invert_yaxis() self.light_chart.axes[1].invert_yaxis() if x_index == 0: x_label = "HJD" elif x_index == 1: x_label = "Phase" self.light_chart.set_labels("", y_label, index=0) self.light_chart.set_labels(x_label, "Residuals", index=1) def plot_selected_velocity_curve(self): self.velocity_chart.clear_all() lc_params = self.main_window.get_lc_params() model_start, model_end = self.main_window.get_lc_boundaries() x_index = None if self.main_window.jd_radiobtn.isChecked(): x_index = 0 elif self.main_window.phase_radiobtn.isChecked(): x_index = 1 lc_params.set_dummy_synthetic_curve() plot_vc1 = False plot_vc2 = False if self.vel_pri_radiobtn.isChecked(): plot_vc1 = True elif self.vel_sec_radiobtn.isChecked(): plot_vc2 = True if self.vel_both_radiobtn.isChecked(): plot_vc1 = True plot_vc2 = True if self.vel_plotobs_chk.isChecked(): if plot_vc1 and self.vel_pri_label.text() != "[Synthetic]": data = self.main_window.loadobservations_widget.velocity_curves[ 0].get_data() s1_obs = data[0], data[1] if self.vel_alias_chk.isChecked(): try: s1_obs = self.alias(s1_obs, model_start, model_end) except ValueError as e: msg = messenger.Messenger("error", "A ValueError has occured:") msg.set_info(e.args[0]) msg.show() return 0 self.velocity_chart.plot(s1_obs[0], s1_obs[1], linestyle="", marker="o", markersize=constants.MARKER_SIZE, color=constants.COLOR_BLUE) if plot_vc2 and self.vel_sec_label.text() != "[Synthetic]": data = self.main_window.loadobservations_widget.velocity_curves[ 1].get_data() s2_obs = data[0], data[1] if self.vel_alias_chk.isChecked(): try: s2_obs = self.alias(s2_obs, model_start, model_end) except ValueError as e: msg = messenger.Messenger("error", "A ValueError has occured:") msg.set_info(e.args[0]) msg.show() return 0 self.velocity_chart.plot(s2_obs[0], s2_obs[1], clear=False, linestyle="", marker="o", markersize=constants.MARKER_SIZE, color=constants.COLOR_GREEN) if self.vel_plotmodel_chk.isChecked(): lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_synthetic_velocity_curve().save().run( ).read_synthetic_velocity_curve() s1_index = 6 s2_index = 7 if plot_vc1: self.velocity_chart.plot(results[x_index], results[s1_index], clear=False, color=constants.COLOR_RED) s1_model = results[x_index], results[s1_index] if plot_vc2: self.velocity_chart.plot(results[x_index], results[s2_index], clear=False, color=constants.COLOR_ORANGE) s2_model = results[x_index], results[s2_index] if self.vel_plotobs_chk.isChecked( ) and self.vel_plotmodel_chk.isChecked(): if plot_vc1 and self.vel_pri_label.text() != "[Synthetic]": residuals = methods.compute_residuals(s1_obs[0], s1_obs[1], s1_model[0], s1_model[1]) self.velocity_chart.plot(s1_obs[0], residuals, index=1, linestyle="", marker="o", markersize=constants.MARKER_SIZE, color=constants.COLOR_BLUE) if plot_vc2 and self.vel_sec_label.text() != "[Synthetic]": residuals = methods.compute_residuals(s2_obs[0], s2_obs[1], s2_model[0], s2_model[1]) self.velocity_chart.plot(s2_obs[0], residuals, index=1, clear=False, linestyle="", marker="o", markersize=constants.MARKER_SIZE, color=constants.COLOR_GREEN) self.velocity_chart.axes[1].axhline([0], color=constants.COLOR_RED) self.velocity_chart.redraw() x_label = "" y_label = "Km/s" if x_index == 0: x_label = "HJD" elif x_index == 1: x_label = "Phase" self.velocity_chart.set_labels("", y_label, index=0) self.velocity_chart.set_labels(x_label, "Residuals", index=1) self.velocity_chart.axes[0].axhline( [self.main_window.vgamma_ipt.value()], color="black", linestyle="--") self.velocity_chart.redraw()
class Widget(QtWidgets.QWidget, dimensions_widget.Ui_DimensionWidget): def __init__(self, parent): super(Widget, self).__init__() self.setupUi(self) self.setWindowIcon(QtGui.QIcon(constants.MAIN_ICON_PATH)) self.main_window = parent self.s1_chart = MatplotlibWidget(self.s1_plot_widget, 1, 1) self.s2_chart = MatplotlibWidget(self.s2_plot_widget, 1, 1) self.s1_chart.create_axis(0, 0, name="Primary Star Dimensions", labels=("", "Fract. Radius")) self.s2_chart.create_axis(0, 0, name="Secondary Star Dimensions", labels=("", "Fract. Radius")) self.s1_pole = [] self.s1_point = [] self.s1_side = [] self.s1_back = [] self.s2_pole = [] self.s2_point = [] self.s2_side = [] self.s2_back = [] self.x = [] self.connect_signals() def connect_signals(self): self.plot_btn.clicked.connect(self.calculate_and_plot) self.s1_pole_chk.toggled.connect(self.update_plots) self.s1_point_chk.toggled.connect(self.update_plots) self.s1_side_chk.toggled.connect(self.update_plots) self.s1_back_chk.toggled.connect(self.update_plots) self.s2_pole_chk.toggled.connect(self.update_plots) self.s2_point_chk.toggled.connect(self.update_plots) self.s2_side_chk.toggled.connect(self.update_plots) self.s2_back_chk.toggled.connect(self.update_plots) def calculate_and_plot(self): self.calculate_component_radii() self.update_plots() def update_plots(self): self.s1_chart.clear_all() self.s2_chart.clear_all() if self.s1_pole_chk.isChecked(): self.s1_chart.plot(self.x, self.s1_pole, clear=False, color=constants.COLOR_BLUE) if self.s1_point_chk.isChecked(): self.s1_chart.plot(self.x, self.s1_point, clear=False, color="black") if self.s1_side_chk.isChecked(): self.s1_chart.plot(self.x, self.s1_side, clear=False, color=constants.COLOR_RED) if self.s1_back_chk.isChecked(): self.s1_chart.plot(self.x, self.s1_back, clear=False, color=constants.COLOR_GREEN) if self.s2_pole_chk.isChecked(): self.s2_chart.plot(self.x, self.s2_pole, clear=False, color=constants.COLOR_BLUE) if self.s2_point_chk.isChecked(): self.s2_chart.plot(self.x, self.s2_point, clear=False, color="black") if self.s2_side_chk.isChecked(): self.s2_chart.plot(self.x, self.s2_side, clear=False, color=constants.COLOR_RED) if self.s2_back_chk.isChecked(): self.s2_chart.plot(self.x, self.s2_back, clear=False, color=constants.COLOR_GREEN) def calculate_component_radii(self): lc_params = self.main_window.get_lc_params() lc_io = wd_io.LCIO(lc_params, wd_path=self.main_window.lc_path, lc_binary_name=self.main_window.lc_binary) results = lc_io.fill_for_component_dimensions().save().run( ).read_component_dimensions() x_index = None if self.main_window.jd_radiobtn.isChecked(): x_index = 0 self.s1_chart.set_labels("HJD", "Fract. Radius") self.s2_chart.set_labels("HJD", "Fract. Radius") elif self.main_window.phase_radiobtn.isChecked(): x_index = 1 self.s1_chart.set_labels("Phase", "Fract. Radius") self.s2_chart.set_labels("Phase", "Fract. Radius") self.x = results[x_index] self.s1_pole = results[2] self.s1_point = results[3] self.s1_side = results[4] self.s1_back = results[5] self.s2_pole = results[6] self.s2_point = results[7] self.s2_side = results[8] self.s2_back = results[9] self.update_plots() def clear(self): self.s1_chart.clear_all() self.s2_chart.clear_all() self.s1_pole = [] self.s1_point = [] self.s1_side = [] self.s1_back = [] self.s2_pole = [] self.s2_point = [] self.s2_side = [] self.s2_back = [] self.x = []