Example #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
Example #2
0
def stsrt(data, cube, **kwargs):
    """
    Smooth Temporal Solar Rotational Tomography.
    Assumes data is sorted by observation time 'DATE_OBS'.

    Returns
    -------
    P : The projector with masking
    D : Smoothness priors
    obj_mask : object mask array
    data_mask : data mask array
    """
    # Parse kwargs.
    obj_rmin = kwargs.get('obj_rmin', None)
    obj_rmax = kwargs.get('obj_rmax', None)
    # mask data
    data_mask = solar.define_data_mask(data, **kwargs)
    # define temporal groups
    times = [solar.convert_time(h['DATE_OBS']) for h in data.header]
    ## if no interval is given separate every image
    dt_min = kwargs.get('dt_min', np.max(np.diff(times)) + 1)
    #groups = solar.temporal_groups(data, dt_min)
    ind = solar.temporal_groups_indexes(data, dt_min)
    n = len(ind)
    # define new 4D cube
    cube4 = cube[..., np.newaxis].repeat(n, axis=-1)
    cube4.header = copy.copy(cube.header)
    cube4.header['NAXIS'] = 4
    cube4.header['NAXIS4'] = cube4.shape[3]
    # define 4d model
    # XXX assumes all groups have same number of elements
    ng = data.shape[-1] / n
    P = siddon4d_lo(data.header, cube4.header, ng=ng, mask=data_mask, obstacle="sun")
    # priors
    D = smoothness_prior(cube4, kwargs.get("height_prior", False))
    # 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[..., np.newaxis].repeat(n, axis=-1)
        if kwargs.get("decimate", False) or kwargs.get("remove_nan", False):
            Mo = lo.decimate(obj_mask)
        else:
            Mo = lo.ndmask(obj_mask)
        P = P * Mo.T
        D = [Di * Mo.T for Di in D]
    else:
        obj_mask = None
    return P, D, obj_mask, data_mask