def get_operator(self): op = np.array(self._get_array_of_operators()) op_sum = [] for band in self.bands: op_sum.append(op[(self.nus > band[0]) * (self.nus < band[1])].sum(axis=0)) return BlockRowOperator(op_sum, new_axisin=0)
def get_subtract_grids_operator(self): """ Return operator to subtract signal from detector pairs. """ nd = len(self.instrument) if nd % 2 != 0: raise ValueError('Odd number of detectors.') partitionin = 2 * (len(self.instrument) // 2, ) return BlockRowOperator([I, -I], axisin=0, partitionin=partitionin)
def test_block_row2(): p = np.matrix([[1, 0], [0, 2], [1, 0]]) o = asoperator(np.matrix(p)) r = BlockRowOperator([o, 2 * o], axisin=0) assert_eq(r.todense(), np.hstack([p, 2 * p])) assert_eq(r.T.todense(), r.todense().T) r = BlockRowOperator([o, 2 * o], new_axisin=0) assert_eq(r.todense(), np.hstack([p, 2 * p])) assert_eq(r.T.todense(), r.todense().T)
def get_operator_to_make_TOD(self): ''' Return a BlockRowOperator of subacquisition operators In polychromatic mode it is only applied to produce the TOD To reconstruct maps one should use the get_operator function ''' if len(self) == 1: return self.get_operator() op = self._get_array_of_operators() return BlockRowOperator(op, new_axisin=0)
def test_block_row2(): p = np.matrix([[1, 0], [0, 2], [1, 0]]) o = asoperator(np.matrix(p)) r = BlockRowOperator([o, 2*o], axisin=0) assert_eq(r.todense(), np.hstack([p, 2*p])) assert_eq(r.T.todense(), r.todense().T) r = BlockRowOperator([o, 2*o], new_axisin=0) assert_eq(r.todense(), np.hstack([p, 2*p])) assert_eq(r.T.todense(), r.todense().T)
def tod2map(self, tod, d, cov=None): tol = d['tol'] maxiter = d['maxiter'] verbose = d['verbose'] p = self.planck H = [] for q, w in zip(self.qubic, self.weights): H.append(QubicPlanckAcquisition(q, p).get_operator() * w) H = np.array(H) H = [H[(self.qubic.nus > mi) * (self.qubic.nus < ma)].sum() * \ self.weights[(self.qubic.nus > mi) * (self.qubic.nus < ma)].sum() \ for (mi, ma) in self.qubic.bands] invntt = self.get_invntt_operator() A_columns = [] for h1 in H: c = [] for h2 in H: c.append(h2.T * invntt * h1) A_columns.append(BlockColumnOperator(c, axisout=0)) A = BlockRowOperator(A_columns, axisin=0) H = [h.T for h in H] b = BlockColumnOperator(H, new_axisout=0) * (invntt * tod) sh = b.shape if (len(self.qubic.nus) - 1) > 1: # If number of subbands is more than one if len(sh) == 3: b = b.reshape((sh[0] * sh[1], sh[2])) else: b = b.reshape((sh[0], sh[1])) preconditioner = self.get_preconditioner(cov) solution = pcg(A, b, M=preconditioner, disp=verbose, tol=tol, maxiter=maxiter) # solution = pcg(A, b, disp=verbose, tol=tol, maxiter=maxiter) if len(sh) == 3: maps_recon = solution['x'].reshape(sh[0], sh[1], sh[2]) else: maps_recon = solution['x'].reshape(sh[0], sh[1]) return maps_recon
def get_filter_operator(self): return BlockRowOperator([ self._get_filter_operator(bandwidth) for bandwidth in self.filter.bandwidth ], new_axisin=0)