Пример #1
0
 def __init__(self, axis, **keywords):
     self.axis = axis
     if self.axis < 0:
         self.slice = [Ellipsis] + (-self.axis) * [slice(None)]
     else:
         self.slice = (self.axis+1) * [slice(None)] + [Ellipsis]
     Operator.__init__(self, **keywords)
Пример #2
0
    def __init__(self, fwhm=None, sigma=None, iter=3, lmax=None,
                 mmax=None, use_weights=False, datapath=None, dtype=float,
                 pol=True, **keywords):
        """
        Keywords are passed to the Healpy function smoothing.

        """
        if fwhm is None and sigma is None:
            raise ValueError('The convolution width is not specified.')
        if fwhm is not None and sigma is not None:
            raise ValueError('Ambiguous convolution width specification.')
        if fwhm is not None and fwhm < 0 or sigma is not None and sigma < 0:
            raise ValueError('The convolution width is not positive.')
        if fwhm in (0, None) and sigma in (0, None):
            self.__class__ = IdentityOperator
            self.__init__(**keywords)
            return
        if fwhm is None:
            fwhm = sigma * np.sqrt(8 * np.log(2))
        if sigma is None:
            sigma = fwhm / np.sqrt(8 * np.log(2))
        self.fwhm = fwhm
        self.sigma = sigma
        self.iter = iter
        self.lmax = lmax
        self.mmax = mmax
        self.use_weights = use_weights
        self.datapath = datapath
        self.pol = pol
        Operator.__init__(self, dtype=dtype, **keywords)
Пример #3
0
 def __init__(self, shapein=3, shapeout=4, **keywords):
     Operator.__init__(self,
                       shapein=shapein,
                       shapeout=shapeout,
                       classout=ndarray1,
                       attrout=attr1,
                       **keywords)
Пример #4
0
 def __init__(self, axis, **keywords):
     self.axis = axis
     if self.axis < 0:
         self.slice = [Ellipsis] + (-self.axis) * [slice(None)]
     else:
         self.slice = (self.axis + 1) * [slice(None)] + [Ellipsis]
     Operator.__init__(self, **keywords)
Пример #5
0
 def __init__(self, size, fftw_flags=['measure', 'unaligned'], **keywords):
     size = int(size)
     array1 = np.empty(size, dtype=var.FLOAT_DTYPE)
     array2 = np.empty(size, dtype=var.FLOAT_DTYPE)
     fplan = fftw3.Plan(array1, array2, direction='forward', flags= \
         fftw_flags, realtypes=['halfcomplex r2c'], nthreads=1)
     bplan = fftw3.Plan(array1, array2, direction='backward', flags=\
         fftw_flags, realtypes=['halfcomplex c2r'], nthreads=1)
     ifplan = fftw3.Plan(array1,
                         direction='forward',
                         flags=fftw_flags,
                         realtypes=['halfcomplex r2c'],
                         nthreads=1)
     ibplan = fftw3.Plan(array1,
                         direction='backward',
                         flags=fftw_flags,
                         realtypes=['halfcomplex c2r'],
                         nthreads=1)
     self.size = size
     self.fftw_flags = fftw_flags
     self.fplan = fplan
     self.bplan = bplan
     self.ifplan = ifplan
     self.ibplan = ibplan
     Operator.__init__(self, **keywords)
Пример #6
0
 def __init__(self, factor, **keywords):
     if factor == 1:
         self.__class__ = IdentityOperator
         self.__init__(**keywords)
         return
     self.factor = int(factor)
     keywords['dtype'] = float
     Operator.__init__(self, **keywords)
Пример #7
0
 def __init__(self, mask, **keywords):
     mask = np.array(mask, np.bool8, copy=False)
     Operator.__init__(self, shapein=mask.shape, shapeout=np.sum(mask == 0),
                       dtype=var.FLOAT_DTYPE, **keywords)
     self.mask = mask
     self.set_rule('.T', lambda s: UnpackOperator(s.mask))
     self.set_rule('.{UnpackOperator}', self._rule_left_unpack, CompositionOperator)
     self.set_rule('{UnpackOperator}.', self._rule_right_unpack, CompositionOperator)
