def check_config(self): if os.path.isfile(constants.PYWD_CONFIG_PATH): try: config = ConfigParser() config.read(constants.PYWD_CONFIG_PATH) lc_path = config.get("wd_paths", "lc_path") dc_path = config.get("wd_paths", "dc_path") if os.path.isfile(lc_path) and os.path.isfile(dc_path): self.lcpath_label.setText(lc_path) self.dcpath_label.setText(dc_path) return True else: msg = messenger.Messenger( "warning", "Paths from the existing pywd_config file are not valid." ) msg.set_info("Please reselect wd binary paths.") msg.show() return self.exec_() except NoOptionError as ex: msg = messenger.Messenger( "error", "A NoOptionError occured during config file read.") msg.set_info( "Config file is malformed. Please reselect wd binary paths.\nAdditional info:\n" + ex.args[0]) msg.show() return self.exec_() else: return self.exec_()
def load_timings(self, filepath): try: data = numpy.loadtxt(filepath, unpack=True) if 1 > len(data): raise IndexError("File has less than 2 columns.") except ValueError as e: msg = messenger.Messenger("error", "A ValueError has occured:") msg.set_info(e.args[0] + "\nEclipse times are not loaded.") msg.show() return False except IndexError as e: msg = messenger.Messenger("error", "An IndexError has occured:") msg.set_info(e.args[0] + "\nEclipse times are not loaded.") msg.show() return False self.datawidget.clear() for row_idx in range(len(data[0])): item = QtWidgets.QTreeWidgetItem(self.datawidget) for col_idx in range(len(data)): item.setText(col_idx, str(data[col_idx][row_idx])) self.filepath_label.setText(filepath)
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 populate_data_from_filepath(self, filepath): try: data = numpy.loadtxt(filepath, unpack=True) if 1 > len(data): raise IndexError("File has less than 2 columns.") except ValueError as e: msg = messenger.Messenger("error", "A ValueError has occured:") msg.set_info(e.args[0]) msg.show() return False except IndexError as e: msg = messenger.Messenger("error", "An IndexError has occured:") msg.set_info(e.args[0]) msg.show() return False self.clear_widgets() self.filepath_label.setText(filepath) self.filepath_label.setToolTip(filepath) header_item = QtWidgets.QTreeWidgetItem() for col_idx in range(len(data)): col_name = "Column " + str(col_idx) header_item.setText(col_idx, col_name) self.time_combobox.addItem(col_name) self.obs_combobox.addItem(col_name) self.weight_combobox.addItem(col_name) self.data_widget.setHeaderItem(header_item) self.weight_combobox.addItem("Constant (1.0)") for row_idx in range(len(data[0])): item = QtWidgets.QTreeWidgetItem(self.data_widget) for col_idx in range(len(data)): item.setText(col_idx, str(data[col_idx][row_idx])) self.data_widget.header().setSectionResizeMode(3) return True
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 save_spots(self): save_path = methods.save_file( self, suffix=".pywdspot", name_filter="PyWD2015 spot file (*.pywdspot)") if save_path is not None: parser = self.write_into_parser(ConfigParser()) with open(save_path, "w") as destination: parser.write(destination) msg = messenger.Messenger("info", "Save completed:") msg.set_info(save_path) msg.show()
def load_spots(self): load_path = methods.load_file( self, suffix=".pywdspot", name_filter="PyWD2015 spot file (*.pywdspot);;" "PyWD2015 project file (*.pywdproject)") if load_path is not None: parser = ConfigParser() with open(load_path, "r") as source: parser.read_file(source) self.read_from_parser(parser) msg = messenger.Messenger("info", "Load completed:") msg.set_info(load_path) msg.show()
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 save(self): error = "" if os.path.isfile(self.lcpath_label.text()) is not True: error = "Can't find LC file in path:\n" + self.lcpath_label.text() if os.path.isfile(self.dcpath_label.text()) is not True: error = error + "\nCan't DC find file in path:\n" + self.dcpath_label.text( ) if error == "": config = ConfigParser() config.add_section("wd_paths") config.set("wd_paths", "lc_path", self.lcpath_label.text()) config.set("wd_paths", "dc_path", self.dcpath_label.text()) with open(constants.PYWD_CONFIG_PATH, "w") as f: config.write(f) self.accept() else: msg = messenger.Messenger("error", "Error(s) occured:") msg.set_info(error) msg.show()
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()
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)