示例#1
0
    def optimization_actions(self):

        print("Optimizing...")
        self.statusBar.showMessage('Optimizing...')

        lpar_new, spar_new = ff.optimize_pars(self.xi1, self.xi2,
                                              self.lgals.ravel(), self.lpar,
                                              self.spar)

        g_limage, g_source, mua, yi1, yi2 = ll.lensed_images(
            self.xi1, self.xi2, lpar_new, spar_new)

        self.slider_re.setValue(round(lpar_new[2] / re_max * nbins))
        self.slider_x1.setValue(round((lpar_new[0] - x1_min) / dpl))
        self.slider_x2.setValue(round((lpar_new[1] - x2_min) / dpl))
        self.slider_ql.setValue(round(lpar_new[4] / ql_max * nbins))
        self.slider_la.setValue(round(lpar_new[5] / la_max * nbins))

        self.slider_rh.setValue(round(spar_new[2] / rh_max * nbins))
        self.slider_y1.setValue(round((spar_new[0] - y1_min) / dps))
        self.slider_y2.setValue(round((spar_new[1] - y2_min) / dps))
        self.slider_qs.setValue(round(spar_new[4] / qs_max * nbins))
        self.slider_sa.setValue(round(spar_new[5] / sa_max * nbins))

        print("Done.")
        self.statusBar.showMessage('Done')

        data_pars = {
            "name": "black",
            "url":
            "http://raw.githubusercontent.com/linan7788626/linan7788626.github.io/master/images/black.png",
            "source": {
                "size": spar_new[2],
                "x": spar_new[0],
                "y": spar_new[1],
                "ell": spar_new[4],
                "ang": spar_new[5]
            },
            "lens": {
                "theta_e": lpar_new[2],
                "x": lpar_new[0],
                "y": lpar_new[1],
                "ell": lpar_new[4],
                "ang": lpar_new[5],
            }
        }

        # Writing JSON data
        f_out_pars = "./josn_outputs/" + data_pars['name'] + '.json'
        with open(f_out_pars, 'w') as f:
            json.dump(data_pars, f)

        # # Reading data back
        # with open(f_out_pars, 'r') as f:
        # data = json.load(f)

        self.statusBar.showMessage('Parameters are saved to %s' % f_out_pars)
示例#2
0
    def on_draw(self):
        """ Redraws the figure
        """

        l_xcen = self.slider_x1.value(
        ) * dpl + x1_min  # x position of center (also try (0.0,0.14)
        l_ycen = self.slider_x2.value() * dpl + x2_min  # y position of center
        l_re = self.slider_re.value(
        ) * re_max / nbins  # Einstein radius of lens.
        l_rc = 0.0  # Core size of lens (in units of Einstein radius).
        l_axrat = self.slider_ql.value(
        ) * ql_max / nbins  # Axis ratio of lens.
        l_pa = self.slider_la.value() * la_max / nbins  # Orintation of lens.

        self.lpar = np.asarray([l_xcen, l_ycen, l_re, l_rc, l_axrat, l_pa])
        #----------------------------------------------------------------------
        g_amp = 1.0  # peak brightness value
        g_sig = self.slider_rh.value(
        ) * rh_max / nbins  # Gaussian "sigma" (i.e., size)
        g_xcen = self.slider_y1.value(
        ) * dps + y1_min  # x position of center (also try (0.0,0.14)
        g_ycen = self.slider_y2.value() * dps + y2_min  # y position of center
        g_axrat = self.slider_qs.value(
        ) * qs_max / nbins  # minor-to-major axis ratio
        g_pa = self.slider_sa.value(
        ) * sa_max / nbins  # major-axis position angle (degrees) c.c.w. from x axis

        self.spar = np.asarray([g_xcen, g_ycen, g_sig, g_amp, g_axrat, g_pa])

        #----------------------------------------------------------------------
        self.g_limage, self.g_source, mua, yi1, yi2 = ll.lensed_images(
            self.xi1, self.xi2, self.lpar, self.spar)
        # self.img_limg.setImage(self.g_limage)
        # self.img_gsrc.setImage(self.g_source)

        g_limg_ctr = self.half_ctr(self.g_limage)
        g_gsrc_ctr = self.half_ctr(self.g_source)

        self.img_limg.setImage(g_limg_ctr)
        self.img_gsrc.setImage(g_gsrc_ctr)