Пример #8
0
 def __init__(self, factor, **keywords):
     if factor == 1:
         self.__class__ = IdentityOperator
         self.__init__(**keywords)
         return
     self.factor = int(factor)
     keywords['dtype'] = float
     Operator.__init__(self, **keywords)
Пример #9
0
 def __init__(self, mask, **keywords):
     mask = np.array(mask, np.bool8, copy=False)
     Operator.__init__(self,
                       shapein=np.sum(mask == 0),
                       shapeout=mask.shape,
                       dtype=var.FLOAT_DTYPE,
                       **keywords)
     self.mask = mask
     self.set_rule('.T', lambda s: PackOperator(s.mask))
Пример #10
0
 def __init__(self, tau, **keywords):
     """
     """
     if hasattr(tau, 'SI'):
         tau = tau.SI
         if tau.unit != '':
             raise ValueError('The time constant must be dimensionless.')
     self.tau = np.array(tau, dtype=var.FLOAT_DTYPE, ndmin=1)
     Operator.__init__(self, **keywords)
Пример #11
0
 def __init__(self, tau, **keywords):
     """
     """
     if hasattr(tau, 'SI'):
         tau = tau.SI
         if tau.unit != '':
             raise ValueError('The time constant must be dimensionless.')
     self.tau = np.array(tau, dtype=var.FLOAT_DTYPE, ndmin=1)
     Operator.__init__(self, **keywords)
Пример #12
0
 def __init__(self):
     Operator.__init__(self)
     self.set_rule('T', '.')
     self.set_rule('C', '1')
     self.set_rule('.,T', '.', CompositionOperator)
     self.set_rule('T,.', '.', CompositionOperator)
     self.set_rule('.,C', '.I', AdditionOperator)
     self.set_rule('H,.', '.I', AdditionOperator)
     self.set_rule('.,C', '.I', MultiplicationOperator)
     self.set_rule('H,.', '.I', MultiplicationOperator)
Пример #13
0
 def __init__(self, left=0, right=0., **keywords):
     left = int(left)
     right = int(right)
     if left < 0:
         raise ValueError('Left padding is not positive.')
     if right < 0:
         raise ValueError('Right padding is not positive.')
     self.left = left
     self.right = right
     Operator.__init__(self, **keywords)
Пример #14
0
 def __init__(self, axis=-1, scalar=1., **keywords):
     if scalar == 0:
         self.__class__ = ZeroOperator
         self.__init__(flags='square', **keywords)
         return
     Operator.__init__(self, dtype=var.FLOAT_DTYPE, **keywords)
     self.axis = axis
     self.scalar = scalar
     self.set_rule('{HomothetyOperator}.', lambda o,s: DdTddOperator(
                   self.axis, o.data * s.scalar), CompositionOperator)
Пример #15
0
 def __init__(self, mask, operator=MPI.SUM, commin=MPI.COMM_WORLD,
              **keywords):
     commout = commin
     shapeout = mask.size - int(np.sum(mask))
     shapein = distribute_shape(mask.shape, comm=commin)
     Operator.__init__(self, shapein=shapein, shapeout=shapeout,
                       commin=commin, commout=commout, **keywords)
     self.mask = mask
     self.chunk_size = product(mask.shape[1:])
     self.operator = operator
Пример #16
0
 def __init__(self, n, axis=None, **keywords):
     Operator.__init__(self, dtype=var.FLOAT_DTYPE, **keywords)
     if axis is None:
         axis = -1 if isscalar(n) else range(-len(n), 0)
     self.axis = (axis,) if isscalar(axis) else tuple(axis)
     self.n = (n,) * len(self.axis) if isscalar(n) else \
              tuple([np.array(m,int) for m in n])
     if len(self.axis) != len(self.n):
         raise ValueError('There is a mismatch between the number of axes an'
                          'd offsets.')
