コード例 #1
0
ファイル: test_core.py プロジェクト: weaverba137/astropy
def test_print_special_operator_CompoundModel(capsys):
    """
    Test that issue #11310 has been fixed
    """

    model = convolve_models(models.Sersic2D(), models.Gaussian2D())
    print(model)

    true_out = "Model: CompoundModel\n" +\
               "Inputs: ('x', 'y')\n" +\
               "Outputs: ('z',)\n" +\
               "Model set size: 1\n" +\
               "Expression: convolve_fft (([0]), ([1]))\n" +\
               "Components: \n" +\
               "    [0]: <Sersic2D(amplitude=1., r_eff=1., n=4., x_0=0., y_0=0., ellip=0., theta=0.)>\n" +\
               "\n" +\
               "    [1]: <Gaussian2D(amplitude=1., x_mean=0., y_mean=0., x_stddev=1., y_stddev=1., theta=0.)>\n" +\
               "Parameters:\n" +\
               "    amplitude_0 r_eff_0 n_0 x_0_0 y_0_0 ... y_mean_1 x_stddev_1 y_stddev_1 theta_1\n" +\
               "    ----------- ------- --- ----- ----- ... -------- ---------- ---------- -------\n" +\
               "            1.0     1.0 4.0   0.0   0.0 ...      0.0        1.0        1.0     0.0\n"

    out, err = capsys.readouterr()
    assert err == ''
    assert out == true_out
コード例 #2
0
def test_print_special_operator_CompoundModel(capsys):
    """
    Test that issue #11310 has been fixed
    """

    model = convolve_models(models.Sersic2D(), models.Gaussian2D())
    with astropy.conf.set_temp('max_width', 80):
        assert str(model) == "Model: CompoundModel\n" +\
                             "Inputs: ('x', 'y')\n" +\
                             "Outputs: ('z',)\n" +\
                             "Model set size: 1\n" +\
                             "Expression: convolve_fft (([0]), ([1]))\n" +\
                             "Components: \n" +\
                             "    [0]: <Sersic2D(amplitude=1., r_eff=1., n=4., x_0=0., y_0=0., ellip=0., theta=0.)>\n" +\
                             "\n" +\
                             "    [1]: <Gaussian2D(amplitude=1., x_mean=0., y_mean=0., x_stddev=1., y_stddev=1., theta=0.)>\n" +\
                             "Parameters:\n" +\
                             "    amplitude_0 r_eff_0 n_0 x_0_0 y_0_0 ... y_mean_1 x_stddev_1 y_stddev_1 theta_1\n" +\
                             "    ----------- ------- --- ----- ----- ... -------- ---------- ---------- -------\n" +\
                             "            1.0     1.0 4.0   0.0   0.0 ...      0.0        1.0        1.0     0.0"
コード例 #3
0
        def _chisq_xys(p,
                       image,
                       psfmodel,
                       psffreeparams,
                       params_range,
                       model_maxlim=np.inf,
                       neg_penal=1.,
                       galmodel=None,
                       galconvpsf=False,
                       largechisq=1.e10):
            """ calculate chisq. Return inf if psfmodel max is larter than model_maxlim. """
            # organize params and params_range
            psfparams_dict = dict(zip(psffreeparams, p[0:len(psffreeparams)]))
            if galmodel is None:
                params_dict = psfparams_dict
            else:
                params_dict = dict(
                    zip(psffreeparams + list(galmodel.param_names), p))
                galmodel.parameters = np.array(p[len(psffreeparams):])
                for key in galmodel.bounds:
                    if key not in params_range:
                        params_range.update({key: galmodel.bounds[key]})
            if not _params_in_range(params_dict, params_range):
                return largechisq

            # transform psf
            psfmodel_new = self._get_shifted_scaled_smoothed_resampled_model(
                psfmodel, **psfparams_dict)
            assert psfmodel_new.pixsize == image.pixsize

            # evaluate galaxy model
            if galmodel is None:
                modeldata = psfmodel_new.data
            else:
                if galconvpsf:  # convolve the 2d gaussian bestfit to psf
                    if 'background' in params_dict:
                        background = params_dict['background']
                    else:
                        background = 0.
                    try:
                        psf_normed = psfmodel_new.data - background
                        psf_normed = psf_normed / psf_normed.max()
                        gaussmodel = self._get_bestfit_gaussian_model(
                            psf_normed, boxsize=16)
                        galmodel_conv = ac.convolve_models(
                            galmodel,
                            gaussmodel,
                            normalize_kernel=True,
                            normalization_zero_tol=1e-8)
                        galdata = self._evaluate_model(galmodel_conv)
                    except:
                        print(
                            'Convolving galaxy with gaussian PSF failed, substituting PSF with default profile. '
                        )
                        gaussmodel = am.models.Gaussian2D(amplitude=1.,
                                                          x_mean=0.,
                                                          y_mean=0.,
                                                          x_stddev=1.,
                                                          y_stddev=1.,
                                                          theta=0.)
                        galmodel_conv = ac.convolve_models(
                            galmodel,
                            gaussmodel,
                            normalize_kernel=True,
                            normalization_zero_tol=1e-8)
                        galdata = self._evaluate_model(galmodel_conv)

                else:
                    galdata = self._evaluate_model(galmodel)
                modeldata = psfmodel_new.data + galdata

            chisq = _calc_chisq(imgdata=image.data,
                                modeldata=modeldata,
                                model_maxlim=model_maxlim,
                                neg_penal=neg_penal)
            return chisq