Esempio n. 1
0
def test3():
    comm_map = MPI.COMM_WORLD
    for obs, tod in ((obs1,tod1), (obs2,tod2)):
        masking = MaskOperator(tod.mask)
        proj = obs.get_projection_operator(downsampling=True,
                                           npixels_per_sample=6,
                                           header=header_ref_global,
                                           commin=comm_map)
        model = masking * proj
        m = mapper_rls(tod, model, tol=tol, maxiter=maxiter, solver=solver,
                       hyper=hyper)
        yield check_map_local, m
Esempio n. 2
0
def pipeline_rls(filenames, output_file, keywords, verbose=False):
    """
    Perform regularized least-square inversion of a simple model (tod
    mask and projection). Processing steps are as follows :
    
        - define PacsObservation instance
        - get Time Ordered Data (get_tod)
        - 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_keys = keywords.get("PacsObservation", {})
    obs = tm.PacsObservation(filenames, **obs_keys)
    # get data
    tod_keys = keywords.get("get_tod", {})
    tod = obs.get_tod(**tod_keys)
    # define projector
    proj_keys = keywords.get("Projection", {})
    projection = tm.Projection(obs, **proj_keys)
    # define mask
    masking_tod = tm.Masking(tod.mask)
    # define full model
    model = masking_tod * projection
    # perform map-making inversion
    mapper_keys = keywords.get("mapper_rls", {})
    map_rls = tm.mapper_rls(tod, model, solver=cgs, **mapper_keys)
    # save
    map_rls.save(output_file)
Esempio n. 3
0
def pipeline_rls(filenames, output_file, keywords, verbose=False):
    """
    Perform regularized least-square inversion of a simple model (tod
    mask and projection). Processing steps are as follows :
    
        - define PacsObservation instance
        - get Time Ordered Data (get_tod)
        - 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_keys = keywords.get("PacsObservation", {})
    obs = tm.PacsObservation(filenames, **obs_keys)
    # get data
    tod_keys = keywords.get("get_tod", {})
    tod = obs.get_tod(**tod_keys)
    # define projector
    proj_keys = keywords.get("Projection", {})
    projection = tm.Projection(obs, **proj_keys)
    # define mask
    masking_tod  = tm.Masking(tod.mask)
    # define full model
    model = masking_tod * projection
    # perform map-making inversion
    mapper_keys = keywords.get("mapper_rls", {})
    map_rls = tm.mapper_rls(tod, model, solver=cgs, **mapper_keys)
    # save
    map_rls.save(output_file)
Esempio n. 4
0
def test1():
    comm_map = MPI.COMM_SELF
    for obs, tod in ((obs1, tod1), (obs2, tod2)):
        masking = MaskOperator(tod.mask)
        proj = obs.get_projection_operator(downsampling=True,
                                           npixels_per_sample=6,
                                           header=header_ref_global,
                                           commin=comm_map)
        model = masking * proj
        m = mapper_rls(tod,
                       model,
                       tol=tol,
                       maxiter=maxiter,
                       solver=solver,
                       hyper=hyper)
        yield check_map_global, m
Esempio n. 5
0
obs.pointing.chop[:] = 0
tod = obs.get_tod(subtraction_mean=True)

projection  = obs.get_projection_operator(resolution=3.2, downsampling=True,
                                          npixels_per_sample=6)
masking_tod = MaskOperator(tod.mask)
model = masking_tod * projection

# iterative map, taking all map pixels
class Callback():
    def __init__(self):
        self.niterations = 0
    def __call__(self, x):
        self.niterations += 1

map_rls = mapper_rls(tod, model, hyper=1., tol=1.e-4, profile=profile,
                     callback=None if tamasis.var.verbose else Callback(),
                     solver=cgs)

if profile is None:
    print 'Elapsed time: ' + str(map_rls.header['TIME'])

def test():
    assert map_rls.header['NITER'] < 49
    ref = Map(data_dir + 'frames_blue_map_rls_cgs_tol1e-6.fits')
    ref.derived_units = map_rls.derived_units
    cov = ref.coverage > 80
    assert all_eq(ref[cov], map_rls[cov], 1.e-1)
    cov = ref.coverage > 125
    assert all_eq(ref[cov], map_rls[cov], 1.e-2)