Пример #17
0
 def __init__(self, left=0, right=0., **keywords):
     left = int(left)
     right = int(right)
     if left < 0:
         raise ValueError('Left padding is not positive.')
     if right < 0:
         raise ValueError('Right padding is not positive.')
     self.left = left
     self.right = right
     Operator.__init__(self, **keywords)        
Пример #18
0
 def __init__(self, axis=-1, scalar=1., **keywords):
     if scalar == 0:
         self.__class__ = ZeroOperator
         self.__init__(flags='square', **keywords)
         return
     Operator.__init__(self, dtype=var.FLOAT_DTYPE, **keywords)
     self.axis = axis
     self.scalar = scalar
     self.set_rule('{HomothetyOperator}.',
                   lambda o, s: DdTddOperator(self.axis, o.data * s.scalar),
                   CompositionOperator)
Пример #19
0
 def __init__(self, n, axis=None, **keywords):
     Operator.__init__(self, dtype=var.FLOAT_DTYPE, **keywords)
     if axis is None:
         axis = -1 if isscalar(n) else range(-len(n), 0)
     self.axis = (axis, ) if isscalar(axis) else tuple(axis)
     self.n = (n,) * len(self.axis) if isscalar(n) else \
              tuple([np.array(m,int) for m in n])
     if len(self.axis) != len(self.n):
         raise ValueError(
             'There is a mismatch between the number of axes an'
             'd offsets.')
Пример #20
0
 def __init__(self, nside, convention, nest=False, dtype=float, **keywords):
     if not isinstance(convention, str):
         raise TypeError("The input convention '{0}' is not a string.".
                         format(convention))
     convention_ = convention.replace(' ', '').lower()
     if convention_ not in self.CONVENTIONS:
         raise ValueError(
             "Invalid spherical convention '{0}'. Expected values are {1}.".
             format(convention, strenum(self.CONVENTIONS)))
     self.nside = int(nside)
     self.convention = convention_
     self.nest = bool(nest)
     Operator.__init__(self, dtype=dtype, **keywords)
Пример #21
0
 def __init__(self, mask, **keywords):
     mask = np.array(mask, np.bool8, copy=False)
     Operator.__init__(self,
                       shapein=mask.shape,
                       shapeout=np.sum(mask == 0),
                       dtype=var.FLOAT_DTYPE,
                       **keywords)
     self.mask = mask
     self.set_rule('.T', lambda s: UnpackOperator(s.mask))
     self.set_rule('.{UnpackOperator}', self._rule_left_unpack,
                   CompositionOperator)
     self.set_rule('{UnpackOperator}.', self._rule_right_unpack,
                   CompositionOperator)
Пример #22
0
 def __init__(self, nside, convention, nest=False, dtype=float, **keywords):
     if not isinstance(convention, str):
         raise TypeError(
             "The input convention '{0}' is not a string.".format(
                 convention))
     convention_ = convention.replace(' ', '').lower()
     if convention_ not in self.CONVENTIONS:
         raise ValueError(
             "Invalid spherical convention '{0}'. Expected values are {1}.".
             format(convention, strenum(self.CONVENTIONS)))
     self.nside = int(nside)
     self.convention = convention_
     self.nest = bool(nest)
     Operator.__init__(self, dtype=dtype, **keywords)
Пример #23
0
    def __init__(self, wcs, **keywords):
        """
        wcs : FITS header or Kapteyn wcs.Projection instance
            Representation of the world coordinate system

        """
        import kapteyn.wcs as kwcs
        if isinstance(wcs, pyfits.Header):
            wcs = kwcs.Projection(wcs)
        if 'dtype' not in keywords:
            keywords['dtype'] = float
        wcs.allow_invalid = True
        Operator.__init__(self, **keywords)
        self.wcs = wcs
