Пример #1
0
    def __init__(self, flags, values, description=None):
        self._description = description
        if isscalarlike(flags):
            if isinstance(flags, str):
                flags = flags.split(',')
            else:
                flags = [flags]
        flags = [_.strip() for _ in flags]
        if isscalarlike(values):
            if isinstance(values, str):
                values = values.split(',')
            else:
                values = [values]
        values = [_.strip().lower() for _ in values]
        if len(flags) != len(values):
            raise ValueError('The number of policy flags is different from the'
                             ' number of policies.')

        self._policy = []
        for flag, value in zip(flags, values):
            if flag[0] == '_':
                raise ValueError('A policy flag should not start with an under'
                                 'score.')
            choices = 'keep', 'mask', 'remove'
            if value not in choices:
                raise KeyError('Invalid policy {}={!r}. Expected values are {}'
                               '.'.format(flag, value, strenum(choices)))
            setattr(self, flag, value)
        self._flags = flags
Пример #2
0
    def __init__(self, shape, topixel=None, to1d=None, origin='upper',
                 startswith1=False, **keywords):
        """
        Parameters
        ----------
        shape : tuple of integers
            The surface shape.
        startswith1 : bool
            If True, columns and row starts with 1 instead of 0.
        topixel : Operator, optional
            World-to-pixel coordinate transform.
        to1d : Operator, optional
            Nd-to-1d pixel index transform.

        """
        origins = 'upper', 'lower'
        if not isinstance(origin, str):
            raise TypeError('Invalid origin.')
        origin = origin.lower()
        if origin not in origins:
            raise ValueError(
                'Invalid origin {0!r}. Expected values are {1}.'.format(
                    origin, strenum(origins)))
        Scene.__init__(self, shape, topixel=topixel, **keywords)
        if self.ndim != 2:
            raise ValueError('The scene is not 2-dimensional.')
        self.origin = origin
        self.startswith1 = bool(startswith1)
        if to1d is not None:
            to1d = asoperator(to1d)
            self.toNd = to1d.I
        else:
            self.toNd = None
        self.to1d = to1d
Пример #3
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)
Пример #4
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)
Пример #5
0
    def __init__(self,
                 nside,
                 kind='I',
                 nest=False,
                 convention='zenith,azimuth',
                 **keywords):
        """
        nside : int
            Value of the map resolution parameter.
        kind : 'I', 'QU' or 'IQU'
            The kind of sky: intensity-only, Q and U Stokes parameters only or
            intensity, Q and U.
        nest : boolean, optional
            For the nested numbering scheme, set it to True. Default is
            the ring scheme.
        convention : string, optional
            Convention used by the 'topixel' operator to convert spherical
            coordinates into Healpix pixel numbers. It can be:
            'zenith,azimuth', 'azimuth,zenith', 'elevation,azimuth' and
            'azimuth,elevation'.

        """
        kinds = 'I', 'QU', 'IQU'
        if not isinstance(kind, str):
            raise TypeError(
                'Invalid type {0!r} for the scene kind. Expected type is strin'
                'g.'.format(type(kind).__name__))
        kind = kind.upper()
        if kind not in kinds:
            raise ValueError('Invalid scene kind {0!r}. Expected kinds are: {1'
                             '}.'.format(kind, strenum(kinds)))
        nside = int(nside)
        topixel = Spherical2HealpixOperator(nside, convention, nest)
        shape = (12 * nside**2, )
        if kind != 'I':
            shape += (len(kind), )
        Scene.__init__(self, shape, topixel, ndim=1, **keywords)
        self.nside = nside
        self.npixel = 12 * nside**2
        self.kind = kind
        self.convention = convention
        self.nest = bool(nest)
        self.solid_angle = 4 * np.pi / self.npixel