Esempio n. 6
0
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)
Esempio n. 7
0
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 = 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)
    # perform map-making inversion
    map_rls = tm.mapper_rls(tod,
                            model,
                            invntt=invntt,
                            solver=cgs,
                            **keywords["mapper_rls"])
    # save
    map_rls.save(output_file)
Esempio n. 8
0
tamasis.var.verbose = True
profile = None#'test_rls.png'
data_dir = os.path.dirname(__file__) + '/data/'

# reference map (no communication)
header_ref_global = create_fitsheader((97,108), cdelt=3.2/3600,
                                      crval=(245.998427916727,61.5147650744551))
comm_tod = MPI.COMM_SELF
comm_map = MPI.COMM_SELF
obs_ref = PacsObservation(data_dir + 'frames_blue.fits', comm=comm_tod)
obs_ref.pointing.chop = 0
tod_ref = obs_ref.get_tod()
model_ref = MaskOperator(tod_ref.mask) * obs_ref.get_projection_operator(
            downsampling=True, npixels_per_sample=6, commin=comm_map,
            header=header_ref_global)
map_ref_global = mapper_rls(tod_ref, model_ref, tol=tol, maxiter=maxiter,
                            solver=solver, hyper=hyper)
header_ref_global = map_ref_global.header
cov_ref_global = map_ref_global.coverage
mask_ref_global = map_ref_global.coverage == 0
tolocal = MPIDistributionGlobalOperator(map_ref_global.shape,
                                        attrin={'header':header_ref_global})
map_ref_local = tolocal(map_ref_global)
cov_ref_local = tolocal(map_ref_global.coverage)
mask_ref_local = tolocal(mask_ref_global)

if rank == 0:
    map_ref_global.save('map_ref_global_v4.fits', comm=MPI.COMM_SELF)

def check_map_global(m):
    assert_all_eq(m.magnitude, map_ref_global.magnitude, mtol)
    assert_all_eq(m.coverage, cov_ref_global, mtol)
Esempio n. 9
0
# reference map (no communication)
header_ref_global = create_fitsheader(
    (97, 108), cdelt=3.2 / 3600, crval=(245.998427916727, 61.5147650744551))
comm_tod = MPI.COMM_SELF
comm_map = MPI.COMM_SELF
obs_ref = PacsObservation(data_dir + 'frames_blue.fits', comm=comm_tod)
obs_ref.pointing.chop = 0
tod_ref = obs_ref.get_tod()
model_ref = MaskOperator(tod_ref.mask) * obs_ref.get_projection_operator(
    downsampling=True,
    npixels_per_sample=6,
    commin=comm_map,
    header=header_ref_global)
map_ref_global = mapper_rls(tod_ref,
                            model_ref,
                            tol=tol,
                            maxiter=maxiter,
                            solver=solver,
                            hyper=hyper)
header_ref_global = map_ref_global.header
cov_ref_global = map_ref_global.coverage
mask_ref_global = map_ref_global.coverage == 0
tolocal = MPIDistributionGlobalOperator(map_ref_global.shape,
                                        attrin={'header': header_ref_global})
map_ref_local = tolocal(map_ref_global)
cov_ref_local = tolocal(map_ref_global.coverage)
mask_ref_local = tolocal(mask_ref_global)

if rank == 0:
    map_ref_global.save('map_ref_global_v4.fits', comm=MPI.COMM_SELF)

Esempio n. 10
0
model = masking_tod * projection


# iterative map, taking all map pixels
class Callback():
    def __init__(self):
        self.niterations = 0

    def __call__(self, x):
        self.niterations += 1


map_rls = mapper_rls(tod,
                     model,
                     hyper=1.,
                     tol=1.e-4,
                     profile=profile,
                     callback=None if tamasis.var.verbose else Callback(),
                     solver=cgs)

if profile is None:
    print 'Elapsed time: ' + str(map_rls.header['TIME'])


def test():
    assert map_rls.header['NITER'] < 49
    ref = Map(data_dir + 'frames_blue_map_rls_cgs_tol1e-6.fits')
    ref.derived_units = map_rls.derived_units
    cov = ref.coverage > 80
    assert all_eq(ref[cov], map_rls[cov], 1.e-1)
    cov = ref.coverage > 125