Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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 = obs.get_projection_operator(**keywords["Projection"])
    # build instrument model
    response = tm.ResponseTruncatedExponentialOperator(
        obs.pack(obs.instrument.detector.time_constant) /
        obs.instrument.SAMPLING_PERIOD)
    compression = tm.CompressionAverageOperator(obs.slice.compression_factor)
    masking = tm.MaskOperator(tod.mask)
    model = masking * compression * response * projection
    # set tod masked values to zero
    tod = masking(tod)
    # N^-1 operator
    invntt = tm.InvNttOperator(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.DiscreteDifferenceOperator(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)
Ejemplo n.º 3
0
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 = obs.get_projection_operator(**keywords["Projection"])
    # build instrument model
    response = tm.ResponseTruncatedExponentialOperator(obs.pack(
                   obs.instrument.detector.time_constant) / 
                   obs.instrument.SAMPLING_PERIOD)
    compression = tm.CompressionAverageOperator(obs.slice.compression_factor)
    masking = tm.MaskOperator(tod.mask)
    model = masking * compression * response * projection
    # set tod masked values to zero
    tod = masking(tod)
    # N^-1 operator
    invntt = tm.InvNttOperator(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.DiscreteDifferenceOperator(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)
Ejemplo n.º 4
0
#!/usr/bin/env python
import numpy as np
import scipy
import linear_operators as lo

# Load the infamous Lena image from scipy
im = scipy.lena()
im = im[::4, ::4]
# Generate a convolution model with a 7x7 uniform kernel
model = lo.convolve_fftw3(im.shape, np.ones((7, 7)))
# convolve the original image
data = model * im.ravel()
# add noise to the convolved data
data += 1e0 * np.random.randn(*data.shape)
# define smoothness prior
#prior = lo.concatenate([lo.diff(im.shape, axis=i) for i in xrange(im.ndim)])
prior = lo.concatenate([lo.diff(im.shape, axis=i) for i in xrange(im.ndim)]
                       + [lo.wavelet2(im.shape, "haar"),])
# generate algorithm
algo = lo.DoubleLoopAlgorithm(model, data, prior)
# start the estimation algorithm
xe = algo()
# reshape the output as the algorithm only handles vectors
xe.resize(im.shape)