Esempio n. 1
0
def stsrt(data, cube, **kwargs):
    """
    Smooth Temporal Solar Rotational Tomography.
    Assumes data is sorted by observation time 'DATE_OBS'.
    """
    # Parse kwargs.
    obj_rmin = kwargs.get('obj_rmin', None)
    obj_rmax = kwargs.get('obj_rmax', None)
    data_rmin = kwargs.get('data_rmin', None)
    data_rmax = kwargs.get('data_rmax', None)
    mask_negative = kwargs.get('mask_negative', False)
    # define temporal groups
    times = [secchi.convert_time(t) for t in data.header['DATE_OBS']]
    ## if no interval is given separate every image
    dt_min = kwargs.get('dt_min', np.max(np.diff(times)) + 1)
    #groups = secchi.temporal_groups(data, dt_min)
    ind = secchi.temporal_groups_indexes(data, dt_min)
    n = len(ind)
    # 4d model
    cube_header = cube.header.copy()
    cube_header.update('NAXIS', 4)
    cube_header.update('NAXIS4', data.shape[-1])
    P = siddon4d_lo(data.header, cube_header, obstacle="sun")
    # define per group summation of maps
    # define new 4D cube
    cube4 = cube.reshape(cube.shape + (1,)).repeat(n, axis=-1)
    cube4.header.update('NAXIS', 4)
    cube4.header.update('NAXIS4', cube4.shape[3])
    cube4.header.update('CRVAL4', 0.)
    cube4.header.update('CDELT4', dt_min)
    S = group_sum(ind, cube, data)
    P = P * S.T
    # priors
    D = [lo.diff(cube4.shape, axis=i) for i in xrange(cube.ndim)]
    # mask object
    if obj_rmin is not None or obj_rmax is not None:
        Mo, obj_mask = mask_object(cube, kwargs)
        obj_mask = obj_mask.reshape(obj_mask.shape + (1,)).repeat(n, axis=-1)
        Mo = lo.mask(obj_mask)
        P = P * Mo.T
        D = [Di * Mo.T for Di in D]
    else:
        obj_mask = None
    # mask data
    if (data_rmin is not None or
        data_rmax is not None or
        mask_negative is not None):
        data_mask = secchi.define_data_mask(data,
                                            Rmin=data_rmin,
                                            Rmax=data_rmax,
                                            mask_negative=True)
        Md = lo.mask(data_mask)
        P = Md * P
    else:
        data_mask = None
    return P, D, obj_mask, data_mask, cube4
Esempio n. 2
0
def mask_object(cube, kwargs):
    obj_rmin = kwargs.get('obj_rmin', None)
    obj_rmax = kwargs.get('obj_rmax', None)
    if obj_rmin is not None or obj_rmax is not None:
        obj_mask = secchi.define_map_mask(cube,
                                          Rmin=obj_rmin,
                                          Rmax=obj_rmax)
        Mo = lo.mask(obj_mask)
    return Mo, obj_mask
Esempio n. 3
0
def srt(data, cube, **kwargs):
    """
    Define Solar Rotational Tomography model with optional masking of
    data and map areas. Can also define priors.
    
    Parameters
    ----------
    data: InfoArray
        data cube
    cube: FitsArray
        map cube
    obj_rmin: float
        Object minimal radius. Areas below obj_rmin are masked out.
    obj_rmax: float
        Object maximal radius. Areas above obj_rmax are masked out.
    data_rmin: float
        Data minimal radius. Areas below data_rmin are masked out.
    data_rmax: float
        Data maximal radius. Areas above data_rmax are masked out.
    mask_negative: boolean
        If true, negative values in the data are masked out.

    Returns
    -------
    P : The projector with masking
    D : Smoothness priors

    """
    # Parse kwargs.
    obj_rmin = kwargs.get('obj_rmin', None)
    obj_rmax = kwargs.get('obj_rmax', None)
    data_rmin = kwargs.get('data_rmin', None)
    data_rmax = kwargs.get('data_rmax', None)
    mask_negative = kwargs.get('mask_negative', None)
    # Model : it is Solar rotational tomography, so obstacle="sun".
    P = siddon_lo(data.header, cube.header, obstacle="sun")
    D = [lo.diff(cube.shape, axis=i) for i in xrange(cube.ndim)]
    # Define masking.
    if obj_rmin is not None or obj_rmax is not None:
        Mo, obj_mask = mask_object(cube, kwargs)
        P = P * Mo.T
        D = [Di * Mo.T for Di in D]
    else:
        obj_mask = None
    if (data_rmin is not None or
        data_rmax is not None or
        mask_negative is not None):
        data_mask = secchi.define_data_mask(data,
                                            Rmin=data_rmin,
                                            Rmax=data_rmax,
                                            mask_negative=True)
        Md = lo.mask(data_mask)
        P = Md * P
    else:
        data_mask = None
    return P, D, obj_mask, data_mask
Esempio n. 4
0
import lo.pywt_lo as pywt_lo

# data
pacs = PacsObservation(filename=tamasis_dir + 'tests/frames_blue.fits',
                       fine_sampling_factor=1,
                       keep_bad_detectors=False)
tod = pacs.get_tod()
# projector
projection = Projection(pacs,
                        resolution=3.2,
                        oversampling=False,
                        npixels_per_sample=6)
