def create_acquisition_operator_REC(pointing, d, nf_sub_rec, verbose=False, instrument=None): # scene s = qubic.QubicScene(d) if d['nf_sub'] == 1: if verbose: print('Making a QubicInstrument.') q = qubic.QubicInstrument(d) # one subfreq for recons _, nus_edge, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, nf_sub_rec, d['filter_relative_bandwidth']) arec = qubic.QubicAcquisition(q, pointing, s, d) return arec else: if instrument is None: if verbose: print('Making a QubicMultibandInstrument.') q = qubic.QubicMultibandInstrument(d) else: q = instrument # number of sub frequencies for reconstruction _, nus_edge, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, nf_sub_rec, d['filter_relative_bandwidth']) # Operator for Maps Reconstruction arec = qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge) return arec
def create_acquisition_operator_REC(pointing, d, nf_sub_rec): # Polychromatic instrument model q = qubic.QubicMultibandInstrument(d) # scene s = qubic.QubicScene(d) # number of sub frequencies for reconstruction _, nus_edge, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, nf_sub_rec, d['filter_relative_bandwidth']) # Operator for Maps Reconstruction arec = qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge) return arec
def create_acquisition_operator_TOD(pointing, d): # Polychromatic instrument model q = qubic.QubicMultibandInstrument(d) # scene s = qubic.QubicScene(d) # number of sub frequencies to build the TOD _, nus_edge_in, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, d['filter_relative_bandwidth'], d['nf_sub']) # Multiband instrument model # Multi-band acquisition model for TOD fabrication atod = qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge_in) return atod
def get_tod(d, p, x0): # Polychromatic instrument model q = qubic.QubicMultibandInstrument(d) # Scene s = qubic.QubicScene(d) # Number of sub frequencies to build the TOD _, nus_edge_in, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, d['filter_relative_bandwidth'], d['nf_sub']) # Multi-band acquisition operator a = qubic.QubicMultibandAcquisition(q, p, s, d, nus_edge_in) tod, _ = a.get_observation(x0, noiseless=True) return q, tod
def make_covTD(d): """ Usually coverage map is provided in a separate file. But if not the case, this method can compute a coverage map Parameters: d: Qubic dictionary Return: cov: coverage map in a.QubicMultibandAcquisition shape (nfreq, npix). """ pointing = qubic.get_pointing(d) q= qubic.QubicMultibandInstrument(d) s= qubic.QubicScene(d) nf_sub_rec = d['nf_recon'] _, nus_edge, nus, _, _, _ = qubic.compute_freq(d['filter_nu'] / 1e9, nf_sub_rec, d['filter_relative_bandwidth']) arec = qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge) cov = arec.get_coverage() return cov
def create_acquisition_operator_TOD(pointing, d, verbose=False): # scene s = qubic.QubicScene(d) if d['nf_sub'] == 1: if verbose: print('Making a QubicInstrument.') q = qubic.QubicInstrument(d) return qubic.QubicAcquisition(q, pointing, s, d) else: # Polychromatic instrument model if verbose: print('Making a QubicMultibandInstrument.') q = qubic.QubicMultibandInstrument(d) # number of sub frequencies to build the TOD _, nus_edge_in, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, d['nf_sub'], # Multiband instrument model d['filter_relative_bandwidth']) # Multi-band acquisition model for TOD fabrication return qubic.QubicMultibandAcquisition(q, pointing, s, d, nus_edge_in)
def get_tod(d, p, x0, closed_horns=None): """ Parameters ---------- d : dictionnary p : pointing x0 : sky closed_horns : array index of closed horns Returns ------- Returns an instrument with closed horns and TOD """ # Polychromatic instrument model q = qubic.QubicMultibandInstrument(d) # q = qubic.QubicInstrument(d) if closed_horns is not None: for i in range(d['nf_sub']): for h in closed_horns: q[i].horn.open[h] = False # Scene s = qubic.QubicScene(d) # Number of sub frequencies to build the TOD _, nus_edge_in, _, _, _, _ = qubic.compute_freq( d['filter_nu'] / 1e9, d['nf_sub'], d['filter_relative_bandwidth']) # Multi-band acquisition operator a = qubic.QubicMultibandAcquisition(q, p, s, d, nus_edge_in) # a = qubic.QubicPolyAcquisition(q, p, s, d) tod = a.get_observation(x0, convolution=False, noiseless=True) return q, tod
name = 'test_scan_source' resultDir = '%s' % name os.makedirs(resultDir, exist_ok=True) alaImager = False # if True, the beam will be a simple gaussian component = 0 # Choose the component number to plot (IQU) oneComponent = False # True if you want to study only I component, otherwise False if you study IQU sel_det = True # True if you want to use one detector, False if you want to use all detectors in focal plane dets_FPindex = [594] # if sel_det == True, choose detector number # Dictionnary d = qubic.qubicdict.qubicDict() d.read_from_file('global_source_oneDet.dict') # Scene s = qubic.QubicScene(d) # Instrument q = qubic.QubicMultibandInstrument(d) if sel_det: make_detector_subset_instrument(q, dets_FPindex, multiband=True) # Pointing p = qubic.get_pointing(d) fix_azimuth = d['fix_azimuth'] print('fix_azimuth', fix_azimuth) plt.figure(figsize=(12, 8)) plt.subplot(411)
def do_some_dets(detnums, d, p, directory, fittedpeakfile, az, el, proj_name, custom=False, q=None, nside=None, tol=5e-3, refit=False, resample=False, newsize=70, doplot=True, verbose=True, sbfitmodel=None, angs=None, usepeaks=None, azmin=None, azmax=None, remove=None, fitted_directory=None, weighted=False, nf_sub_rec=1, lowcut=1e-3, highcut=0.3): if nside is not None: d['nside'] = nside s = qubic.QubicScene(d) if q == None: q = qubic.QubicMultibandInstrument(d) if len(q) == 1: xgrf, ygrf, FP_index, index_q = sc.get_TES_Instru_coords(q, frame='GRF', verbose=False) else: xgrf, ygrf, FP_index, index_q = sc.get_TES_Instru_coords(q[0], frame='GRF', verbose=False) # Create TES, index and ASIC numbers assuming detnums is continuos TES number (1-248). tes, asic = np.zeros((len(detnums), ), dtype=int), np.zeros( (len(detnums), ), dtype=int) qpix = np.zeros((len(detnums), ), dtype=int) for j, npix in enumerate(detnums): tes[j], asic[j] = (npix, 1) if (npix < 128) else (npix - 128, 2) qpix[j] = tes2pix(tes[j], asic[j]) - 1 if verbose: print("DETNUM{} TES{} ASIC{} QPIX{}".format( npix, tes[j], asic[j], qpix[j])) #Center of FOV azcen_fov = np.mean(az) elcen_fov = np.mean(el) #Directory where the maps are: mapsdir = directory #File where the fitted peaks are: peaksdir = fittedpeakfile if not custom: if verbose: print('') print('Normal Reconstruction') qcut = select_det(qubic.QubicMultibandInstrument(d), detnums) #qcut = select_det(qubic.QubicMultibandInstrument(d),[145]) else: if verbose: print('') print('Custom Reconstruction') ### Refit or not the locations of the peaks ### from the synthesized beam images ### First instantiate a jchinstrument (modified from instrument ### to be able to read peaks from a file) print("Generating jchinstrument") qcut = select_det( jcinst.QubicMultibandInstrument(d, peakfile=fittedpeakfile, tes=tes, asic=asic), qpix) print("LEN(qcut) and detector", len(qcut), np.shape(qcut[0].detector.center)) print("Generating jchinstrument"[::-1]) ### In the present case, we use the peak measurements at 150 GHz ### So we assume its index is len(qcut)//2 id150 = len(qcut) // 2 nu = qcut[id150].filter.nu synthbeam = qcut[id150].synthbeam horn = getattr(qcut[id150], 'horn', None) primary_beam = getattr(qcut[id150], 'primary_beam', None) # Cosine projection with elevation center of the FOV considering symetric scan in azimuth for each elevation step thecos = np.cos(np.radians(elcen_fov)) #Read map (flat or healpy) for each detector print("TES ASIC", tes, asic) filemaps = readmaps(directory, tes, asic, az, el, p, proj_name=proj_name, nside=d['nside'], verbose=verbose) # Compute measured coordenates allphis_M, allthetas_M, allvals_M = get_data_Mrefsyst( detnums, filemaps, az, el, fitted_directory, fittedpeakfile, proj_name, resample=resample, newsize=newsize, azmin=azmin, azmax=azmax, remove=remove, sbfitmodel=sbfitmodel, refit=refit, verbose=verbose) if doplot: _plot_onemap(filemaps, az, el, [allphis_M, allthetas_M], proj_name, makerotation=False) ### Now we want to perform the rotation to go to boresight ### reference frame (used internally by QubicSoft) if verbose: print("Solid angles synthbeam = {:.3e}, QubicScene {:.3e}".format( synthbeam.peak150.solid_angle, s.solid_angle)) allphis_Q, allthetas_Q, allvals_Q, numpeak = convert_M2Q( detnums, allphis_M, allthetas_M, allvals_M, elcen_fov, solid_angle=synthbeam.peak150.solid_angle, nu=nu, horn=horn, solid_angle_s=s.solid_angle, angs=angs, verbose=verbose) print("allphis_Q , allvals_Q shapes", np.shape(allphis_Q), np.shape(allvals_Q)) if doplot: plt.title("xy coord. of peaks in M and Q ref system") plt.plot(np.cos(allphis_M[0]) * np.sin(allthetas_M[0]), np.sin(allphis_M[0]) * np.sin(allthetas_M[0]), 'r+', ms=10, label="M ref syst") plt.plot(np.cos(allphis_Q[0]) * np.sin(allthetas_Q[0]), np.sin(allphis_Q[0]) * np.sin(allthetas_Q[0]), 'b+', ms=10, label="Q ref syst") plt.legend() plt.show() if doplot: # Plot peaks in measured reference frame. _plot_grfRF(detnums, xgrf, ygrf, qcut, numpeak) for idet in range(len(detnums)): position = np.ravel(qcut[0].detector[idet].center) position = -position / np.sqrt(np.sum(position**2)) theta_center = np.arcsin(np.sqrt(position[0]**2 + position[1]**2)) phi_center = np.arctan2(position[1], position[0]) rav_thQ = np.ravel(allthetas_Q[idet, :]) rav_phQ = np.ravel(allphis_Q[idet, :]) ## Now we identify the nearest peak to the theoretical Line Of Sight angdist = np.zeros(len(rav_phQ)) for k in range(len(rav_phQ)): angdist[k] = sbfit.ang_dist([theta_center, phi_center], [rav_thQ[k], rav_phQ[k]]) print(k, np.degrees(angdist[k])) idxmin = np.argmin(angdist) numpeak[idet] = idxmin ### We nowwrite the temporary file that contains the peaks locations to be used if usepeaks is None: peaknums = np.arange(9) else: peaknums = usepeaks data = [ allthetas_Q[:, peaknums], allphis_Q[:, peaknums] - np.pi, allvals_Q[:, peaknums], numpeak ] file = open(os.environ['QUBIC_PEAKS'] + 'peaks.pk', 'wb') pickle.dump(data, file) file.close() ### Make the TODs from the measured synthesized beams realTOD = np.zeros((len(detnums), len(p))) sigmaTOD = np.zeros(len(detnums)) if weighted: sumweight = 0. allimg = [] for i in range(len(detnums)): if proj_name == "flat": filename = directory + 'flat_ASIC{}TES{}.fits'.format( asic[i], tes[i]) img = FitsArray(filename) elif proj_name == "healpix": filename = directory + '../../Flat/synth_beam/flat_ASIC{}TES{}.fits'.format( asic[i], tes[i]) img = FitsArray(filename) allimg.append(img) fact = 1 #5e-28 realTOD[i, :] = np.ravel(img) * fact if weighted: ## Not to be used - old test... realTOD[i, :] *= 1. / ss**2 sumweight += 1. / ss**2 print("All img", np.shape(allimg)) ### new code multiband plt.figure() for i in range(len(detnums)): plt.plot(realTOD[i, :], label='TES#{0:}'.format(detnums[i])) plt.legend() plt.xlabel('Samples') plt.ylabel('TOD') plt.show() plt.figure() for i in range(len(detnums)): spectrum_f, freq_f = ft.power_spectrum(np.arange(len(realTOD[i, :])), realTOD[i, :]) pl = plt.plot(freq_f, spectrum_f, label='TES#{0:}'.format(detnums[i]), alpha=0.5) plt.xscale('log') plt.yscale('log') plt.legend() plt.xlabel('Fourier mode') plt.ylabel('Power Spectrum') plt.title('Before Filtering') plt.show() for i in range(len(detnums)): realTOD[i, :] = ft.filter_data(np.arange(len(realTOD[i, :])), realTOD[i, :], lowcut, highcut) mm, ss = ft.meancut(realTOD[i, :], 3) sigmaTOD[i] = ss if doplot: for i in range(len(detnums)): plt.figure() plt.subplot(1, 2, 1) plt.imshow(allimg[i] * fact, vmin=mm - 3 * ss, vmax=mm + 3 * ss, extent=[ np.max(az) * thecos, np.min(az) * thecos, np.min(el), np.max(el) ], aspect='equal') plt.colorbar() plt.title('Init - TOD {0:} RMS={1:5.2g}'.format( detnums[i], sigmaTOD[i])) plt.subplot(1, 2, 2) plt.imshow(np.reshape(realTOD[i, :], np.shape(img)), vmin=mm - 3 * ss, vmax=mm + 3 * ss, extent=[ np.max(az) * thecos, np.min(az) * thecos, np.min(el), np.max(el) ], aspect='equal') plt.colorbar() plt.title('Filtered - TOD {0:} RMS={1:5.2g}'.format( detnums[i], sigmaTOD[i])) plt.figure() for i in range(len(detnums)): spectrum_f, freq_f = ft.power_spectrum(np.arange(len(realTOD[i, :])), realTOD[i, :]) pl = plt.plot(freq_f, spectrum_f, label='TES#{0:} Var*2pi={1:5.2g}'.format( detnums[i], sigmaTOD[i]**2 * 2 * np.pi), alpha=0.5) plt.plot(freq_f, freq_f * 0 + sigmaTOD[i]**2 * 2 * np.pi, color=pl[0].get_color()) plt.xscale('log') plt.yscale('log') plt.ylim(np.min(sigmaTOD**2 * 2 * np.pi), np.max(sigmaTOD**2 * 2 * np.pi) * 1e9) plt.legend() plt.xlabel('Fourier mode') plt.ylabel('Power Spectrum') plt.title('After Filtering') if lowcut: plt.axvline(x=lowcut, color='k') if highcut: plt.axvline(x=highcut, color='k') plt.show() plt.figure() plt.clf() print('%%%%%%%%%%%%%%%%%%%%%%') ax = plt.subplot(111, projection='polar') print("len qcut", len(qcut[0].detector.center)) print("=?===============================") print(np.shape(realTOD), np.shape(p), nf_sub_rec, np.shape(qcut)) print("=?===============================") maps_recon, cov, nus, nus_edge = si.reconstruct_maps( realTOD, d, p, nf_sub_rec, x0=None, instrument=qcut, #verbose=True, forced_tes_sigma=sigmaTOD) ax.set_rmax(0.5) #legend(fontsize=8) if weighted: maps_recon /= sumweight / len(detnums) return maps_recon, qcut, np.mean(cov, axis=0), nus, nus_edge