def get_pointing_matrix(self, header, npixels_per_sample=0, method=None, downsampling=False, section=None, comm=MPI.COMM_WORLD): # let's get the pointing matrix associated to the section if npixels_per_sample not in (0, self.info.npixels_per_sample): raise ValueError('The npixels_per_sample value is incompatible wi' \ 'th the MADMAP1 file.') npixels_per_sample = self.info.npixels_per_sample # if no slice is provided, return a pointing matrix for each of them if section is None: return super(MadMap1Observation, self).get_pointing_matrix(header, npixels_per_sample, method) if method is None: method = 'default' method = method.lower() if method != 'default': raise ValueError("Invalid pointing matrix method '" + method + "'.") header = gather_fitsheader_if_needed(header, comm=comm) shape_input = tuple(header['NAXIS' + str(i+1)] for i in range(header['NAXIS']))[::-1] if product(shape_input) > np.iinfo(np.int32).max: raise RuntimeError('The map is too large: pixel indices cannot be s' 'stored using 32 bits: {0}>{1}'.format(product(shape_input), np.iinfo(np.int32).max)) pointing = self.pointing[section.start:section.stop] ndetectors = self.get_ndetectors() nsamples = int(np.sum(~pointing.removed)) tod = np.empty((ndetectors, nsamples)) try: islice = list(self.slice.start).index(section.start) if self.slice[islice].stop != section.stop: raise ValueError() except ValueError: raise RuntimeError('Only observation slice can be specified through' ' the section keyword.') shape = (ndetectors, nsamples, npixels_per_sample) info = {'header' : header, 'method' : method, 'outside': False, 'npixels_per_sample_min': npixels_per_sample} try: pmatrix = PointingMatrix.empty(shape, shape_input, info=info, verbose=False) except MemoryError: gc.collect() pmatrix = PointingMatrix.empty(shape, shape_input, info=info, verbose=False) status = tmf.madmap1_read_tod(self.info.todfile, self.info.invnttfile, self.info.convert, npixels_per_sample, islice + 1, tod.T, pmatrix.ravel().view(np.int64)) if status != 0: raise RuntimeError() return pmatrix
def test_pack(): expected = PointingMatrix.empty((2, 4), (6, )) expected[0] = [(0, .25), (1, .25), (2, .25), (3, .25)] expected[1] = [(4, .50), (5, .50), (-1, 0), (-1, 0)] packed = matrix.copy() packed.pack(matrix.get_mask()) assert_equal(packed, expected) assert_equal(packed.shape_input, expected.shape_input)
def test_pack(): expected = PointingMatrix.empty((2, 4), (6,)) expected[0] = [(0, .25), (1, .25), (2, .25), (3, .25)] expected[1] = [(4, .50), (5, .50), (-1, 0), (-1, 0)] packed = matrix.copy() packed.pack(matrix.get_mask()) assert_equal(packed, expected) assert_equal(packed.shape_input, expected.shape_input)
def test_constructor(): shape = (2,) shape_input = (3, 4) array = np.zeros(shape, dtype=np.int64) def func(matrix): assert matrix.shape_input == shape_input assert matrix.value.shape == shape assert matrix.index.shape == shape for matrix in [PointingMatrix(array, shape_input, copy=False), PointingMatrix.empty(shape, shape_input), PointingMatrix.zeros(shape, shape_input)]: yield func, matrix
def test_constructor(): shape = (2, ) shape_input = (3, 4) array = np.zeros(shape, dtype=np.int64) def func(matrix): assert matrix.shape_input == shape_input assert matrix.value.shape == shape assert matrix.index.shape == shape for matrix in [ PointingMatrix(array, shape_input, copy=False), PointingMatrix.empty(shape, shape_input), PointingMatrix.zeros(shape, shape_input) ]: yield func, matrix
def get_pointing_matrix(self, header, npixels_per_sample=0, method=None, downsampling=False, section=None, comm=MPI.COMM_WORLD): # let's get the pointing matrix associated to the section if npixels_per_sample not in (0, self.info.npixels_per_sample): raise ValueError('The npixels_per_sample value is incompatible wi' \ 'th the MADMAP1 file.') npixels_per_sample = self.info.npixels_per_sample # if no slice is provided, return a pointing matrix for each of them if section is None: return super(MadMap1Observation, self).get_pointing_matrix(header, npixels_per_sample, method) if method is None: method = 'default' method = method.lower() if method != 'default': raise ValueError("Invalid pointing matrix method '" + method + "'.") header = gather_fitsheader_if_needed(header, comm=comm) shape_input = tuple(header['NAXIS' + str(i + 1)] for i in range(header['NAXIS']))[::-1] if product(shape_input) > np.iinfo(np.int32).max: raise RuntimeError( 'The map is too large: pixel indices cannot be s' 'stored using 32 bits: {0}>{1}'.format(product(shape_input), np.iinfo(np.int32).max)) pointing = self.pointing[section.start:section.stop] ndetectors = self.get_ndetectors() nsamples = int(np.sum(~pointing.removed)) tod = np.empty((ndetectors, nsamples)) try: islice = list(self.slice.start).index(section.start) if self.slice[islice].stop != section.stop: raise ValueError() except ValueError: raise RuntimeError( 'Only observation slice can be specified through' ' the section keyword.') shape = (ndetectors, nsamples, npixels_per_sample) info = { 'header': header, 'method': method, 'outside': False, 'npixels_per_sample_min': npixels_per_sample } try: pmatrix = PointingMatrix.empty(shape, shape_input, info=info, verbose=False) except MemoryError: gc.collect() pmatrix = PointingMatrix.empty(shape, shape_input, info=info, verbose=False) status = tmf.madmap1_read_tod(self.info.todfile, self.info.invnttfile, self.info.convert, npixels_per_sample, islice + 1, tod.T, pmatrix.ravel().view(np.int64)) if status != 0: raise RuntimeError() return pmatrix
PointingMatrix(array, shape_input, copy=False), PointingMatrix.empty(shape, shape_input), PointingMatrix.zeros(shape, shape_input) ]: yield func, matrix # we assume that the input map is 2x5 # ----------- # |0|1|2|3|4| # |-+-+-+-+-| # |5|6|7|8|9| # ----------- # The first sample intersects a quarter of 0, 1, 5 and 6 # and the second sample intersects half of 6 and 7. matrix = PointingMatrix.empty((2, 4), (2, 5)) matrix[0] = [(0, .25), (1, .25), (5, .25), (6, .25)] matrix[1] = [(7, .50), (8, .50), (-1, 0), (-1, 0)] def test_isvalid(): assert matrix.isvalid() invalid1 = matrix.copy() invalid1[0, 2] = (-2, 0) assert not invalid1.isvalid() invalid2 = matrix.copy() invalid2[0, 2] = (10, 0) assert not invalid2.isvalid()
for matrix in [PointingMatrix(array, shape_input, copy=False), PointingMatrix.empty(shape, shape_input), PointingMatrix.zeros(shape, shape_input)]: yield func, matrix # we assume that the input map is 2x5 # ----------- # |0|1|2|3|4| # |-+-+-+-+-| # |5|6|7|8|9| # ----------- # The first sample intersects a quarter of 0, 1, 5 and 6 # and the second sample intersects half of 6 and 7. matrix = PointingMatrix.empty((2, 4), (2, 5)) matrix[0] = [(0, .25), (1, .25), (5, .25), (6, .25)] matrix[1] = [(7, .50), (8, .50), (-1, 0), (-1, 0)] def test_isvalid(): assert matrix.isvalid() invalid1 = matrix.copy() invalid1[0, 2] = (-2, 0) assert not invalid1.isvalid() invalid2 = matrix.copy() invalid2[0, 2] = (10, 0) assert not invalid2.isvalid()