def pipeline_dli(filename, output_file, keywords, verbose=False): import numpy as np import linear_operators as lo import tamasis as tm # verbosity tm.var.verbose = verbose # define observation obs = tm.PacsObservation(filename, **keywords["PacsObservation"]) # extra masking tm.step_scanline_masking(obs, **keywords["scanline_masking"]) # get data tod = obs.get_tod(**keywords["get_tod"]) # deglitching tm.step_deglitching(obs, tod, **keywords["deglitching"]) # median filtering tod = tm.filter_median(tod, **keywords["filter_median"]) # define projector projection = tm.Projection(obs, **keywords["Projection"]) # build instrument model response = tm.ResponseTruncatedExponential(obs.pack( obs.instrument.detector.time_constant) / obs.SAMPLING_PERIOD) compression = tm.CompressionAverage(obs.slice.compression_factor) masking = tm.Masking(tod.mask) model = masking * compression * response * projection # set tod masked values to zero tod = masking(tod) # N^-1 operator invntt = tm.InvNtt(obs) # for the dli algorithm M = map_mask(tod, model, **keywords["map_mask"]) # recast model as a new-style LinearOperator from linear_operators package H = lo.aslinearoperator(model) * M.T N = lo.aslinearoperator(invntt) # vectorize data so it is accepted by LinearOperators y = tod.ravel() Ds = [tm.DiscreteDifference(axis=i, shapein=projection.shapein) for i in (0, 1)] Ds = [lo.aslinearoperator(D) for D in Ds] Ds = [D * M.T for D in Ds] D = lo.concatenate(Ds) # handle tau which needs to be an ndarray keywords["dli"]["tau"] *= np.ones(D.shape[0]) algo = lo.DoubleLoopAlgorithm(H, y, D, noise_covariance=N, fmin_args=keywords["fmin_args"], lanczos=keywords["lanczos"], **keywords["dli"]) # optimize xe = algo() # reshape xe = (M.T * xe).reshape(projection.shapein) # recast as tamasis map xe = tm.Map(xe) # save xe.save(output_file)
def noise_covariance(tod, obs): """ Defines the noise covariance matrix """ length = 2 ** np.ceil(np.log2(np.array(tod.nsamples) + 200)) invNtt = tm.InvNtt(length, obs.get_filter_uncorrelated()) fft = tm.Fft(length) padding = tm.Padding(left=invNtt.ncorrelations, right=length - tod.nsamples - invNtt.ncorrelations) masking = tm.Masking(tod.mask) cov = masking * padding.T * fft.T * invNtt * fft * padding * masking return cov
def generate_noise_filter(obs1, P, band): # data if band == "red": shape0 = 512. if band == "green" or band == "blue": shape0 = 2048. nsamples = P.shape[0] / shape0 # 1/f noise model length = 2 ** np.ceil(np.log2(np.array(nsamples))) # square root in Fourier !!! filt = obs1.get_filter_uncorrelated() fft0 = lo.fft2(filt.shape, axes=(1,)) filt2 = np.real(fft0.T(np.sqrt(fft0(filt)))) invNtt = tm.InvNtt(length, filt2) fft = tm.FftHalfComplex(length) padding = tm.Padding(left=invNtt.ncorrelations, right=length - nsamples - invNtt.ncorrelations) cov = padding.T * fft.T * invNtt * fft * padding N12 = lo.aslinearoperator(cov) return N12
def pipeline_wrls(filenames, output_file, keywords, verbose=False): """ Perform regularized least-square inversion of state of the art PACS model. The PACS model includes tod mask, compression, response, projection and noise covariance (invntt). Processing steps are as follows : - define PacsObservation instance - mask first scanlines to avoid drift - get Time Ordered Data (get_tod) - 2nd level deglitching (with standard projector and tod median filtering with a narrow window) - median filtering - define projection - perform inversion on model - save file Arguments --------- filenames: list of strings List of data filenames. output_file : string Name of the output fits file. keywords: dict Dictionary containing options for all steps as dictionary. verbose: boolean (default False) Set verbosity. Returns ------- Returns nothing. Save result as a fits file. """ from scipy.sparse.linalg import cgs import tamasis as tm # verbosity keywords["mapper_rls"]["verbose"] = verbose # define observation obs = tm.PacsObservation(filenames, **keywords["PacsObservation"]) # extra masking tm.step_scanline_masking(obs, **keywords["scanline_masking"]) # get data tod = obs.get_tod(**keywords["get_tod"]) # deglitching tm.step_deglitching(obs, tod, **keywords["deglitching"]) # median filtering tod = tm.filter_median(tod, **keywords["filter_median"]) # define projector projection = tm.Projection(obs, **keywords["Projection"]) # build instrument model response = tm.ResponseTruncatedExponential( obs.pack(obs.instrument.detector.time_constant) / obs.SAMPLING_PERIOD) compression = tm.CompressionAverage(obs.slice.compression_factor) masking = tm.Masking(tod.mask) model = masking * compression * response * projection # set tod masked values to zero tod = masking(tod) # N^-1 operator invntt = tm.InvNtt(obs) # perform map-making inversion map_rls = tm.mapper_rls(tod, model, invntt=invntt, solver=cgs, **keywords["mapper_rls"]) # save map_rls.save(output_file)