Пример #24
0
 def __init__(self, fft_filter, ncorrelations, nsamples,
              fftw_flags=['measure', 'unaligned']):
     filter_length = fft_filter.shape[-1]
     array = np.empty(filter_length, dtype=var.FLOAT_DTYPE)
     self.fft_filter = fft_filter
     self.filter_length = filter_length
     self.left = ncorrelations
     self.right = filter_length - nsamples - ncorrelations
     self.fftw_flags = fftw_flags
     self.fplan = fftw3.Plan(array, direction='forward', flags=fftw_flags,
         realtypes=['halfcomplex r2c'], nthreads=1)
     self.bplan = fftw3.Plan(array, direction='backward', flags=fftw_flags,
         realtypes=['halfcomplex c2r'], nthreads=1)
     Operator.__init__(self, shapein=(fft_filter.shape[0], nsamples))
Пример #25
0
    def __init__(self, wcs, **keywords):
        """
        wcs : FITS header or Kapteyn wcs.Projection instance
            Representation of the world coordinate system

        """
        import kapteyn.wcs as kwcs
        if isinstance(wcs, pyfits.Header):
            wcs = kwcs.Projection(wcs)
        if 'dtype' not in keywords:
            keywords['dtype'] = float
        wcs.allow_invalid = True
        Operator.__init__(self, **keywords)
        self.wcs = wcs
Пример #26
0
    def __init__(self, wcs, origin=0, **keywords):
        """
        wcs : FITS header or astropy.wcs.WCS instance
            Representation of the world coordinate system
        origin : int, optional
            Indexing convention : 0 for 0-based indexing such as C or numpy),
            1 for FITS or Fortran 1-based indexing.

        """
        if not isinstance(wcs, astropy.wcs.WCS):
            wcs = astropy.wcs.WCS(wcs)
        if 'dtype' not in keywords:
            keywords['dtype'] = float
        Operator.__init__(self, **keywords)
        self.wcs = wcs
        self.origin = origin
Пример #27
0
    def __init__(self, wcs, origin=0, **keywords):
        """
        wcs : FITS header or astropy.wcs.WCS instance
            Representation of the world coordinate system
        origin : int, optional
            Indexing convention : 0 for 0-based indexing such as C or numpy),
            1 for FITS or Fortran 1-based indexing.

        """
        if not isinstance(wcs, astropy.wcs.WCS):
            wcs = astropy.wcs.WCS(wcs)
        if 'dtype' not in keywords:
            keywords['dtype'] = float
        Operator.__init__(self, **keywords)
        self.wcs = wcs
        self.origin = origin
Пример #28
0
    def __init__(self, xin, xout, **keywords):
        xin = np.asarray(xin)
        xout = np.asarray(xout)
        if xin.shape[-1] != 2:
            raise ValueError('The shape of the object plane coordinates should'
                             ' be (npoints,ndims), where ndims is only impleme'
                             'nted for 2.')
        if xin.shape != xout.shape:
            raise ValueError('The object and image coordinates do not have the'
                             ' same shape.')

        keywords['dtype'] = float
        Operator.__init__(self, **keywords)
        self.interp0 = interp.CloughTocher2DInterpolator(xin, xout[..., 0])
        self.interp1 = interp.CloughTocher2DInterpolator(xin, xout[..., 1])
        self.set_rule('I', lambda s: DistortionOperator(xout, xin))
Пример #29
0
    def __init__(self, xin, xout, **keywords):
        xin = np.asarray(xin)
        xout = np.asarray(xout)
        if xin.shape[-1] != 2:
            raise ValueError('The shape of the object plane coordinates should'
                             ' be (npoints,ndims), where ndims is only impleme'
                             'nted for 2.')
        if xin.shape != xout.shape:
            raise ValueError('The object and image coordinates do not have the'
                             ' same shape.')

        keywords['dtype'] = float
        Operator.__init__(self, **keywords)
        self.interp0 = interp.CloughTocher2DInterpolator(xin, xout[..., 0])
        self.interp1 = interp.CloughTocher2DInterpolator(xin, xout[..., 1])
        self.set_rule('I', lambda s: DistortionOperator(xout, xin))
