def generate_model(ra0, dec0, pointing_params, repeats=1, cross_scan=False, span_angles=False, band="red", map_header=None, npixels_per_sample=0): """ Generate a PACS projector. """ pointing1 = tm.pacs_create_scan(ra0, dec0, **pointing_params) # create obs object obs1 = tm.PacsSimulation(pointing1, band) if map_header is None: map_header = obs1.get_map_header() # create projector projection1 = tm.Projection(obs1, header=map_header, npixels_per_sample=npixels_per_sample) P = lo.aslinearoperator(projection1) # cross scan if cross_scan: pointing_params["scan_angle"] += 90. pointing2 = tm.pacs_create_scan(ra0, dec0, **pointing_params) obs2 = tm.PacsSimulation(pointing2, band) projection2 = tm.Projection(obs2, header=map_header, npixels_per_sample=npixels_per_sample) P2 = lo.aslinearoperator(projection2) P = lo.concatenate((P, P2)) # repeats if repeats > 1: P = lo.concatenate((P, ) * repeats) if span_angles: if cross_scan: raise ValueError("Span_angles and cross_scan are incompatible.") # equally spaced but exclude 0 and 90 angles = np.linspace(0, 90, repeats + 2)[1:-1] for a in angles: pointing_params["scan_angle"] = a pointing2 = tm.pacs_create_scan(ra0, dec0, **pointing_params) obs2 = tm.PacsSimulation(pointing2, band) projection2 = tm.Projection(obs2, header=map_header, npixels_per_sample=npixels_per_sample) P2 = lo.aslinearoperator(projection2) P = lo.concatenate((P, P2)) # noise N = generate_noise_filter(obs1, P, band) # covered area map_shape = map_header['NAXIS2'], map_header['NAXIS1'] coverage = (P.T * np.ones(P.shape[0])).reshape(map_shape) seen = coverage != 0 M = lo.decimate(coverage < 10) # global model H = N * P * M.T return H
import tamasis as tm import csh # my PACS inversion routines import fitsarray as fa import lo # scan parameters ra0, dec0 = 30., 30. pointing_params = { 'cam_angle': 0., "scan_angle": 0., "scan_nlegs": 1, "scan_length": 400., "scan_speed": 60.0, "compression_factor": 1 # we will compress later } pointing = tm.pacs_create_scan(ra0, dec0, **pointing_params) # create obs object obs = tm.PacsSimulation(pointing, "red", policy_bad_detector="keep") # we dont need 200 first and last frames obs.pointing.removed[200:] = True obs.pointing.removed[-201:] = True # create projector projection = tm.Projection(obs, npixels_per_sample=4) P = lo.aslinearoperator(projection) # simulate data x0 = tm.gaussian(projection.shapein, 3) # map with gaussian source tod0 = projection(x0) # data n = np.random.randn(*tod0.shape) # noise nsr = 1e-2 tod = tod0 + nsr * n # noisy data y = tod.ravel() # as 1d array
# python setup.py install # define projection matrix # ------------------------ # center of the map ra0, dec0 = 30., 30. # let us define a small scan with 1 leg for testing purposes : pointing_params = { 'cam_angle':0., "scan_angle":0., "scan_nlegs":1, "scan_length":4., "compression_factor":1, "scan_speed":60.0 } pointing = tm.pacs_create_scan(ra0, dec0, **pointing_params) # create obs object obs = tm.PacsSimulation(pointing, "red", policy_bad_detector="keep") # to define my compression matrix I need only 8 frames # so I mask the others : obs.pointing.removed[:] = True obs.pointing.removed[201:209] = False # create projector projection = tm.Projection(obs) P = lo.aslinearoperator(projection) # define masking of coefficients # ------------------------------ # number of coefficients to keep factor = 8. nk = P.shape[0] / factor