예제 #1
0
    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 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)
예제 #3
0
    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 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_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 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)