Пример #30
0
 def __init__(self,
              mask,
              operator=MPI.SUM,
              commin=MPI.COMM_WORLD,
              **keywords):
     commout = commin
     shapeout = mask.size - int(np.sum(mask))
     shapein = distribute_shape(mask.shape, comm=commin)
     Operator.__init__(self,
                       shapein=shapein,
                       shapeout=shapeout,
                       commin=commin,
                       commout=commout,
                       **keywords)
     self.mask = mask
     self.chunk_size = product(mask.shape[1:])
     self.operator = operator
Пример #31
0
 def __init__(self, size, fftw_flags=['measure', 'unaligned'], **keywords):
     size = int(size)
     array1 = np.empty(size, dtype=var.FLOAT_DTYPE)
     array2 = np.empty(size, dtype=var.FLOAT_DTYPE)
     fplan = fftw3.Plan(array1, array2, direction='forward', flags= \
         fftw_flags, realtypes=['halfcomplex r2c'], nthreads=1)
     bplan = fftw3.Plan(array1, array2, direction='backward', flags=\
         fftw_flags, realtypes=['halfcomplex c2r'], nthreads=1)
     ifplan = fftw3.Plan(array1, direction='forward', flags=fftw_flags,
         realtypes=['halfcomplex r2c'], nthreads=1)
     ibplan = fftw3.Plan(array1, direction='backward', flags=fftw_flags,
         realtypes=['halfcomplex c2r'], nthreads=1)
     self.size = size
     self.fftw_flags = fftw_flags
     self.fplan = fplan
     self.bplan = bplan
     self.ifplan = ifplan
     self.ibplan = ibplan
     Operator.__init__(self, **keywords)
Пример #32
0
    def __init__(self,
                 fwhm=None,
                 sigma=None,
                 iter=3,
                 lmax=None,
                 mmax=None,
                 use_weights=False,
                 datapath=None,
                 dtype=float,
                 pol=True,
                 **keywords):
        """
        Keywords are passed to the Healpy function smoothing.

        """
        if fwhm is None and sigma is None:
            raise ValueError('The convolution width is not specified.')
        if fwhm is not None and sigma is not None:
            raise ValueError('Ambiguous convolution width specification.')
        if fwhm is not None and fwhm < 0 or sigma is not None and sigma < 0:
            raise ValueError('The convolution width is not positive.')
        if fwhm in (0, None) and sigma in (0, None):
            self.__class__ = IdentityOperator
            self.__init__(**keywords)
            return
        if fwhm is None:
            fwhm = sigma * np.sqrt(8 * np.log(2))
        if sigma is None:
            sigma = fwhm / np.sqrt(8 * np.log(2))
        self.fwhm = fwhm
        self.sigma = sigma
        self.iter = iter
        self.lmax = lmax
        self.mmax = mmax
        self.use_weights = use_weights
        self.datapath = datapath
        self.pol = pol
        Operator.__init__(self, dtype=dtype, **keywords)
Пример #33
0
 def __init__(self,
              fft_filter,
              ncorrelations,
              nsamples,
              fftw_flags=['measure', 'unaligned']):
     filter_length = fft_filter.shape[-1]
     array = np.empty(filter_length, dtype=var.FLOAT_DTYPE)
     self.fft_filter = fft_filter
     self.filter_length = filter_length
     self.left = ncorrelations
     self.right = filter_length - nsamples - ncorrelations
     self.fftw_flags = fftw_flags
     self.fplan = fftw3.Plan(array,
                             direction='forward',
                             flags=fftw_flags,
                             realtypes=['halfcomplex r2c'],
                             nthreads=1)
     self.bplan = fftw3.Plan(array,
                             direction='backward',
                             flags=fftw_flags,
                             realtypes=['halfcomplex c2r'],
                             nthreads=1)
     Operator.__init__(self, shapein=(fft_filter.shape[0], nsamples))
Пример #34
0
 def __init__(self, pointing, **keywords):
     if any(k not in pointing.dtype.names for k in ('ra', 'dec', 'pa')):
         raise TypeError('The input is not an equatorial pointing.')
     self.pointing = pointing
     Operator.__init__(self, **keywords)