Пример #6
0
    def __init__(self, nside, kind='I', nest=False,
                 convention='zenith,azimuth', **keywords):
        """
        nside : int
            Value of the map resolution parameter.
        kind : 'I', 'QU' or 'IQU'
            The kind of sky: intensity-only, Q and U Stokes parameters only or
            intensity, Q and U.
        nest : boolean, optional
            For the nested numbering scheme, set it to True. Default is
            the ring scheme.
        convention : string, optional
            Convention used by the 'topixel' operator to convert spherical
            coordinates into Healpix pixel numbers. It can be:
            'zenith,azimuth', 'azimuth,zenith', 'elevation,azimuth' and
            'azimuth,elevation'.

        """
        kinds = 'I', 'QU', 'IQU'
        if not isinstance(kind, str):
            raise TypeError(
                'Invalid type {0!r} for the scene kind. Expected type is strin'
                'g.'.format(type(kind).__name__))
        kind = kind.upper()
        if kind not in kinds:
            raise ValueError('Invalid scene kind {0!r}. Expected kinds are: {1'
                             '}.'.format(kind, strenum(kinds)))
        nside = int(nside)
        topixel = Spherical2HealpixOperator(nside, convention, nest)
        shape = (12 * nside**2,)
        if kind != 'I':
            shape += (len(kind),)
        Scene.__init__(self, shape, topixel, ndim=1, **keywords)
        self.nside = nside
        self.npixel = 12 * nside**2
        self.kind = kind
        self.convention = convention
        self.nest = bool(nest)
        self.solid_angle = 4 * np.pi / self.npixel
Пример #7
0
    def __init__(self, name=None, calibration=None,
                 band=150,
                 detector_sigma=10, detector_fknee=0, detector_fslope=1,
                 detector_ncorr=10, detector_tau=0.01,
                 synthbeam_dtype=np.float32, synthbeam_fraction=0.99,
                 ngrids=2, nside=256, **keywords):
        """
        Parameters
        ----------
        name : str
            Deprecated.
        calibration : QubicCalibration
            The calibration tree.
        band : int or numpy array of two elements
            Frequensies of light in GHz for two focal planes
        detector_tau : array-like
            The detector time constants in seconds.
        detector_sigma : array-like
            The standard deviation of the detector white noise component.
        detector_fknee : array-like
            The detector 1/f knee frequency in Hertz.
        detector_fslope : array-like
            The detector 1/f slope index.
        detector_ncorr : int
            The detector 1/f correlation length.
        nside : int, optional
            Deprecated.
        synthbeam_dtype : dtype, optional
            The data type for the synthetic beams (default: float32).
            It is the dtype used to store the values of the pointing matrix.
        synthbeam_fraction: float, optional
            The fraction of significant peaks retained for the computation
            of the synthetic beam.
        ngrids : int, optional
            Number of detector grids.

        """
        if name is not None:
            skind = ", kind='I'" if 'nopol' in name else ''
            snside = ', nside={0}'.format(nside) if nside is not None else ''
            warn('Please update your code:\nacq = QubicAcquisition(150, sam'
                 'pling{0}{1})\n'.format(skind, snside),
                 QubicDeprecationWarning)
            name = name.replace(' ', '').lower()
            names = 'monochromatic', 'monochromatic,qu', 'monochromatic,nopol'
            if name not in names:
                raise ValueError(
                    "The only modes implemented are {0}.".format(
                        strenum(names, 'and')))
            self._init_deprecated_sky(name, band, nside)

        if calibration is None:
            calibration = QubicCalibration()
        self.calibration = calibration
        layout = self._get_detector_layout(
            ngrids, detector_sigma, detector_fknee, detector_fslope,
            detector_ncorr, detector_tau)
        Instrument.__init__(self, 'QUBIC', layout)
        self._init_primary_beam()
        self._init_optics(**keywords)
        self._init_horns()
        self._init_synthetic_beam(synthbeam_dtype, synthbeam_fraction)
Пример #8
0
def test_strenum():
    assert_eq(strenum(["blue", "red", "yellow"], "or"), "'blue', 'red' or 'yellow'")
Пример #9
0
def test_strenum():
    assert_eq(strenum(['blue', 'red', 'yellow'], 'or'),
              "'blue', 'red' or 'yellow'")