コード例 #1
0
ファイル: test_regrid_unit.py プロジェクト: saulecast/sherpa
def test_evaluation_space2d_overlaps(setup_overlapping_spaces):
    x1, y1, x2, y2, overlaps = setup_overlapping_spaces

    space_one = EvaluationSpace2D(x=x1[0], xhi=x1[1], y=y1[0], yhi=y1[1])
    space_two = EvaluationSpace2D(x=x2[0], xhi=x2[1], y=y2[0], yhi=y2[1])

    assert space_one.overlaps(space_two) is overlaps
コード例 #2
0
def test_evaluation_space2d_grid():
    xlo = [1, 2, 3]
    xhi = [2, 3, 4]
    ylo = [4, 5, 6]
    yhi = [5, 6, 7]

    expected_xlo, expected_ylo = [1, 2, 3, 1, 2, 3, 1, 2,
                                  3], [4, 4, 4, 5, 5, 5, 6, 6, 6]
    expected_xhi, expected_yhi = [2, 3, 4, 2, 3, 4, 2, 3,
                                  4], [5, 5, 5, 6, 6, 6, 7, 7, 7]

    eval_space = EvaluationSpace2D(x=xlo, xhi=xhi, y=ylo, yhi=yhi)

    np.testing.assert_array_equal(
        eval_space.grid,
        (expected_xlo, expected_ylo, expected_xhi, expected_yhi))
コード例 #3
0
 def __attrs_post_init__(self):
     self.data_space = EvaluationSpace2D(*self.image.get_indep(
         filter=False))
コード例 #4
0
    def fold(self, data):
        # FIXME how will we know the native dimensionality of the
        # raveled model without the values?
        kargs = {}

        kshape = None
        dshape = data.get_dims()

        (size, center, origin, kargs['norm'],
         radial) = (self.size, self.center, self.origin,
                    bool_cast(self.norm.val), int(self.radial.val))

        kargs['size'] = size
        kargs['center'] = center
        kargs['origin'] = origin
        kargs['is_model'] = False
        kargs['do_pad'] = False

        kargs['args'] = data.get_indep()

        pixel_size_comparison = self._check_pixel_size(data)

        if pixel_size_comparison == self.SAME_RESOLUTION:  # Don't do anything special
            self.data_space = EvaluationSpace2D(*data.get_indep())
            self._must_rebin = False
        elif pixel_size_comparison == self.BETTER_RESOLUTION:  # Evaluate model in PSF space
            self.data_space = EvaluationSpace2D(*data.get_indep())
            self.psf_space = PSFSpace2D(self.data_space, self, data.sky.cdelt)
            kargs['args'] = self.psf_space.grid
            dshape = self.psf_space.shape
            self._must_rebin = True
        else:  # PSF has worse resolution, error out
            raise AttributeError(
                "The PSF has a worse resolution than the data.")

        if isinstance(self.kernel, Data):

            kshape = self.kernel.get_dims()
            # (kargs['lo'], kargs['hi'],
            # kargs['width']) = _get_axis_info(self.kernel.get_indep(), kshape)

            kargs['lo'] = [1] * len(kshape)
            kargs['hi'] = kshape
            kargs['width'] = [1] * len(kshape)

            if center is None:
                kargs['center'] = [int(dim / 2.) for dim in kshape]
                # update center param to default
                self.center = kargs['center']

            if size is None:
                kargs['size'] = kshape
                # update size param to default
                self.size = kargs['size']

        else:
            if (self.kernel is None) or (not callable(self.kernel)):
                raise PSFErr('nopsf', self._name)
            kshape = data.get_dims()
            # (kargs['lo'], kargs['hi'],
            # kargs['width']) = _get_axis_info(kargs['args'], dshape)

            kargs['lo'] = [1] * len(kshape)
            kargs['hi'] = kshape
            kargs['width'] = [1] * len(kshape)

            if center is None:
                kargs['center'] = [int(dim / 2.) for dim in dshape]
                # update center param to default
                self.center = kargs['center']

            if size is None:
                kargs['size'] = dshape
                # update size param to default
                self.size = kargs['size']

            kargs['is_model'] = True
            if hasattr(self.kernel, 'pars'):
                # freeze all PSF model parameters if not already.
                for par in self.kernel.pars:
                    par.freeze()

            if hasattr(self.kernel, 'thawedpars'):
                kargs['frozen'] = (len(self.kernel.thawedpars) == 0)

        is_kernel = (kargs['is_model'] and not kargs['norm']
                     and len(kshape) == 1)
        # Handle noticed regions for convolution
        if numpy.iterable(data.mask):
            kargs['do_pad'] = True
            kargs['pad_mask'] = data.mask

        if is_kernel:
            for id in ['is_model', 'lo', 'hi', 'width', 'size']:
                kargs.pop(id)
            self.model = Kernel(dshape, kshape, **kargs)
            return

        if radial:
            self.model = RadialProfileKernel(dshape, kshape, **kargs)
            return

        self.model = PSFKernel(dshape, kshape, **kargs)
        return
コード例 #5
0
def test_evaluation_space2d_is_integrated(xlo, xhi, ylo, yhi, is_integrated):
    assert EvaluationSpace2D(x=xlo, xhi=xhi, y=ylo, yhi=yhi).is_integrated\
           is is_integrated
コード例 #6
0
def test_evaluation_space2d_empty_no_args():
    assert EvaluationSpace2D().is_empty
コード例 #7
0
def test_evaluation_space2d_empty(x, y):
    assert EvaluationSpace2D(x=x, y=y).is_empty
コード例 #8
0
def test_evaluation_space2d_start_end(xlo, xhi, ylo, yhi):
    assert EvaluationSpace2D(x=xlo, xhi=xhi, y=ylo, yhi=yhi).start == (1, 1)
    assert EvaluationSpace2D(x=xlo, xhi=xhi, y=ylo, yhi=yhi).end == (3, 3)
コード例 #9
0
def test_evaluation_space2d_is_ascending_error():
    with pytest.raises(ValueError):
        EvaluationSpace2D(x=None, xhi=None, y=None, yhi=None).is_ascending
コード例 #10
0
def test_evaluation_space2d_is_ascending(xlo, xhi, ylo, yhi, is_ascending):
    assert EvaluationSpace2D(x=xlo, xhi=xhi, y=ylo, yhi=yhi).is_ascending \
           == is_ascending
コード例 #11
0
 def regrid(self, *args, **kwargs):
     eval_space = EvaluationSpace2D(*args)
     regridder = ModelDomainRegridder2D(eval_space)
     return regridder.apply_to(self)