model = projection
# naive map
backmap = model.transpose(tod)
# mask
M = lo.mask(backmap < 0).T
#M = lo.identity(2 * (backmap.size,))
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator()) * M
# prior
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * M
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * M
Dw = pywt_lo.wavelet2(backmap.shape, "haar") * M
# inversion
y = tod.flatten()
callback = lo.CallbackFactory(verbose=True)
x = it.rirls(P, (Dx, Dy, Dw), y, p=1.5, maxiter=100, callback=callback)
sol = backmap.zeros(backmap.shape)
sol[:] = (M * x).reshape(sol.shape)
Esempio n. 5
0
import numpy as np
import lo
import lo.iterative as it
import lo.pywt_lo as pywt_lo

# data
pacs = PacsObservation(filename=tamasis_dir+'tests/frames_blue.fits',
                       fine_sampling_factor=1, 
                       keep_bad_detectors=False)
tod = pacs.get_tod()
# projector
projection = Projection(pacs, resolution=3.2, oversampling=False, npixels_per_sample=6)
model = projection
# naive map
backmap = model.transpose(tod)
# mask
M = lo.mask(backmap < 0).T
#M = lo.identity(2 * (backmap.size,))
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator()) * M
# prior
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * M
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * M
Dw = pywt_lo.wavelet2(backmap.shape, "haar") * M
# inversion
y = tod.flatten()
callback = lo.CallbackFactory(verbose=True)
x = it.rirls(P, (Dx ,Dy, Dw), y, p=1.5, maxiter=100, callback=callback)
sol = backmap.zeros(backmap.shape)
sol[:] = (M * x).reshape(sol.shape)
Esempio n. 6
0
# ctod = compression.direct(uctod)
# model
masking = tm.Masking(uctod.mask)
model = masking * projection
# remove drift
# ctod = tm.filter_median(ctod, length=3000 / 8.)
# first map
M = C * lo.aslinearoperator(model.aslinearoperator())
# P = lo.aslinearoperator(projection.aslinearoperator())
# C = csh.averaging(tod.shape, factor=8)
# I = lo.mask(uctod.mask)
# M = C * I.T * I * P
# M = C * P
backmap = (M.T * ctod.flatten()).reshape(projection.shapein)
# weights = (M.T * np.ones(ctod.size)).reshape(projection.shapein)
weights = projection.transpose(tod.ones(tod.shape))
MM = lo.mask(weights == 0)
M = M * MM.T
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * MM.T
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * MM.T
# Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(M, (Dx, Dy), (1e0, 1e0), ctod.flatten())
sol = tm.Map(np.zeros(backmap.shape))
sol[:] = (MM.T * x).reshape(sol.shape)
sol.header = header
# save
sol.writefits(os.path.join(os.getenv("HOME"), "data", "csh", "output", "ngc6946_cs_rls.fits"))
Esempio n. 7
0
projection = tm.Projection(pacs, resolution=3., npixels_per_sample=6)
tm.deglitch_l2mad(tod, projection)
# model
masking = tm.Masking(tod.mask)
model = masking * projection
# remove drift
tod = tm.filter_median(tod, length=999)

model = masking * projection
# naive map
backmap = model.transpose(tod)
# coverage map
weights = model.transpose(tod.ones(tod.shape))
# mask on map
mask = weights == 0
M = lo.mask(mask)
# preconditionner
iweights = 1 / weights
iweights[np.where(np.isfinite(iweights) == 0)] = 0.
M0 = lo.diag(iweights.flatten())
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator())
# priors
Dx = lo.diff(backmap.shape, axis=0)
Dy = lo.diff(backmap.shape, axis=1)
# inversion
y = (masking.T * tod).flatten()
# algos
algos = [spl.cg, spl.cgs, spl.bicg, spl.bicgstab]
models = [P.T * P, P.T * P + Dx.T * Dx + Dy.T * Dy,]
n_iterations = []
Esempio n. 8
0
                       keep_bad_detectors=False)
tod = pacs.get_tod()
# compression model
C = lo.binning(tod.shape, factor=8, axis=1, dtype=np.float64)
# compress data
ctod = C * tod.flatten()
# projector
projection = Projection(pacs, resolution=3.2, oversampling=False, npixels_per_sample=6)
model = projection
# naive map
backmap = model.transpose(tod)
# coverage map
weights = model.transpose(tod.ones(tod.shape))
# mask on map
mask = weights == 0
M = lo.mask(mask)
# transform to lo
#P = lo.ndsubclass(backmap, tod, matvec=model.direct, rmatvec=model.transpose)
P = lo.aslinearoperator(model.aslinearoperator())
# full model
A = C * P * M.T
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * M.T
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * M.T
Dw = lo.pywt_lo.wavelet2(backmap.shape, "haar") * M.T
# inversion
y = ctod.flatten()
x, conv = lo.rls(A, (Dx, Dy, Dw), (1e1, 1e1, 1e1),  y)
sol = backmap.zeros(backmap.shape)
sol[mask == 0] = x
Esempio n. 9
0
                        header=header,
                        resolution=resolution,
                        npixels_per_sample=5)
deglitch_l2mad(tod, projection)
# model
masking = Masking(tod.mask)
model = masking * projection
# remove drift
#tod = filter_median(tod, length=3000)
# first map
backmap = model.transpose(tod)
# coverage
weights = model.transpose(tod.ones(tod.shape))
P = lo.aslinearoperator(model.aslinearoperator())
# mask not seen part of the map
MM = lo.mask(weights == 0)
y = tod.flatten()
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64)
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64)
#Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(P * MM.T, (Dx * MM.T, Dy * MM.T), (1e1, 1e1), y)
sol = backmap.zeros(backmap.shape)
sol[:] = (MM.T * x).reshape(sol.shape)
# save
sol.header = header
sol.writefits(
    os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                 'ngc6946_rls.fits'))