def index2tes(FPindex, FPidentity=None): """Return ASIC and TES numbers (instrument numbering) from the FPindex coming from q.detector.index""" if FPidentity is None: FPidentity = make_id_focalplane() TES = int(FPidentity.TES[FPidentity.index == FPindex]) ASIC = int(FPidentity.ASIC[FPidentity.index == FPindex]) return ASIC, TES
def get_all_tes_numbers(q): """Return a 2D array with ASIC and TES numbers ordered as in Qubic soft.""" FPidentity = make_id_focalplane() ndet = q.detector.index.shape[0] tes = np.zeros((ndet, 2), dtype=int) for i in range(ndet): FPindex = q.detector.index[i] tes[i, 0], tes[i, 1] = index2tes(FPindex, FPidentity) return tes
def tes_signal2image_fp(tes_signal, asics): """ tes_signal : array of shape (128, #ASICS) Signal on each TES, for each ASIC. asics : list Indices of the asics used between 1 and 8. """ thermos = [4, 36, 68, 100] image_fp = np.empty((34, 34)) image_fp[:] = np.nan FPidentity = make_id_focalplane() for ASIC in asics: for TES in range(128): if TES + 1 not in thermos: index = tes2index(TES + 1, ASIC) image_fp[index // 34, index % 34] = tes_signal[TES, ASIC - 1] return image_fp
def _init_id(self, ident_focalplane, num, asic=None): """ Generates focal plane identifications from user input Parameter: num: is the detector or pixel number. asic: ASIC number if ident_focalplane = TESName and num has to be the tes number. """ if ident_focalplane == 'FileName': self.npix = num self.tes, self.asic = (self.npix, 1) if (self.npix < 128) else (self.npix - 128, 2) self.qpix = tes2pix(self.tes, self.asic) - 1 elif ident_focalplane == 'qsName': FPidentity = make_id_focalplane() self.qpix = num det_index = self.instrument.detector[self.qpix].index[0] self.tes = FPidentity[det_index].TES self.asic = FPidentity[det_index].ASIC self.npix = self.tes if self.asic == 1 else self.tes + 128 elif ident_focalplane == 'TESName': if num > 128: raise ValueError( "Wrong TES value. You gave a TES number greater than 128.") else: if asic == None: raise ValueError( "You choose {} identification but ASIC number is missing." .format(ident_focalplane)) else: self.tes = num self.asic = asic self.npix = self.tes if self.asic == 1 else self.tes + 128 self.qpix = tes2pix(self.tes, self.asic) - 1 if self.verbose: print("You are running fitting in healpix maps.") print("========================================") print("TES number {} asic number {}".format(self.tes, self.asic)) print("In FileName format the number of tes is {}".format( self.npix)) print("Index number: qpack {} qsoft {} ".format(\ tes2index(self.tes, self.asic), self.instrument.detector[self.qpix].index[0] )) print("qubicsoft number: {}".format(self.qpix)) return
def get_real_fp(full_fp, quadrant=None): """ Return the real focal plane, one pixel for each TES. Parameters ---------- full_fp : 2D array of shape (34, 34) Image of the focal plane. quadrant : int If you only want one quadrant of the focal plane, you can choose one in [1, 2, 3, 4] Returns ------- full_real_fp : full fp (34x34) quart_fp : one quadrant (17x17) """ if np.shape(full_fp) != (34, 34): raise ValueError('The focal plane shape should be (34, 34).') else: FPidentity = make_id_focalplane() tes = np.reshape(FPidentity.TES, (34, 34)) # The rotation is needed to be in the ONAFP frame quad = np.rot90(np.reshape(FPidentity.quadrant, (34, 34)), k=-1, axes=(0, 1)) # Put the pixels that are not TES to NAN full_real_fp = np.where(tes == 0, np.nan, full_fp) if quadrant is None: return full_real_fp else: if quadrant not in [1, 2, 3, 4]: raise ValueError('quadrant must be 1, 2, 3 or 4') else: # Get only one quadrant quart = full_real_fp[ np.where(quad != quadrant, 6, full_real_fp) != 6] quart_fp = np.reshape(quart, (17, 17)) return full_real_fp, quart_fp
def get_dead_detectors_mask(self, quadrant=3): """ Build masks for the FP where bad detectors are NAN and good detectors are 1., one of shape (34x34) and one of shape (17x17) for one quadrant. We use the ONAFP frame. Parameters ---------- quadrant : int Quadrant of the focal plane in [1, 2, 3, 4] By default is 3 for the TD Returns ------- full_mask : array of shape (34x34) mask for the full FP. quart_mask = array of shape (17x17) mask for one quadrant """ FPidentity = make_id_focalplane() quad = np.rot90(np.reshape(FPidentity.quadrant, (34, 34)), k=-1, axes=(0, 1)) calfile_path = Qubic_DataDir(datafile=self.d['detarray']) calfile = fits.open(calfile_path + '/' + self.d['detarray']) if self.d['detarray'] == 'CalQubic_DetArray_P87_TD.fits': full_mask = np.rot90(calfile['removed'].data, k=-1, axes=(0, 1)) full_mask = np.where(full_mask == 1, np.nan, full_mask) full_mask = np.where(full_mask == 0, 1, full_mask) quart = full_mask[np.where(quad != quadrant, 6, full_mask) != 6] quart_mask = np.reshape(quart, (17, 17)) return full_mask, quart_mask else: print('There is no dead detectors in this calfile')
def index2TESandASIC(index): """ Convert an index on the FP to the corresponding TES and ASICS. Parameters ---------- index : int index on the FP between 0 and 1155. Returns ------- TES: int between 1 and 128 if the given index corresponds to a TES, 0 if not. ASIC: int between 1 and 8 if the given index corresponds to a TES, 0 if not. """ if index < 0 or index > 1155: raise ValueError('index must be between 0 and 1155') else: FPidentity = make_id_focalplane() TES = FPidentity[index].TES ASIC = FPidentity[index].ASIC return TES, ASIC