Пример #35
0
 def __init__(self, arg1, value, arg3, mykey=None, **keywords):
     Operator.__init__(self, **keywords)
     self.arg1 = arg1
     self.value = value
     self.arg3 = arg3
     self.mykey = mykey
Пример #36
0
 def __init__(self, **keywords):
     Operator.__init__(self, classout=ndarray1, attrout=attr1, **keywords)
Пример #37
0
 def __init__(self, i, **keywords):
     self.i = i
     Operator.__init__(self, dtype=np.array(mat).dtype, **keywords)
Пример #38
0
 def __init__(self, i, **keywords):
     self.i = i
     Operator.__init__(self, dtype=np.array(mat).dtype, **keywords)
Пример #39
0
 def __init__(self, value=3., **keywords):
     self.value = np.array(value)
     Operator.__init__(self, **keywords)
     self.set_rule(('.', HomothetyOperator), lambda s, o:
                   AbsorbRightOperator(s.value * o.data),
                   CompositionOperator)
Пример #40
0
 def __init__(self, **keywords):
     Operator.__init__(self, classout=ndarray1, attrout=attr1, **keywords)
Пример #41
0
 def __init__(self, nside, nest=False, dtype=float, **keywords):
     self.nside = int(nside)
     self.nest = bool(nest)
     Operator.__init__(self, dtype=dtype, **keywords)
Пример #42
0
 def __init__(self, value=3., **keywords):
     self.value = np.array(value)
     Operator.__init__(self, **keywords)
     self.set_rule((HomothetyOperator, '.'), lambda o, s:
                   AbsorbLeftOperator(s.value * o.data),
                   CompositionOperator)
Пример #43
0
 def __init__(self, value, **keywords):
     Operator.__init__(self, **keywords)
     self.value = value
Пример #44
0
 def __init__(self, axis=-1, **keywords):
     Operator.__init__(self, dtype=var.FLOAT_DTYPE, **keywords)
     self.axis = axis
     self.set_rule('.T.', self._rule_ddtdd, CompositionOperator)
Пример #45
0
 def __init__(self, nside, nest=False, dtype=float, **keywords):
     self.nside = int(nside)
     self.nest = bool(nest)
     Operator.__init__(self, dtype=dtype, **keywords)
Пример #46
0
 def __init__(self, axis=-1, **keywords):
     Operator.__init__(self, dtype=var.FLOAT_DTYPE, **keywords)
     self.axis = axis
     self.set_rule('.T.', self._rule_ddtdd, CompositionOperator)
Пример #47
0
 def __init__(self, x):
     Operator.__init__(self, dtype=float)
     self.x = x
Пример #48
0
 def __init__(self, mask, **keywords):
     mask = np.array(mask, np.bool8, copy=False)
     Operator.__init__(self, shapein=np.sum(mask == 0), shapeout=mask.shape,
                       dtype=var.FLOAT_DTYPE, **keywords)
     self.mask = mask
     self.set_rule('.T', lambda s: PackOperator(s.mask))
Пример #49
0
 def __init__(self, value, **keywords):
     Operator.__init__(self, **keywords)
     self.value = value
Пример #50
0
 def __init__(self, pointing, **keywords):
     if any(k not in pointing.dtype.names for k in ('ra', 'dec', 'pa')):
         raise TypeError('The input is not an equatorial pointing.')
     self.pointing = pointing
     Operator.__init__(self, **keywords)
Пример #51
0
 def __init__(self, x):
     Operator.__init__(self, dtype=float)
     self.x = x
Пример #52
0
 def __init__(self, arg1, value, arg3, mykey=None, **keywords):
     Operator.__init__(self, **keywords)
     self.arg1 = arg1
     self.value = value
     self.arg3 = arg3
     self.mykey = mykey
Пример #53
0
 def __init__(self, shapein=3, **keywords):
     Operator.__init__(self, shapein=shapein, classout=ndarray1,
                       attrout=attr1, **keywords)