示例#3
0
    def optimization_actions(self):
        print "Optimizing..."
        lpar_new, spar_new = ff.optimize_pars(self.xi1, self.xi2,
                                              self.lgals.ravel(), self.lpar,
                                              self.spar)

        g_limage, g_source, mua, yi1, yi2 = ll.lensed_images(
            self.xi1, self.xi2, lpar_new, spar_new)
        print "Done."

        self.slider_re.setValue(round(lpar_new[2] / re_max * nbins))
        self.slider_x1.setValue(round((lpar_new[0] - x1_min) / dpl))
        self.slider_x2.setValue(round((lpar_new[1] - x2_min) / dpl))
        self.slider_ql.setValue(round(lpar_new[4] / ql_max * nbins))
        self.slider_la.setValue(round(lpar_new[5] / la_max * nbins))

        self.slider_rh.setValue(round(spar_new[2] / rh_max * nbins))
        self.slider_y1.setValue(round((spar_new[0] - y1_min) / dps))
        self.slider_y2.setValue(round((spar_new[1] - y2_min) / dps))
        self.slider_qs.setValue(round(spar_new[4] / qs_max * nbins))
        self.slider_sa.setValue(round(spar_new[5] / sa_max * nbins))

        levels = [
            0.5,
        ]
        levels_imgs = [0.0, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5]
        self.axesa.clear()
        self.axesa.set_xlim(y1_min, y1_max)
        self.axesa.set_ylim(y2_min, y2_max)
        self.axesa.set_xticks(
            [ybc1 - 0.4, ybc1 - 0.2, ybc1, ybc1 + 0.2, ybc1 + 0.4])
        self.axesa.set_yticks(
            [ybc2 - 0.4, ybc2 - 0.2, ybc2, ybc2 + 0.2, ybc2 + 0.4])
        # self.axesa.contourf(self.xi1,self.xi2,self.sgals,levels_imgs,cmap=pl.cm.gray)
        self.axesa.contour(self.xi1,
                           self.xi2,
                           g_source,
                           levels,
                           colors=('deepskyblue'))
        self.axesa.contour(yi1, yi2, mua, 0, colors=('r'), linewidths=2.0)

        self.axesb.clear()
        self.axesb.set_xlim(x1_min, x1_max)
        self.axesb.set_ylim(x2_min, x2_max)
        self.axesb.set_xticks(
            [xbc1 - 2.0, xbc1 - 1.0, xbc1, xbc1 + 1.0, xbc1 + 2.0])
        self.axesb.set_yticks(
            [xbc2 - 2.0, xbc2 - 1.0, xbc2, xbc2 + 1.0, xbc2 + 2.0])
        self.axesb.contourf(self.xi1,
                            self.xi2,
                            self.lgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesb.contour(self.xi1,
                           self.xi2,
                           g_limage,
                           levels,
                           colors=('deepskyblue'))
        self.axesb.contour(self.xi1,
                           self.xi2,
                           mua,
                           colors=('r'),
                           linewidths=2.0)

        self.canvas.draw()

        print "opt----", spar_new
示例#4
0
    def on_draw(self):
        """ Redraws the figure
        """

        l_xcen = self.slider_x1.value(
        ) * dpl + x1_min  # x position of center (also try (0.0,0.14)
        l_ycen = self.slider_x2.value() * dpl + x2_min  # y position of center
        l_re = self.slider_re.value(
        ) * re_max / nbins  # Einstein radius of lens.
        l_rc = 0.0  # Core size of lens (in units of Einstein radius).
        l_axrat = self.slider_ql.value(
        ) * ql_max / nbins  # Axis ratio of lens.
        l_pa = self.slider_la.value() * la_max / nbins  # Orintation of lens.

        self.lpar = np.asarray([l_xcen, l_ycen, l_re, l_rc, l_axrat, l_pa])
        #----------------------------------------------------------------------
        g_amp = 1.0  # peak brightness value
        g_sig = self.slider_rh.value(
        ) * rh_max / nbins  # Gaussian "sigma" (i.e., size)
        g_xcen = self.slider_y1.value(
        ) * dps + y1_min  # x position of center (also try (0.0,0.14)
        g_ycen = self.slider_y2.value() * dps + y2_min  # y position of center
        g_axrat = self.slider_qs.value(
        ) * qs_max / nbins  # minor-to-major axis ratio
        g_pa = self.slider_sa.value(
        ) * sa_max / nbins  # major-axis position angle (degrees) c.c.w. from x axis

        self.spar = np.asarray([g_xcen, g_ycen, g_sig, g_amp, g_axrat, g_pa])

        #----------------------------------------------------------------------
        g_limage, g_source, mua, yi1, yi2 = ll.lensed_images(
            self.xi1, self.xi2, self.lpar, self.spar)
        #--------------------------lens images contour------------------------

        levels = [
            0.5,
        ]
        levels_imgs = [0.0, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5]

        self.axesa.clear()
        self.axesa.set_xlim(y1_min, y1_max)
        self.axesa.set_ylim(y2_min, y2_max)
        self.axesa.set_xticks(
            [ybc1 - 0.4, ybc1 - 0.2, ybc1, ybc1 + 0.2, ybc1 + 0.4])
        self.axesa.set_yticks(
            [ybc2 - 0.4, ybc2 - 0.2, ybc2, ybc2 + 0.2, ybc2 + 0.4])
        self.axesa.contourf(self.xi1,
                            self.xi2,
                            self.sgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesa.contour(self.xi1,
                           self.xi2,
                           g_source,
                           levels,
                           colors=('deepskyblue'))
        self.axesa.contour(yi1, yi2, mua, 0, colors=('r'), linewidths=2.0)

        self.axesb.clear()
        self.axesb.set_xlim(x1_min, x1_max)
        self.axesb.set_ylim(x2_min, x2_max)
        self.axesb.set_xticks([xbc1 - 2, xbc1 - 1, xbc1, xbc1 + 1, xbc1 + 2])
        self.axesb.set_yticks([xbc2 - 2, xbc2 - 1, xbc2, xbc2 + 1, xbc2 + 2])
        self.axesb.contourf(self.xi1,
                            self.xi2,
                            self.lgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesb.contour(self.xi1,
                           self.xi2,
                           g_limage,
                           levels,
                           colors=('deepskyblue'))
        self.axesb.contour(self.xi1,
                           self.xi2,
                           mua,
                           colors=('r'),
                           linewidths=2.0)

        self.canvas.draw()
示例#5
0
    def optimization_actions(self):
        print "Optimizing..."
        lpar_new, spar_new = ff.optimize_pars(self.xi1, self.xi2,
                                              self.lgals.ravel(), self.lpar,
                                              self.spar)

        g_limage, g_source, mua, yi1, yi2 = ll.lensed_images(
            self.xi1, self.xi2, lpar_new, spar_new)
        print "Done."

        self.slider_re.setValue(round(lpar_new[2] / 2.0 * nbins))
        self.slider_x1.setValue(
            round((lpar_new[0] + self.bsz / 2.0 - self.bsz / nbins / 2.0) /
                  self.bsz * nbins))
        self.slider_x2.setValue(
            round((lpar_new[1] + self.bsz / 2.0 - self.bsz / nbins / 2.0) /
                  self.bsz * nbins))
        self.slider_ql.setValue(round(lpar_new[4] * nbins))
        self.slider_la.setValue(round(lpar_new[5] / 360.0 * nbins))

        self.slider_rh.setValue(round(spar_new[2] / 0.5 * nbins))
        self.slider_y1.setValue(
            round((spar_new[0] + self.bsz / 8.0 - self.bsz / nbins / 8.0) /
                  (self.bsz / 4.0) * nbins))
        self.slider_y2.setValue(
            round((spar_new[1] + self.bsz / 8.0 - self.bsz / nbins / 8.0) /
                  (self.bsz / 4.0) * nbins))
        self.slider_qs.setValue(round(spar_new[4] * nbins))
        self.slider_sa.setValue(round(spar_new[5] / 360.0 * nbins))

        levels = [
            0.5,
        ]
        levels_imgs = [0.0, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5]
        self.axesa.clear()
        # pl.xticks([-2.0, 1.0, 0.0, 1.0, 2.0])
        # pl.yticks([-2.0, 1.0, 0.0, 1.0, 2.0])
        self.axesa.set_xlim(-self.bsz / 8.0, self.bsz / 8.0)
        self.axesa.set_ylim(-self.bsz / 8.0, self.bsz / 8.0)
        self.axesa.contourf(self.xi1,
                            self.xi2,
                            self.sgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesa.contour(self.xi1,
                           self.xi2,
                           g_source,
                           levels,
                           colors=('deepskyblue'))
        self.axesa.contour(yi1, yi2, mua, 0, colors=('g'), linewidths=2.0)

        self.axesb.clear()
        # pl.xticks([-0.2,-0.1,0.0,0.1,0.2])
        # pl.yticks([-0.2,-0.1,0.0,0.1,0.2])
        self.axesb.set_xlim(-self.bsz / 2.0, self.bsz / 2.0)
        self.axesb.set_ylim(-self.bsz / 2.0, self.bsz / 2.0)
        self.axesb.contourf(self.xi1,
                            self.xi2,
                            self.lgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesb.contour(self.xi1,
                           self.xi2,
                           g_limage,
                           levels,
                           colors=('deepskyblue'))
        self.axesb.contour(self.xi1,
                           self.xi2,
                           mua,
                           colors=('r'),
                           linewidths=2.0)

        self.canvas.draw()

        print "opt----", spar_new
示例#6
0
    def on_draw(self):
        """ Redraws the figure
        """

        l_xcen = self.slider_x1.value(
        ) * self.bsz / nbins - self.bsz / 2.0 + self.bsz / nbins / 2.0  # x position of center (also try (0.0,0.14)
        l_ycen = self.slider_x2.value(
        ) * self.bsz / nbins - self.bsz / 2.0 + self.bsz / nbins / 2.0  # y position of center
        l_re = self.slider_re.value() * 2.0 / nbins  # Einstein radius of lens.
        l_rc = 0.0  # Core size of lens (in units of Einstein radius).
        l_axrat = self.slider_ql.value() * 1.0 / nbins  # Axis ratio of lens.
        l_pa = self.slider_la.value() * 360.0 / nbins  # Orintation of lens.

        self.lpar = np.asarray([l_xcen, l_ycen, l_re, l_rc, l_axrat, l_pa])
        #----------------------------------------------------------------------
        g_amp = 1.0  # peak brightness value
        g_sig = self.slider_rh.value(
        ) * 0.5 / nbins  # Gaussian "sigma" (i.e., size)
        g_xcen = self.slider_y1.value(
        ) * self.bsz / 4.0 / nbins - self.bsz / 8.0 + self.bsz / nbins / 8.0  # x position of center (also try (0.0,0.14)
        g_ycen = self.slider_y2.value(
        ) * self.bsz / 4.0 / nbins - self.bsz / 8.0 + self.bsz / nbins / 8.0  # y position of center
        g_axrat = self.slider_qs.value(
        ) * 1.0 / nbins  # minor-to-major axis ratio
        g_pa = self.slider_sa.value(
        ) * 360.0 / nbins  # major-axis position angle (degrees) c.c.w. from x axis

        self.spar = np.asarray([g_xcen, g_ycen, g_sig, g_amp, g_axrat, g_pa])

        print "plot***", self.spar
        #----------------------------------------------------------------------
        g_limage, g_source, mua, yi1, yi2 = ll.lensed_images(
            self.xi1, self.xi2, self.lpar, self.spar)
        #--------------------------lens images contour------------------------

        levels = [
            0.5,
        ]
        levels_imgs = [0.0, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5]

        self.axesa.clear()
        self.axesa.set_xlim(-self.bsz / 8.0, self.bsz / 8.0)
        self.axesa.set_ylim(-self.bsz / 8.0, self.bsz / 8.0)
        self.axesa.set_xticks([-0.4, -0.2, 0.0, 0.2, 0.4])
        self.axesa.set_yticks([-0.4, -0.2, 0.0, 0.2, 0.4])
        self.axesa.contourf(self.xi1,
                            self.xi2,
                            self.sgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesa.contour(self.xi1,
                           self.xi2,
                           g_source,
                           levels,
                           colors=('deepskyblue'))
        self.axesa.contour(yi1, yi2, mua, 0, colors=('r'), linewidths=2.0)

        self.axesb.clear()
        # pl.xticks([-2.0, -1.0, 0.0, 1.0, 2.0])
        # pl.yticks([-2.0, -1.0, 0.0, 1.0, 2.0])
        self.axesb.set_xlim(-self.bsz / 2.0, self.bsz / 2.0)
        self.axesb.set_ylim(-self.bsz / 2.0, self.bsz / 2.0)
        self.axesb.contourf(self.xi1,
                            self.xi2,
                            self.lgals,
                            levels_imgs,
                            cmap=pl.cm.gray)
        self.axesb.contour(self.xi1,
                           self.xi2,
                           g_limage,
                           levels,
                           colors=('deepskyblue'))
        self.axesb.contour(self.xi1,
                           self.xi2,
                           mua,
                           colors=('r'),
                           linewidths=2.0)

        self.canvas.draw()

        self.slider_label_re.setText("Re: %.2f" % self.lpar[2])